Detect NTRCARD and FIRM1 boot sources properly...

Always display the configuration menu if booted from NTRCARD (because it's painful to get to otherwise -- even if b9s has a 2s delay), with the mention "Booted from NTRCARD" in the title.
This commit is contained in:
TuxSH 2017-08-19 01:40:55 +02:00
parent c92de03a5f
commit f79923814d
4 changed files with 39 additions and 13 deletions

View File

@ -11,6 +11,6 @@ SECTIONS
.data : ALIGN(4) { *(.data*); . = ALIGN(4); } .data : ALIGN(4) { *(.data*); . = ALIGN(4); }
.bss : ALIGN(8) { __bss_start = .; *(.bss* COMMON); . = ALIGN(8); __bss_end = .; } .bss : ALIGN(8) { __bss_start = .; *(.bss* COMMON); . = ALIGN(8); __bss_end = .; }
__stack_top__ = 0x1FFFF000; __stack_top__ = 0x1FFFE000;
. = ALIGN(4); . = ALIGN(4);
} }

View File

@ -239,14 +239,12 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
initScreens(); initScreens();
drawString(true, 10, 10, COLOR_TITLE, CONFIG_TITLE); 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");
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to save"); endPos += SPACING_Y;
//Character to display a selected option //Character to display a selected option
char selected = 'x'; char selected = 'x';
u32 endPos = 10 + 2 * SPACING_Y;
//Display all the multiple choice options in white //Display all the multiple choice options in white
for(u32 i = 0; i < multiOptionsAmount; i++) for(u32 i = 0; i < multiOptionsAmount; i++)
{ {

View File

@ -43,7 +43,8 @@ extern ConfigurationStatus needConfig;
extern FirmwareSource firmSource; extern FirmwareSource firmSource;
bool isFirmlaunch = false, bool isFirmlaunch = false,
isSdMode; isSdMode,
isNTRCARDBoot;
u16 launchedPath[41]; u16 launchedPath[41];
void main(int argc, char **argv, u32 magicWord) void main(int argc, char **argv, u32 magicWord)
@ -53,6 +54,13 @@ void main(int argc, char **argv, u32 magicWord)
FirmwareType firmType; FirmwareType firmType;
FirmwareSource nandType; FirmwareSource nandType;
static const u8 *const bootMediaStatus = (const u8 * const)0x1FFFE00C;
static const u8 *const bootPartitionsStatus = (const u8 * const)0x1FFFE010;
static const u8 zeroes[8] = {0};
isNTRCARDBoot =
bootMediaStatus[3] == 2 && //shell closed
bootMediaStatus[1] == 0 && //no error booting NTRCARD
memcmp(bootPartitionsStatus, zeroes, 8) == 0; //NAND paritions not even considered
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal boot if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal boot
{ {
u32 i; u32 i;
@ -72,9 +80,27 @@ void main(int argc, char **argv, u32 magicWord)
} }
else if(magicWord == 0xB002) else if(magicWord == 0xB002)
{ {
static const char argv[] = "firm0:"; bool isFirm1 = bootPartitionsStatus[2] != 0; //No NTRCARD boot and FIRM0 didn't boot successfully
for(u32 i = 0; i < sizeof(argv); i++) //Copy and convert the path to UTF-16 char path[9] = {0}; // Clearing here for null terminator
launchedPath[i] = argv[i]; u32 pathLen;
if(isNTRCARDBoot)
{
memcpy(path, "ntrcard:", 8); //This mount point doesn't actually exist, firmlaunch will fail as intended
pathLen = 8;
}
else if(!isFirm1)
{
memcpy(path, "firm0:", 6);
pathLen = 6;
}
else
{
memcpy(path, "firm1:", 6);
pathLen = 6;
}
for(u32 i = 0; i < pathLen + 1; i++) //Copy and convert the path to UTF-16
launchedPath[i] = path[i];
} }
else error("Launched using an unsupported loader."); else error("Launched using an unsupported loader.");
@ -89,7 +115,7 @@ void main(int argc, char **argv, u32 magicWord)
if(!mountFs(false, true)) error("Failed to mount CTRNAND."); if(!mountFs(false, true)) error("Failed to mount CTRNAND.");
isSdMode = false; isSdMode = false;
} }
else if(memcmp(launchedPath, u"firm", 8) == 0) else if(memcmp(launchedPath, u"firm", 8) == 0 || memcmp(launchedPath, u"ntrcard", 14) == 0)
{ {
setupKeyslots(); setupKeyslots();
@ -174,8 +200,8 @@ void main(int argc, char **argv, u32 magicWord)
u32 pinMode = MULTICONFIG(PIN); u32 pinMode = MULTICONFIG(PIN);
bool pinExists = pinMode != 0 && verifyPin(pinMode); bool pinExists = pinMode != 0 && verifyPin(pinMode);
//If no configuration file exists or SELECT is held, load configuration menu //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); bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT) || isNTRCARDBoot;
if(shouldLoadConfigMenu) if(shouldLoadConfigMenu)
{ {

View File

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