Skip to content

Commit

Permalink
Bootloader: improved bootloop preventation on FCRAM boots
Browse files Browse the repository at this point in the history
... also beautified the battery symbol a little
  • Loading branch information
d0k3 committed Sep 20, 2017
1 parent 2a98ab8 commit c80ebb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions source/common/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define COLOR_TINTEDYELLOW RGB(0xD0, 0xD0, 0x60)
#define COLOR_TINTEDGREEN RGB(0x70, 0x80, 0x70)
#define COLOR_LIGHTGREY RGB(0xB0, 0xB0, 0xB0)
#define COLOR_LIGHTERGREY RGB(0xD0, 0xD0, 0xD0)
#define COLOR_DARKGREY RGB(0x50, 0x50, 0x50)
#define COLOR_DARKESTGREY RGB(0x20, 0x20, 0x20)

Expand Down
16 changes: 10 additions & 6 deletions source/godmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ void CheckBattery(u32* battery, bool* is_charging) {

void GenerateBatteryBitmap(u8* bitmap, u32 width, u32 height, u32 color_bg) {
const u32 color_outline = COLOR_BLACK;
const u32 color_inline = COLOR_WHITE;
const u32 color_inside = COLOR_GREY;
const u32 color_inline = COLOR_LIGHTGREY;
const u32 color_inside = COLOR_LIGHTERGREY;

if ((width < 8) || (height < 6)) return;

Expand Down Expand Up @@ -1642,20 +1642,24 @@ u32 GodMode(bool is_b9s) {
bool bootmenu = bootloader && (ntrboot || CheckButton(BOOTMENU_KEY));
bool godmode9 = !bootloader;
FirmHeader* firm_in_mem = (FirmHeader*) DIR_BUFFER;
memcpy(firm_in_mem, "NOPE", 4); // to prevent bootloops
if (bootloader) { // check for FIRM in FCRAM, but prevent bootloops
bool found = false;
for (u8* addr = (u8*) 0x20000200; addr < (u8*) 0x24000000; addr += 0x400000) {
if (memcmp(addr - 0x200, "A9NC", 4) != 0) continue;
if (ValidateFirmHeader((FirmHeader*) (void*) addr, 0x100000) != 0) continue;
if (!found) memmove(firm_in_mem, addr, 0x100000);
if (memcmp(firm_in_mem, "FIRM", 4) != 0) memmove(firm_in_mem, addr, 0x100000);
if (memcmp(addr, "FIRM", 4) == 0) memcpy(addr, "NOPE", 4); // prevent bootloops
found = true;
}
}

const char* disp_mode =
ntrboot ? "ntrboot mode" :
bootmenu ? "bootmenu mode" :
bootloader ? "bootloader mode" :
!is_b9s ? "oldloader mode" : NULL;

ClearScreenF(true, true, COLOR_STD_BG);
SplashInit(ntrboot ? "ntrboot mode" : bootmenu ? "bootmenu mode" : bootloader ? "bootloader mode" : NULL);
SplashInit(disp_mode);
u64 timer = timer_start(); // show splash

if ((sizeof(DirStruct) > 0x78000) || (N_PANES * sizeof(PaneData) > 0x10000)) {
Expand Down

0 comments on commit c80ebb1

Please sign in to comment.