diff --git a/common/defaults/BCT.ini b/common/defaults/BCT.ini index f98177b90..81d69e48e 100644 --- a/common/defaults/BCT.ini +++ b/common/defaults/BCT.ini @@ -9,4 +9,5 @@ debugmode = 0 debugmode_user = 0 [stratosphere] -nogc = 0 +; To force-enable nogc, add nogc = 1 +; To force-disable nogc, add nogc = 0 diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 87703c90b..e023e23fa 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -28,6 +28,7 @@ #include "mc.h" #include "se.h" #include "pmc.h" +#include "fuse.h" #include "i2c.h" #include "ips.h" #include "stratosphere.h" @@ -85,13 +86,13 @@ static int exosphere_ini_handler(void *user, const char *section, const char *na } static int stratosphere_ini_handler(void *user, const char *section, const char *name, const char *value) { + stratosphere_cfg_t *strat_cfg = (stratosphere_cfg_t *)user; int tmp = 0; if (strcmp(section, "stratosphere") == 0) { if (strcmp(name, STRATOSPHERE_NOGC_KEY) == 0) { + strat_cfg->has_nogc_config = true; sscanf(value, "%d", &tmp); - if (tmp) { - kip_patches_set_enable_nogc(); - } + strat_cfg->enable_nogc = tmp != 0; } else { return 0; } @@ -150,6 +151,25 @@ static void nxboot_configure_exosphere(uint32_t target_firmware, unsigned int ke *(MAILBOX_EXOSPHERE_CONFIGURATION) = exo_cfg; } +static void nxboot_configure_stratosphere(uint32_t target_firmware) { + stratosphere_cfg_t strat_cfg = {0}; + if (ini_parse_string(get_loader_ctx()->bct0, stratosphere_ini_handler, &strat_cfg) < 0) { + fatal_error("[NXBOOT]: Failed to parse BCT.ini!\n"); + } + + /* Enable NOGC patches if the user requested it, or if the user is booting into 4.0.0+ with 3.0.2- fuses. */ + if (strat_cfg.has_nogc_config) { + if (strat_cfg.enable_nogc) { + kip_patches_set_enable_nogc(); + } + } else { + /* Check if fuses are < 4.0.0, but firmware is >= 4.0.0 */ + if (target_firmware >= EXOSPHERE_TARGET_FIRMWARE_400 && !(fuse_get_reserved_odm(7) & ~0x0000000F)) { + kip_patches_set_enable_nogc(); + } + } +} + static void nxboot_set_bootreason() { boot_reason_t boot_reason = {0}; FILE *boot0; @@ -444,11 +464,11 @@ uint32_t nxboot_main(void) { } print(SCREEN_LOG_LEVEL_MANDATORY, "[NXBOOT]: Rebuilding package2...\n"); + + /* Parse stratosphere config. */ + nxboot_configure_stratosphere(MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware); /* Patch package2, adding Thermosphère + custom KIPs. */ - if (ini_parse_string(get_loader_ctx()->bct0, stratosphere_ini_handler, NULL) < 0) { - fatal_error("[NXBOOT]: Failed to parse BCT.ini!\n"); - } package2_rebuild_and_copy(package2, MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware); print(SCREEN_LOG_LEVEL_INFO, u8"[NXBOOT]: Reading Exosphère...\n"); diff --git a/fusee/fusee-secondary/src/stratosphere.h b/fusee/fusee-secondary/src/stratosphere.h index 58caae31f..127e62ad9 100644 --- a/fusee/fusee-secondary/src/stratosphere.h +++ b/fusee/fusee-secondary/src/stratosphere.h @@ -31,6 +31,10 @@ void stratosphere_free_ini1(void); ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, unsigned int num_inis); +typedef struct { + bool has_nogc_config; + bool enable_nogc; +} stratosphere_cfg_t; #define STRATOSPHERE_NOGC_KEY "nogc"