Skip to content

Commit 49b5b55

Browse files
committed
Allow compile as open installer
1 parent 8282c8e commit 49b5b55

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ else
4747
CFLAGS += -DFONT_6X10
4848
endif
4949

50+
ifeq ($(OPEN),1)
51+
CFLAGS += -DOPEN_INSTALLER
52+
endif
53+
5054
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
5155

5256
ASFLAGS := -g $(ARCH)

source/common/common.h

+20-8
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,30 @@
3737
#define align(v,a) \
3838
(((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v))
3939

40-
#define ENTRY_BRAHMA (1)
41-
#define ENTRY_GATEWAY (2)
42-
4340
// SafeB9SInstaller version
44-
#define VERSION "0.0.6"
45-
46-
// testfing flags, only useful to devs
47-
// #define NO_WRITE // disables all NAND writes, just for testing
48-
// #define FAIL_TEST // to test the emergency screen, only works with NO_TRANSFER defined
41+
#define VERSION "0.0.7"
4942

5043
// name of the FIRM to install (also name of the input path)
44+
#ifndef OPEN_INSTALLER
5145
#define NAME_FIRM "boot9strap"
46+
#else
47+
#define NAME_FIRM "sighax"
48+
#endif
5249

5350
// input / output paths
5451
#define INPUT_PATH "0:/" NAME_FIRM
5552

53+
// cosmetic stuff (for installer status)
54+
#ifndef OPEN_INSTALLER
55+
#define APP_TITLE "SafeB9SInstaller" " v" VERSION
56+
#define APP_URL "https://github.com/d0k3/SafeB9SInstaller"
57+
#define APP_USAGE "Usage instructions: https://%s3ds.guide/", IS_DEVKIT ? "dev." : ""
58+
#else
59+
#define APP_TITLE "OpenFirmInstaller" " v" VERSION
60+
#define APP_URL "https://github.com/d0k3/SafeB9SInstaller"
61+
#define APP_USAGE "Based on SafeB9SInstaller by d0k3"
62+
#endif
63+
5664
// buffer area defines (big buffer for firm)
5765
#define WORK_BUFFER ((u8*) 0x21000000)
5866
#define WORK_BUFFER_SIZE (0x400000)
@@ -61,6 +69,10 @@
6169
#define NAND_BUFFER ((u8*) 0x21800000)
6270
#define NAND_BUFFER_SIZE (0x100000)
6371

72+
// testfing flags, only useful to devs
73+
// #define NO_WRITE // disables all NAND writes, just for testing
74+
// #define FAIL_TEST // to test the emergency screen, only works with NO_TRANSFER defined
75+
6476
inline u32 strchrcount(const char* str, char symbol) {
6577
u32 count = 0;
6678
for (u32 i = 0; str[i] != '\0'; i++) {

source/installer.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ u32 ShowInstallerStatus(void) {
4646
const u32 pos_y0 = pos_yb + 50;
4747
const u32 stp = 14;
4848

49-
DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, "SafeB9SInstaller v" VERSION "\n" "-----------------------" "\n" "https://github.com/d0k3/SafeB9SInstaller");
49+
// DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, "SafeB9SInstaller v" VERSION "\n" "-----------------------" "\n" "https://github.com/d0k3/SafeB9SInstaller");
50+
DrawStringF(BOT_SCREEN, pos_xb, pos_yb, COLOR_STD_FONT, COLOR_STD_BG, APP_TITLE "\n" "%.*s" "\n" APP_URL,
51+
strnlen(APP_TITLE, 32), "--------------------------------");
5052

5153
DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (0*stp), COLOR_STD_FONT, COLOR_STD_BG, "ARM9LoaderHax -");
5254
DrawStringF(BOT_SCREEN, pos_x0, pos_y0 + (1*stp), COLOR_STD_FONT, COLOR_STD_BG, "MicroSD Card -");
@@ -64,7 +66,7 @@ u32 ShowInstallerStatus(void) {
6466
DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (5*stp), COLOR_STATUS(statusBackup) , COLOR_STD_BG, "%-21.21s", msgBackup );
6567
DrawStringF(BOT_SCREEN, pos_x1, pos_y0 + (6*stp), COLOR_STATUS(statusInstall), COLOR_STD_BG, "%-21.21s", msgInstall);
6668

67-
DrawStringF(BOT_SCREEN, pos_xb, pos_yu - 10, COLOR_STD_FONT, COLOR_STD_BG, "Usage instructions: https://%s3ds.guide/", IS_DEVKIT ? "dev." : "");
69+
DrawStringF(BOT_SCREEN, pos_xb, pos_yu - 10, COLOR_STD_FONT, COLOR_STD_BG, APP_USAGE);
6870
return 0;
6971
}
7072

@@ -129,12 +131,11 @@ u32 SafeB9SInstaller(void) {
129131
statusFirm = STATUS_RED;
130132
return 1;
131133
}
132-
if (CheckBoot9Strap(FIRM_BUFFER) != 0) {
133-
snprintf(msgFirm, 64, "not boot9strap");
134+
if (CheckFirmPayload(FIRM_BUFFER, msgFirm) != 0) {
134135
statusFirm = STATUS_RED;
135136
return 1;
136137
}
137-
snprintf(msgFirm, 64, "loaded & verified");
138+
// snprintf(msgFirm, 64, "loaded & verified");
138139
statusFirm = STATUS_GREEN;
139140
ShowInstallerStatus();
140141
// provided FIRM is okay!

source/safety/validator.c

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#define B9S_MAGIC "B9S"
99
#define B9S_OFFSET (0x40 - strnlen(B9S_MAGIC, 0x10))
1010

11+
#define FB3_MAGIC "FASTBOOT 3DS "
12+
#define FB3_OFFSET 0x200 // this is not actually used
13+
1114
// see: https://www.3dbrew.org/wiki/FIRM#Firmware_Section_Headers
1215
typedef struct {
1316
u32 offset;
@@ -130,3 +133,28 @@ u32 CheckFirmSigHax(void* firm) {
130133
u32 CheckBoot9Strap(void* firm) {
131134
return (memcmp(((u8*) firm) + B9S_OFFSET, B9S_MAGIC, strnlen(B9S_MAGIC, 0x10)) == 0) ? 0 : 1;
132135
}
136+
137+
u32 CheckFastBoot3DS(void* firm) {
138+
FirmHeader* header = (FirmHeader*) firm;
139+
u32 offset = 0;
140+
for (u32 i = 0; (i < 4) && !offset; i++) { // find ARM9 section
141+
FirmSectionHeader* section = header->sections + i;
142+
if (section->size && (section->type == 0))
143+
offset = section->offset;
144+
}
145+
return (offset && (memcmp(((u8*) firm) + offset, FB3_MAGIC, strnlen(FB3_MAGIC, 0x10)) == 0)) ? 0 : 1;
146+
}
147+
148+
u32 CheckFirmPayload(void* firm, char* result) {
149+
if (CheckBoot9Strap(firm) == 0) {
150+
if (result) snprintf(result, 32, "boot9strap firm");
151+
return 0;
152+
#ifdef OPEN_INSTALLER
153+
} else if (CheckFastBoot3DS(firm) == 0) {
154+
if (result) snprintf(result, 32, "fastboot3ds firm");
155+
return 0;
156+
#endif
157+
}
158+
if (result) snprintf(result, 32, "unknown firm");
159+
return 1;
160+
}

source/safety/validator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
u32 ValidateFirm(void* firm, u8* firm_sha, u32 firm_size, char* output);
66
u32 ValidateSector(void* sector);
77
u32 CheckFirmSigHax(void* firm);
8-
u32 CheckBoot9Strap(void* firm);
8+
u32 CheckFirmPayload(void* firm, char* result);

0 commit comments

Comments
 (0)