diff --git a/source/emunand.c b/source/emunand.c index 67c888a..89a07bb 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -102,7 +102,7 @@ static inline u32 getFreeK9Space(u8 *pos, u32 size, u8 **freeK9Space) //Looking for the last free space before Process9 *freeK9Space = memsearch(pos + 0x13500, pattern, size - 0x13500, sizeof(pattern)) + 0x455; - return *freeK9Space == NULL ? 1 : 0; + return *freeK9Space == NULL ? 1 : 0; } static inline u32 getSdmmc(u8 *pos, u32 size, u32 *sdmmc) @@ -171,13 +171,13 @@ static inline u32 patchMpu(u8 *pos, u32 size) return ret; } -u32 patchEmuNand(u8 *arm9Section, u8 *process9Offset, u32 process9Size, u32 emuHeader) +u32 patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32 process9Size, u32 emuHeader, u8 *kernel9Address) { u32 ret = 0; //Copy EmuNAND code u8 *freeK9Space; - ret += getFreeK9Space(arm9Section, firm->section[2].size, &freeK9Space); + ret += getFreeK9Space(arm9Section, arm9SectionSize, &freeK9Space); if(!ret) { memcpy(freeK9Space, emunand_bin, emunand_bin_size); @@ -195,10 +195,10 @@ u32 patchEmuNand(u8 *arm9Section, u8 *process9Offset, u32 process9Size, u32 emuH if(!ret) *posSdmmc = sdmmc; //Add EmuNAND hooks - ret += patchNandRw(process9Offset, process9Size, (u32)(freeK9Space - arm9Section + firm->section[2].address)); + ret += patchNandRw(process9Offset, process9Size, (u32)(freeK9Space - arm9Section + kernel9Address)); //Set MPU - ret += patchMpu(arm9Section, firm->section[2].size); + ret += patchMpu(arm9Section, arm9SectionSize); } return ret; diff --git a/source/emunand.h b/source/emunand.h index 70f41a2..bf1480a 100644 --- a/source/emunand.h +++ b/source/emunand.h @@ -27,4 +27,4 @@ #define ROUND_TO_4MB(a) (((a) + 0x2000 - 1) & (~(0x2000 - 1))) void locateEmuNand(u32 *emuHeader, FirmwareSource *nandType); -u32 patchEmuNand(u8 *arm9Section, u8 *process9Offset, u32 process9Size, u32 emuHeader); \ No newline at end of file +u32 patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32 process9Size, u32 emuHeader, u8 *kernel9Address); \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index b8af875..ec12891 100755 --- a/source/firm.c +++ b/source/firm.c @@ -34,6 +34,8 @@ #include "screen.h" #include "../build/bundled.h" +static Firm *firm = (Firm *)0x24000000; + u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode) { const char *firmwareFiles[] = { @@ -140,7 +142,7 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, u32 ret += patchSignatureChecks(process9Offset, process9Size); //Apply EmuNAND patches - if(nandType != FIRMWARE_SYSNAND) ret += patchEmuNand(arm9Section, process9Offset, process9Size, emuHeader); + if(nandType != FIRMWARE_SYSNAND) ret += patchEmuNand(arm9Section, firm->section[2].size, process9Offset, process9Size, emuHeader, firm->section[2].address); //Apply FIRM0/1 writes patches on sysNAND to protect A9LH else if(ISA9LH || (ISFIRMLAUNCH && BOOTCFG_A9LH != 0)) ret += patchFirmWrites(process9Offset, process9Size); diff --git a/source/types.h b/source/types.h index 9238d14..54a3f47 100644 --- a/source/types.h +++ b/source/types.h @@ -100,5 +100,4 @@ typedef enum FirmwareType NATIVE_FIRM1X2X } FirmwareType; -extern u16 launchedFirmTidLow[8]; //Defined in start.s -static Firm *const firm = (Firm *)0x24000000; \ No newline at end of file +extern u16 launchedFirmTidLow[8]; //Defined in start.s \ No newline at end of file