From 79d96bbdfdf385f27bf29c5dbacc0a5dc3149e8d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 27 May 2019 12:07:51 -0700 Subject: [PATCH] fusee/exo: add emunand configitem support --- exosphere/src/configitem.c | 3 +++ exosphere/src/configitem.h | 3 +++ exosphere/src/exocfg.c | 8 ++++++++ exosphere/src/exocfg.h | 13 +++++++++---- fusee/fusee-secondary/src/exocfg.h | 12 ++++++++---- fusee/fusee-secondary/src/nxboot.c | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/exosphere/src/configitem.c b/exosphere/src/configitem.c index b53421d6f..dc6cbf2dc 100644 --- a/exosphere/src/configitem.c +++ b/exosphere/src/configitem.c @@ -284,6 +284,9 @@ uint32_t configitem_get(bool privileged, ConfigItem item, uint64_t *p_outvalue) /* UNOFFICIAL: Gets whether this unit has the RCM bug patched. */ *p_outvalue = (int)(fuse_has_rcm_bug_patch());; break; + case CONFIGITEM_EMUNAND_CONFIG: + /* UNOFFICIAL: Gets configuration meta for emunand. */ + *p_outvalue = exosphere_get_emunand_config(); default: result = 2; break; diff --git a/exosphere/src/configitem.h b/exosphere/src/configitem.h index b9600c833..f727e87f0 100644 --- a/exosphere/src/configitem.h +++ b/exosphere/src/configitem.h @@ -45,6 +45,9 @@ typedef enum { CONFIGITEM_NEEDS_SHUTDOWN = 65002, CONFIGITEM_EXOSPHERE_VERHASH = 65003, CONFIGITEM_HAS_RCM_BUG_PATCH = 65004, + + /* These are unofficial, emunand-related. */ + CONFIGITEM_EMUNAND_CONFIG = 65100, } ConfigItem; #define REBOOT_KIND_NO_REBOOT 0 diff --git a/exosphere/src/exocfg.c b/exosphere/src/exocfg.c index 533de8beb..ad782b33d 100644 --- a/exosphere/src/exocfg.c +++ b/exosphere/src/exocfg.c @@ -83,3 +83,11 @@ unsigned int exosphere_should_disable_usermode_exception_handlers(void) { return EXOSPHERE_CHECK_FLAG(EXOSPHERE_FLAG_DISABLE_USERMODE_EXCEPTION_HANDLERS); } + +uint64_t exosphere_get_emunand_config(void) { + if (!g_has_loaded_config) { + generic_panic(); + } + + return g_exosphere_cfg.emunand_config; +} diff --git a/exosphere/src/exocfg.h b/exosphere/src/exocfg.h index ba53be403..d6a12eb22 100644 --- a/exosphere/src/exocfg.h +++ b/exosphere/src/exocfg.h @@ -42,12 +42,15 @@ #define EXOSPHERE_FLAGS_DEFAULT (EXOSPHERE_FLAG_IS_DEBUGMODE_PRIV) typedef struct { - unsigned int magic; - unsigned int target_firmware; - unsigned int flags; - unsigned int reserved; + uint32_t magic; + uint32_t target_firmware; + uint32_t flags; + uint32_t reserved; + uint64_t emunand_config; } exosphere_config_t; +_Static_assert(sizeof(exosphere_config_t) == 0x18, "exosphere config definition"); + unsigned int exosphere_load_config(void); unsigned int exosphere_get_target_firmware(void); unsigned int exosphere_should_perform_620_keygen(void); @@ -55,6 +58,8 @@ unsigned int exosphere_should_override_debugmode_priv(void); unsigned int exosphere_should_override_debugmode_user(void); unsigned int exosphere_should_disable_usermode_exception_handlers(void); +uint64_t exosphere_get_emunand_config(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_CONFIG) { diff --git a/fusee/fusee-secondary/src/exocfg.h b/fusee/fusee-secondary/src/exocfg.h index e8054ec9d..97e505cd7 100644 --- a/fusee/fusee-secondary/src/exocfg.h +++ b/fusee/fusee-secondary/src/exocfg.h @@ -17,6 +17,7 @@ #ifndef FUSEE_EXOSPHERE_CONFIG_H #define FUSEE_EXOSPHERE_CONFIG_H +#include #include /* This serves to set configuration for *exosphere itself*, separate from the SecMon Exosphere mimics. */ @@ -31,12 +32,15 @@ #define EXOSPHERE_FLAGS_DEFAULT (EXOSPHERE_FLAG_IS_DEBUGMODE_PRIV) typedef struct { - unsigned int magic; - unsigned int target_firmware; - unsigned int flags; - unsigned int reserved; + uint32_t magic; + uint32_t target_firmware; + uint32_t flags; + uint32_t reserved; + uint64_t emunand_config; } exosphere_config_t; +_Static_assert(sizeof(exosphere_config_t) == 0x18, "exosphere config definition"); + #define MAILBOX_EXOSPHERE_CONFIGURATION ((volatile exosphere_config_t *)(0x8000F000ull)) #define EXOSPHERE_TARGETFW_KEY "target_firmware" diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 4d775517c..3a33463ab 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -125,7 +125,7 @@ static int exosphere_ini_handler(void *user, const char *section, const char *na int tmp = 0; if (strcmp(section, "exosphere") == 0) { if (strcmp(name, EXOSPHERE_TARGETFW_KEY) == 0) { - sscanf(value, "%d", &exo_cfg->target_firmware); + sscanf(value, "%ld", &exo_cfg->target_firmware); } else if (strcmp(name, EXOSPHERE_DEBUGMODE_PRIV_KEY) == 0) { sscanf(value, "%d", &tmp); if (tmp) {