diff --git a/k11_extension/include/config.h b/k11_extension/include/config.h index cfe0485d..18f2bb8c 100644 --- a/k11_extension/include/config.h +++ b/k11_extension/include/config.h @@ -12,6 +12,7 @@ #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) #define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) enum multiOptions { diff --git a/source/config.c b/source/config.c index 077d3a95..7f315904 100644 --- a/source/config.c +++ b/source/config.c @@ -239,12 +239,14 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) initScreens(); - u32 endPos = drawFormattedString(true, 10, 10, COLOR_TITLE, "%s%s\n%s", CONFIG_TITLE, isNtrcardBoot ? "\nBooted from NTRCARD" : "", "Press A to select, START to save"); - endPos += SPACING_Y; + drawString(true, 10, 10, COLOR_TITLE, CONFIG_TITLE); + drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to save"); //Character to display a selected option char selected = 'x'; + u32 endPos = 10 + 2 * SPACING_Y; + //Display all the multiple choice options in white for(u32 i = 0; i < multiOptionsAmount; i++) { diff --git a/source/config.h b/source/config.h index de86c20a..730b269b 100644 --- a/source/config.h +++ b/source/config.h @@ -39,6 +39,7 @@ #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) #define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) enum multiOptions { diff --git a/source/firm.c b/source/firm.c index 07f03340..1ed58ff6 100755 --- a/source/firm.c +++ b/source/firm.c @@ -335,7 +335,7 @@ static inline void mergeSection0(FirmwareType firmType, u32 firmVersion, bool lo } } -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode, bool doUnitinfoPatch) +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool isSafeMode, bool doUnitinfoPatch) { u8 *arm9Section = (u8 *)firm + firm->section[2].offset, *arm11Section1 = (u8 *)firm + firm->section[1].offset; @@ -376,7 +376,7 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStora if(nandType != FIRMWARE_SYSNAND) ret += patchEmuNand(arm9Section, kernel9Size, process9Offset, process9Size, firm->section[2].address, firmVersion); //Apply FIRM0/1 writes patches on SysNAND to protect A9LH - else ret += patchFirmWrites(process9Offset, process9Size); + else if(isFirmProtEnabled) ret += patchFirmWrites(process9Offset, process9Size); //Apply firmlaunch patches ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr); diff --git a/source/firm.h b/source/firm.h index f9c7d38e..337c2e1b 100644 --- a/source/firm.h +++ b/source/firm.h @@ -31,7 +31,7 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode); void loadHomebrewFirm(u32 pressed); -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode, bool doUnitinfoPatch); +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool isSafeMode, bool doUnitinfoPatch); u32 patchTwlFirm(u32 firmVersion, bool loadFromStorage, bool doUnitinfoPatch); u32 patchAgbFirm(bool loadFromStorage, bool doUnitinfoPatch); u32 patch1x2xNativeAndSafeFirm(void); diff --git a/source/main.c b/source/main.c index ec4730c4..c96e8bba 100644 --- a/source/main.c +++ b/source/main.c @@ -43,21 +43,24 @@ extern ConfigurationStatus needConfig; extern FirmwareSource firmSource; bool isFirmlaunch = false, - isSdMode, - isNtrcardBoot; + isSdMode; u16 launchedPath[41]; void main(int argc, char **argv, u32 magicWord) { - bool isSafeMode = false, + bool isFirmProtEnabled, + isNtrcardBoot, + isSafeMode = false, isNoForceFlagSet = false; - const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C, - *bootPartitionsStatus = (const vu8 *)0x1FFFE010; - isNtrcardBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1]; //Shell closed, no error booting NTRCARD, NAND paritions not even considered FirmwareType firmType; FirmwareSource nandType; + const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C; + const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010; - if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal boot + //Shell closed, no error booting NTRCARD, NAND paritions not even considered + isNtrcardBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1]; + + if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot { u32 i; for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16 @@ -74,13 +77,15 @@ void main(int argc, char **argv, u32 magicWord) isFirmlaunch = true; } - else if(magicWord == 0xB002) + else if(magicWord == 0xB002) //FIRM/NTRCARD boot { - //"ntrcard:" doesn't actually exist, firmlaunch will fail as intended - const char *path = isNtrcardBoot ? "ntrcard:" : (!bootPartitionsStatus[2] ? "firm1:" : "firm0:"); + if(!isNtrcardBoot) + { + const char *path = !((vu8 *)bootPartitionsStatus)[2] ? "firm1:" : "firm0:"; - for(u32 i = 0; i < 40 && path[i] != 0; i++) //Copy and convert the path to UTF-16 - launchedPath[i] = path[i]; + for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16 + launchedPath[i] = path[i]; + } } else error("Launched using an unsupported loader."); @@ -95,7 +100,7 @@ void main(int argc, char **argv, u32 magicWord) if(!mountFs(false, true)) error("Failed to mount CTRNAND."); isSdMode = false; } - else if(memcmp(launchedPath, u"firm", 8) == 0 || memcmp(launchedPath, u"ntrcard", 14) == 0) + else if(memcmp(launchedPath, u"firm", 8) == 0 || isNtrcardBoot) { setupKeyslots(); @@ -115,6 +120,12 @@ void main(int argc, char **argv, u32 magicWord) error("Launched from an unsupported location: %s.", mountPoint); } + if(isNtrcardBoot && magicWord == 0xB002) + { + loadHomebrewFirm(0); + mcuPowerOff(); + } + //Attempt to read the configuration file needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; @@ -138,6 +149,7 @@ void main(int argc, char **argv, u32 magicWord) nandType = (FirmwareSource)BOOTCFG_NAND; firmSource = (FirmwareSource)BOOTCFG_FIRM; + isFirmProtEnabled = !BOOTCFG_NTRCARDBOOT; goto boot; } @@ -146,6 +158,7 @@ void main(int argc, char **argv, u32 magicWord) installArm9Handlers(); firmType = NATIVE_FIRM; + isFirmProtEnabled = !isNtrcardBoot; //Get pressed buttons u32 pressed = HID_PAD; @@ -181,7 +194,7 @@ void main(int argc, char **argv, u32 magicWord) bool pinExists = pinMode != 0 && verifyPin(pinMode); //If no configuration file exists or SELECT is held or if booted from NTRCARD, load configuration menu - bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT) || isNtrcardBoot; + bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT); if(shouldLoadConfigMenu) { @@ -288,7 +301,7 @@ boot: if(!isFirmlaunch) { - configData.bootConfig = ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType; + configData.bootConfig = ((u32)isNtrcardBoot << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType; writeConfig(false); } @@ -302,7 +315,7 @@ boot: switch(firmType) { case NATIVE_FIRM: - res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isSafeMode, doUnitinfoPatch); + res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, isSafeMode, doUnitinfoPatch); break; case TWL_FIRM: res = patchTwlFirm(firmVersion, loadFromStorage, doUnitinfoPatch); diff --git a/source/types.h b/source/types.h index f3ec2e7b..8a1d8e25 100644 --- a/source/types.h +++ b/source/types.h @@ -115,8 +115,7 @@ typedef enum FirmwareType } FirmwareType; extern bool isFirmlaunch, - isSdMode, - isNtrcardBoot; + isSdMode; extern u16 launchedFirmTidLow[8]; extern u16 launchedPath[41]; diff --git a/sysmodules/loader/source/patcher.h b/sysmodules/loader/source/patcher.h index f2e8a4b1..e9891c7a 100644 --- a/sysmodules/loader/source/patcher.h +++ b/sysmodules/loader/source/patcher.h @@ -14,6 +14,7 @@ #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) #define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1) +#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1) enum multiOptions {