From 045f9b2f1561619ba693337b750c6dc1413f5f71 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 5 Sep 2021 15:45:40 -0700 Subject: [PATCH] fusee: fix buildsystem, rename secondary -> package3 --- .gitignore | 2 + Makefile | 37 ++++++-- fusee/Makefile | 44 +++++++++ .../split_bin.py => build_package3.py} | 94 +++++++++++-------- fusee/program/Makefile | 2 +- fusee/program/lz4_compress.py | 35 +++++++ ...archive.hpp => fusee_external_package.hpp} | 30 +++--- fusee/program/source/fusee_main.cpp | 45 +++++---- fusee/program/source/fusee_malloc.cpp | 1 - .../program/source/fusee_overlay_manager.cpp | 18 ++-- fusee/program/source/fusee_setup_horizon.cpp | 18 ++-- fusee/program/source/fusee_stratosphere.cpp | 22 ++--- .../source/amsmitm_initialization.cpp | 10 +- stratosphere/boot/Makefile | 12 +-- stratosphere/boot/source/boot_power_utils.cpp | 12 +-- .../pm/source/impl/pm_resource_manager.cpp | 3 +- 16 files changed, 246 insertions(+), 139 deletions(-) create mode 100644 fusee/Makefile rename fusee/{program/split_bin.py => build_package3.py} (60%) create mode 100644 fusee/program/lz4_compress.py rename fusee/program/source/{fusee_secondary_archive.hpp => fusee_external_package.hpp} (71%) diff --git a/.gitignore b/.gitignore index fb9109d4e..c3a56e220 100644 --- a/.gitignore +++ b/.gitignore @@ -95,4 +95,6 @@ dkms.conf **/build_nintendo_nx_x64 **/build_nintendo_nx_x86 +package3 + stratosphere/test/ diff --git a/Makefile b/Makefile index cc6235e06..7a0a6afd9 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,26 @@ endif COMPONENTS := fusee stratosphere mesosphere exosphere thermosphere troposphere libraries all: $(COMPONENTS) + $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval MINORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MINOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval MICROVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MICRO\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval S_MAJORVER = $(shell grep 'define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval S_MINORVER = $(shell grep 'define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval S_MICROVER = $(shell grep 'define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + @python fusee/build_package3.py $(CURDIR) release $(AMSHASH) $(MAJORVER) $(MINORVER) $(MICROVER) 0 $(S_MAJORVER) $(S_MINORVER) $(S_MICROVER) 0 + @echo "Built package3!" thermosphere: $(MAKE) -C thermosphere all @@ -64,9 +84,9 @@ dist-no-debug: all mkdir -p atmosphere-$(AMSVER)/atmosphere/config mkdir -p atmosphere-$(AMSVER)/atmosphere/flags touch atmosphere-$(AMSVER)/atmosphere/flags/clean_stratosphere_for_0.19.0.flag - cp fusee/fusee-primary/fusee-primary.bin atmosphere-$(AMSVER)/atmosphere/reboot_payload.bin - cp fusee/fusee-secondary/fusee-secondary-experimental.bin atmosphere-$(AMSVER)/atmosphere/fusee-secondary.bin - cp config_templates/BCT.ini atmosphere-$(AMSVER)/atmosphere/config_templates/BCT.ini + cp fusee/fusee.bin atmosphere-$(AMSVER)/atmosphere/reboot_payload.bin + cp fusee/package3 atmosphere-$(AMSVER)/atmosphere/package3 + cp config_templates/stratosphere.ini atmosphere-$(AMSVER)/atmosphere/config_templates/stratosphere.ini cp config_templates/override_config.ini atmosphere-$(AMSVER)/atmosphere/config_templates/override_config.ini cp config_templates/system_settings.ini atmosphere-$(AMSVER)/atmosphere/config_templates/system_settings.ini cp config_templates/exosphere.ini atmosphere-$(AMSVER)/atmosphere/config_templates/exosphere.ini @@ -96,13 +116,10 @@ dist-no-debug: all cp troposphere/reboot_to_payload/reboot_to_payload.nro atmosphere-$(AMSVER)/switch/reboot_to_payload.nro cp troposphere/daybreak/daybreak.nro atmosphere-$(AMSVER)/switch/daybreak.nro cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../; - cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/atmosphere/fusee-secondary.bin - cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER)-WITHOUT_MESOSPHERE.zip ./*; cd ../; - rm -r atmosphere-$(AMSVER) + rm -rf atmosphere-$(AMSVER) mkdir out mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip - mv atmosphere-$(AMSVER)-WITHOUT_MESOSPHERE.zip out/atmosphere-$(AMSVER)-WITHOUT_MESOSPHERE.zip - cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin + cp fusee/fusee.bin out/fusee.bin dist: dist-no-debug $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ @@ -117,8 +134,8 @@ dist: dist-no-debug $(eval AMSVER = $(MAJORVER).$(MINORVER).$(MICROVER)-$(AMSREV)) rm -rf atmosphere-$(AMSVER)-debug mkdir atmosphere-$(AMSVER)-debug - cp fusee/fusee-primary/fusee-primary.elf atmosphere-$(AMSVER)-debug/fusee-primary.elf - cp fusee/fusee-secondary/fusee-secondary-experimental.elf atmosphere-$(AMSVER)-debug/fusee-secondary.elf + cp fusee/loader_stub/loader_stub.elf atmosphere-$(AMSVER)-debug/fusee-loader-stub.elf + cp fusee/program/program.elf atmosphere-$(AMSVER)-debug/fusee-program.elf cp exosphere/loader_stub/loader_stub.elf atmosphere-$(AMSVER)-debug/exosphere-loader-stub.elf cp exosphere/program/program.elf atmosphere-$(AMSVER)-debug/exosphere-program.elf cp exosphere/warmboot/warmboot.elf atmosphere-$(AMSVER)-debug/exosphere-warmboot.elf diff --git a/fusee/Makefile b/fusee/Makefile new file mode 100644 index 000000000..3656e7fee --- /dev/null +++ b/fusee/Makefile @@ -0,0 +1,44 @@ +ATMOSPHERE_BUILD_CONFIGS := +all: release + +define ATMOSPHERE_ADD_TARGET + +ATMOSPHERE_BUILD_CONFIGS += $(strip $1) + +$(strip $1): fusee$(strip $2).bin + +fusee$(strip $2).bin: loader_stub/loader_stub$(strip $2).bin + @cp loader_stub/loader_stub$(strip $2).bin fusee$(strip $2).bin + @echo "Built fusee$(strip $2).bin..." + +check_program_$(strip $1): + @$$(MAKE) -C program $(strip $1) + +loader_stub/loader_stub$(strip $2).bin: check_program_$(strip $1) + @$$(MAKE) -C loader_stub $(strip $1) + +clean-$(strip $1): clean-program-$(strip $1) clean-loader_stub-$(strip $1) + @rm -rf fusee$(strip $2).bin + +clean-program-$(strip $1): + @$$(MAKE) -C program clean-$(strip $1) + +clean-loader_stub-$(strip $1): + @$$(MAKE) -C loader_stub clean-$(strip $1) + +endef + +$(eval $(call ATMOSPHERE_ADD_TARGET, release, )) +$(eval $(call ATMOSPHERE_ADD_TARGET, debug, _debug)) +$(eval $(call ATMOSPHERE_ADD_TARGET, audit, _audit)) + +clean: clean-program clean-loader_stub + @rm -rf fusee*.bin package3* + +clean-program: + @$(MAKE) -C program clean + +clean-loader_stub: + @$(MAKE) -C loader_stub clean + +.PHONY: all clean clean-program clean-loader_stub $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),check_program_$(config) check_warmboot_$(strip $1) clean-$(config) clean-program-$(config) clean-loader_stub-$(config) clean-warmboot-$(config)) diff --git a/fusee/program/split_bin.py b/fusee/build_package3.py similarity index 60% rename from fusee/program/split_bin.py rename to fusee/build_package3.py index f2117c455..b66cde2e7 100644 --- a/fusee/program/split_bin.py +++ b/fusee/build_package3.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import sys, lz4, hashlib +import sys, lz4, hashlib, os from struct import unpack as up, pack as pk def lz4_compress(data): @@ -22,15 +22,15 @@ def get_overlay(program, i): KIP_NAMES = ['Loader', 'NCM', 'ProcessManager', 'sm', 'boot', 'spl', 'ams_mitm'] -def get_kips(): - emummc = read_file('../../../../emummc/emummc_unpacked.kip') - loader = read_file('../../../../stratosphere/loader/loader.kip') - ncm = read_file('../../../../stratosphere/ncm/ncm.kip') - pm = read_file('../../../../stratosphere/pm/pm.kip') - sm = read_file('../../../../stratosphere/sm/sm.kip') - boot = read_file('../../../../stratosphere/boot/boot.kip') - spl = read_file('../../../../stratosphere/spl/spl.kip') - ams_mitm = read_file('../../../../stratosphere/ams_mitm/ams_mitm.kip') +def get_kips(ams_dir): + emummc = read_file(os.path.join(ams_dir, 'emummc/emummc_unpacked.kip')) + loader = read_file(os.path.join(ams_dir, 'stratosphere/loader/loader.kip')) + ncm = read_file(os.path.join(ams_dir, 'stratosphere/ncm/ncm.kip')) + pm = read_file(os.path.join(ams_dir, 'stratosphere/pm/pm.kip')) + sm = read_file(os.path.join(ams_dir, 'stratosphere/sm/sm.kip')) + boot = read_file(os.path.join(ams_dir, 'stratosphere/boot/boot.kip')) + spl = read_file(os.path.join(ams_dir, 'stratosphere/spl/spl.kip')) + ams_mitm = read_file(os.path.join(ams_dir, 'stratosphere/ams_mitm/ams_mitm.kip')) return (emummc, { 'Loader' : loader, 'NCM' : ncm, @@ -49,7 +49,7 @@ def write_kip_meta(f, kip, ofs): # Write hash f.write(hashlib.sha256(kip).digest()) -def write_header(f, all_kips, meso_size): +def write_header(f, all_kips, meso_size, git_revision, major, minor, micro, relstep, s_major, s_minor, s_micro, s_relstep): # Unpack kips emummc, kips = all_kips # Write reserved0 (previously entrypoint) as infinite loop instruction. @@ -75,11 +75,11 @@ def write_header(f, all_kips, meso_size): # Write num_content_headers; f.write(pk('::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(0xC0000000); } + ALWAYS_INLINE const ExternalPackage &GetExternalPackage() { return *reinterpret_cast(0xC0000000); } } diff --git a/fusee/program/source/fusee_main.cpp b/fusee/program/source/fusee_main.cpp index 6dc15fbe2..e4a6b69ff 100644 --- a/fusee/program/source/fusee_main.cpp +++ b/fusee/program/source/fusee_main.cpp @@ -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(file_size) != SecondaryArchiveSize) { - ShowFatalError("fusee-secondary seems corrupted (size 0x%zx != 0x%zx)", static_cast(file_size), SecondaryArchiveSize); + if (static_cast(file_size) != ExternalPackageSize) { + ShowFatalError("package3 seems corrupted (size 0x%zx != 0x%zx)", static_cast(file_size), ExternalPackageSize); } } - void ReadFullSecondaryArchive() { + void ReadFullExternalPackage() { Result result; - if (R_FAILED((result = fs::ReadFile(g_archive_file, 0, const_cast(static_cast(std::addressof(GetSecondaryArchive()))), SecondaryArchiveSize)))) { - ShowFatalError("Failed to read %s!\n", SecondaryArchiveFilePath); + if (R_FAILED((result = fs::ReadFile(g_package_file, 0, const_cast(static_cast(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(); diff --git a/fusee/program/source/fusee_malloc.cpp b/fusee/program/source/fusee_malloc.cpp index d41fe2293..9211582ff 100644 --- a/fusee/program/source/fusee_malloc.cpp +++ b/fusee/program/source/fusee_malloc.cpp @@ -15,7 +15,6 @@ */ #include #include "fusee_malloc.hpp" -#include "fusee_secondary_archive.hpp" #include "fusee_fatal.hpp" namespace ams::nxboot { diff --git a/fusee/program/source/fusee_overlay_manager.cpp b/fusee/program/source/fusee_overlay_manager.cpp index a50a215e0..77f75ef12 100644 --- a/fusee/program/source/fusee_overlay_manager.cpp +++ b/fusee/program/source/fusee_overlay_manager.cpp @@ -15,7 +15,7 @@ */ #include #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(GetOverlayDestination())[-2]; - store_hash = reinterpret_cast(GetOverlayDestination())[(sizeof(SecondaryArchive{}.ovl_mtc_erista) / sizeof(u32)) - 1]; + store_hash = reinterpret_cast(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(GetOverlayDestination())[-1]; - store_hash = reinterpret_cast(GetOverlayDestination())[(sizeof(SecondaryArchive{}.ovl_mtc_mariko) / sizeof(u32)) - 1]; + store_hash = reinterpret_cast(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(GetSecondaryArchive().ovl_mtc_erista), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_erista)); */ + /* std::memcpy(const_cast(GetExternalPackage().ovl_mtc_erista), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_erista)); */ } else /* if (fuse::GetSocType() == fuse::SocType_Mariko) */ { - std::memcpy(const_cast(GetSecondaryArchive().ovl_mtc_mariko), GetOverlayDestination(), sizeof(SecondaryArchive{}.ovl_mtc_mariko) - 0x2000); + std::memcpy(const_cast(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(), 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); } } diff --git a/fusee/program/source/fusee_setup_horizon.cpp b/fusee/program/source/fusee_setup_horizon.cpp index dc469c684..d279e2f5c 100644 --- a/fusee/program/source/fusee_setup_horizon.cpp +++ b/fusee/program/source/fusee_setup_horizon.cpp @@ -16,7 +16,7 @@ #include #include #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(); - 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(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(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)); } } diff --git a/fusee/program/source/fusee_stratosphere.cpp b/fusee/program/source/fusee_stratosphere.cpp index c3f6edee9..4e061a764 100644 --- a/fusee/program/source/fusee_stratosphere.cpp +++ b/fusee/program/source/fusee_stratosphere.cpp @@ -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(secondary_archive.kips + meta.offset), std::addressof(meta.hash)); + AddInitialProcess(reinterpret_cast(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(); @@ -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(ReadFile(std::addressof(emummc_size), "sdmc:/atmosphere/emummc.kip")); if (emummc == nullptr) { - emummc = reinterpret_cast(secondary_archive.kips + secondary_archive.header.emummc_meta.offset); - emummc_size = secondary_archive.header.emummc_meta.size; + emummc = reinterpret_cast(external_package.kips + external_package.header.emummc_meta.offset); + emummc_size = external_package.header.emummc_meta.size; } } diff --git a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp index efc41d600..bb66550a6 100644 --- a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp @@ -64,9 +64,9 @@ namespace ams::mitm { /* Emummc file protection. */ FsFile g_emummc_file; - /* Maintain exclusive access to the fusee-secondary archive. */ + /* Maintain exclusive access to the fusee external package. */ FsFile g_stratosphere_file; - FsFile g_secondary_file; + FsFile g_package3_file; constexpr inline bool IsHexadecimal(const char *str) { while (*str) { @@ -134,12 +134,12 @@ namespace ams::mitm { /* NOTE: g_bis_key_file is intentionally not closed here. This prevents any other process from opening it. */ } - /* Open a reference to the fusee-secondary archive. */ - /* As upcoming/current atmosphere releases will contain more than one zip which users much choose between, */ + /* Open a reference to the fusee external package. */ + /* As upcoming/current atmosphere releases may contain more than one zip which users much choose between, */ /* maintaining an open reference prevents cleanly the issue of "automatic" updaters selecting the incorrect */ /* zip, and encourages good updating hygiene -- atmosphere should not be updated on SD while HOS is alive. */ { - R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_secondary_file), "/atmosphere/fusee-secondary.bin", ams::fs::OpenMode_Read)); + R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_package3_file), "/atmosphere/package3", ams::fs::OpenMode_Read)); R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_stratosphere_file), "/atmosphere/stratosphere.romfs", ams::fs::OpenMode_Read)); } } diff --git a/stratosphere/boot/Makefile b/stratosphere/boot/Makefile index 4775ea178..a944797aa 100644 --- a/stratosphere/boot/Makefile +++ b/stratosphere/boot/Makefile @@ -14,7 +14,7 @@ export OUTPUT := $(CURDIR)/$(TARGET) export TOPDIR := $(CURDIR) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) $(TOPDIR)/../../fusee/fusee-primary + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) $(TOPDIR)/../../fusee export DEPSDIR := $(CURDIR)/$(BUILD) @@ -22,7 +22,7 @@ CFILES := $(call FIND_SOURCE_FILES,$(SOURCES),c) CPPFILES := $(call FIND_SOURCE_FILES,$(SOURCES),cpp) SFILES := $(call FIND_SOURCE_FILES,$(SOURCES),s) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) fusee-primary.bin +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) fusee.bin #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C @@ -68,7 +68,7 @@ endif all: $(BUILD) check_fusee: - @$(MAKE) -C $(TOPDIR)/../../fusee/fusee-primary all + @$(MAKE) -C $(TOPDIR)/../../fusee release $(BUILD): check_fusee @[ -d $@ ] || mkdir -p $@ @@ -77,7 +77,7 @@ $(BUILD): check_fusee #--------------------------------------------------------------------------------- clean: @echo clean ... - @$(MAKE) -C $(TOPDIR)/../../fusee/fusee-primary clean + @$(MAKE) -C $(TOPDIR)/../../fusee clean @rm -fr $(BUILD) $(TARGET).kip $(TARGET).elf @@ -96,12 +96,12 @@ $(OUTPUT).kip : $(OUTPUT).elf $(OUTPUT).elf : $(OFILES) -boot_power_utils.o: fusee-primary.bin.o +boot_power_utils.o: fusee.bin.o #--------------------------------------------------------------------------------- # you need a rule like this for each extension you use as binary data #--------------------------------------------------------------------------------- -fusee-primary.bin.o: fusee-primary.bin +fusee.bin.o: fusee.bin #--------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) diff --git a/stratosphere/boot/source/boot_power_utils.cpp b/stratosphere/boot/source/boot_power_utils.cpp index b84ac8674..375c607ee 100644 --- a/stratosphere/boot/source/boot_power_utils.cpp +++ b/stratosphere/boot/source/boot_power_utils.cpp @@ -16,7 +16,7 @@ #include #include "boot_power_utils.hpp" #include "boot_pmic_driver.hpp" -#include "fusee-primary_bin.h" +#include "fusee_bin.h" namespace ams::boot { @@ -48,8 +48,8 @@ namespace ams::boot { ClearIram(); /* Copy in payload. */ - for (size_t ofs = 0; ofs < fusee_primary_bin_size; ofs += sizeof(g_work_page)) { - std::memcpy(g_work_page, &fusee_primary_bin[ofs], std::min(static_cast(fusee_primary_bin_size - ofs), sizeof(g_work_page))); + for (size_t ofs = 0; ofs < fusee_bin_size; ofs += sizeof(g_work_page)) { + std::memcpy(g_work_page, &fusee_bin[ofs], std::min(static_cast(fusee_bin_size - ofs), sizeof(g_work_page))); exosphere::CopyToIram(IramPayloadBase + ofs, g_work_page, sizeof(g_work_page)); } @@ -61,8 +61,8 @@ namespace ams::boot { ClearIram(); /* Copy in payload. */ - for (size_t ofs = 0; ofs < fusee_primary_bin_size; ofs += sizeof(g_work_page)) { - std::memcpy(g_work_page, &fusee_primary_bin[ofs], std::min(static_cast(fusee_primary_bin_size - ofs), sizeof(g_work_page))); + for (size_t ofs = 0; ofs < fusee_bin_size; ofs += sizeof(g_work_page)) { + std::memcpy(g_work_page, &fusee_bin[ofs], std::min(static_cast(fusee_bin_size - ofs), sizeof(g_work_page))); exosphere::CopyToIram(IramPayloadBase + ofs, g_work_page, sizeof(g_work_page)); } @@ -93,7 +93,7 @@ namespace ams::boot { } void SetInitialRebootPayload() { - ::ams::SetInitialRebootPayload(fusee_primary_bin, fusee_primary_bin_size); + ::ams::SetInitialRebootPayload(fusee_bin, fusee_bin_size); } void RebootForFatalError(ams::FatalErrorContext *ctx) { diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index 7ba5e0c90..7eca4f16d 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -271,8 +271,7 @@ namespace ams::pm::resource { /* Adjust memory limits for atmosphere. */ /* We take memory away from applet normally, but away from application on < 3.0.0 to avoid a rare hang on boot. */ - /* NOTE: On Version 5.0.0+, we cannot set the pools so simply. We must instead modify the kernel, which we do */ - /* via patches in fusee-secondary. */ + /* NOTE: On Version 5.0.0+, we cannot set the pools so simply. We must instead rely on mesosphere support. */ const size_t extra_memory_size = hos_version == hos::Version_5_0_0 ? ExtraSystemMemorySizeAtmosphere500 : ExtraSystemMemorySizeAtmosphere; const auto src_group = hos_version >= hos::Version_3_0_0 ? ResourceLimitGroup_Applet : ResourceLimitGroup_Application; for (size_t i = 0; i < spl::MemoryArrangement_Count; i++) {