From 3d6405be85bb3e97940a1b2e0723af491022de3c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 30 Jan 2019 13:53:16 -0800 Subject: [PATCH] exo: change config to its own static page This is necessary to support both pre-7.0.0 and 7.0.0... --- exosphere/src/exocfg.c | 12 ++---------- exosphere/src/exocfg.h | 15 +++++++-------- fusee/fusee-secondary/src/exocfg.h | 10 ++++------ fusee/fusee-secondary/src/nxboot.c | 2 +- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/exosphere/src/exocfg.c b/exosphere/src/exocfg.c index 08a929d7f..71b9cd3be 100644 --- a/exosphere/src/exocfg.c +++ b/exosphere/src/exocfg.c @@ -22,12 +22,7 @@ #include "mmu.h" #include "memory_map.h" -#define MAILBOX_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_NXBOOTLOADER_MAILBOX)) - -/* TODO: Should this be at a non-static location? */ -#define MAILBOX_EXOSPHERE_CONFIG (*((volatile exosphere_config_t *)(MAILBOX_BASE + 0xE40ULL))) - -static exosphere_config_t g_exosphere_cfg = {MAGIC_EXOSPHERE_BOOTCONFIG, ATMOSPHERE_TARGET_FIRMWARE_DEFAULT_FOR_DEBUG, EXOSPHERE_FLAGS_DEFAULT}; +static exosphere_config_t g_exosphere_cfg = {MAGIC_EXOSPHERE_CONFIG, ATMOSPHERE_TARGET_FIRMWARE_DEFAULT_FOR_DEBUG, EXOSPHERE_FLAGS_DEFAULT}; static bool g_has_loaded_config = false; #define EXOSPHERE_CHECK_FLAG(flag) ((g_exosphere_cfg.flags & flag) != 0) @@ -42,11 +37,8 @@ unsigned int exosphere_load_config(void) { const unsigned int magic = MAILBOX_EXOSPHERE_CONFIG.magic; - if (magic == MAGIC_EXOSPHERE_BOOTCONFIG) { + if (magic == MAGIC_EXOSPHERE_CONFIG) { g_exosphere_cfg = MAILBOX_EXOSPHERE_CONFIG; - } else if (magic == MAGIC_EXOSPHERE_BOOTCONFIG_0) { - g_exosphere_cfg = MAILBOX_EXOSPHERE_CONFIG; - g_exosphere_cfg.flags = EXOSPHERE_FLAGS_DEFAULT; } return g_exosphere_cfg.target_firmware; diff --git a/exosphere/src/exocfg.h b/exosphere/src/exocfg.h index 2f41c6cf1..a2c2580e7 100644 --- a/exosphere/src/exocfg.h +++ b/exosphere/src/exocfg.h @@ -25,17 +25,15 @@ /* This serves to set configuration for *exosphere itself*, separate from the SecMon Exosphere mimics. */ -/* "XBC0" */ -#define MAGIC_EXOSPHERE_BOOTCONFIG_0 (0x30434258) -/* "XBC1" */ -#define MAGIC_EXOSPHERE_BOOTCONFIG (0x31434258) +/* "EXO0" */ +#define MAGIC_EXOSPHERE_CONFIG (0x304F5845) #define EXOSPHERE_LOOSEN_PACKAGE2_RESTRICTIONS_FOR_DEBUG 1 -#define MAILBOX_BASE_PHYS (MMIO_GET_DEVICE_PA(MMIO_DEVID_NXBOOTLOADER_MAILBOX)) +#define MAILBOX_EXOSPHERE_CONFIG (*((volatile exosphere_config_t *)(0x8000F000ull))) -/* TODO: Should this be at a non-static location? */ -#define MAILBOX_EXOSPHERE_CONFIG_PHYS (*((volatile exosphere_config_t *)(MAILBOX_BASE_PHYS + 0xE40ULL))) +/* Exosphere config in DRAM shares physical/virtual mapping. */ +#define MAILBOX_EXOSPHERE_CONFIG_PHYS MAILBOX_EXOSPHERE_CONFIG #define EXOSPHERE_FLAGS_DEFAULT 0x00000000 #define EXOSPHERE_FLAG_PERFORM_620_KEYGEN (1 << 0u) @@ -46,6 +44,7 @@ typedef struct { unsigned int magic; unsigned int target_firmware; unsigned int flags; + unsigned int reserved; } exosphere_config_t; unsigned int exosphere_load_config(void); @@ -56,7 +55,7 @@ unsigned int exosphere_should_override_debugmode_user(void); static inline unsigned int exosphere_get_target_firmware_for_init(void) { const unsigned int magic = MAILBOX_EXOSPHERE_CONFIG_PHYS.magic; - if (magic == MAGIC_EXOSPHERE_BOOTCONFIG || magic == MAGIC_EXOSPHERE_BOOTCONFIG_0) { + if (magic == MAGIC_EXOSPHERE_CONFIG) { return MAILBOX_EXOSPHERE_CONFIG_PHYS.target_firmware; } else { return ATMOSPHERE_TARGET_FIRMWARE_DEFAULT_FOR_DEBUG; diff --git a/fusee/fusee-secondary/src/exocfg.h b/fusee/fusee-secondary/src/exocfg.h index 55c8d12c5..72c9e89dd 100644 --- a/fusee/fusee-secondary/src/exocfg.h +++ b/fusee/fusee-secondary/src/exocfg.h @@ -21,11 +21,8 @@ /* This serves to set configuration for *exosphere itself*, separate from the SecMon Exosphere mimics. */ -/* "XBC0" */ -#define MAGIC_EXOSPHERE_BOOTCONFIG_0 (0x30434258) -/* "XBC1" */ -#define MAGIC_EXOSPHERE_BOOTCONFIG (0x31434258) - +/* "EXO0" */ +#define MAGIC_EXOSPHERE_CONFIG (0x304F5845) #define EXOSPHERE_FLAGS_DEFAULT 0x00000000 #define EXOSPHERE_FLAG_PERFORM_620_KEYGEN (1 << 0u) @@ -36,9 +33,10 @@ typedef struct { unsigned int magic; unsigned int target_firmware; unsigned int flags; + unsigned int reserved; } exosphere_config_t; -#define MAILBOX_EXOSPHERE_CONFIGURATION ((volatile exosphere_config_t *)(0x40002E40)) +#define MAILBOX_EXOSPHERE_CONFIGURATION ((volatile exosphere_config_t *)(0x8000F000ull)) #define EXOSPHERE_TARGETFW_KEY "target_firmware" #define EXOSPHERE_DEBUGMODE_PRIV_KEY "debugmode" diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 18697e75a..6a64c38c1 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -174,7 +174,7 @@ static uint32_t nxboot_get_target_firmware(const void *package1loader) { static void nxboot_configure_exosphere(uint32_t target_firmware, unsigned int keygen_type) { exosphere_config_t exo_cfg = {0}; - exo_cfg.magic = MAGIC_EXOSPHERE_BOOTCONFIG; + exo_cfg.magic = MAGIC_EXOSPHERE_CONFIG; exo_cfg.target_firmware = target_firmware; if (keygen_type) { exo_cfg.flags = EXOSPHERE_FLAGS_DEFAULT | EXOSPHERE_FLAG_PERFORM_620_KEYGEN;