Fix reboot patch and argument handling

This commit is contained in:
TuxSH 2017-05-20 00:18:41 +02:00
parent 6ccc0f0538
commit 2349370960
4 changed files with 34 additions and 20 deletions

View File

@ -181,6 +181,8 @@ nand_mount: .dcw "nand"
blo copy_loop32 blo copy_loop32
bx lr bx lr
.pool
copy_launch_stub_end: copy_launch_stub_end:
flushCaches: flushCaches:
@ -209,5 +211,4 @@ nand_mount: .dcw "nand"
bx lr bx lr
.pool
.close .close

View File

@ -189,8 +189,8 @@ void loadPayload(u32 pressed, const char *payloadPath)
char path[62] = {0}, char path[62] = {0},
absPath[92] = {0}; absPath[92] = {0};
char mountPoint[5] = {0}; u16 mountPoint[5] = {0};
for(u32 i = 0; i < 4 && launchedPath[i] != ':'; i++) for(u32 i = 0; i < 4 && launchedPath[i] != u':'; i++)
mountPoint[i] = launchedPath[i]; mountPoint[i] = launchedPath[i];
if(payloadPath == NULL) if(payloadPath == NULL)
@ -222,7 +222,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
if(!info.fname[0]) return; if(!info.fname[0]) return;
sprintf(path, "payloads/%s", info.altname); sprintf(path, "payloads/%s", info.altname);
if(memcmp(mountPoint, "nand", 4)) if(memcmp(mountPoint, u"nand", 8))
sprintf(absPath, "nand:/rw/luma/payloads/%s", info.altname); sprintf(absPath, "nand:/rw/luma/payloads/%s", info.altname);
else else
sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, info.altname); sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, info.altname);
@ -231,7 +231,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
} }
else else
{ {
if(memcmp(mountPoint, "nand", 4)) if(memcmp(mountPoint, u"nand", 8))
sprintf(absPath, "nand:/rw/luma/payloads/%s", payloadPath); sprintf(absPath, "nand:/rw/luma/payloads/%s", payloadPath);
else else
sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, payloadPath); sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, payloadPath);

View File

@ -49,17 +49,19 @@ void main(int argc, char **argv)
FirmwareType firmType; FirmwareType firmType;
FirmwareSource nandType; FirmwareSource nandType;
char errbuf[128];
switch(argc) switch(argc)
{ {
case 0: case 0:
error("Unsupported launcher."); error("Unsupported launcher (argc = 0).");
break; break;
case 1: //Normal boot case 1: //Normal boot
{ {
u32 i; u32 i;
for(i = 0; i < 40 && launchedPath[i] != 0; i++) //Copy and convert the path to utf16 for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to utf16
launchedPath[2 * i] = argv[0][i]; launchedPath[i] = argv[0][i];
for(; i < 41; i++) for(; i < 41; i++)
launchedPath[i] = 0; launchedPath[i] = 0;
@ -71,7 +73,7 @@ void main(int argc, char **argv)
{ {
u32 i; u32 i;
u16 *p = (u16 *)argv[0]; u16 *p = (u16 *)argv[0];
for(i = 0; i < 40 && launchedPath[i] != 0; i++) for(i = 0; i < 40 && p[i] != 0; i++)
launchedPath[i] = p[i]; launchedPath[i] = p[i];
for(; i < 41; i++) for(; i < 41; i++)
launchedPath[i] = 0; launchedPath[i] = 0;
@ -79,28 +81,40 @@ void main(int argc, char **argv)
memcpy(launchedFirmTidLow, (u16 *)argv[1], 16); memcpy(launchedFirmTidLow, (u16 *)argv[1], 16);
break; break;
} }
default:
sprintf(errbuf, "Unsupported launcher (argc = %d > 2).", argc);
error(errbuf);
break;
} }
char mountPoint[5] = {0}; u16 mountPoint[5] = {0};
for(u32 i = 0; i < 4 && argv[0][i] != ':'; i++) for(u32 i = 0; i < 4 && launchedPath[i] != u':'; i++)
mountPoint[i] = argv[0][i]; mountPoint[i] = launchedPath[i];
//Mount SD or CTRNAND //Mount SD or CTRNAND
bool isSdMode; bool isSdMode;
if(memcmp(mountPoint, "sdmc", 4) == 0) if(memcmp(mountPoint, u"sdmc", 8) == 0)
{ {
if(!mountFs(true, false)) error("Failed to mount SD."); if(!mountFs(true, false)) error("Failed to mount SD.");
isSdMode = true; isSdMode = true;
} }
else if(memcmp(mountPoint, "nand", 4) == 0) else if(memcmp(mountPoint, u"nand", 8) == 0)
{ {
firmSource = FIRMWARE_SYSNAND; firmSource = FIRMWARE_SYSNAND;
if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND."); if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND.");
isSdMode = false; isSdMode = false;
} }
else else
error("Launched from an unsupported location"); {
char mount8[5] = {0};
for(u32 i = 0 ; i < 4; i++)
mount8[i] = (char)mountPoint[i];
sprintf(errbuf, "Launched from an unsupported location: %s.", mount8);
error(errbuf);
}
//Attempt to read the configuration file //Attempt to read the configuration file
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
@ -305,9 +319,8 @@ boot:
if(res != 0) if(res != 0)
{ {
char patchesError[43]; sprintf(errbuf, "Failed to apply %u FIRM patch(es).", res);
sprintf(patchesError, "Failed to apply %u FIRM patch(es).", res); error(errbuf);
error(patchesError);
} }
launchFirm(firmType, loadFromStorage); launchFirm(firmType, loadFromStorage);

View File

@ -135,8 +135,8 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr)
u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_bin_size, 4); u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_bin_size, 4);
*pos_fopen = fOpenOffset; *pos_fopen = fOpenOffset;
u16 *fname = (u16 *)memsearch(off, u"sd", reboot_bin_size, 4); u16 *fname = (u16 *)memsearch(off, u"sdmc", reboot_bin_size, 8);
memcpy(fname, launchedPath, 82); memcpy(fname, launchedPath, sizeof(launchedPath));
return 0; return 0;
} }