Skip to content

Commit

Permalink
Allow compile as open installer
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Jun 3, 2017
1 parent 8282c8e commit 49b5b55
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ else
CFLAGS += -DFONT_6X10
endif

ifeq ($(OPEN),1)
CFLAGS += -DOPEN_INSTALLER
endif

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
Expand Down
28 changes: 20 additions & 8 deletions source/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,30 @@
#define align(v,a) \
(((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v))

#define ENTRY_BRAHMA (1)
#define ENTRY_GATEWAY (2)

// SafeB9SInstaller version
#define VERSION "0.0.6"

// 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
#define VERSION "0.0.7"

// name of the FIRM to install (also name of the input path)
#ifndef OPEN_INSTALLER
#define NAME_FIRM "boot9strap"
#else
#define NAME_FIRM "sighax"
#endif

// input / output paths
#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)
#define WORK_BUFFER ((u8*) 0x21000000)
#define WORK_BUFFER_SIZE (0x400000)
Expand All @@ -61,6 +69,10 @@
#define NAND_BUFFER ((u8*) 0x21800000)
#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) {
u32 count = 0;
for (u32 i = 0; str[i] != '\0'; i++) {
Expand Down
11 changes: 6 additions & 5 deletions source/installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ u32 ShowInstallerStatus(void) {
const u32 pos_y0 = pos_yb + 50;
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 + (1*stp), COLOR_STD_FONT, COLOR_STD_BG, "MicroSD Card -");
Expand All @@ -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 + (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;
}

Expand Down Expand Up @@ -129,12 +131,11 @@ u32 SafeB9SInstaller(void) {
statusFirm = STATUS_RED;
return 1;
}
if (CheckBoot9Strap(FIRM_BUFFER) != 0) {
snprintf(msgFirm, 64, "not boot9strap");
if (CheckFirmPayload(FIRM_BUFFER, msgFirm) != 0) {
statusFirm = STATUS_RED;
return 1;
}
snprintf(msgFirm, 64, "loaded & verified");
// snprintf(msgFirm, 64, "loaded & verified");
statusFirm = STATUS_GREEN;
ShowInstallerStatus();
// provided FIRM is okay!
Expand Down
28 changes: 28 additions & 0 deletions source/safety/validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define B9S_MAGIC "B9S"
#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
typedef struct {
u32 offset;
Expand Down Expand Up @@ -130,3 +133,28 @@ u32 CheckFirmSigHax(void* firm) {
u32 CheckBoot9Strap(void* firm) {
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;
}
2 changes: 1 addition & 1 deletion source/safety/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
u32 ValidateFirm(void* firm, u8* firm_sha, u32 firm_size, char* output);
u32 ValidateSector(void* sector);
u32 CheckFirmSigHax(void* firm);
u32 CheckBoot9Strap(void* firm);
u32 CheckFirmPayload(void* firm, char* result);

1 comment on commit 49b5b55

@Ryumarubr
Copy link

@Ryumarubr Ryumarubr commented on 49b5b55 Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installer has support for performing the upgrade procedure, for version 1.1 of boot9strap ?

Please sign in to comment.