From 1047ceab983f2628adefc469a6a4ecb7e505d058 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 12 Jun 2020 01:29:54 -0700 Subject: [PATCH] exo2/fusee: full 1.0.0 support. --- .../program/source/smc/secmon_smc_handler.cpp | 6 +++--- .../source/smc/secmon_smc_power_management.cpp | 4 +++- fusee/fusee-secondary/src/nxboot.c | 18 ++++++------------ fusee/fusee-secondary/src/nxboot.h | 12 +++++------- fusee/fusee-secondary/src/nxboot_iram.c | 18 ++++-------------- 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/exosphere/program/source/smc/secmon_smc_handler.cpp b/exosphere/program/source/smc/secmon_smc_handler.cpp index a3cc7929c..005a4f8a3 100644 --- a/exosphere/program/source/smc/secmon_smc_handler.cpp +++ b/exosphere/program/source/smc/secmon_smc_handler.cpp @@ -124,11 +124,11 @@ namespace ams::secmon::smc { /* Deprecated handlerss. */ constexpr inline const HandlerInfo DecryptAndImportEsDeviceKeyHandlerInfo = { - 0xC300100C, Restriction_DeviceUniqueDataNotAllowed, SmcDecryptAndImportEsDeviceKey + 0xC300100C, Restriction_Normal, SmcDecryptAndImportEsDeviceKey }; constexpr inline const HandlerInfo DecryptAndImportLotusKeyHandlerInfo = { - 0xC300100E, Restriction_DeviceUniqueDataNotAllowed, SmcDecryptAndImportLotusKey + 0xC300100E, Restriction_SafeModeNotAllowed, SmcDecryptAndImportLotusKey }; constinit HandlerInfo g_kern_handlers[] = { @@ -231,7 +231,7 @@ namespace ams::secmon::smc { SmcResult InvokeSmcHandler(const HandlerInfo &info, SmcArguments &args) { /* Check if the smc is restricted. */ - if (AMS_UNLIKELY(IsHandlerRestricted(info))) { + if (GetTargetFirmware() >= TargetFirmware_4_0_0 && AMS_UNLIKELY(IsHandlerRestricted(info))) { return SmcResult::NotPermitted; } diff --git a/exosphere/program/source/smc/secmon_smc_power_management.cpp b/exosphere/program/source/smc/secmon_smc_power_management.cpp index 97bb80399..66251b42e 100644 --- a/exosphere/program/source/smc/secmon_smc_power_management.cpp +++ b/exosphere/program/source/smc/secmon_smc_power_management.cpp @@ -348,7 +348,9 @@ namespace ams::secmon::smc { SaveSecureContext(); /* Load and start the sc7 firmware on the bpmp. */ - LoadAndStartSc7BpmpFirmware(); + if (GetTargetFirmware() >= TargetFirmware_2_0_0) { + LoadAndStartSc7BpmpFirmware(); + } /* Log our suspension. */ /* NOTE: Nintendo only does this on dev, but we will always do it. */ diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 6a87a34f1..c89127b04 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -598,8 +598,8 @@ static void nxboot_move_bootconfig() { fclose(bcfile); /* Select the actual BootConfig size and destination address. */ - bootconfig_addr = (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware < ATMOSPHERE_TARGET_FIRMWARE_6_0_0) ? 0x4003D000 : 0x4003F800; - bootconfig_size = (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware < ATMOSPHERE_TARGET_FIRMWARE_4_0_0) ? 0x3000 : 0x1000; + bootconfig_addr = 0x4003F800; + bootconfig_size = 0x800; /* Copy the BootConfig into IRAM. */ memset((void *)bootconfig_addr, 0, bootconfig_size); @@ -870,7 +870,9 @@ uint32_t nxboot_main(void) { /* Initialize Boot Reason on older firmware versions. */ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_4_0_0) { print(SCREEN_LOG_LEVEL_INFO, "[NXBOOT] Initializing Boot Reason...\n"); - nxboot_set_bootreason((void *)MAILBOX_NX_BOOTLOADER_BOOT_REASON_BASE(target_firmware)); + nxboot_set_bootreason((void *)MAILBOX_NX_BOOTLOADER_BOOT_REASON_BASE); + } else { + memset((void *)MAILBOX_NX_BOOTLOADER_BOOT_REASON_BASE, 0, 0x200); } /* Read the warmboot firmware from a file, otherwise from Atmosphere's implementation. */ @@ -919,15 +921,7 @@ uint32_t nxboot_main(void) { } /* Select the right address for the warmboot firmware. */ - if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware < ATMOSPHERE_TARGET_FIRMWARE_4_0_0) { - warmboot_memaddr = (void *)0x8000D000; - } else if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware < ATMOSPHERE_TARGET_FIRMWARE_6_0_0) { - warmboot_memaddr = (void *)0x4003B000; - } else if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware < ATMOSPHERE_TARGET_FIRMWARE_7_0_0) { - warmboot_memaddr = (void *)0x4003D800; - } else { - warmboot_memaddr = (void *)0x4003E000; - } + warmboot_memaddr = (void *)0x4003E000; print(SCREEN_LOG_LEVEL_INFO, "[NXBOOT] Copying warmboot firmware...\n"); diff --git a/fusee/fusee-secondary/src/nxboot.h b/fusee/fusee-secondary/src/nxboot.h index 8d007b1f9..ebcc878b3 100644 --- a/fusee/fusee-secondary/src/nxboot.h +++ b/fusee/fusee-secondary/src/nxboot.h @@ -33,14 +33,12 @@ typedef struct { char nintendo_path[0x80]; } emummc_config_t; -#define MAILBOX_NX_BOOTLOADER_BASE_100_620 0x40002E00 -#define MAILBOX_NX_BOOTLOADER_BASE_700 0x40000000 -#define MAILBOX_NX_BOOTLOADER_BASE(targetfw) (MAILBOX_NX_BOOTLOADER_BASE_700) -#define MAKE_MAILBOX_NX_BOOTLOADER_REG(targetfw, n) MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE(targetfw) + n) +#define MAILBOX_NX_BOOTLOADER_BASE 0x40000000 +#define MAKE_MAILBOX_NX_BOOTLOADER_REG(n) MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE + n) -#define MAILBOX_NX_BOOTLOADER_BOOT_REASON_BASE(targetfw) (MAILBOX_NX_BOOTLOADER_BASE(targetfw) + 0x10) -#define MAILBOX_NX_BOOTLOADER_SETUP_STATE(targetfw) MAKE_MAILBOX_NX_BOOTLOADER_REG(targetfw, 0xF8) -#define MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE(targetfw) MAKE_MAILBOX_NX_BOOTLOADER_REG(targetfw, 0xFC) +#define MAILBOX_NX_BOOTLOADER_BOOT_REASON_BASE MAKE_MAILBOX_NX_BOOTLOADER_REG(0x10) +#define MAILBOX_NX_BOOTLOADER_SETUP_STATE MAKE_MAILBOX_NX_BOOTLOADER_REG(0xF8) +#define MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE MAKE_MAILBOX_NX_BOOTLOADER_REG(0xFC) #define NX_BOOTLOADER_STATE_INIT 0 #define NX_BOOTLOADER_STATE_MOVED_BOOTCONFIG 1 diff --git a/fusee/fusee-secondary/src/nxboot_iram.c b/fusee/fusee-secondary/src/nxboot_iram.c index 17df294c5..3fc9ff3d0 100644 --- a/fusee/fusee-secondary/src/nxboot_iram.c +++ b/fusee/fusee-secondary/src/nxboot_iram.c @@ -28,15 +28,9 @@ #include "sysreg.h" void nxboot_finish(uint32_t boot_memaddr) { - uint32_t target_firmware = MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware; - /* Boot up Exosphère. */ - MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE(target_firmware) = 0; - if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_4_0_0) { - MAILBOX_NX_BOOTLOADER_SETUP_STATE(target_firmware) = NX_BOOTLOADER_STATE_LOADED_PACKAGE2; - } else { - MAILBOX_NX_BOOTLOADER_SETUP_STATE(target_firmware) = NX_BOOTLOADER_STATE_DRAM_INITIALIZED_4X; - } + MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE = 0; + MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_DRAM_INITIALIZED_4X; /* Terminate the display. */ display_end(); @@ -58,16 +52,12 @@ void nxboot_finish(uint32_t boot_memaddr) { } /* Wait for Exosphère to wake up. */ - while (MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE(target_firmware) == 0) { + while (MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE == 0) { udelay(1); } /* Signal Exosphère. */ - if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_4_0_0) { - MAILBOX_NX_BOOTLOADER_SETUP_STATE(target_firmware) = NX_BOOTLOADER_STATE_FINISHED; - } else { - MAILBOX_NX_BOOTLOADER_SETUP_STATE(target_firmware) = NX_BOOTLOADER_STATE_FINISHED_4X; - } + MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_FINISHED_4X; /* Halt ourselves in waitevent state. */ while (1) {