From b9eea8e92b5f5a3bf3da0264662d723900fb5305 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Tue, 4 Jul 2017 02:22:35 +0200 Subject: [PATCH] Allow booting FIRM images ... works only with latest boot9strap nightly --- source/filesys/filetype.h | 1 + source/godmode.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/filesys/filetype.h b/source/filesys/filetype.h index 257ad86..3dc8a39 100644 --- a/source/filesys/filetype.h +++ b/source/filesys/filetype.h @@ -49,5 +49,6 @@ #define FTYPE_XORPAD(tp) (tp&(BIN_NCCHNFO)) #define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT)) #define FTYPE_PAYLOAD(tp) (tp&(BIN_LAUNCH)) +#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM)) u32 IdentifyFileType(const char* path); diff --git a/source/godmode.c b/source/godmode.c index 8d3e804..cb798a4 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -885,9 +885,10 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur bool xorpadable = (FTYPE_XORPAD(filetype)); bool scriptable = (FTYPE_SCRIPT(filetype)); bool launchable = ((FTYPE_PAYLOAD(filetype)) && (drvtype & DRV_FAT) && !IS_SIGHAX); + bool bootable = ((FTYPE_BOOTABLE(filetype)) && !PathExist("0:/bootonce.firm") && IS_SIGHAX); // works only with boot9strap nightly bool special_opt = mountable || verificable || decryptable || encryptable || cia_buildable || cia_buildable_legit || cxi_dumpable || tik_buildable || key_buildable || titleinfo || renamable || transferable || hsinjectable || restorable || xorpadable || - ebackupable || launchable || scriptable; + ebackupable || launchable || bootable || scriptable; char pathstr[32+1]; TruncateString(pathstr, curr_entry->path, 32, 8); @@ -1044,6 +1045,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur int xorpad = (xorpadable) ? ++n_opt : -1; int xorpad_inplace = (xorpadable) ? ++n_opt : -1; int launch = (launchable) ? ++n_opt : -1; + int boot = (bootable) ? ++n_opt : -1; int script = (scriptable) ? ++n_opt : -1; if (mount > 0) optionstr[mount-1] = "Mount image to drive"; if (restore > 0) optionstr[restore-1] = "Restore SysNAND (safe)"; @@ -1064,6 +1066,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur if (xorpad > 0) optionstr[xorpad-1] = "Build XORpads (SD output)"; if (xorpad_inplace > 0) optionstr[xorpad_inplace-1] = "Build XORpads (inplace)"; if (launch > 0) optionstr[launch-1] = "Launch as ARM9 payload"; + if (boot > 0) optionstr[boot-1] = "Boot FIRM via boot9strap"; if (script > 0) optionstr[script-1] = "Execute GM9 script"; // auto select when there is only one option @@ -1406,6 +1409,14 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur } // failed load is basically impossible here } return 0; + } else if ((user_select == boot)) { + size_t payload_size = FileGetSize(curr_entry->path); + if (ShowUnlockSequence(3, "%s (%dkB)\nBoot FIRM via boot9strap?", pathstr, payload_size / 1024)) { + u32 flags = OVERWRITE_ALL; + if (PathMoveCopy("0:/bootonce.firm", curr_entry->path, &flags, false)) + Reboot(); + } + return 0; } else if ((user_select == script)) { static bool show_disclaimer = true; if (show_disclaimer) ShowPrompt(false, "Warning: Do not run scripts\nfrom untrusted sources.");