diff --git a/Makefile b/Makefile index 587bb17..ab86727 100644 --- a/Makefile +++ b/Makefile @@ -64,22 +64,14 @@ ifeq ($(SWITCH_SCREENS),1) CFLAGS += -DSWITCH_SCREENS endif +ifeq ($(AUTORUN_SCRIPT),1) + CFLAGS += -DAUTORUN_SCRIPT +endif + ifdef FIXED_BRIGHTNESS CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS) endif -ifneq ("$(wildcard $(CURDIR)/../$(DATA)/README.md)","") - CFLAGS += -DHARDCODE_README -endif - -ifneq ("$(wildcard $(CURDIR)/../$(DATA)/aeskeydb.bin)","") - CFLAGS += -DHARDCODE_KEYS -endif - -ifneq ("$(wildcard $(CURDIR)/../$(DATA)/autorun.gm9)","") - CFLAGS += -DAUTORUN_SCRIPT -endif - CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions LDFLAGS = -T../link.ld -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map,-z,max-page-size=512 @@ -111,14 +103,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/README.md))) \ - $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/aeskeydb.bin))) \ - $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/autorun.gm9))) -ifeq ($(SAFEMODE),1) - BINFILES += $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/sm9*.*))) -else - BINFILES += $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/gm9*.*))) -endif +BINFILES := #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C @@ -145,11 +130,7 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) -ifeq ("$(wildcard $(CURDIR)/$(DATA)/vram0.img)","") - export FTCOMMON := -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf -C NDMA XDMA -else - export FTCOMMON := -A 0x18000000 -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf $(CURDIR)/$(DATA)/vram0.img -C NDMA XDMA memcpy -endif +export FTCOMMON := -A 0x18000000 -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf $(CURDIR)/resources/vram0.tar -C NDMA XDMA memcpy .PHONY: common clean all firm binary screeninit release @@ -214,28 +195,6 @@ $(OUTPUT).elf : $(OFILES) @$(OBJCOPY) --set-section-flags .bss=alloc,load,contents -O binary $< $@ @echo built ... $(notdir $@) -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%_qlz.h %.qlz.o: %.qlz -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) -#--------------------------------------------------------------------------------- -%_bin.h %.bin.o: %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) -#--------------------------------------------------------------------------------- -%_gm9.h %.gm9.o: %.gm9 -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) -#--------------------------------------------------------------------------------- -%_md.h %.md.o: %.md -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) -include $(DEPENDS) diff --git a/resources/vram0.tar b/resources/vram0.tar new file mode 100644 index 0000000..e5842bb Binary files /dev/null and b/resources/vram0.tar differ diff --git a/source/crypto/keydb.c b/source/crypto/keydb.c index 68b64ed..c7c9bf7 100644 --- a/source/crypto/keydb.c +++ b/source/crypto/keydb.c @@ -2,9 +2,7 @@ #include "aes.h" #include "sha.h" #include "ff.h" -#ifdef HARDCODE_KEYS -#include "aeskeydb_bin.h" -#endif +#include "vram0.h" typedef struct { u8 slot; // keyslot, 0x00...0x39 @@ -123,16 +121,17 @@ u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) { f_close(&fp); } } else { - #ifdef HARDCODE_KEYS + // check for hardcoded key database + u64 aeskeydb_bin_size = 0; + void* aeskeydb_bin = FindVTarFileInfo(VRAM0_AESKEY_DB, &aeskeydb_bin_size, NULL); fsize = (aeskeydb_bin_size <= bsize) ? aeskeydb_bin_size : 0; if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size); - #else + // try to load aeskeydb.bin file if (f_open(&fp, SUPPORT_PATH "/" KEYDB_NAME, FA_READ | FA_OPEN_EXISTING) == FR_OK) { if ((f_read(&fp, keydb, bsize, &fsize) != FR_OK) || (fsize >= bsize)) fsize = 0; f_close(&fp); } - #endif } u32 nkeys = 0; diff --git a/source/godmode.c b/source/godmode.c index 4c04bbe..7a4cbb4 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -28,17 +28,8 @@ #include "rtc.h" #include "power.h" #include "vff.h" +#include "vram0.h" -#include QLZ_SPLASH_H -#ifdef AUTORUN_SCRIPT -#include "autorun_gm9.h" -#endif -#ifdef HARDCODE_README -#include "README_md.h" -#else -#define README_md NULL -#define README_md_size 0 -#endif #define N_PANES 2 @@ -71,6 +62,7 @@ #define BOOTMENU_KEY BUTTON_START #endif + typedef struct { char path[256]; u32 cursor; @@ -1607,7 +1599,7 @@ u32 HomeMoreMenu(char* current_path) { int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1; int clock = ++n_opt; int sysinfo = ++n_opt; - int readme = (README_md != NULL) ? (int) ++n_opt : -1; + int readme = (FindVTarFileInfo(VRAM0_README_MD, NULL, NULL)) ? (int) ++n_opt : -1; if (sdformat > 0) optionstr[sdformat - 1] = "SD format menu"; if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup"; @@ -1721,7 +1713,9 @@ u32 HomeMoreMenu(char* current_path) { return 0; } else if (user_select == readme) { // Display GodMode9 readme - MemToCViewer((const char*) README_md, README_md_size, "GodMode9 ReadMe Table of Contents"); + u64 README_md_size; + char* README_md = FindVTarFileInfo(VRAM0_README_MD, &README_md_size, NULL); + MemToCViewer(README_md, README_md_size, "GodMode9 ReadMe Table of Contents"); return 0; } else return 1; @@ -1729,6 +1723,7 @@ u32 HomeMoreMenu(char* current_path) { } u32 SplashInit(const char* modestr) { + void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL, NULL); const char* namestr = FLAVOR " " VERSION; const char* loadstr = "booting..."; const u32 pos_xb = 10; @@ -1737,7 +1732,8 @@ u32 SplashInit(const char* modestr) { const u32 pos_yu = SCREEN_HEIGHT - 10 - GetDrawStringHeight(loadstr); ClearScreenF(true, true, COLOR_STD_BG); - QlzDecompress(TOP_SCREEN, QLZ_SPLASH, 0); + if (splash) QlzDecompress(TOP_SCREEN, splash, 0); + else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(splash not found)"); if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr), SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr); @@ -2317,14 +2313,20 @@ u32 ScriptRunner(int entrypoint) { InitNandCrypto(entrypoint != ENTRY_B9S); InitExtFS(); - while (CheckButton(BUTTON_A)); // don't continue while A is held + while (HID_STATE); // wait until no buttons are pressed while (timer_msec( timer ) < 500); // show splash for at least 0.5 sec ClearScreenF(true, true, COLOR_STD_BG); // clear splash - // copy script to script buffer and run it - memset(SCRIPT_BUFFER, 0, SCRIPT_BUFFER_SIZE); - memcpy(SCRIPT_BUFFER, autorun_gm9, autorun_gm9_size); - ExecuteGM9Script(NULL); + // get script from VRAM0 TAR + u64 autorun_gm9_size = 0; + void* autorun_gm9 = FindVTarFileInfo(VRAM0_AUTORUN_GM9, &autorun_gm9_size, NULL); + + if (autorun_gm9 && autorun_gm9_size) { + // copy script to script buffer and run it + memset(SCRIPT_BUFFER, 0, SCRIPT_BUFFER_SIZE); + memcpy(SCRIPT_BUFFER, autorun_gm9, autorun_gm9_size); + ExecuteGM9Script(NULL); + } else ShowPrompt(false, "Compiled as script autorunner\nbut no autorun.gm9 provided.\n \nDerp!"); // deinit DeinitExtFS(); diff --git a/source/system/tar.c b/source/system/tar.c index 1b316a9..94107bf 100644 --- a/source/system/tar.c +++ b/source/system/tar.c @@ -79,7 +79,6 @@ void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* TarHeader* tar = tardata; if (ValidateTarHeader(tardata, tardata_end) != 0) break; - ShowPrompt(false, "%s\n%s", tar->fname, fname); if ((strncasecmp(tar->fname, fname, 100) == 0) && (tar->ftype == '0')) return GetTarFileInfo(tardata, NULL, fsize, is_dir); tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512); diff --git a/source/system/vram0.h b/source/system/vram0.h index b94a27a..383d201 100644 --- a/source/system/vram0.h +++ b/source/system/vram0.h @@ -4,6 +4,17 @@ #include "tar.h" +// known file names inside VRAM0 TAR +#define VRAM0_AUTORUN_GM9 "autorun.gm9" +#define VRAM0_README_MD "README.md" +#define VRAM0_AESKEY_DB "aeskey.db" +#ifndef SAFEMODE +#define VRAM0_SPLASH_QLZ "gm9_splash.qlz" +#else +#define VRAM0_SPLASH_QLZ "sm9_splash_baby.qlz" +#endif + + #define VRAM0_OFFSET 0x18000000 #define VRAM0_LIMIT 0x00300000 diff --git a/source/utils/scripting.c b/source/utils/scripting.c index 947de19..5f147ce 100644 --- a/source/utils/scripting.c +++ b/source/utils/scripting.c @@ -823,11 +823,12 @@ bool run_line(const char* line_start, const char* line_end, u32* flags, char* er // checks for illegal ASCII symbols bool ValidateText(const char* text, u32 len) { + if (!len) return false; for (u32 i = 0; i < len; i++) { char c = text[i]; if ((c == '\r') && ((i+1) < len) && (text[i+1] != '\n')) return false; // CR without LF if ((c < 0x20) && (c != '\t') && (c != '\r') && (c != '\n')) return false; // illegal control char - if (c == 0xFF) return false; // other illegal char + if (c == 0xFF) return false; // 0xFF illegal char } return true; }