mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-18 00:54:23 -04:00
boot: move updater to sts::updater namespace
This commit is contained in:
parent
c87be7cd69
commit
4fbae9e5a4
12 changed files with 1098 additions and 997 deletions
|
@ -20,10 +20,10 @@
|
||||||
static u8 __attribute__((__aligned__(0x1000))) g_boot_image_work_buffer[0x10000];
|
static u8 __attribute__((__aligned__(0x1000))) g_boot_image_work_buffer[0x10000];
|
||||||
|
|
||||||
void Boot::CheckAndRepairBootImages() {
|
void Boot::CheckAndRepairBootImages() {
|
||||||
const BootImageUpdateType boot_image_update_type = Updater::GetBootImageUpdateType(Boot::GetHardwareType());
|
const auto boot_image_update_type = sts::updater::GetBootImageUpdateType(Boot::GetHardwareType());
|
||||||
|
|
||||||
bool repaired_normal, repaired_safe;
|
bool repaired_normal, repaired_safe;
|
||||||
if (R_SUCCEEDED(Updater::VerifyBootImagesAndRepairIfNeeded(&repaired_normal, &repaired_safe, g_boot_image_work_buffer, sizeof(g_boot_image_work_buffer), boot_image_update_type)) && repaired_normal) {
|
if (R_SUCCEEDED(sts::updater::VerifyBootImagesAndRepairIfNeeded(&repaired_normal, &repaired_safe, g_boot_image_work_buffer, sizeof(g_boot_image_work_buffer), boot_image_update_type)) && repaired_normal) {
|
||||||
/* Nintendo only performs a reboot on successful normal repair. */
|
/* Nintendo only performs a reboot on successful normal repair. */
|
||||||
Boot::RebootSystem();
|
Boot::RebootSystem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,41 @@
|
||||||
|
|
||||||
#include "updater_api.hpp"
|
#include "updater_api.hpp"
|
||||||
#include "updater_bis_save.hpp"
|
#include "updater_bis_save.hpp"
|
||||||
|
#include "updater_files.hpp"
|
||||||
|
#include "updater_paths.hpp"
|
||||||
|
|
||||||
Result Updater::ValidateWorkBuffer(const void *work_buffer, size_t work_buffer_size) {
|
namespace sts::updater {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
/* Validation Prototypes. */
|
||||||
|
Result ValidateWorkBuffer(const void *work_buffer, size_t work_buffer_size);
|
||||||
|
|
||||||
|
/* Configuration Prototypes. */
|
||||||
|
bool HasEks(BootImageUpdateType boot_image_update_type);
|
||||||
|
bool HasAutoRcmPreserve(BootImageUpdateType boot_image_update_type);
|
||||||
|
u32 GetNcmTitleType(BootModeType mode);
|
||||||
|
Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size);
|
||||||
|
|
||||||
|
/* Verification Prototypes. */
|
||||||
|
Result GetVerificationState(VerificationState *out, void *work_buffer, size_t work_buffer_size);
|
||||||
|
Result VerifyBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
Result VerifyBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
Result VerifyBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
|
||||||
|
/* Update Prototypes. */
|
||||||
|
Result SetVerificationNeeded(BootModeType mode, bool needed, void *work_buffer, size_t work_buffer_size);
|
||||||
|
Result UpdateBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
Result UpdateBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
Result UpdateBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
|
||||||
|
/* Package helpers. */
|
||||||
|
Result ValidateBctFileHash(Boot0Accessor &accessor, Boot0Partition which, const void *stored_hash, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
|
Result GetPackage2Hash(void *dst_hash, size_t package2_size, void *work_buffer, size_t work_buffer_size, Package2Type which);
|
||||||
|
Result WritePackage2(void *work_buffer, size_t work_buffer_size, Package2Type which, BootImageUpdateType boot_image_update_type);
|
||||||
|
|
||||||
|
/* Implementations. */
|
||||||
|
Result ValidateWorkBuffer(const void *work_buffer, size_t work_buffer_size) {
|
||||||
if (work_buffer_size < BctSize + EksSize) {
|
if (work_buffer_size < BctSize + EksSize) {
|
||||||
return ResultUpdaterTooSmallWorkBuffer;
|
return ResultUpdaterTooSmallWorkBuffer;
|
||||||
}
|
}
|
||||||
|
@ -33,53 +66,40 @@ Result Updater::ValidateWorkBuffer(const void *work_buffer, size_t work_buffer_s
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
BootImageUpdateType Updater::GetBootImageUpdateType(HardwareType hw_type) {
|
bool HasEks(BootImageUpdateType boot_image_update_type) {
|
||||||
switch (hw_type) {
|
|
||||||
case HardwareType_Icosa:
|
|
||||||
case HardwareType_Copper:
|
|
||||||
return BootImageUpdateType_Erista;
|
|
||||||
case HardwareType_Hoag:
|
|
||||||
case HardwareType_Iowa:
|
|
||||||
return BootImageUpdateType_Mariko;
|
|
||||||
default:
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Updater::HasEks(BootImageUpdateType boot_image_update_type) {
|
|
||||||
switch (boot_image_update_type) {
|
switch (boot_image_update_type) {
|
||||||
case BootImageUpdateType_Erista:
|
case BootImageUpdateType::Erista:
|
||||||
return true;
|
return true;
|
||||||
case BootImageUpdateType_Mariko:
|
case BootImageUpdateType::Mariko:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Updater::HasAutoRcmPreserve(BootImageUpdateType boot_image_update_type) {
|
bool HasAutoRcmPreserve(BootImageUpdateType boot_image_update_type) {
|
||||||
switch (boot_image_update_type) {
|
switch (boot_image_update_type) {
|
||||||
case BootImageUpdateType_Erista:
|
case BootImageUpdateType::Erista:
|
||||||
return true;
|
return true;
|
||||||
case BootImageUpdateType_Mariko:
|
case BootImageUpdateType::Mariko:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Updater::GetNcmTitleType(BootModeType mode) {
|
u32 GetNcmTitleType(BootModeType mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BootModeType_Normal:
|
case BootModeType::Normal:
|
||||||
return NcmContentMetaType_BootImagePackage;
|
return NcmContentMetaType_BootImagePackage;
|
||||||
case BootModeType_Safe:
|
case BootModeType::Safe:
|
||||||
return NcmContentMetaType_BootImagePackageSafe;
|
return NcmContentMetaType_BootImagePackageSafe;
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::GetVerificationState(VerificationState *out, void *work_buffer, size_t work_buffer_size) {
|
Result GetVerificationState(VerificationState *out, void *work_buffer, size_t work_buffer_size) {
|
||||||
/* Always set output to true before doing anything else. */
|
/* Always set output to true before doing anything else. */
|
||||||
out->needs_verify_normal = true;
|
out->needs_verify_normal = true;
|
||||||
out->needs_verify_safe = true;
|
out->needs_verify_safe = true;
|
||||||
|
@ -96,60 +116,14 @@ Result Updater::GetVerificationState(VerificationState *out, void *work_buffer,
|
||||||
R_TRY(save.Load());
|
R_TRY(save.Load());
|
||||||
|
|
||||||
/* Read data from save. */
|
/* Read data from save. */
|
||||||
out->needs_verify_normal = save.GetNeedsVerification(BootModeType_Normal);
|
out->needs_verify_normal = save.GetNeedsVerification(BootModeType::Normal);
|
||||||
out->needs_verify_safe = save.GetNeedsVerification(BootModeType_Safe);
|
out->needs_verify_safe = save.GetNeedsVerification(BootModeType::Safe);
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::VerifyBootImagesAndRepairIfNeeded(bool *out_repaired_normal, bool *out_repaired_safe, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result VerifyBootImagesAndRepairIfNeeded(bool *out_repaired, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
|
|
||||||
/* Always set output to false before doing anything else. */
|
|
||||||
*out_repaired_normal = false;
|
|
||||||
*out_repaired_safe = false;
|
|
||||||
|
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
|
||||||
|
|
||||||
/* Get verification state from NAND. */
|
|
||||||
VerificationState verification_state;
|
|
||||||
R_TRY(GetVerificationState(&verification_state, work_buffer, work_buffer_size));
|
|
||||||
|
|
||||||
/* If we don't need to verify anything, we're done. */
|
|
||||||
if (!verification_state.needs_verify_normal && !verification_state.needs_verify_safe) {
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get a session to ncm. */
|
|
||||||
DoWithSmSession([&]() {
|
|
||||||
if (R_FAILED(ncmInitialize())) {
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ON_SCOPE_EXIT { ncmExit(); };
|
|
||||||
|
|
||||||
/* Verify normal, verify safe as needed. */
|
|
||||||
if (verification_state.needs_verify_normal) {
|
|
||||||
R_TRY_CATCH(VerifyBootImagesAndRepairIfNeeded(out_repaired_normal, BootModeType_Normal, work_buffer, work_buffer_size, boot_image_update_type)) {
|
|
||||||
R_CATCH(ResultUpdaterBootImagePackageNotFound) {
|
|
||||||
/* Nintendo considers failure to locate bip a success. TODO: don't do that? */
|
|
||||||
}
|
|
||||||
} R_END_TRY_CATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verification_state.needs_verify_safe) {
|
|
||||||
R_TRY_CATCH(VerifyBootImagesAndRepairIfNeeded(out_repaired_safe, BootModeType_Safe, work_buffer, work_buffer_size, boot_image_update_type)) {
|
|
||||||
R_CATCH(ResultUpdaterBootImagePackageNotFound) {
|
|
||||||
/* Nintendo considers failure to locate bip a success. TODO: don't do that? */
|
|
||||||
}
|
|
||||||
} R_END_TRY_CATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Updater::VerifyBootImagesAndRepairIfNeeded(bool *out_repaired, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
|
||||||
/* Get system data id for boot images (819/81A/81B/81C). */
|
/* Get system data id for boot images (819/81A/81B/81C). */
|
||||||
u64 bip_data_id;
|
u64 bip_data_id = 0;
|
||||||
R_TRY(GetBootImagePackageDataId(&bip_data_id, mode, work_buffer, work_buffer_size));
|
R_TRY(GetBootImagePackageDataId(&bip_data_id, mode, work_buffer, work_buffer_size));
|
||||||
|
|
||||||
/* Verify the boot images in NAND. */
|
/* Verify the boot images in NAND. */
|
||||||
|
@ -165,7 +139,7 @@ Result Updater::VerifyBootImagesAndRepairIfNeeded(bool *out_repaired, BootModeTy
|
||||||
return SetVerificationNeeded(mode, false, work_buffer, work_buffer_size);
|
return SetVerificationNeeded(mode, false, work_buffer, work_buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size) {
|
Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size) {
|
||||||
/* Ensure we can read content metas. */
|
/* Ensure we can read content metas. */
|
||||||
constexpr size_t MaxContentMetas = 0x40;
|
constexpr size_t MaxContentMetas = 0x40;
|
||||||
if (work_buffer_size < sizeof(NcmMetaRecord) * MaxContentMetas) {
|
if (work_buffer_size < sizeof(NcmMetaRecord) * MaxContentMetas) {
|
||||||
|
@ -209,44 +183,18 @@ Result Updater::GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, v
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::VerifyBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result VerifyBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BootModeType_Normal:
|
case BootModeType::Normal:
|
||||||
return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
||||||
case BootModeType_Safe:
|
case BootModeType::Safe:
|
||||||
return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::ValidateBctFileHash(Boot0Accessor &accessor, Boot0Partition which, const void *stored_hash, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result VerifyBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
|
||||||
|
|
||||||
void *bct = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + 0);
|
|
||||||
void *work = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + BctSize);
|
|
||||||
|
|
||||||
size_t size;
|
|
||||||
R_TRY(ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
|
||||||
if (HasEks(boot_image_update_type)) {
|
|
||||||
R_TRY(accessor.UpdateEks(bct, work));
|
|
||||||
}
|
|
||||||
if (HasAutoRcmPreserve(boot_image_update_type)) {
|
|
||||||
R_TRY(accessor.PreserveAutoRcm(bct, work, which));
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 file_hash[SHA256_HASH_SIZE];
|
|
||||||
sha256CalculateHash(file_hash, bct, BctSize);
|
|
||||||
|
|
||||||
if (std::memcmp(file_hash, stored_hash, SHA256_HASH_SIZE) == 0) {
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResultUpdaterNeedsRepairBootImages;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Updater::VerifyBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
@ -301,7 +249,7 @@ Result Updater::VerifyBootImagesNormal(u64 data_id, void *work_buffer, size_t wo
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::VerifyBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result VerifyBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
@ -361,18 +309,18 @@ Result Updater::VerifyBootImagesSafe(u64 data_id, void *work_buffer, size_t work
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::UpdateBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result UpdateBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BootModeType_Normal:
|
case BootModeType::Normal:
|
||||||
return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
||||||
case BootModeType_Safe:
|
case BootModeType::Safe:
|
||||||
return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::UpdateBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result UpdateBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
@ -429,7 +377,7 @@ Result Updater::UpdateBootImagesNormal(u64 data_id, void *work_buffer, size_t wo
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::UpdateBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
Result UpdateBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
@ -490,7 +438,7 @@ Result Updater::UpdateBootImagesSafe(u64 data_id, void *work_buffer, size_t work
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::SetVerificationNeeded(BootModeType mode, bool needed, void *work_buffer, size_t work_buffer_size) {
|
Result SetVerificationNeeded(BootModeType mode, bool needed, void *work_buffer, size_t work_buffer_size) {
|
||||||
/* Ensure work buffer is big enough for us to do what we want to do. */
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
@ -509,7 +457,33 @@ Result Updater::SetVerificationNeeded(BootModeType mode, bool needed, void *work
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::GetPackage2Hash(void *dst_hash, size_t package2_size, void *work_buffer, size_t work_buffer_size, Package2Type which) {
|
Result ValidateBctFileHash(Boot0Accessor &accessor, Boot0Partition which, const void *stored_hash, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
void *bct = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + 0);
|
||||||
|
void *work = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(work_buffer) + BctSize);
|
||||||
|
|
||||||
|
size_t size;
|
||||||
|
R_TRY(ReadFile(&size, bct, BctSize, GetBctPath(boot_image_update_type)));
|
||||||
|
if (HasEks(boot_image_update_type)) {
|
||||||
|
R_TRY(accessor.UpdateEks(bct, work));
|
||||||
|
}
|
||||||
|
if (HasAutoRcmPreserve(boot_image_update_type)) {
|
||||||
|
R_TRY(accessor.PreserveAutoRcm(bct, work, which));
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 file_hash[SHA256_HASH_SIZE];
|
||||||
|
sha256CalculateHash(file_hash, bct, BctSize);
|
||||||
|
|
||||||
|
if (std::memcmp(file_hash, stored_hash, SHA256_HASH_SIZE) != 0) {
|
||||||
|
return ResultUpdaterNeedsRepairBootImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result GetPackage2Hash(void *dst_hash, size_t package2_size, void *work_buffer, size_t work_buffer_size, Package2Type which) {
|
||||||
Package2Accessor accessor(which);
|
Package2Accessor accessor(which);
|
||||||
R_TRY(accessor.Initialize());
|
R_TRY(accessor.Initialize());
|
||||||
ON_SCOPE_EXIT { accessor.Finalize(); };
|
ON_SCOPE_EXIT { accessor.Finalize(); };
|
||||||
|
@ -517,10 +491,72 @@ Result Updater::GetPackage2Hash(void *dst_hash, size_t package2_size, void *work
|
||||||
return accessor.GetHash(dst_hash, package2_size, work_buffer, work_buffer_size, Package2Partition::Package2);
|
return accessor.GetHash(dst_hash, package2_size, work_buffer, work_buffer_size, Package2Partition::Package2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::WritePackage2(void *work_buffer, size_t work_buffer_size, Package2Type which, BootImageUpdateType boot_image_update_type) {
|
Result WritePackage2(void *work_buffer, size_t work_buffer_size, Package2Type which, BootImageUpdateType boot_image_update_type) {
|
||||||
Package2Accessor accessor(which);
|
Package2Accessor accessor(which);
|
||||||
R_TRY(accessor.Initialize());
|
R_TRY(accessor.Initialize());
|
||||||
ON_SCOPE_EXIT { accessor.Finalize(); };
|
ON_SCOPE_EXIT { accessor.Finalize(); };
|
||||||
|
|
||||||
return accessor.Write(GetPackage2Path(boot_image_update_type), work_buffer, work_buffer_size, Package2Partition::Package2);
|
return accessor.Write(GetPackage2Path(boot_image_update_type), work_buffer, work_buffer_size, Package2Partition::Package2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BootImageUpdateType GetBootImageUpdateType(HardwareType hw_type) {
|
||||||
|
switch (hw_type) {
|
||||||
|
case HardwareType_Icosa:
|
||||||
|
case HardwareType_Copper:
|
||||||
|
return BootImageUpdateType::Erista;
|
||||||
|
case HardwareType_Hoag:
|
||||||
|
case HardwareType_Iowa:
|
||||||
|
return BootImageUpdateType::Mariko;
|
||||||
|
default:
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result VerifyBootImagesAndRepairIfNeeded(bool *out_repaired_normal, bool *out_repaired_safe, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type) {
|
||||||
|
/* Always set output to false before doing anything else. */
|
||||||
|
*out_repaired_normal = false;
|
||||||
|
*out_repaired_safe = false;
|
||||||
|
|
||||||
|
/* Ensure work buffer is big enough for us to do what we want to do. */
|
||||||
|
R_TRY(ValidateWorkBuffer(work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
/* Get verification state from NAND. */
|
||||||
|
VerificationState verification_state;
|
||||||
|
R_TRY(GetVerificationState(&verification_state, work_buffer, work_buffer_size));
|
||||||
|
|
||||||
|
/* If we don't need to verify anything, we're done. */
|
||||||
|
if (!verification_state.needs_verify_normal && !verification_state.needs_verify_safe) {
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a session to ncm. */
|
||||||
|
DoWithSmSession([&]() {
|
||||||
|
if (R_FAILED(ncmInitialize())) {
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ON_SCOPE_EXIT { ncmExit(); };
|
||||||
|
|
||||||
|
/* Verify normal, verify safe as needed. */
|
||||||
|
if (verification_state.needs_verify_normal) {
|
||||||
|
R_TRY_CATCH(VerifyBootImagesAndRepairIfNeeded(out_repaired_normal, BootModeType::Normal, work_buffer, work_buffer_size, boot_image_update_type)) {
|
||||||
|
R_CATCH(ResultUpdaterBootImagePackageNotFound) {
|
||||||
|
/* Nintendo considers failure to locate bip a success. TODO: don't do that? */
|
||||||
|
}
|
||||||
|
} R_END_TRY_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verification_state.needs_verify_safe) {
|
||||||
|
R_TRY_CATCH(VerifyBootImagesAndRepairIfNeeded(out_repaired_safe, BootModeType::Safe, work_buffer, work_buffer_size, boot_image_update_type)) {
|
||||||
|
R_CATCH(ResultUpdaterBootImagePackageNotFound) {
|
||||||
|
/* Nintendo considers failure to locate bip a success. TODO: don't do that? */
|
||||||
|
}
|
||||||
|
} R_END_TRY_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -20,43 +20,10 @@
|
||||||
|
|
||||||
#include "updater_types.hpp"
|
#include "updater_types.hpp"
|
||||||
|
|
||||||
class Boot0Accessor;
|
namespace sts::updater {
|
||||||
enum class Boot0Partition;
|
|
||||||
enum class Package2Type;
|
|
||||||
|
|
||||||
class Updater {
|
/* Public API. */
|
||||||
private:
|
BootImageUpdateType GetBootImageUpdateType(HardwareType hw_type);
|
||||||
static bool HasEks(BootImageUpdateType boot_image_update_type);
|
Result VerifyBootImagesAndRepairIfNeeded(bool *out_repaired_normal, bool *out_repaired_safe, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
||||||
static bool HasAutoRcmPreserve(BootImageUpdateType boot_image_update_type);
|
|
||||||
static u32 GetNcmTitleType(BootModeType mode);
|
|
||||||
static Result ValidateWorkBuffer(const void *work_buffer, size_t work_buffer_size);
|
|
||||||
static Result GetVerificationState(VerificationState *out, void *work_buffer, size_t work_buffer_size);
|
|
||||||
static Result VerifyBootImagesAndRepairIfNeeded(bool *out_repaired, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size);
|
|
||||||
static Result VerifyBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result VerifyBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result VerifyBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result UpdateBootImages(u64 data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result UpdateBootImagesNormal(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result UpdateBootImagesSafe(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result SetVerificationNeeded(BootModeType mode, bool needed, void *work_buffer, size_t work_buffer_size);
|
|
||||||
static Result RepairBootImages(u64 data_id, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
|
|
||||||
/* Path functionality. */
|
}
|
||||||
static const char *GetBootImagePackageMountPath();
|
|
||||||
static const char *GetBctPath(BootImageUpdateType boot_image_update_type);
|
|
||||||
static const char *GetPackage1Path(BootImageUpdateType boot_image_update_type);
|
|
||||||
static const char *GetPackage2Path(BootImageUpdateType boot_image_update_type);
|
|
||||||
|
|
||||||
/* File helpers. */
|
|
||||||
static Result ReadFile(size_t *out_size, void *dst, size_t dst_size, const char *path);
|
|
||||||
static Result GetFileHash(size_t *out_size, void *dst_hash, const char *path, void *work_buffer, size_t work_buffer_size);
|
|
||||||
|
|
||||||
/* Package helpers. */
|
|
||||||
static Result ValidateBctFileHash(Boot0Accessor &accessor, Boot0Partition which, const void *stored_hash, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
static Result GetPackage2Hash(void *dst_hash, size_t package2_size, void *work_buffer, size_t work_buffer_size, Package2Type which);
|
|
||||||
static Result WritePackage2(void *work_buffer, size_t work_buffer_size, Package2Type which, BootImageUpdateType boot_image_update_type);
|
|
||||||
public:
|
|
||||||
static BootImageUpdateType GetBootImageUpdateType(HardwareType hw_type);
|
|
||||||
static Result VerifyBootImagesAndRepairIfNeeded(bool *out_repaired_normal, bool *out_repaired_safe, void *work_buffer, size_t work_buffer_size, BootImageUpdateType boot_image_update_type);
|
|
||||||
};
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "updater_bis_management.hpp"
|
#include "updater_bis_management.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
Result BisAccessor::Initialize() {
|
Result BisAccessor::Initialize() {
|
||||||
R_TRY(fsOpenBisStorage(&this->storage, this->partition_id));
|
R_TRY(fsOpenBisStorage(&this->storage, this->partition_id));
|
||||||
this->active = true;
|
this->active = true;
|
||||||
|
@ -162,3 +164,5 @@ Result Boot0Accessor::PreserveAutoRcm(void *dst_bct, void *work_buffer, Boot0Par
|
||||||
std::memcpy(dst_pubk, src_pubk, BctPubkSize);
|
std::memcpy(dst_pubk, src_pubk, BctPubkSize);
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "updater_types.hpp"
|
#include "updater_types.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
class BisAccessor {
|
class BisAccessor {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t SectorAlignment = 0x200;
|
static constexpr size_t SectorAlignment = 0x200;
|
||||||
|
@ -234,3 +236,4 @@ class Package2Accessor : public PartitionAccessor<Package2Meta> {
|
||||||
Package2Accessor(Package2Type which) : PartitionAccessor<Package2Meta>(GetPackage2StorageId(which)) { }
|
Package2Accessor(Package2Type which) : PartitionAccessor<Package2Meta>(GetPackage2StorageId(which)) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
|
|
||||||
#include "updater_bis_save.hpp"
|
#include "updater_bis_save.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
size_t BisSave::GetVerificationFlagOffset(BootModeType mode) {
|
size_t BisSave::GetVerificationFlagOffset(BootModeType mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BootModeType_Normal:
|
case BootModeType::Normal:
|
||||||
return 0;
|
return 0;
|
||||||
case BootModeType_Safe:
|
case BootModeType::Safe:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -60,3 +62,5 @@ bool BisSave::GetNeedsVerification(BootModeType mode) {
|
||||||
void BisSave::SetNeedsVerification(BootModeType mode, bool needs_verification) {
|
void BisSave::SetNeedsVerification(BootModeType mode, bool needs_verification) {
|
||||||
reinterpret_cast<u8 *>(this->save_buffer)[GetVerificationFlagOffset(mode)] = needs_verification ? 1 : 0;
|
reinterpret_cast<u8 *>(this->save_buffer)[GetVerificationFlagOffset(mode)] = needs_verification ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "updater_types.hpp"
|
#include "updater_types.hpp"
|
||||||
#include "updater_bis_management.hpp"
|
#include "updater_bis_management.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
class BisSave {
|
class BisSave {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t SaveSize = BctSize;
|
static constexpr size_t SaveSize = BctSize;
|
||||||
|
@ -40,3 +42,5 @@ class BisSave {
|
||||||
bool GetNeedsVerification(BootModeType mode);
|
bool GetNeedsVerification(BootModeType mode);
|
||||||
void SetNeedsVerification(BootModeType mode, bool needs_verification);
|
void SetNeedsVerification(BootModeType mode, bool needs_verification);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
#include "updater_api.hpp"
|
#include "updater_api.hpp"
|
||||||
|
|
||||||
Result Updater::ReadFile(size_t *out_size, void *dst, size_t dst_size, const char *path) {
|
namespace sts::updater {
|
||||||
|
|
||||||
|
Result ReadFile(size_t *out_size, void *dst, size_t dst_size, const char *path) {
|
||||||
FILE *fp = fopen(path, "rb");
|
FILE *fp = fopen(path, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return ResultUpdaterInvalidBootImagePackage;
|
return ResultUpdaterInvalidBootImagePackage;
|
||||||
|
@ -35,7 +37,7 @@ Result Updater::ReadFile(size_t *out_size, void *dst, size_t dst_size, const cha
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Updater::GetFileHash(size_t *out_size, void *dst_hash, const char *path, void *work_buffer, size_t work_buffer_size) {
|
Result GetFileHash(size_t *out_size, void *dst_hash, const char *path, void *work_buffer, size_t work_buffer_size) {
|
||||||
FILE *fp = fopen(path, "rb");
|
FILE *fp = fopen(path, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return ResultUpdaterInvalidBootImagePackage;
|
return ResultUpdaterInvalidBootImagePackage;
|
||||||
|
@ -66,3 +68,5 @@ Result Updater::GetFileHash(size_t *out_size, void *dst_hash, const char *path,
|
||||||
*out_size = total_size;
|
*out_size = total_size;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
29
stratosphere/boot/source/updater/updater_files.hpp
Normal file
29
stratosphere/boot/source/updater/updater_files.hpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <switch.h>
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
|
#include "updater_types.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
|
/* File helpers. */
|
||||||
|
Result ReadFile(size_t *out_size, void *dst, size_t dst_size, const char *path);
|
||||||
|
Result GetFileHash(size_t *out_size, void *dst_hash, const char *path, void *work_buffer, size_t work_buffer_size);
|
||||||
|
|
||||||
|
}
|
|
@ -18,21 +18,22 @@
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "updater_api.hpp"
|
#include "updater_paths.hpp"
|
||||||
|
|
||||||
static const char *BootImagePackageMountPath = "bip";
|
namespace sts::updater {
|
||||||
static const char *BctPathNx = "bip:/nx/bct";
|
|
||||||
static const char *Package1PathNx = "bip:/nx/package1";
|
|
||||||
static const char *Package2PathNx = "bip:/nx/package2";
|
|
||||||
static const char *BctPathA = "bip:/a/bct";
|
|
||||||
static const char *Package1PathA = "bip:/a/package1";
|
|
||||||
static const char *Package2PathA = "bip:/a/package2";
|
|
||||||
|
|
||||||
const char *Updater::GetBootImagePackageMountPath() {
|
namespace {
|
||||||
return BootImagePackageMountPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *ChooseCandidatePath(const char **candidates, size_t num_candidates) {
|
/* Actual paths. */
|
||||||
|
constexpr const char *BootImagePackageMountPath = "bip";
|
||||||
|
constexpr const char *BctPathNx = "bip:/nx/bct";
|
||||||
|
constexpr const char *Package1PathNx = "bip:/nx/package1";
|
||||||
|
constexpr const char *Package2PathNx = "bip:/nx/package2";
|
||||||
|
constexpr const char *BctPathA = "bip:/a/bct";
|
||||||
|
constexpr const char *Package1PathA = "bip:/a/package1";
|
||||||
|
constexpr const char *Package2PathA = "bip:/a/package2";
|
||||||
|
|
||||||
|
const char *ChooseCandidatePath(const char * const *candidates, size_t num_candidates) {
|
||||||
if (num_candidates == 0) {
|
if (num_candidates == 0) {
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
@ -54,16 +55,23 @@ static const char *ChooseCandidatePath(const char **candidates, size_t num_candi
|
||||||
return candidates[num_candidates - 1];
|
return candidates[num_candidates - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Updater::GetBctPath(BootImageUpdateType boot_image_update_type) {
|
}
|
||||||
|
|
||||||
|
const char *GetBootImagePackageMountPath() {
|
||||||
|
return BootImagePackageMountPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *GetBctPath(BootImageUpdateType boot_image_update_type) {
|
||||||
switch (boot_image_update_type) {
|
switch (boot_image_update_type) {
|
||||||
case BootImageUpdateType_Erista:
|
case BootImageUpdateType::Erista:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {BctPathNx};
|
constexpr const char *candidates[] = {BctPathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
case BootImageUpdateType_Mariko:
|
case BootImageUpdateType::Mariko:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {BctPathA, BctPathNx};
|
constexpr const char *candidates[] = {BctPathA, BctPathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -71,16 +79,16 @@ const char *Updater::GetBctPath(BootImageUpdateType boot_image_update_type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Updater::GetPackage1Path(BootImageUpdateType boot_image_update_type) {
|
const char *GetPackage1Path(BootImageUpdateType boot_image_update_type) {
|
||||||
switch (boot_image_update_type) {
|
switch (boot_image_update_type) {
|
||||||
case BootImageUpdateType_Erista:
|
case BootImageUpdateType::Erista:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {Package1PathNx};
|
constexpr const char *candidates[] = {Package1PathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
case BootImageUpdateType_Mariko:
|
case BootImageUpdateType::Mariko:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {Package1PathA, Package1PathNx};
|
constexpr const char *candidates[] = {Package1PathA, Package1PathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -88,19 +96,24 @@ const char *Updater::GetPackage1Path(BootImageUpdateType boot_image_update_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Updater::GetPackage2Path(BootImageUpdateType boot_image_update_type) {
|
const char *GetPackage2Path(BootImageUpdateType boot_image_update_type) {
|
||||||
switch (boot_image_update_type) {
|
switch (boot_image_update_type) {
|
||||||
case BootImageUpdateType_Erista:
|
case BootImageUpdateType::Erista:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {Package2PathNx};
|
constexpr const char *candidates[] = {Package2PathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
case BootImageUpdateType_Mariko:
|
case BootImageUpdateType::Mariko:
|
||||||
{
|
{
|
||||||
const char *candidates[] = {Package2PathA, Package2PathNx};
|
constexpr const char *candidates[] = {Package2PathA, Package2PathNx};
|
||||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
31
stratosphere/boot/source/updater/updater_paths.hpp
Normal file
31
stratosphere/boot/source/updater/updater_paths.hpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <switch.h>
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
|
#include "updater_types.hpp"
|
||||||
|
|
||||||
|
namespace sts::updater {
|
||||||
|
|
||||||
|
/* Path functionality. */
|
||||||
|
const char *GetBootImagePackageMountPath();
|
||||||
|
const char *GetBctPath(BootImageUpdateType boot_image_update_type);
|
||||||
|
const char *GetPackage1Path(BootImageUpdateType boot_image_update_type);
|
||||||
|
const char *GetPackage2Path(BootImageUpdateType boot_image_update_type);
|
||||||
|
|
||||||
|
}
|
|
@ -21,22 +21,28 @@
|
||||||
/* TODO: Better way to do this? */
|
/* TODO: Better way to do this? */
|
||||||
#include "../boot_types.hpp"
|
#include "../boot_types.hpp"
|
||||||
|
|
||||||
enum BootImageUpdateType {
|
namespace sts::updater {
|
||||||
BootImageUpdateType_Erista,
|
|
||||||
BootImageUpdateType_Mariko,
|
/* Types. */
|
||||||
|
enum class BootImageUpdateType {
|
||||||
|
Erista,
|
||||||
|
Mariko,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BootModeType {
|
enum class BootModeType {
|
||||||
BootModeType_Normal,
|
Normal,
|
||||||
BootModeType_Safe,
|
Safe,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr size_t BctSize = 0x4000;
|
|
||||||
static constexpr size_t EksSize = 0x4000;
|
|
||||||
static constexpr size_t EksEntrySize = 0x200;
|
|
||||||
static constexpr size_t EksBlobSize = 0xB0;
|
|
||||||
|
|
||||||
struct VerificationState {
|
struct VerificationState {
|
||||||
bool needs_verify_normal;
|
bool needs_verify_normal;
|
||||||
bool needs_verify_safe;
|
bool needs_verify_safe;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Convenience size definitions. */
|
||||||
|
constexpr size_t BctSize = 0x4000;
|
||||||
|
constexpr size_t EksSize = 0x4000;
|
||||||
|
constexpr size_t EksEntrySize = 0x200;
|
||||||
|
constexpr size_t EksBlobSize = 0xB0;
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue