fusee: fix buildsystem, rename secondary -> package3
This commit is contained in:
@@ -19,11 +19,11 @@
|
||||
|
||||
namespace ams::nxboot {
|
||||
|
||||
constexpr inline const size_t SecondaryArchiveSize = 8_MB;
|
||||
constexpr inline const size_t ExternalPackageSize = 8_MB;
|
||||
|
||||
constexpr inline const size_t InitialProcessStorageSizeMax = 3_MB / 8;
|
||||
|
||||
struct SecondaryArchiveContentMeta {
|
||||
struct ExternalPackageContentMeta {
|
||||
u32 offset;
|
||||
u32 size;
|
||||
u8 type;
|
||||
@@ -31,17 +31,17 @@ namespace ams::nxboot {
|
||||
u32 pad;
|
||||
char name[0x10];
|
||||
};
|
||||
static_assert(sizeof(SecondaryArchiveContentMeta) == 0x20);
|
||||
static_assert(sizeof(ExternalPackageContentMeta) == 0x20);
|
||||
|
||||
struct SecondaryArchiveKipMeta {
|
||||
struct ExternalPackageKipMeta {
|
||||
u64 program_id;
|
||||
u32 offset;
|
||||
u32 size;
|
||||
se::Sha256Hash hash;
|
||||
};
|
||||
static_assert(sizeof(SecondaryArchiveKipMeta) == 0x30);
|
||||
static_assert(sizeof(ExternalPackageKipMeta) == 0x30);
|
||||
|
||||
struct SecondaryArchiveHeader {
|
||||
struct ExternalPackageHeader {
|
||||
static constexpr u32 Magic = util::FourCC<'F','S','S','0'>::Code;
|
||||
|
||||
u32 reserved0; /* Previously entrypoint. */
|
||||
@@ -58,15 +58,15 @@ namespace ams::nxboot {
|
||||
u32 supported_hos_version;
|
||||
u32 release_version;
|
||||
u32 git_revision;
|
||||
SecondaryArchiveContentMeta content_metas[(0x400 - 0x40) / sizeof(SecondaryArchiveContentMeta)];
|
||||
SecondaryArchiveKipMeta emummc_meta;
|
||||
SecondaryArchiveKipMeta kip_metas[8];
|
||||
u8 reserved3[0x800 - (0x400 + 9 * sizeof(SecondaryArchiveKipMeta))];
|
||||
ExternalPackageContentMeta content_metas[(0x400 - 0x40) / sizeof(ExternalPackageContentMeta)];
|
||||
ExternalPackageKipMeta emummc_meta;
|
||||
ExternalPackageKipMeta kip_metas[8];
|
||||
u8 reserved3[0x800 - (0x400 + 9 * sizeof(ExternalPackageKipMeta))];
|
||||
};
|
||||
static_assert(sizeof(SecondaryArchiveHeader) == 0x800);
|
||||
static_assert(sizeof(ExternalPackageHeader) == 0x800);
|
||||
|
||||
struct SecondaryArchive {
|
||||
SecondaryArchiveHeader header; /* 0x000000-0x000800 */
|
||||
struct ExternalPackage {
|
||||
ExternalPackageHeader header; /* 0x000000-0x000800 */
|
||||
u8 warmboot[0x1800]; /* 0x000800-0x002000 */
|
||||
u8 tsec_keygen[0x2000]; /* 0x002000-0x004000 */
|
||||
u8 mariko_fatal[0x1C000]; /* 0x004000-0x020000 */
|
||||
@@ -80,8 +80,8 @@ namespace ams::nxboot {
|
||||
u8 reboot_stub[0x1000]; /* 0x7E0000-0x7E1000 */
|
||||
u8 reserved[0x1F000]; /* 0x7E1000-0x800000 */
|
||||
};
|
||||
static_assert(sizeof(SecondaryArchive) == SecondaryArchiveSize);
|
||||
static_assert(sizeof(ExternalPackage) == ExternalPackageSize);
|
||||
|
||||
ALWAYS_INLINE const SecondaryArchive &GetSecondaryArchive() { return *reinterpret_cast<const SecondaryArchive *>(0xC0000000); }
|
||||
ALWAYS_INLINE const ExternalPackage &GetExternalPackage() { return *reinterpret_cast<const ExternalPackage *>(0xC0000000); }
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "fusee_overlay_manager.hpp"
|
||||
#include "fusee_sd_card.hpp"
|
||||
#include "fusee_fatal.hpp"
|
||||
#include "fusee_secondary_archive.hpp"
|
||||
#include "fusee_external_package.hpp"
|
||||
#include "fusee_setup_horizon.hpp"
|
||||
#include "fusee_secmon_sync.hpp"
|
||||
|
||||
@@ -30,41 +30,40 @@ namespace ams::nxboot {
|
||||
|
||||
namespace {
|
||||
|
||||
/* TODO: Change to fusee-secondary.bin when development is done. */
|
||||
constexpr const char SecondaryArchiveFilePath[] = "sdmc:/atmosphere/fusee-boogaloo.bin";
|
||||
constexpr const char ExternalPackageFilePath[] = "sdmc:/atmosphere/package3";
|
||||
|
||||
constinit fs::FileHandle g_archive_file;
|
||||
constinit fs::FileHandle g_package_file;
|
||||
|
||||
void OpenSecondaryArchive() {
|
||||
void OpenExternalPackage() {
|
||||
Result result;
|
||||
|
||||
/* Open fusee-secondary. */
|
||||
if (R_FAILED((result = fs::OpenFile(std::addressof(g_archive_file), SecondaryArchiveFilePath, fs::OpenMode_Read)))) {
|
||||
ShowFatalError("Failed to open %s!\n", SecondaryArchiveFilePath);
|
||||
/* Open external package. */
|
||||
if (R_FAILED((result = fs::OpenFile(std::addressof(g_package_file), ExternalPackageFilePath, fs::OpenMode_Read)))) {
|
||||
ShowFatalError("Failed to open %s!\n", ExternalPackageFilePath);
|
||||
}
|
||||
|
||||
/* Get file size. */
|
||||
s64 file_size;
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(file_size), g_archive_file)))) {
|
||||
ShowFatalError("Failed to get fusee-secondary size: 0x%08" PRIx32 "\n", result.GetValue());
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(file_size), g_package_file)))) {
|
||||
ShowFatalError("Failed to get package3 size: 0x%08" PRIx32 "\n", result.GetValue());
|
||||
}
|
||||
|
||||
/* Check file size. */
|
||||
if (static_cast<size_t>(file_size) != SecondaryArchiveSize) {
|
||||
ShowFatalError("fusee-secondary seems corrupted (size 0x%zx != 0x%zx)", static_cast<size_t>(file_size), SecondaryArchiveSize);
|
||||
if (static_cast<size_t>(file_size) != ExternalPackageSize) {
|
||||
ShowFatalError("package3 seems corrupted (size 0x%zx != 0x%zx)", static_cast<size_t>(file_size), ExternalPackageSize);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadFullSecondaryArchive() {
|
||||
void ReadFullExternalPackage() {
|
||||
Result result;
|
||||
|
||||
if (R_FAILED((result = fs::ReadFile(g_archive_file, 0, const_cast<void *>(static_cast<const void *>(std::addressof(GetSecondaryArchive()))), SecondaryArchiveSize)))) {
|
||||
ShowFatalError("Failed to read %s!\n", SecondaryArchiveFilePath);
|
||||
if (R_FAILED((result = fs::ReadFile(g_package_file, 0, const_cast<void *>(static_cast<const void *>(std::addressof(GetExternalPackage()))), ExternalPackageSize)))) {
|
||||
ShowFatalError("Failed to read %s!\n", ExternalPackageFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
void CloseSecondaryArchive() {
|
||||
fs::CloseFile(g_archive_file);
|
||||
void CloseExternalPackage() {
|
||||
fs::CloseFile(g_package_file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,17 +97,17 @@ namespace ams::nxboot {
|
||||
/* If we have a fatal error, save and display it. */
|
||||
SaveAndShowFatalError();
|
||||
|
||||
/* Open the secondary archive. */
|
||||
OpenSecondaryArchive();
|
||||
/* Open the external package. */
|
||||
OpenExternalPackage();
|
||||
|
||||
/* Load the memory training overlay. */
|
||||
LoadOverlay(g_archive_file, OverlayId_MemoryTraining);
|
||||
LoadOverlay(g_package_file, OverlayId_MemoryTraining);
|
||||
|
||||
/* Do memory training. */
|
||||
DoMemoryTraining();
|
||||
|
||||
/* Read the rest of the archive file. */
|
||||
ReadFullSecondaryArchive();
|
||||
ReadFullExternalPackage();
|
||||
|
||||
/* Save the memory training overlay. */
|
||||
SaveMemoryTrainingOverlay();
|
||||
@@ -117,8 +116,8 @@ namespace ams::nxboot {
|
||||
InitializeDisplay();
|
||||
ShowDisplay();
|
||||
|
||||
/* Close the secondary archive. */
|
||||
CloseSecondaryArchive();
|
||||
/* Close the external package. */
|
||||
CloseExternalPackage();
|
||||
|
||||
/* Perform rest of the boot process. */
|
||||
SetupAndStartHorizon();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "fusee_malloc.hpp"
|
||||
#include "fusee_secondary_archive.hpp"
|
||||
#include "fusee_fatal.hpp"
|
||||
|
||||
namespace ams::nxboot {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "fusee_overlay_manager.hpp"
|
||||
#include "fusee_secondary_archive.hpp"
|
||||
#include "fusee_external_package.hpp"
|
||||
#include "fusee_fatal.hpp"
|
||||
|
||||
namespace ams::nxboot {
|
||||
@@ -33,13 +33,13 @@ namespace ams::nxboot {
|
||||
u32 verif_hash;
|
||||
u32 store_hash;
|
||||
if (fuse::GetSocType() == fuse::SocType_Erista) {
|
||||
result = fs::ReadFile(archive_file, __builtin_offsetof(SecondaryArchive, ovl_mtc_erista), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_erista));
|
||||
result = fs::ReadFile(archive_file, __builtin_offsetof(ExternalPackage, ovl_mtc_erista), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_erista));
|
||||
verif_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[-2];
|
||||
store_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[(sizeof(SecondaryArchive{}.ovl_mtc_erista) / sizeof(u32)) - 1];
|
||||
store_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[(sizeof(ExternalPackage{}.ovl_mtc_erista) / sizeof(u32)) - 1];
|
||||
} else /* if (fuse::GetSocType() == fuse::SocType_Mariko) */ {
|
||||
result = fs::ReadFile(archive_file, __builtin_offsetof(SecondaryArchive, ovl_mtc_mariko), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_mariko));
|
||||
result = fs::ReadFile(archive_file, __builtin_offsetof(ExternalPackage, ovl_mtc_mariko), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_mariko));
|
||||
verif_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[-1];
|
||||
store_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[(sizeof(SecondaryArchive{}.ovl_mtc_mariko) / sizeof(u32)) - 1];
|
||||
store_hash = reinterpret_cast<const u32 *>(GetOverlayDestination())[(sizeof(ExternalPackage{}.ovl_mtc_mariko) / sizeof(u32)) - 1];
|
||||
}
|
||||
|
||||
if (R_FAILED(result)) {
|
||||
@@ -64,19 +64,19 @@ namespace ams::nxboot {
|
||||
void SaveMemoryTrainingOverlay() {
|
||||
if (fuse::GetSocType() == fuse::SocType_Erista) {
|
||||
/* NOTE: Erista does not do memory clock restoration. */
|
||||
/* std::memcpy(const_cast<u8 *>(GetSecondaryArchive().ovl_mtc_erista), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_erista)); */
|
||||
/* std::memcpy(const_cast<u8 *>(GetExternalPackage().ovl_mtc_erista), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_erista)); */
|
||||
} else /* if (fuse::GetSocType() == fuse::SocType_Mariko) */ {
|
||||
std::memcpy(const_cast<u8 *>(GetSecondaryArchive().ovl_mtc_mariko), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_mariko) - 0x2000);
|
||||
std::memcpy(const_cast<u8 *>(GetExternalPackage().ovl_mtc_mariko), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_mariko) - 0x2000);
|
||||
}
|
||||
}
|
||||
|
||||
void RestoreMemoryTrainingOverlay() {
|
||||
if (fuse::GetSocType() == fuse::SocType_Erista) {
|
||||
/* NOTE: Erista does not do memory clock restoration. */
|
||||
/* std::memcpy(GetOverlayDestination(), GetSecondaryArchive().ovl_mtc_erista, sizeof(SecondaryArchive{}.ovl_mtc_erista)); */
|
||||
/* std::memcpy(GetOverlayDestination(), GetExternalPackage().ovl_mtc_erista, sizeof(ExternalPackage{}.ovl_mtc_erista)); */
|
||||
} else /* if (fuse::GetSocType() == fuse::SocType_Mariko) */ {
|
||||
std::memcpy(g_secmon_debug_storage, secmon::MemoryRegionPhysicalIramSecureMonitorDebug.GetPointer<void>(), sizeof(g_secmon_debug_storage));
|
||||
std::memcpy(GetOverlayDestination(), GetSecondaryArchive().ovl_mtc_mariko, sizeof(SecondaryArchive{}.ovl_mtc_mariko) - 0x2000);
|
||||
std::memcpy(GetOverlayDestination(), GetExternalPackage().ovl_mtc_mariko, sizeof(ExternalPackage{}.ovl_mtc_mariko) - 0x2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <exosphere.hpp>
|
||||
#include <exosphere/secmon/secmon_monitor_context.hpp>
|
||||
#include "fusee_key_derivation.hpp"
|
||||
#include "fusee_secondary_archive.hpp"
|
||||
#include "fusee_external_package.hpp"
|
||||
#include "fusee_setup_horizon.hpp"
|
||||
#include "fusee_ini.hpp"
|
||||
#include "fusee_emummc.hpp"
|
||||
@@ -44,7 +44,7 @@ namespace ams::nxboot {
|
||||
if (soc_type == fuse::SocType_Erista) {
|
||||
clkrst::SetBpmpClockRate(clkrst::BpmpClockRate_408MHz);
|
||||
|
||||
if (!tsec::RunTsecFirmware(GetSecondaryArchive().tsec_keygen, sizeof(GetSecondaryArchive().tsec_keygen))) {
|
||||
if (!tsec::RunTsecFirmware(GetExternalPackage().tsec_keygen, sizeof(GetExternalPackage().tsec_keygen))) {
|
||||
ShowFatalError("Failed to run tsec_keygen firmware!\n");
|
||||
}
|
||||
|
||||
@@ -428,10 +428,10 @@ namespace ams::nxboot {
|
||||
|
||||
void LoadWarmbootFirmware(fuse::SocType soc_type, ams::TargetFirmware target_firmware, const u8 *package1) {
|
||||
u8 *warmboot_dst = secmon::MemoryRegionPhysicalIramWarmbootBin.GetPointer<u8>();
|
||||
size_t warmboot_size = std::min(sizeof(GetSecondaryArchive().warmboot), secmon::MemoryRegionPhysicalIramWarmbootBin.GetSize());
|
||||
size_t warmboot_size = std::min(sizeof(GetExternalPackage().warmboot), secmon::MemoryRegionPhysicalIramWarmbootBin.GetSize());
|
||||
if (soc_type == fuse::SocType_Erista) {
|
||||
/* Copy the ams warmboot binary. */
|
||||
std::memcpy(warmboot_dst, GetSecondaryArchive().warmboot, warmboot_size);
|
||||
std::memcpy(warmboot_dst, GetExternalPackage().warmboot, warmboot_size);
|
||||
|
||||
/* Set the rsa modulus. */
|
||||
if (fuse::GetHardwareState() == fuse::HardwareState_Production) {
|
||||
@@ -694,7 +694,7 @@ namespace ams::nxboot {
|
||||
|
||||
/* Get the size. */
|
||||
s64 size;
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(size), exo_file))) || size > sizeof(GetSecondaryArchive().exosphere)) {
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(size), exo_file))) || size > sizeof(GetExternalPackage().exosphere)) {
|
||||
ShowFatalError("Invalid SD exosphere size: 0x%08" PRIx32 ", %" PRIx64 "!\n", result.GetValue(), static_cast<u64>(size));
|
||||
}
|
||||
|
||||
@@ -706,7 +706,7 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
if (!use_sd_exo) {
|
||||
std::memcpy(exosphere_dst, GetSecondaryArchive().exosphere, sizeof(GetSecondaryArchive().exosphere));
|
||||
std::memcpy(exosphere_dst, GetExternalPackage().exosphere, sizeof(GetExternalPackage().exosphere));
|
||||
}
|
||||
|
||||
/* Copy mariko fatal. */
|
||||
@@ -726,7 +726,7 @@ namespace ams::nxboot {
|
||||
|
||||
/* Get the size. */
|
||||
s64 size;
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(size), mariko_program_file))) || size > sizeof(GetSecondaryArchive().mariko_fatal)) {
|
||||
if (R_FAILED((result = fs::GetFileSize(std::addressof(size), mariko_program_file))) || size > sizeof(GetExternalPackage().mariko_fatal)) {
|
||||
ShowFatalError("Invalid SD mariko_fatal size: 0x%08" PRIx32 ", %" PRIx64 "!\n", result.GetValue(), static_cast<u64>(size));
|
||||
}
|
||||
|
||||
@@ -736,12 +736,12 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
/* Clear the remainder. */
|
||||
std::memset(mariko_fatal_dst + size, 0, sizeof(GetSecondaryArchive().mariko_fatal) - size);
|
||||
std::memset(mariko_fatal_dst + size, 0, sizeof(GetExternalPackage().mariko_fatal) - size);
|
||||
}
|
||||
}
|
||||
|
||||
if (!use_sd_mariko_fatal) {
|
||||
std::memcpy(mariko_fatal_dst, GetSecondaryArchive().mariko_fatal, sizeof(GetSecondaryArchive().mariko_fatal));
|
||||
std::memcpy(mariko_fatal_dst, GetExternalPackage().mariko_fatal, sizeof(GetExternalPackage().mariko_fatal));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "fusee_stratosphere.hpp"
|
||||
#include "fusee_fatal.hpp"
|
||||
#include "fusee_malloc.hpp"
|
||||
#include "fusee_secondary_archive.hpp"
|
||||
#include "fusee_external_package.hpp"
|
||||
#include "fs/fusee_fs_api.hpp"
|
||||
|
||||
namespace ams::nxboot {
|
||||
@@ -726,11 +726,11 @@ namespace ams::nxboot {
|
||||
|
||||
/* Add the stratosphere kips. */
|
||||
{
|
||||
const auto &secondary_archive = GetSecondaryArchive();
|
||||
for (u32 i = 0; i < secondary_archive.header.num_kips; ++i) {
|
||||
const auto &meta = secondary_archive.header.kip_metas[i];
|
||||
const auto &external_package = GetExternalPackage();
|
||||
for (u32 i = 0; i < external_package.header.num_kips; ++i) {
|
||||
const auto &meta = external_package.header.kip_metas[i];
|
||||
|
||||
AddInitialProcess(reinterpret_cast<const InitialProcessHeader *>(secondary_archive.kips + meta.offset), std::addressof(meta.hash));
|
||||
AddInitialProcess(reinterpret_cast<const InitialProcessHeader *>(external_package.kips + meta.offset), std::addressof(meta.hash));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -893,8 +893,8 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
void RebuildPackage2(ams::TargetFirmware target_firmware, bool emummc_enabled) {
|
||||
/* Get the secondary archive. */
|
||||
const auto &secondary_archive = GetSecondaryArchive();
|
||||
/* Get the external package. */
|
||||
const auto &external_package = GetExternalPackage();
|
||||
|
||||
/* Clear package2 header. */
|
||||
auto *package2 = secmon::MemoryRegionDramPackage2.GetPointer<pkg2::Package2Header>();
|
||||
@@ -918,8 +918,8 @@ namespace ams::nxboot {
|
||||
if (void *sd_meso = ReadFile(std::addressof(meso_size), "sdmc:/atmosphere/mesosphere.bin"); sd_meso != nullptr) {
|
||||
std::memcpy(payload_data, sd_meso, meso_size);
|
||||
} else {
|
||||
meso_size = secondary_archive.header.meso_size;
|
||||
std::memcpy(payload_data, secondary_archive.mesosphere, meso_size);
|
||||
meso_size = external_package.header.meso_size;
|
||||
std::memcpy(payload_data, external_package.mesosphere, meso_size);
|
||||
}
|
||||
|
||||
/* Read emummc, if needed. */
|
||||
@@ -928,8 +928,8 @@ namespace ams::nxboot {
|
||||
if (emummc_enabled) {
|
||||
emummc = static_cast<const InitialProcessHeader *>(ReadFile(std::addressof(emummc_size), "sdmc:/atmosphere/emummc.kip"));
|
||||
if (emummc == nullptr) {
|
||||
emummc = reinterpret_cast<const InitialProcessHeader *>(secondary_archive.kips + secondary_archive.header.emummc_meta.offset);
|
||||
emummc_size = secondary_archive.header.emummc_meta.size;
|
||||
emummc = reinterpret_cast<const InitialProcessHeader *>(external_package.kips + external_package.header.emummc_meta.offset);
|
||||
emummc_size = external_package.header.emummc_meta.size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user