Use vram0.tar instead of standard bin2o method

This commit is contained in:
d0k3 2017-11-01 18:05:30 +01:00
parent 2d36460a02
commit 0f3fc2a5d1
7 changed files with 44 additions and 73 deletions

View File

@ -64,22 +64,14 @@ ifeq ($(SWITCH_SCREENS),1)
CFLAGS += -DSWITCH_SCREENS CFLAGS += -DSWITCH_SCREENS
endif endif
ifeq ($(AUTORUN_SCRIPT),1)
CFLAGS += -DAUTORUN_SCRIPT
endif
ifdef FIXED_BRIGHTNESS ifdef FIXED_BRIGHTNESS
CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS) CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS)
endif 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 CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
LDFLAGS = -T../link.ld -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map,-z,max-page-size=512 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))) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/README.md))) \ BINFILES :=
$(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
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C # 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) export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ("$(wildcard $(CURDIR)/$(DATA)/vram0.img)","") export FTCOMMON := -A 0x18000000 -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf $(CURDIR)/resources/vram0.tar -C NDMA XDMA memcpy
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
.PHONY: common clean all firm binary screeninit release .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 $< $@ @$(OBJCOPY) --set-section-flags .bss=alloc,load,contents -O binary $< $@
@echo built ... $(notdir $@) @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) -include $(DEPENDS)

BIN
resources/vram0.tar Normal file

Binary file not shown.

View File

@ -2,9 +2,7 @@
#include "aes.h" #include "aes.h"
#include "sha.h" #include "sha.h"
#include "ff.h" #include "ff.h"
#ifdef HARDCODE_KEYS #include "vram0.h"
#include "aeskeydb_bin.h"
#endif
typedef struct { typedef struct {
u8 slot; // keyslot, 0x00...0x39 u8 slot; // keyslot, 0x00...0x39
@ -123,16 +121,17 @@ u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) {
f_close(&fp); f_close(&fp);
} }
} else { } 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; fsize = (aeskeydb_bin_size <= bsize) ? aeskeydb_bin_size : 0;
if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size); if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size);
#else
// try to load aeskeydb.bin file // try to load aeskeydb.bin file
if (f_open(&fp, SUPPORT_PATH "/" KEYDB_NAME, FA_READ | FA_OPEN_EXISTING) == FR_OK) { 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; if ((f_read(&fp, keydb, bsize, &fsize) != FR_OK) || (fsize >= bsize)) fsize = 0;
f_close(&fp); f_close(&fp);
} }
#endif
} }
u32 nkeys = 0; u32 nkeys = 0;

View File

@ -28,17 +28,8 @@
#include "rtc.h" #include "rtc.h"
#include "power.h" #include "power.h"
#include "vff.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 #define N_PANES 2
@ -71,6 +62,7 @@
#define BOOTMENU_KEY BUTTON_START #define BOOTMENU_KEY BUTTON_START
#endif #endif
typedef struct { typedef struct {
char path[256]; char path[256];
u32 cursor; u32 cursor;
@ -1607,7 +1599,7 @@ u32 HomeMoreMenu(char* current_path) {
int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1; int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1;
int clock = ++n_opt; int clock = ++n_opt;
int sysinfo = ++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 (sdformat > 0) optionstr[sdformat - 1] = "SD format menu";
if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup"; if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup";
@ -1721,7 +1713,9 @@ u32 HomeMoreMenu(char* current_path) {
return 0; return 0;
} }
else if (user_select == readme) { // Display GodMode9 readme 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; return 0;
} else return 1; } else return 1;
@ -1729,6 +1723,7 @@ u32 HomeMoreMenu(char* current_path) {
} }
u32 SplashInit(const char* modestr) { u32 SplashInit(const char* modestr) {
void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL, NULL);
const char* namestr = FLAVOR " " VERSION; const char* namestr = FLAVOR " " VERSION;
const char* loadstr = "booting..."; const char* loadstr = "booting...";
const u32 pos_xb = 10; const u32 pos_xb = 10;
@ -1737,7 +1732,8 @@ u32 SplashInit(const char* modestr) {
const u32 pos_yu = SCREEN_HEIGHT - 10 - GetDrawStringHeight(loadstr); const u32 pos_yu = SCREEN_HEIGHT - 10 - GetDrawStringHeight(loadstr);
ClearScreenF(true, true, COLOR_STD_BG); 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), if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr),
SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr); SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr);
@ -2317,14 +2313,20 @@ u32 ScriptRunner(int entrypoint) {
InitNandCrypto(entrypoint != ENTRY_B9S); InitNandCrypto(entrypoint != ENTRY_B9S);
InitExtFS(); 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 while (timer_msec( timer ) < 500); // show splash for at least 0.5 sec
ClearScreenF(true, true, COLOR_STD_BG); // clear splash ClearScreenF(true, true, COLOR_STD_BG); // clear splash
// 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 // copy script to script buffer and run it
memset(SCRIPT_BUFFER, 0, SCRIPT_BUFFER_SIZE); memset(SCRIPT_BUFFER, 0, SCRIPT_BUFFER_SIZE);
memcpy(SCRIPT_BUFFER, autorun_gm9, autorun_gm9_size); memcpy(SCRIPT_BUFFER, autorun_gm9, autorun_gm9_size);
ExecuteGM9Script(NULL); ExecuteGM9Script(NULL);
} else ShowPrompt(false, "Compiled as script autorunner\nbut no autorun.gm9 provided.\n \nDerp!");
// deinit // deinit
DeinitExtFS(); DeinitExtFS();

View File

@ -79,7 +79,6 @@ void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64*
TarHeader* tar = tardata; TarHeader* tar = tardata;
if (ValidateTarHeader(tardata, tardata_end) != 0) break; 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')) if ((strncasecmp(tar->fname, fname, 100) == 0) && (tar->ftype == '0'))
return GetTarFileInfo(tardata, NULL, fsize, is_dir); return GetTarFileInfo(tardata, NULL, fsize, is_dir);
tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512); tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512);

View File

@ -4,6 +4,17 @@
#include "tar.h" #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_OFFSET 0x18000000
#define VRAM0_LIMIT 0x00300000 #define VRAM0_LIMIT 0x00300000

View File

@ -823,11 +823,12 @@ bool run_line(const char* line_start, const char* line_end, u32* flags, char* er
// checks for illegal ASCII symbols // checks for illegal ASCII symbols
bool ValidateText(const char* text, u32 len) { bool ValidateText(const char* text, u32 len) {
if (!len) return false;
for (u32 i = 0; i < len; i++) { for (u32 i = 0; i < len; i++) {
char c = text[i]; char c = text[i];
if ((c == '\r') && ((i+1) < len) && (text[i+1] != '\n')) return false; // CR without LF 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 < 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; return true;
} }