From 9c02388d15fa8154c21ba09cc9f485df88a3051f Mon Sep 17 00:00:00 2001 From: d0k3 Date: Mon, 21 Aug 2017 21:33:22 +0200 Subject: [PATCH] Scripting: add boot command --- HelloScript.gm9 | 5 +++++ source/filesys/fsscript.c | 16 +++++++++++++++- source/godmode.c | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/HelloScript.gm9 b/HelloScript.gm9 index 0e538e1..77d939c 100644 --- a/HelloScript.gm9 +++ b/HelloScript.gm9 @@ -155,6 +155,11 @@ verify S:/firm1.bin # -l / --legit force CIA to be legit (only works for legit system installed titles) # 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 # These are used to reboot or power off the 3DS console set ERRORMSG "Test script finished,\n(without reboot)\n \nIgnore the error message." diff --git a/source/filesys/fsscript.c b/source/filesys/fsscript.c index a0bf653..209a046 100644 --- a/source/filesys/fsscript.c +++ b/source/filesys/fsscript.c @@ -7,6 +7,8 @@ #include "gameutil.h" #include "keydbutil.h" #include "filetype.h" +#include "bootfirm.h" +#include "firm.h" #include "power.h" #include "vff.h" #include "rtc.h" @@ -85,7 +87,7 @@ Gm9ScriptCmd cmd_list[] = { { CMD_ID_DECRYPT , "decrypt" , 1, 0 }, { CMD_ID_ENCRYPT , "encrypt" , 1, 0 }, { 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_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) { ret = (BuildCiaFromGameFile(argv[0], (flags & _FLG('n'))) == 0); 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) { Reboot(); } else if (id == CMD_ID_POWEROFF) { diff --git a/source/godmode.c b/source/godmode.c index d02f53c..a480228 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -1468,7 +1468,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur BootFirm((FirmHeader*)(void*)TEMP_BUFFER, fixpath); while(1); } - } else ShowPrompt(false, "Not a vaild FIRM, can't launch"); + } else ShowPrompt(false, "Not a bootable FIRM, can't boot"); } return 0; } else if ((user_select == script)) {