Skip to content

Commit

Permalink
Minor style stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraWright committed Aug 19, 2017
1 parent f799238 commit dc3fa06
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions source/main.c
Expand Up @@ -44,23 +44,19 @@ extern FirmwareSource firmSource;

bool isFirmlaunch = false,
isSdMode,
isNTRCARDBoot;
isNtrcardBoot;
u16 launchedPath[41];

void main(int argc, char **argv, u32 magicWord)
{
bool isSafeMode = false,
isNoForceFlagSet = false;
static const u8 *bootMediaStatus = (const u8 *)0x1FFFE00C,
*bootPartitionsStatus = (const u8 *)0x1FFFE010;
isNtrcardBoot = bootMediaStatus[3] == 2 && bootMediaStatus[1] == 0 && !bootPartitionsStatus[0] && !bootPartitionsStatus[1]; //Shell closed, no error booting NTRCARD, NAND paritions not even considered
FirmwareType firmType;
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
{
u32 i;
Expand All @@ -80,26 +76,9 @@ void main(int argc, char **argv, u32 magicWord)
}
else if(magicWord == 0xB002)
{
bool isFirm1 = bootPartitionsStatus[2] != 0; //No NTRCARD boot and FIRM0 didn't boot successfully
char path[9] = {0}; // Clearing here for null terminator
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;
}
char *path = isNTRCARDBoot ? "ntrcard:" : (!bootPartitionsStatus[2] ? "firm1:" : "firm0:"); //This mount point doesn't actually exist, firmlaunch will fail as intended

for(u32 i = 0; i < pathLen + 1; i++) //Copy and convert the path to UTF-16
for(u32 i = 0; i < 40 && path[i] != 0; i++) //Copy and convert the path to UTF-16
launchedPath[i] = path[i];
}
else error("Launched using an unsupported loader.");
Expand Down

0 comments on commit dc3fa06

Please sign in to comment.