From 5b417189db5c3bab5bf523bfbd832eca4763c462 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Sun, 9 Jul 2023 00:22:45 +0200 Subject: [PATCH] Remove "Use EmuNAND FIRM with R" option This is a leftover from the Gateway era that has long lost its utility and that unnecessarily complicated the code base. Please just load an external FIRM from SD card if you need something similar. Also refactor the multi-EmuNAND code and CTRNAND mounting code. --- arm9/data/config_template.ini | Bin 6777 -> 6256 bytes arm9/source/config.c | 38 +++------ arm9/source/config.h | 11 ++- arm9/source/crypto.c | 6 +- arm9/source/crypto.h | 2 +- arm9/source/emunand.c | 33 +++++--- arm9/source/emunand.h | 2 +- arm9/source/firm.c | 2 +- arm9/source/fs.c | 70 ++++++++++++----- arm9/source/fs.h | 5 +- arm9/source/main.c | 78 +++++++------------ arm9/source/types.h | 3 - arm9/source/utils.c | 3 + k11_extension/include/config.h | 9 +-- sysmodules/loader/source/patcher.c | 23 +----- sysmodules/loader/source/patcher.h | 9 +-- sysmodules/pm/source/luma.h | 9 +-- sysmodules/rosalina/data/config_template.ini | Bin 6777 -> 6256 bytes sysmodules/rosalina/include/luma_config.h | 1 - sysmodules/rosalina/source/luma_config.c | 7 +- 20 files changed, 145 insertions(+), 166 deletions(-) diff --git a/arm9/data/config_template.ini b/arm9/data/config_template.ini index 762a903761791cddda2d0071372f4bc53ceda1b3..0fb6b0a90d439679c85f843d9d74393c6dcb5ac2 100644 GIT binary patch delta 17 Ycmexq^1)!kH^$A$%(g6>Z8&U&07`TQl>h($ delta 518 zcmZ{hy-EW?6opw33oEhI=5|qtNd!9)47f@PBP0a2TV^wNox$0eWoI_aR(S|tM96Dd zSP6FCnN5fmcEg?ToO6FZN8i`)U(tG!18SBjw|6WbUeL> zMk)mv9^HgGaw<3hP9Qu?W=~-9@V2OM>F5`W+RN;K1kXfOjkMVR%e8VoHIUX`be?DpHxJ zRa#bPEp9%d$Ak4H%v&47?QWoMW!om 0, "wrong data size"); static const char *singleOptionIniNamesBoot[] = { "autoboot_emunand", - "use_emunand_firm_if_r_pressed", "enable_external_firm_and_modules", "enable_game_patching", "app_syscore_threads_on_core_2", @@ -642,10 +641,9 @@ static size_t saveLumaIniConfigToStr(char *out) lumaVerStr, lumaRevSuffixStr, (int)CONFIG_VERSIONMAJOR, (int)CONFIG_VERSIONMINOR, - (int)CONFIG(AUTOBOOTEMU), (int)CONFIG(USEEMUFIRM), - (int)CONFIG(LOADEXTFIRMSANDMODULES), (int)CONFIG(PATCHGAMES), - (int)CONFIG(REDIRECTAPPTHREADS), (int)CONFIG(PATCHVERSTRING), - (int)CONFIG(SHOWGBABOOT), + (int)CONFIG(AUTOBOOTEMU), (int)CONFIG(LOADEXTFIRMSANDMODULES), + (int)CONFIG(PATCHGAMES), (int)CONFIG(REDIRECTAPPTHREADS), + (int)CONFIG(PATCHVERSTRING), (int)CONFIG(SHOWGBABOOT), 1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS), splashPosStr, (unsigned int)cfg->splashDurationMsec, @@ -820,7 +818,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) }; static const char *singleOptionsText[] = { "( ) Autoboot EmuNAND", - "( ) Use EmuNAND FIRM if booting with R", "( ) Enable loading external FIRMs and modules", "( ) Enable game patching", "( ) Redirect app. syscore threads to core2", @@ -829,8 +826,9 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) }; static const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" - "It will be booted when no\n" - "directional pad buttons are pressed.", + "It will be booted when no directional\n" + "pad buttons are pressed (Up/Right/Down\n" + "/Left equal EmuNANDs 1/2/3/4).", "Select the screen brightness.", @@ -876,17 +874,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) "(Up/Right/Down/Left equal EmuNANDs\n" "1/2/3/4).", - "If enabled, when holding R on boot\n" - "SysNAND will be booted with an\n" - "EmuNAND FIRM.\n\n" - "Otherwise, an EmuNAND will be booted\n" - "with the SysNAND FIRM.\n\n" - "To use a different EmuNAND from the\n" - "default, hold a directional pad button\n" - "(Up/Right/Down/Left equal EmuNANDs\n" - "1/2/3/4), also add A if you have\n" - "a matching payload.", - "Enable loading external FIRMs and\n" "system modules.\n\n" "This isn't needed in most cases.\n\n" @@ -910,14 +897,10 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) "by about 10%. Can break some games\n" "and other applications.\n", - "Enable showing the current NAND/FIRM:\n\n" + "Enable showing the current NAND:\n\n" "\t* Sys = SysNAND\n" "\t* Emu = EmuNAND 1\n" - "\t* EmuX = EmuNAND X\n" - "\t* SysE = SysNAND with EmuNAND 1 FIRM\n" - "\t* SyEX = SysNAND with EmuNAND X FIRM\n" - "\t* EmuS = EmuNAND 1 with SysNAND FIRM\n" - "\t* EmXS = EmuNAND X with SysNAND FIRM\n\n" + "\t* EmuX = EmuNAND X\n\n" "or a user-defined custom string in\n" "System Settings.\n\n" "Refer to the wiki for instructions.", @@ -929,8 +912,10 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) FirmwareSource nandType = FIRMWARE_SYSNAND; if(isSdMode) { + // Check if there is at least one emuNAND + u32 emuIndex = 0; nandType = FIRMWARE_EMUNAND; - locateEmuNand(&nandType); + locateEmuNand(&nandType, &emuIndex, false); } struct multiOption { @@ -953,7 +938,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) bool enabled; bool visible; } singleOptions[] = { - { .visible = nandType == FIRMWARE_EMUNAND }, { .visible = nandType == FIRMWARE_EMUNAND }, { .visible = true }, { .visible = true }, diff --git a/arm9/source/config.h b/arm9/source/config.h index f7920db..aabdb5e 100644 --- a/arm9/source/config.h +++ b/arm9/source/config.h @@ -36,12 +36,12 @@ #define CONFIG_FILE "config.ini" #define CONFIG_VERSIONMAJOR 3 -#define CONFIG_VERSIONMINOR 7 +#define CONFIG_VERSIONMINOR 8 -#define BOOTCFG_NAND BOOTCONFIG(0, 7) -#define BOOTCFG_FIRM BOOTCONFIG(3, 7) -#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) -#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) +#define BOOTCFG_NAND BOOTCONFIG(0, 1) +#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3) +#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1) enum multiOptions { @@ -57,7 +57,6 @@ enum multiOptions enum singleOptions { AUTOBOOTEMU = 0, - USEEMUFIRM, LOADEXTFIRMSANDMODULES, PATCHGAMES, REDIRECTAPPTHREADS, diff --git a/arm9/source/crypto.c b/arm9/source/crypto.c index ce90847..a79c2d7 100755 --- a/arm9/source/crypto.c +++ b/arm9/source/crypto.c @@ -322,7 +322,7 @@ __attribute__((aligned(4))) static u8 nandCtr[AES_BLOCK_SIZE]; static u8 nandSlot; static u32 fatStart = 0; -FirmwareSource firmSource = FIRMWARE_SYSNAND; +FirmwareSource ctrNandLocation = FIRMWARE_SYSNAND; __attribute__((aligned(4))) static const u8 key1s[2][AES_BLOCK_SIZE] = { {0x07, 0x29, 0x44, 0x38, 0xF8, 0xC9, 0x75, 0x93, 0xAA, 0x0E, 0x4A, 0xB4, 0xAE, 0x84, 0xC1, 0xD8}, @@ -348,7 +348,7 @@ int ctrNandInit(void) u8 __attribute__((aligned(4))) temp[0x200]; //Read NCSD header - result = firmSource == FIRMWARE_SYSNAND ? sdmmc_nand_readsectors(0, 1, temp) : sdmmc_sdcard_readsectors(emuOffset + emuHeader, 1, temp); + result = ctrNandLocation == FIRMWARE_SYSNAND ? sdmmc_nand_readsectors(0, 1, temp) : sdmmc_sdcard_readsectors(emuOffset + emuHeader, 1, temp); if(!result) { @@ -375,7 +375,7 @@ int ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf) //Read int result; - if(firmSource == FIRMWARE_SYSNAND) + if(ctrNandLocation == FIRMWARE_SYSNAND) result = sdmmc_nand_readsectors(sector + fatStart, sectorCount, outbuf); else { diff --git a/arm9/source/crypto.h b/arm9/source/crypto.h index ea74496..57806ec 100755 --- a/arm9/source/crypto.h +++ b/arm9/source/crypto.h @@ -110,7 +110,7 @@ #define SHA_224_HASH_SIZE (224 / 8) #define SHA_1_HASH_SIZE (160 / 8) -extern FirmwareSource firmSource; +extern FirmwareSource ctrNandLocation; void sha(void *res, const void *src, u32 size, u32 mode); diff --git a/arm9/source/emunand.c b/arm9/source/emunand.c index fa0f380..0032424 100644 --- a/arm9/source/emunand.c +++ b/arm9/source/emunand.c @@ -38,7 +38,7 @@ u32 emuOffset, emuHeader; -void locateEmuNand(FirmwareSource *nandType) +void locateEmuNand(FirmwareSource *nandType, u32 *emunandIndex, bool configureCtrNandParams) { static u8 __attribute__((aligned(4))) temp[0x200]; static u32 nandSize = 0, @@ -51,7 +51,10 @@ void locateEmuNand(FirmwareSource *nandType) fatStart = *(u32 *)(temp + 0x1C6); //First sector of the FAT partition } - for(u32 i = 0; i < 3; i++) + /*if (*nandType == FIRMWARE_SYSNAND) + return;*/ + + for(u32 i = 0; i < 3; i++) // Test the different kinds of multi-EmuNAND there are, unless we are looking for the first one { static const u32 roundedMinsizes[] = {0x1D8000, 0x26E000}; @@ -65,39 +68,45 @@ void locateEmuNand(FirmwareSource *nandType) nandOffset = roundedMinsizes[ISN3DS ? 1 : 0]; //"Minsize" layout break; case 0: - nandOffset = *nandType == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout + nandOffset = nandSize > 0x200000 ? 0x400000 : 0x200000; //"Legacy" layout break; } - if(*nandType != FIRMWARE_EMUNAND) nandOffset *= ((u32)*nandType - 1); + nandOffset *= *emunandIndex; // always 0 for 1st EmuNAND if(fatStart >= nandOffset + roundedMinsizes[ISN3DS ? 1 : 0]) { //Check for RedNAND if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0) { - emuOffset = nandOffset + 1; - emuHeader = 0; + if (configureCtrNandParams) + { + emuOffset = nandOffset + 1; + emuHeader = 0; + } return; } //Check for Gateway EmuNAND else if(i != 2 && !sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0) { - emuOffset = nandOffset; - emuHeader = nandSize; + if (configureCtrNandParams) + { + emuOffset = nandOffset; + emuHeader = nandSize; + } return; } } - if(*nandType == FIRMWARE_EMUNAND) break; + if(*emunandIndex == 0) break; // See above comments } //Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any - if(*nandType != FIRMWARE_EMUNAND) + if(*emunandIndex != 0) { - *nandType = FIRMWARE_EMUNAND; - locateEmuNand(nandType); + *emunandIndex = 0; + locateEmuNand(nandType, emunandIndex, configureCtrNandParams); } else *nandType = FIRMWARE_SYSNAND; } diff --git a/arm9/source/emunand.h b/arm9/source/emunand.h index 58941ca..369baab 100644 --- a/arm9/source/emunand.h +++ b/arm9/source/emunand.h @@ -37,5 +37,5 @@ extern u32 emuOffset, emuHeader; -void locateEmuNand(FirmwareSource *nandType); +void locateEmuNand(FirmwareSource *nandType, u32 *emunandIndex, bool configureCtrNandParams); u32 patchEmuNand(u8 *arm9Section, u32 kernel9Size, u8 *process9Offset, u32 process9Size, u8 *kernel9Address, u32 firmVersion); diff --git a/arm9/source/firm.c b/arm9/source/firm.c index 4bd15b3..2829a8b 100755 --- a/arm9/source/firm.c +++ b/arm9/source/firm.c @@ -154,7 +154,7 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadF u32 firmVersion = 0xFFFFFFFF, firmSize; - bool ctrNandError = isSdMode && !mountFs(false, false); + bool ctrNandError = isSdMode && !remountCtrNandPartition(false); if(!ctrNandError) { diff --git a/arm9/source/fs.c b/arm9/source/fs.c index ed73187..0a3dd1f 100644 --- a/arm9/source/fs.c +++ b/arm9/source/fs.c @@ -58,21 +58,40 @@ static bool switchToMainDir(bool isSd) } } -bool mountFs(bool isSd, bool switchToCtrNand) +bool mountSdCardPartition(bool switchMainDir) { - static bool sdInitialized = false, nandInitialized = false; - if (isSd) + static bool sdInitialized = false; + if (!sdInitialized) + sdInitialized = f_mount(&sdFs, "sdmc:", 1) == FR_OK; + + if (sdInitialized && switchMainDir) + return f_chdrive("sdmc:") == FR_OK && switchToMainDir(true); + return sdInitialized; +} + +bool remountCtrNandPartition(bool switchMainDir) +{ + static bool nandInitialized = false; + + if (nandInitialized) { - if (!sdInitialized) - sdInitialized = f_mount(&sdFs, "sdmc:", 1) == FR_OK; - return sdInitialized && switchToMainDir(true); - } - else - { - if (!nandInitialized) - nandInitialized = f_mount(&nandFs, "nand:", 1) == FR_OK; - return nandInitialized && (!switchToCtrNand || (f_chdrive("nand:") == FR_OK && switchToMainDir(false))); + if (f_unmount("nand:") != FR_OK) + return false; + nandInitialized = false; } + + if (!nandInitialized) + nandInitialized = f_mount(&nandFs, "nand:", 1) == FR_OK; + + if (nandInitialized && switchMainDir) + return f_chdrive("nand:") == FR_OK && switchToMainDir(false); + return nandInitialized; +} + +void unmountPartitions(void) +{ + f_unmount("nand:"); + f_unmount("sdmc:"); } u32 fileRead(void *dest, const char *path, u32 maxSize) @@ -412,8 +431,7 @@ static bool backupEssentialFiles(void) { size_t sz = sizeof(fileCopyBuffer); - bool ok = !(isSdMode && !mountFs(false, false)); - + bool ok = true; ok = ok && fileCopy("nand:/ro/sys/HWCAL0.dat", "backups/HWCAL0.dat", false, fileCopyBuffer, sz); ok = ok && fileCopy("nand:/ro/sys/HWCAL1.dat", "backups/HWCAL1.dat", false, fileCopyBuffer, sz); @@ -454,10 +472,19 @@ static bool backupEssentialFiles(void) bool doLumaUpgradeProcess(void) { - // Ensure CTRNAND is mounted - bool ok = mountFs(false, false), ok2 = true; - if (!ok) - return false; + FirmwareSource oldCtrNandLocation = ctrNandLocation; + bool ok = true, ok2 = true, ok3 = true; + + // Ensure SysNAND CTRNAND is mounted + if (isSdMode) + { + ctrNandLocation = FIRMWARE_SYSNAND; + if (!remountCtrNandPartition(false)) + { + ctrNandLocation = oldCtrNandLocation; + return false; + } + } // Try to boot.firm to CTRNAND, when applicable if (isSdMode && memcmp(launchedPathForFatfs, "sdmc:", 5) == 0) @@ -470,5 +497,10 @@ bool doLumaUpgradeProcess(void) fileDelete("sdmc:/luma/config.bin"); fileDelete("nand:/rw/luma/config.bin"); - return ok && ok2; + if (isSdMode) + { + ctrNandLocation = oldCtrNandLocation; + ok3 = remountCtrNandPartition(false); + } + return ok && ok2 && ok3; } diff --git a/arm9/source/fs.h b/arm9/source/fs.h index 477432c..0261a84 100644 --- a/arm9/source/fs.h +++ b/arm9/source/fs.h @@ -30,7 +30,10 @@ #define PATTERN(a) a "_*.firm" -bool mountFs(bool isSd, bool switchToCtrNand); +bool mountSdCardPartition(bool switchMainDir); +bool remountCtrNandPartition(bool switchMainDir); +void unmountPartitions(void); + u32 fileRead(void *dest, const char *path, u32 maxSize); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); diff --git a/arm9/source/main.c b/arm9/source/main.c index dd3ccbe..248bbff 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -45,7 +45,6 @@ extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[] extern CfgData configData; extern ConfigurationStatus needConfig; -extern FirmwareSource firmSource; bool isSdMode; char launchedPathForFatfs[256]; @@ -57,14 +56,16 @@ u8 mcuConsoleInfo[9]; void main(int argc, char **argv, u32 magicWord) { - bool isFirmProtEnabled, + bool isFirmProtEnabled = true, isSafeMode = false, needToInitSd = false, isNoForceFlagSet = false, isInvalidLoader = false, - isNtrBoot; - FirmwareType firmType; - FirmwareSource nandType; + isNtrBoot = false; + FirmwareType firmType = NATIVE_FIRM; + FirmwareSource nandType = FIRMWARE_SYSNAND; + u32 emunandIndex = 0; + const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C; const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010; u32 firmlaunchTidLow = 0; @@ -145,18 +146,18 @@ void main(int argc, char **argv, u32 magicWord) if(memcmp(launchedPath, u"sdmc", 8) == 0) { - if(!mountFs(true, false)) error("Failed to mount SD."); + if(!mountSdCardPartition(true)) error("Failed to mount SD."); isSdMode = true; } else if(memcmp(launchedPath, u"nand", 8) == 0) { - if(!mountFs(false, true)) error("Failed to mount CTRNAND."); + if(!remountCtrNandPartition(true)) error("Failed to mount CTRNAND."); isSdMode = false; } else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0) { - if(mountFs(true, false)) isSdMode = true; - else if(mountFs(false, true)) isSdMode = false; + if(mountSdCardPartition(true)) isSdMode = true; + else if(remountCtrNandPartition(true)) isSdMode = false; else error("Failed to mount SD and CTRNAND."); if(bootType == NTR) @@ -202,7 +203,7 @@ void main(int argc, char **argv, u32 magicWord) } nandType = (FirmwareSource)BOOTCFG_NAND; - firmSource = (FirmwareSource)BOOTCFG_FIRM; + emunandIndex = BOOTCFG_EMUINDEX; isFirmProtEnabled = !BOOTCFG_NTRCARDBOOT; goto boot; @@ -227,13 +228,12 @@ void main(int argc, char **argv, u32 magicWord) if(bootenv == 7) { nandType = FIRMWARE_SYSNAND; - firmSource = (BOOTCFG_NAND != 0) == (BOOTCFG_FIRM != 0) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM; // Prevent multiple boot options-forcing // This bit is a bit weird. Basically, as you return to Home Menu by pressing either // the HOME or POWER button, nandType will be overridden to "SysNAND" (needed). But, // if you reboot again (e.g. via Rosalina menu), it'll use your default settings. - if(nandType != BOOTCFG_NAND || firmSource != BOOTCFG_FIRM) isNoForceFlagSet = true; + if(nandType != BOOTCFG_NAND) isNoForceFlagSet = true; goto boot; } @@ -247,7 +247,7 @@ void main(int argc, char **argv, u32 magicWord) if(validTlnc || !(pressed || BOOTCFG_NOFORCEFLAG)) { nandType = (FirmwareSource)BOOTCFG_NAND; - firmSource = (FirmwareSource)BOOTCFG_FIRM; + emunandIndex = BOOTCFG_EMUINDEX; goto boot; } @@ -280,7 +280,6 @@ void main(int argc, char **argv, u32 magicWord) if(!CFG_BOOTENV && pressed == SAFE_MODE) { nandType = FIRMWARE_SYSNAND; - firmSource = FIRMWARE_SYSNAND; isSafeMode = true; needToInitSd = true; @@ -308,7 +307,6 @@ void main(int argc, char **argv, u32 magicWord) if(!CFG_BOOTENV && pressed == SAFE_MODE) { nandType = FIRMWARE_SYSNAND; - firmSource = FIRMWARE_SYSNAND; isSafeMode = true; needToInitSd = true; @@ -322,51 +320,29 @@ void main(int argc, char **argv, u32 magicWord) //If booting from CTRNAND, always use SysNAND if(!isSdMode) nandType = FIRMWARE_SYSNAND; - - //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one - else if(pressed & BUTTON_R1) - { - if(CONFIG(USEEMUFIRM)) - { - nandType = FIRMWARE_SYSNAND; - firmSource = FIRMWARE_EMUNAND; - } - else - { - nandType = FIRMWARE_EMUNAND; - firmSource = FIRMWARE_SYSNAND; - } - } - - /* Else, boot the NAND the user set to autoboot or the opposite one, depending on L, - with their own FIRM */ - else firmSource = nandType = (autoBootEmu == ((pressed & BUTTON_L1) == BUTTON_L1)) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND; + else nandType = (autoBootEmu == ((pressed & BUTTON_L1) == BUTTON_L1)) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND; //If we're booting EmuNAND or using EmuNAND FIRM, determine which one from the directional pad buttons, or otherwise from the config - if(nandType == FIRMWARE_EMUNAND || firmSource == FIRMWARE_EMUNAND) + if(nandType == FIRMWARE_EMUNAND) { - FirmwareSource tempNand; switch(pressed & DPAD_BUTTONS) { case BUTTON_UP: - tempNand = FIRMWARE_EMUNAND; + emunandIndex = 0; break; case BUTTON_RIGHT: - tempNand = FIRMWARE_EMUNAND2; + emunandIndex = 1; break; case BUTTON_DOWN: - tempNand = FIRMWARE_EMUNAND3; + emunandIndex = 2; break; case BUTTON_LEFT: - tempNand = FIRMWARE_EMUNAND4; + emunandIndex = 3; break; default: - tempNand = (FirmwareSource)(1 + MULTICONFIG(DEFAULTEMU)); + emunandIndex = MULTICONFIG(DEFAULTEMU); break; } - - if(nandType == FIRMWARE_EMUNAND) nandType = tempNand; - else firmSource = tempNand; } boot: @@ -374,24 +350,21 @@ boot: //If we need to boot EmuNAND, make sure it exists if(nandType != FIRMWARE_SYSNAND) { - locateEmuNand(&nandType); - if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND; - else if((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) //Make sure the SD card isn't write protected + locateEmuNand(&nandType, &emunandIndex, true); + if(nandType == FIRMWARE_EMUNAND && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) //Make sure the SD card isn't write protected error("The SD card is locked, EmuNAND can not be used.\nPlease turn the write protection switch off."); } - //Same if we're using EmuNAND as the FIRM source - else if(firmSource != FIRMWARE_SYSNAND) - locateEmuNand(&firmSource); + ctrNandLocation = nandType; // for CTRNAND partition if(bootType != FIRMLAUNCH) { - configData.bootConfig = ((bootType == NTR ? 1 : 0) << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType; + configData.bootConfig = ((bootType == NTR ? 1 : 0) << 4) | ((u32)isNoForceFlagSet << 3) | ((u32)emunandIndex << 1) | (u32)nandType; writeConfig(false); } bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES); - u32 firmVersion = loadNintendoFirm(&firmType, firmSource, loadFromStorage, isSafeMode); + u32 firmVersion = loadNintendoFirm(&firmType, nandType, loadFromStorage, isSafeMode); bool doUnitinfoPatch = CONFIG(PATCHUNITINFO); u32 res = 0; @@ -417,6 +390,7 @@ boot: if(res != 0) error("Failed to apply %u FIRM patch(es).", res); + unmountPartitions(); if(bootType != FIRMLAUNCH) deinitScreens(); launchFirm(0, NULL); } diff --git a/arm9/source/types.h b/arm9/source/types.h index 6c5c9b4..3f0ddde 100644 --- a/arm9/source/types.h +++ b/arm9/source/types.h @@ -122,9 +122,6 @@ typedef enum FirmwareSource { FIRMWARE_SYSNAND = 0, FIRMWARE_EMUNAND, - FIRMWARE_EMUNAND2, - FIRMWARE_EMUNAND3, - FIRMWARE_EMUNAND4 } FirmwareSource; typedef enum FirmwareType diff --git a/arm9/source/utils.c b/arm9/source/utils.c index e97bc29..d3e7aed 100644 --- a/arm9/source/utils.c +++ b/arm9/source/utils.c @@ -115,6 +115,9 @@ u32 waitInput(bool isMenu) void mcuPowerOff(void) { + // Unmount partitions + unmountPartitions(); + if(!needToSetupScreens) clearScreens(false); //Shutdown LCD diff --git a/k11_extension/include/config.h b/k11_extension/include/config.h index 205e7c4..87de174 100644 --- a/k11_extension/include/config.h +++ b/k11_extension/include/config.h @@ -9,10 +9,10 @@ #define MULTICONFIG(a) ((cfwInfo.multiConfig >> (2 * (a))) & 3) #define BOOTCONFIG(a, b) ((cfwInfo.bootConfig >> (a)) & (b)) -#define BOOTCFG_NAND BOOTCONFIG(0, 7) -#define BOOTCFG_FIRM BOOTCONFIG(3, 7) -#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) -#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) +#define BOOTCFG_NAND BOOTCONFIG(0, 1) +#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3) +#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1) enum multiOptions { @@ -28,7 +28,6 @@ enum multiOptions enum singleOptions { AUTOBOOTEMU = 0, - USEEMUFIRM, LOADEXTFIRMSANDMODULES, PATCHGAMES, REDIRECTAPPTHREADS, diff --git a/sysmodules/loader/source/patcher.c b/sysmodules/loader/source/patcher.c index ecefbbd..a7d0301 100644 --- a/sysmodules/loader/source/patcher.c +++ b/sysmodules/loader/source/patcher.c @@ -695,7 +695,7 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro && CONFIG(PATCHVERSTRING)) { static const u16 pattern[] = u"Ve"; - u16 *patch; + const u16 *patch; u32 patchSize = 0, currentNand = BOOTCFG_NAND; @@ -706,26 +706,9 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro else { patchSize = 8; - u32 currentFirm = BOOTCFG_FIRM; - static u16 *verStringsNands[] = { u" Sys", - u" Emu", - u"Emu2", - u"Emu3", - u"Emu4" }, - - *verStringsEmuSys[] = { u"EmuS", - u"Em2S", - u"Em3S", - u"Em4S" }, - - *verStringsSysEmu[] = { u"SysE", - u"SyE2", - u"SyE3", - u"SyE4" }; - - patch = (currentFirm != 0) == (currentNand != 0) ? verStringsNands[currentNand] : - (!currentNand ? verStringsSysEmu[currentFirm - 1] : verStringsEmuSys[currentNand - 1]); + static const u16 *const verStringNandEmu[] = { u" Emu", u"Emu2", u"Emu3", u"Emu4" }; + patch = currentNand == 0 ? u" Sys" : verStringNandEmu[BOOTCFG_EMUINDEX]; } //Patch Ver. string diff --git a/sysmodules/loader/source/patcher.h b/sysmodules/loader/source/patcher.h index 97d1375..9f125f0 100644 --- a/sysmodules/loader/source/patcher.h +++ b/sysmodules/loader/source/patcher.h @@ -12,10 +12,10 @@ #define MULTICONFIG(a) ((multiConfig >> (2 * (a))) & 3) #define BOOTCONFIG(a, b) ((bootConfig >> (a)) & (b)) -#define BOOTCFG_NAND BOOTCONFIG(0, 7) -#define BOOTCFG_FIRM BOOTCONFIG(3, 7) -#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) -#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) +#define BOOTCFG_NAND BOOTCONFIG(0, 1) +#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3) +#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1) enum multiOptions { @@ -31,7 +31,6 @@ enum multiOptions enum singleOptions { AUTOBOOTEMU = 0, - USEEMUFIRM, LOADEXTFIRMSANDMODULES, PATCHGAMES, REDIRECTAPPTHREADS, diff --git a/sysmodules/pm/source/luma.h b/sysmodules/pm/source/luma.h index d999a68..68c917a 100644 --- a/sysmodules/pm/source/luma.h +++ b/sysmodules/pm/source/luma.h @@ -6,10 +6,10 @@ #define MULTICONFIG(a) ((multiConfig >> (2 * (a))) & 3) #define BOOTCONFIG(a, b) ((bootConfig >> (a)) & (b)) -#define BOOTCFG_NAND BOOTCONFIG(0, 7) -#define BOOTCFG_FIRM BOOTCONFIG(3, 7) -#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) -#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) +#define BOOTCFG_NAND BOOTCONFIG(0, 1) +#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3) +#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1) enum multiOptions { @@ -25,7 +25,6 @@ enum multiOptions enum singleOptions { AUTOBOOTEMU = 0, - USEEMUFIRM, LOADEXTFIRMSANDMODULES, PATCHGAMES, REDIRECTAPPTHREADS, diff --git a/sysmodules/rosalina/data/config_template.ini b/sysmodules/rosalina/data/config_template.ini index 762a903761791cddda2d0071372f4bc53ceda1b3..0fb6b0a90d439679c85f843d9d74393c6dcb5ac2 100644 GIT binary patch delta 17 Ycmexq^1)!kH^$A$%(g6>Z8&U&07`TQl>h($ delta 518 zcmZ{hy-EW?6opw33oEhI=5|qtNd!9)47f@PBP0a2TV^wNox$0eWoI_aR(S|tM96Dd zSP6FCnN5fmcEg?ToO6FZN8i`)U(tG!18SBjw|6WbUeL> zMk)mv9^HgGaw<3hP9Qu?W=~-9@V2OM>F5`W+RN;K1kXfOjkMVR%e8VoHIUX`be?DpHxJ zRa#bPEp9%d$Ak4H%v&47?QWoMW!omformatVersionMajor, (int)cfg->formatVersionMinor, - (int)CONFIG(AUTOBOOTEMU), (int)CONFIG(USEEMUFIRM), - (int)CONFIG(LOADEXTFIRMSANDMODULES), (int)CONFIG(PATCHGAMES), - (int)CONFIG(REDIRECTAPPTHREADS), (int)CONFIG(PATCHVERSTRING), - (int)CONFIG(SHOWGBABOOT), + (int)CONFIG(AUTOBOOTEMU), (int)CONFIG(LOADEXTFIRMSANDMODULES), + (int)CONFIG(PATCHGAMES), (int)CONFIG(REDIRECTAPPTHREADS), + (int)CONFIG(PATCHVERSTRING), (int)CONFIG(SHOWGBABOOT), 1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS), splashPosStr, (unsigned int)cfg->splashDurationMsec,