Fix: FIRM from FCRAM handling

This commit is contained in:
d0k3 2018-02-05 01:19:50 +01:00
parent a2bbcef1a0
commit 14323b4d8d
2 changed files with 28 additions and 11 deletions

View File

@ -1,4 +1,5 @@
#include "godmode.h" #include "godmode.h"
#include "memmap.h"
#include "support.h" #include "support.h"
#include "ui.h" #include "ui.h"
#include "hid.h" #include "hid.h"
@ -1867,17 +1868,17 @@ u32 GodMode(int entrypoint) {
bool bootloader = IS_SIGHAX && (entrypoint == ENTRY_NANDBOOT); bool bootloader = IS_SIGHAX && (entrypoint == ENTRY_NANDBOOT);
bool bootmenu = bootloader && (BOOTMENU_KEY != BUTTON_START) && CheckButton(BOOTMENU_KEY); bool bootmenu = bootloader && (BOOTMENU_KEY != BUTTON_START) && CheckButton(BOOTMENU_KEY);
bool godmode9 = !bootloader; bool godmode9 = !bootloader;
/*FirmHeader* firm_in_mem = (FirmHeader*) (void*) (TEMP_BUFFER + TEMP_BUFFER_SIZE); // should be safe here FirmHeader* firm_in_mem = (FirmHeader*) __FIRMTMP_ADDR; // should be safe here
memcpy(firm_in_mem, "NOPE", 4); // to prevent bootloops memcpy(firm_in_mem, "NOPE", 4); // to prevent bootloops
if (bootloader) { // check for FIRM in FCRAM, but prevent bootloops if (bootloader) { // check for FIRM in FCRAM, but prevent bootloops
for (u8* addr = (u8*) 0x20000200; addr < (u8*) 0x22000000; addr += 0x400000) { for (u8* addr = (u8*) __FCRAM0_ADDR + 0x200; addr < (u8*) __HEAP_END; addr += 0x400000) { // don't search the stack
if (memcmp(addr - 0x200, "A9NC", 4) != 0) continue; if (memcmp(addr - 0x200, "A9NC", 4) != 0) continue;
u32 firm_size = GetFirmSize((FirmHeader*) (void*) addr); u32 firm_size = GetFirmSize((FirmHeader*) (void*) addr);
if (!firm_size || (firm_size > (0x400000 - 0x200))) continue; if (!firm_size || (firm_size > (0x400000 - 0x200))) continue;
if (memcmp(firm_in_mem, "FIRM", 4) != 0) memmove(firm_in_mem, addr, firm_size); if (memcmp(firm_in_mem, "FIRM", 4) != 0) memmove(firm_in_mem, addr, firm_size);
if (memcmp(addr, "FIRM", 4) == 0) memcpy(addr, "NOPE", 4); // prevent bootloops if (memcmp(addr, "FIRM", 4) == 0) memcpy(addr, "NOPE", 4); // prevent bootloops
} }
}*/ }
// get mode string for splash screen // get mode string for splash screen
const char* disp_mode = NULL; const char* disp_mode = NULL;
@ -1977,7 +1978,7 @@ u32 GodMode(int entrypoint) {
// bootloader handler // bootloader handler
if (bootloader) { if (bootloader) {
const char* bootfirm_paths[] = { BOOTFIRM_PATHS }; const char* bootfirm_paths[] = { BOOTFIRM_PATHS };
// if (IsBootableFirm(firm_in_mem, FIRM_MAX_SIZE)) BootFirm(firm_in_mem, "sdmc:/bootonce.firm"); if (IsBootableFirm(firm_in_mem, FIRM_MAX_SIZE)) BootFirm(firm_in_mem, "sdmc:/bootonce.firm");
for (u32 i = 0; i < sizeof(bootfirm_paths) / sizeof(char*); i++) { for (u32 i = 0; i < sizeof(bootfirm_paths) / sizeof(char*); i++) {
BootFirmHandler(bootfirm_paths[i], false, (BOOTFIRM_TEMPS >> i) & 0x1); BootFirmHandler(bootfirm_paths[i], false, (BOOTFIRM_TEMPS >> i) & 0x1);
} }

View File

@ -1,12 +1,28 @@
# pragma once # pragma once
// not complete! (!!!)
#define __RAMDRV_ADDR 0x22800000 // general memory areas
#define __RAMDRV_END 0x28000000
#define __STACK_ADDR (__RAMDRV_ADDR - 0x800000) #define __FCRAM0_ADDR 0x20000000
#define __STACK_END __RAMDRV_ADDR #define __FCRAM0_END 0x28000000
#define __HEAP_ADDR 0x20700000 #define __FCRAM1_ADDR 0x28000000
#define __HEAP_END __STACK_ADDR #define __FCRAM1_END 0x30000000
// stuff in FCRAM
#define __FIRMTMP_ADDR (__FCRAM0_END - 0x0800000)
#define __FIRMTMP_END (__FIRMTMP_ADDR + 0x0400000)
#define __RAMDRV_ADDR (__FCRAM0_ADDR + 0x2800000)
#define __RAMDRV_END __FCRAM0_END // can be bigger on N3DS
#define __STACK_TOP __RAMDRV_ADDR
#define __STACK_SIZE 0x7F0000
#define __STACKABT_TOP (__STACK_TOP - __STACK_SIZE)
#define __STACKABT_SIZE 0x10000
#define __HEAP_ADDR (__FCRAM0_ADDR + 0x0700000)
#define __HEAP_END (__STACKABT_TOP - __STACKABT_SIZE)