Allow compile as open installer

This commit is contained in:
d0k3 2017-06-03 13:50:01 +02:00
parent 8282c8e769
commit 49b5b55221
5 changed files with 59 additions and 14 deletions

View File

@ -47,6 +47,10 @@ else
CFLAGS += -DFONT_6X10 CFLAGS += -DFONT_6X10
endif endif
ifeq ($(OPEN),1)
CFLAGS += -DOPEN_INSTALLER
endif
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)

View File

@ -37,22 +37,30 @@
#define align(v,a) \ #define align(v,a) \
(((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v)) (((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v))
#define ENTRY_BRAHMA (1)
#define ENTRY_GATEWAY (2)
// SafeB9SInstaller version // SafeB9SInstaller version
#define VERSION "0.0.6" #define VERSION "0.0.7"
// testfing flags, only useful to devs
// #define NO_WRITE // disables all NAND writes, just for testing
// #define FAIL_TEST // to test the emergency screen, only works with NO_TRANSFER defined
// name of the FIRM to install (also name of the input path) // name of the FIRM to install (also name of the input path)
#ifndef OPEN_INSTALLER
#define NAME_FIRM "boot9strap" #define NAME_FIRM "boot9strap"
#else
#define NAME_FIRM "sighax"
#endif
// input / output paths // input / output paths
#define INPUT_PATH "0:/" NAME_FIRM #define INPUT_PATH "0:/" NAME_FIRM
// cosmetic stuff (for installer status)
#ifndef OPEN_INSTALLER
#define APP_TITLE "SafeB9SInstaller" " v" VERSION
#define APP_URL "https://github.com/d0k3/SafeB9SInstaller"
#define APP_USAGE "Usage instructions: https://%s3ds.guide/", IS_DEVKIT ? "dev." : ""
#else
#define APP_TITLE "OpenFirmInstaller" " v" VERSION
#define APP_URL "https://github.com/d0k3/SafeB9SInstaller"
#define APP_USAGE "Based on SafeB9SInstaller by d0k3"
#endif
// buffer area defines (big buffer for firm) // buffer area defines (big buffer for firm)
#define WORK_BUFFER ((u8*) 0x21000000) #define WORK_BUFFER ((u8*) 0x21000000)
#define WORK_BUFFER_SIZE (0x400000) #define WORK_BUFFER_SIZE (0x400000)
@ -61,6 +69,10 @@
#define NAND_BUFFER ((u8*) 0x21800000) #define NAND_BUFFER ((u8*) 0x21800000)
#define NAND_BUFFER_SIZE (0x100000) #define NAND_BUFFER_SIZE (0x100000)
// testfing flags, only useful to devs
// #define NO_WRITE // disables all NAND writes, just for testing
// #define FAIL_TEST // to test the emergency screen, only works with NO_TRANSFER defined
inline u32 strchrcount(const char* str, char symbol) { inline u32 strchrcount(const char* str, char symbol) {
u32 count = 0; u32 count = 0;
for (u32 i = 0; str[i] != '\0'; i++) { for (u32 i = 0; str[i] != '\0'; i++) {

View File

@ -46,7 +46,9 @@ u32 ShowInstallerStatus(void) {
const u32 pos_y0 = pos_yb + 50; const u32 pos_y0 = pos_yb + 50;
const u32 stp = 14; const u32 stp = 14;
DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, "SafeB9SInstaller v" VERSION "\n" "-----------------------" "\n" "https://github.com/d0k3/SafeB9SInstaller"); // DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, "SafeB9SInstaller v" VERSION "\n" "-----------------------" "\n" "https://github.com/d0k3/SafeB9SInstaller");
DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, APP_TITLE "\n" "%.*s" "\n" APP_URL,
strnlen(APP_TITLE, 32), "--------------------------------");
DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (0*stp), COLOR_STD_FONT, COLOR_STD_BG, "ARM9LoaderHax -"); DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (0*stp), COLOR_STD_FONT, COLOR_STD_BG, "ARM9LoaderHax -");
DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (1*stp), COLOR_STD_FONT, COLOR_STD_BG, "MicroSD Card -"); DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (1*stp), COLOR_STD_FONT, COLOR_STD_BG, "MicroSD Card -");
@ -64,7 +66,7 @@ u32 ShowInstallerStatus(void) {
DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (5*stp), COLOR_STATUS(statusBackup) , COLOR_STD_BG, "%-21.21s", msgBackup ); DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (5*stp), COLOR_STATUS(statusBackup) , COLOR_STD_BG, "%-21.21s", msgBackup );
DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (6*stp), COLOR_STATUS(statusInstall), COLOR_STD_BG, "%-21.21s", msgInstall); DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (6*stp), COLOR_STATUS(statusInstall), COLOR_STD_BG, "%-21.21s", msgInstall);
DrawStringF(BOT_SCREEN, pos_xb, pos_yu - 10, COLOR_STD_FONT, COLOR_STD_BG, "Usage instructions: https://%s3ds.guide/", IS_DEVKIT ? "dev." : ""); DrawStringF(BOT_SCREEN, pos_xb, pos_yu - 10, COLOR_STD_FONT, COLOR_STD_BG, APP_USAGE);
return 0; return 0;
} }
@ -129,12 +131,11 @@ u32 SafeB9SInstaller(void) {
statusFirm = STATUS_RED; statusFirm = STATUS_RED;
return 1; return 1;
} }
if (CheckBoot9Strap(FIRM_BUFFER) != 0) { if (CheckFirmPayload(FIRM_BUFFER, msgFirm) != 0) {
snprintf(msgFirm, 64, "not boot9strap");
statusFirm = STATUS_RED; statusFirm = STATUS_RED;
return 1; return 1;
} }
snprintf(msgFirm, 64, "loaded & verified"); // snprintf(msgFirm, 64, "loaded & verified");
statusFirm = STATUS_GREEN; statusFirm = STATUS_GREEN;
ShowInstallerStatus(); ShowInstallerStatus();
// provided FIRM is okay! // provided FIRM is okay!

View File

@ -8,6 +8,9 @@
#define B9S_MAGIC "B9S" #define B9S_MAGIC "B9S"
#define B9S_OFFSET (0x40 - strnlen(B9S_MAGIC, 0x10)) #define B9S_OFFSET (0x40 - strnlen(B9S_MAGIC, 0x10))
#define FB3_MAGIC "FASTBOOT 3DS "
#define FB3_OFFSET 0x200 // this is not actually used
// see: https://www.3dbrew.org/wiki/FIRM#Firmware_Section_Headers // see: https://www.3dbrew.org/wiki/FIRM#Firmware_Section_Headers
typedef struct { typedef struct {
u32 offset; u32 offset;
@ -130,3 +133,28 @@ u32 CheckFirmSigHax(void* firm) {
u32 CheckBoot9Strap(void* firm) { u32 CheckBoot9Strap(void* firm) {
return (memcmp(((u8*) firm) + B9S_OFFSET, B9S_MAGIC, strnlen(B9S_MAGIC, 0x10)) == 0) ? 0 : 1; return (memcmp(((u8*) firm) + B9S_OFFSET, B9S_MAGIC, strnlen(B9S_MAGIC, 0x10)) == 0) ? 0 : 1;
} }
u32 CheckFastBoot3DS(void* firm) {
FirmHeader* header = (FirmHeader*) firm;
u32 offset = 0;
for (u32 i = 0; (i < 4) && !offset; i++) { // find ARM9 section
FirmSectionHeader* section = header->sections + i;
if (section->size && (section->type == 0))
offset = section->offset;
}
return (offset && (memcmp(((u8*) firm) + offset, FB3_MAGIC, strnlen(FB3_MAGIC, 0x10)) == 0)) ? 0 : 1;
}
u32 CheckFirmPayload(void* firm, char* result) {
if (CheckBoot9Strap(firm) == 0) {
if (result) snprintf(result, 32, "boot9strap firm");
return 0;
#ifdef OPEN_INSTALLER
} else if (CheckFastBoot3DS(firm) == 0) {
if (result) snprintf(result, 32, "fastboot3ds firm");
return 0;
#endif
}
if (result) snprintf(result, 32, "unknown firm");
return 1;
}

View File

@ -5,4 +5,4 @@
u32 ValidateFirm(void* firm, u8* firm_sha, u32 firm_size, char* output); u32 ValidateFirm(void* firm, u8* firm_sha, u32 firm_size, char* output);
u32 ValidateSector(void* sector); u32 ValidateSector(void* sector);
u32 CheckFirmSigHax(void* firm); u32 CheckFirmSigHax(void* firm);
u32 CheckBoot9Strap(void* firm); u32 CheckFirmPayload(void* firm, char* result);