Skip to content

Commit

Permalink
Enhanced Boot Order Preference: firmware check
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugNPush committed Jan 18, 2024
1 parent 18b4f66 commit a07bd46
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions stage2/arm9/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,8 @@ static void invokeArm11Function(Arm11Operation op)
while(*operation != ARM11_READY);
}

const char *getFirmNameFromBootOrder(void)
static FirmLoadStatus trialLoadFirm(Firm **outFirm, char* firmName)
{
const char* bootOrder = NULL;
if (fileExists("boot_order.txt"))
bootOrder = "boot_order.txt";
else if (fileExists("bootorder.txt"))
bootOrder = "bootorder.txt";

if (bootOrder)
{
static char line[2048];
u32 lineNumber = 0;
u32 bytesRead;

while ((bytesRead = fileReadLine(line, bootOrder, lineNumber, sizeof(line))) > 0)
{
line[bytesRead] = '\0';

if (fileExists(line))
return line;

lineNumber++;
}
}

return "boot.firm";
}

static FirmLoadStatus loadFirm(Firm **outFirm)
{
const char *firmName = getFirmNameFromBootOrder();

Firm *firmHeader = (Firm *)0x080A0000;
u32 rd = fileRead(firmHeader, firmName, 0x200, 0);
if (rd != 0x200)
Expand Down Expand Up @@ -103,6 +73,44 @@ static FirmLoadStatus loadFirm(Firm **outFirm)
return FIRM_LOAD_OK;
}

static FirmLoadStatus loadFirmFromBootOrder(Firm **outFirm)
{
const char* bootOrder = NULL;
if (fileExists("boot_order.txt"))
bootOrder = "boot_order.txt";
else if (fileExists("boot-order.txt"))
bootOrder = "boot-order.txt";
else if (fileExists("bootorder.txt"))
bootOrder = "bootorder.txt";

if (bootOrder)
{
static char line[2048];
u32 lineNumber = 0;
u32 bytesRead;

while ((bytesRead = fileReadLine(line, bootOrder, lineNumber, sizeof(line))) > 0)
{
line[bytesRead] = '\0';
if (fileExists(line))
{
FirmLoadStatus status = trialLoadFirm(outFirm, line);
if (status == FIRM_LOAD_OK)
return status;
}

lineNumber++;
}
}

return trialLoadFirm(outFirm, "boot.firm");
}

static FirmLoadStatus loadFirm(Firm **outFirm)
{
return loadFirmFromBootOrder(outFirm);
}

static void bootFirm(Firm *firm, bool isNand)
{
bool isScreenInit = (firm->reserved2[0] & 1) != 0;
Expand Down

0 comments on commit a07bd46

Please sign in to comment.