Scripting: add boot command

This commit is contained in:
d0k3 2017-08-21 21:33:22 +02:00
parent 551a48149f
commit 9c02388d15
3 changed files with 21 additions and 2 deletions

View File

@ -155,6 +155,11 @@ verify S:/firm1.bin
# -l / --legit force CIA to be legit (only works for legit system installed titles) # -l / --legit force CIA to be legit (only works for legit system installed titles)
# buildcia 0:/x.ncch # buildcia 0:/x.ncch
# 'boot' COMMAND
# Use this command to chainload a compatible FIRM
# boot 0:/boot.firm
# disabled cause it would leave the script
# 'reboot' / 'poweroff' COMMAND # 'reboot' / 'poweroff' COMMAND
# These are used to reboot or power off the 3DS console # These are used to reboot or power off the 3DS console
set ERRORMSG "Test script finished,\n(without reboot)\n \nIgnore the error message." set ERRORMSG "Test script finished,\n(without reboot)\n \nIgnore the error message."

View File

@ -7,6 +7,8 @@
#include "gameutil.h" #include "gameutil.h"
#include "keydbutil.h" #include "keydbutil.h"
#include "filetype.h" #include "filetype.h"
#include "bootfirm.h"
#include "firm.h"
#include "power.h" #include "power.h"
#include "vff.h" #include "vff.h"
#include "rtc.h" #include "rtc.h"
@ -85,7 +87,7 @@ Gm9ScriptCmd cmd_list[] = {
{ CMD_ID_DECRYPT , "decrypt" , 1, 0 }, { CMD_ID_DECRYPT , "decrypt" , 1, 0 },
{ CMD_ID_ENCRYPT , "encrypt" , 1, 0 }, { CMD_ID_ENCRYPT , "encrypt" , 1, 0 },
{ CMD_ID_BUILDCIA, "buildcia", 1, _FLG('l') }, { CMD_ID_BUILDCIA, "buildcia", 1, _FLG('l') },
// { CMD_ID_BOOT , "boot" , 1, 0 }, // not supported yet { CMD_ID_BOOT , "boot" , 1, 0 },
{ CMD_ID_REBOOT , "reboot" , 0, 0 }, { CMD_ID_REBOOT , "reboot" , 0, 0 },
{ CMD_ID_POWEROFF, "poweroff", 0, 0 } { CMD_ID_POWEROFF, "poweroff", 0, 0 }
}; };
@ -470,6 +472,18 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
} else if (id == CMD_ID_BUILDCIA) { } else if (id == CMD_ID_BUILDCIA) {
ret = (BuildCiaFromGameFile(argv[0], (flags & _FLG('n'))) == 0); ret = (BuildCiaFromGameFile(argv[0], (flags & _FLG('n'))) == 0);
if (err_str) snprintf(err_str, _ERR_STR_LEN, "build CIA failed"); if (err_str) snprintf(err_str, _ERR_STR_LEN, "build CIA failed");
} else if (id == CMD_ID_BOOT) {
size_t firm_size = FileGetData(argv[0], TEMP_BUFFER, TEMP_BUFFER_SIZE, 0);
ret = firm_size && (firm_size < TEMP_BUFFER_SIZE) &&
(ValidateFirm(TEMP_BUFFER, firm_size, false) == 0);
if (ret) {
char fixpath[256] = { 0 };
if ((*argv[0] == '0') || (*argv[0] == '1'))
snprintf(fixpath, 256, "%s%s", (*argv[0] == '0') ? "sdmc" : "nand", argv[0] + 1);
else strncpy(fixpath, argv[0], 256);
BootFirm((FirmHeader*)(void*)TEMP_BUFFER, fixpath);
while(1);
} else if (err_str) snprintf(err_str, _ERR_STR_LEN, "not a bootable firm");
} else if (id == CMD_ID_REBOOT) { } else if (id == CMD_ID_REBOOT) {
Reboot(); Reboot();
} else if (id == CMD_ID_POWEROFF) { } else if (id == CMD_ID_POWEROFF) {

View File

@ -1468,7 +1468,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
BootFirm((FirmHeader*)(void*)TEMP_BUFFER, fixpath); BootFirm((FirmHeader*)(void*)TEMP_BUFFER, fixpath);
while(1); while(1);
} }
} else ShowPrompt(false, "Not a vaild FIRM, can't launch"); } else ShowPrompt(false, "Not a bootable FIRM, can't boot");
} }
return 0; return 0;
} else if ((user_select == script)) { } else if ((user_select == script)) {