Refactor boot mode/firmlaunch detection, fix firmlaunch from FIRM boots
This commit is contained in:
parent
2492c8273a
commit
df93e4797e
@ -91,19 +91,6 @@ void detectAndProcessExceptionDumps(void)
|
|||||||
if(dumpHeader->processor == 11) posY = drawFormattedString(true, 10, 30, COLOR_WHITE, "Processor: ARM11 (core %u)", dumpHeader->core);
|
if(dumpHeader->processor == 11) posY = drawFormattedString(true, 10, 30, COLOR_WHITE, "Processor: ARM11 (core %u)", dumpHeader->core);
|
||||||
else posY = drawString(true, 10, 30, COLOR_WHITE, "Processor: ARM9");
|
else posY = drawString(true, 10, 30, COLOR_WHITE, "Processor: ARM9");
|
||||||
|
|
||||||
const char *faultStatusInfos = NULL;
|
|
||||||
if(dumpHeader->type >= 2)
|
|
||||||
{
|
|
||||||
u32 xfsr = dumpHeader->type == 2 ? regs[18] : regs[17];
|
|
||||||
xfsr &= 0xF;
|
|
||||||
for(u32 i = 0; i < 15; i++)
|
|
||||||
if(xfsr == faultStatusValues[i])
|
|
||||||
{
|
|
||||||
faultStatusInfos = faultStatusNames[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dumpHeader->type == 2)
|
if(dumpHeader->type == 2)
|
||||||
{
|
{
|
||||||
if((regs[16] & 0x20) == 0 && dumpHeader->codeDumpSize >= 4)
|
if((regs[16] & 0x20) == 0 && dumpHeader->codeDumpSize >= 4)
|
||||||
@ -130,7 +117,17 @@ void detectAndProcessExceptionDumps(void)
|
|||||||
else
|
else
|
||||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
||||||
|
|
||||||
if(faultStatusInfos != NULL) posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Fault status: %s", faultStatusInfos);
|
if(dumpHeader->type >= 2)
|
||||||
|
{
|
||||||
|
u32 xfsr = (dumpHeader->type == 2 ? regs[18] : regs[17]) & 0xF;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < 15; i++)
|
||||||
|
if(xfsr == faultStatusValues[i])
|
||||||
|
{
|
||||||
|
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Fault status: %s", faultStatusNames[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(dumpHeader->processor == 11 && dumpHeader->additionalDataSize != 0)
|
if(dumpHeader->processor == 11 && dumpHeader->additionalDataSize != 0)
|
||||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
|
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
|
||||||
|
@ -42,8 +42,7 @@ extern CfgData configData;
|
|||||||
extern ConfigurationStatus needConfig;
|
extern ConfigurationStatus needConfig;
|
||||||
extern FirmwareSource firmSource;
|
extern FirmwareSource firmSource;
|
||||||
|
|
||||||
bool isFirmlaunch = false,
|
bool isSdMode;
|
||||||
isSdMode;
|
|
||||||
u16 launchedPath[41];
|
u16 launchedPath[41];
|
||||||
BootType bootType;
|
BootType bootType;
|
||||||
|
|
||||||
@ -51,17 +50,20 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
{
|
{
|
||||||
bool isFirmProtEnabled,
|
bool isFirmProtEnabled,
|
||||||
isSafeMode = false,
|
isSafeMode = false,
|
||||||
isNoForceFlagSet = false;
|
isNoForceFlagSet = false,
|
||||||
|
isNtrBoot;
|
||||||
FirmwareType firmType;
|
FirmwareType firmType;
|
||||||
FirmwareSource nandType;
|
FirmwareSource nandType;
|
||||||
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
||||||
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
||||||
|
|
||||||
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
||||||
bootType = (bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1]) ? NTR : B9S;
|
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
||||||
|
|
||||||
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot
|
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot
|
||||||
{
|
{
|
||||||
|
bootType = isNtrBoot ? B9SNTR : B9S;
|
||||||
|
|
||||||
u32 i;
|
u32 i;
|
||||||
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
|
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
|
||||||
launchedPath[i] = argv[0][i];
|
launchedPath[i] = argv[0][i];
|
||||||
@ -69,17 +71,18 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
}
|
}
|
||||||
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
|
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
|
||||||
{
|
{
|
||||||
|
bootType = FIRMLAUNCH;
|
||||||
|
|
||||||
u32 i;
|
u32 i;
|
||||||
u16 *p = (u16 *)argv[0];
|
u16 *p = (u16 *)argv[0];
|
||||||
for(i = 0; i < 40 && p[i] != 0; i++)
|
for(i = 0; i < 40 && p[i] != 0; i++)
|
||||||
launchedPath[i] = p[i];
|
launchedPath[i] = p[i];
|
||||||
launchedPath[i] = 0;
|
launchedPath[i] = 0;
|
||||||
|
|
||||||
isFirmlaunch = true;
|
|
||||||
}
|
}
|
||||||
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
||||||
{
|
{
|
||||||
if(bootType != NTR)
|
if(isNtrBoot) bootType = NTR;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
if(!((vu8 *)bootPartitionsStatus)[2])
|
if(!((vu8 *)bootPartitionsStatus)[2])
|
||||||
@ -96,6 +99,8 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16
|
for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16
|
||||||
launchedPath[i] = path[i];
|
launchedPath[i] = path[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupKeyslots();
|
||||||
}
|
}
|
||||||
else error("Launched using an unsupported loader.");
|
else error("Launched using an unsupported loader.");
|
||||||
|
|
||||||
@ -110,13 +115,18 @@ 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(bootType != B9S)
|
else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0)
|
||||||
{
|
{
|
||||||
setupKeyslots();
|
|
||||||
|
|
||||||
if(mountFs(true, false)) isSdMode = true;
|
if(mountFs(true, false)) isSdMode = true;
|
||||||
else if(mountFs(false, true)) isSdMode = false;
|
else if(mountFs(false, true)) isSdMode = false;
|
||||||
else error("Failed to mount SD and CTRNAND.");
|
else error("Failed to mount SD and CTRNAND.");
|
||||||
|
|
||||||
|
if(bootType == NTR)
|
||||||
|
{
|
||||||
|
while(HID_PAD & NTRBOOT_BUTTONS);
|
||||||
|
loadHomebrewFirm(0);
|
||||||
|
mcuPowerOff();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -130,18 +140,11 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
error("Launched from an unsupported location: %s.", mountPoint);
|
error("Launched from an unsupported location: %s.", mountPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bootType == NTR && magicWord == 0xB002)
|
|
||||||
{
|
|
||||||
while(HID_PAD & NTRBOOT_BUTTONS);
|
|
||||||
loadHomebrewFirm(0);
|
|
||||||
mcuPowerOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Attempt to read the configuration file
|
//Attempt to read the configuration file
|
||||||
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
|
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
|
||||||
|
|
||||||
//Determine if this is a firmlaunch boot
|
//Determine if this is a firmlaunch boot
|
||||||
if(isFirmlaunch)
|
if(bootType == FIRMLAUNCH)
|
||||||
{
|
{
|
||||||
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
||||||
|
|
||||||
@ -177,7 +180,6 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
//If it's a MCU reboot, try to force boot options
|
//If it's a MCU reboot, try to force boot options
|
||||||
if(CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
|
if(CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Always force a SysNAND boot when quitting AGB_FIRM
|
//Always force a SysNAND boot when quitting AGB_FIRM
|
||||||
if(CFG_BOOTENV == 7)
|
if(CFG_BOOTENV == 7)
|
||||||
{
|
{
|
||||||
@ -310,7 +312,7 @@ boot:
|
|||||||
else if(firmSource != FIRMWARE_SYSNAND)
|
else if(firmSource != FIRMWARE_SYSNAND)
|
||||||
locateEmuNand(&firmSource);
|
locateEmuNand(&firmSource);
|
||||||
|
|
||||||
if(!isFirmlaunch)
|
if(bootType == FIRMLAUNCH)
|
||||||
{
|
{
|
||||||
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
|
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
|
||||||
writeConfig(false);
|
writeConfig(false);
|
||||||
@ -343,6 +345,6 @@ boot:
|
|||||||
|
|
||||||
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
||||||
|
|
||||||
if(!isFirmlaunch) deinitScreens();
|
if(bootType != FIRMLAUNCH) deinitScreens();
|
||||||
launchFirm(0, NULL);
|
launchFirm(0, NULL);
|
||||||
}
|
}
|
||||||
|
@ -117,16 +117,16 @@ typedef enum FirmwareType
|
|||||||
typedef enum bootType
|
typedef enum bootType
|
||||||
{
|
{
|
||||||
B9S = 0,
|
B9S = 0,
|
||||||
NTR,
|
B9SNTR,
|
||||||
FIRM0,
|
FIRM0,
|
||||||
FIRM1
|
FIRM1,
|
||||||
|
FIRMLAUNCH,
|
||||||
|
NTR
|
||||||
} BootType;
|
} BootType;
|
||||||
|
|
||||||
extern bool isFirmlaunch,
|
extern bool isSdMode;
|
||||||
isSdMode;
|
|
||||||
|
|
||||||
extern BootType bootType;
|
extern BootType bootType;
|
||||||
|
|
||||||
extern u16 launchedFirmTidLow[8];
|
extern u16 launchedFirmTidLow[8];
|
||||||
extern u16 launchedPath[41];
|
extern u16 launchedPath[41];
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ u32 waitInput(bool isMenu)
|
|||||||
|
|
||||||
void mcuPowerOff(void)
|
void mcuPowerOff(void)
|
||||||
{
|
{
|
||||||
if(!isFirmlaunch && ARESCREENSINITIALIZED) clearScreens(false);
|
if(bootType != FIRMLAUNCH && ARESCREENSINITIALIZED) clearScreens(false);
|
||||||
|
|
||||||
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||||
flushEntireDCache();
|
flushEntireDCache();
|
||||||
@ -131,7 +131,7 @@ void error(const char *fmt, ...)
|
|||||||
vsprintf(buf, fmt, args);
|
vsprintf(buf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if(!isFirmlaunch)
|
if(bootType != FIRMLAUNCH)
|
||||||
{
|
{
|
||||||
initScreens();
|
initScreens();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user