Change ntrboot behavior, turn Luma into a chainloader when used as ntrboot FIRM as it can not be functional, disable FIRM protection when ran from ntrboot B9S

This commit is contained in:
Aurora Wright 2017-08-20 16:08:54 +02:00
parent 18db70a669
commit 13317b9548
8 changed files with 40 additions and 23 deletions

View File

@ -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
{

View File

@ -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++)
{

View File

@ -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
{

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -115,8 +115,7 @@ typedef enum FirmwareType
} FirmwareType;
extern bool isFirmlaunch,
isSdMode,
isNtrcardBoot;
isSdMode;
extern u16 launchedFirmTidLow[8];
extern u16 launchedPath[41];

View File

@ -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
{