From 2f6afe9932ef51824420f7e5829fc272cfa4969c Mon Sep 17 00:00:00 2001 From: Aurora Date: Thu, 8 Sep 2016 01:50:02 +0200 Subject: [PATCH 1/2] Minor stuff --- source/fatfs/sdmmc/sdmmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/fatfs/sdmmc/sdmmc.c b/source/fatfs/sdmmc/sdmmc.c index 74901e0..27966a1 100644 --- a/source/fatfs/sdmmc/sdmmc.c +++ b/source/fatfs/sdmmc/sdmmc.c @@ -107,8 +107,8 @@ static void __attribute__ ((noinline)) sdmmc_send_command(struct mmcdevice *ctx, u8 *rDataPtr = ctx->rData; const u8 *tDataPtr = ctx->tData; - int rUseBuf = NULL != rDataPtr; - int tUseBuf = NULL != tDataPtr; + bool rUseBuf = rDataPtr != NULL; + bool tUseBuf = tDataPtr != NULL; u16 status0 = 0; while(true) From 277d7239928915c38c304beb6c8a44a4148cdf39 Mon Sep 17 00:00:00 2001 From: Aurora Date: Thu, 8 Sep 2016 02:12:29 +0200 Subject: [PATCH 2/2] Minor stuff (2) --- injector/source/patcher.c | 6 +++--- source/config.c | 4 ++-- source/config.h | 4 ++-- source/emunand.c | 29 ++++++++++++++--------------- source/fatfs/sdmmc/sdmmc.c | 4 ++-- source/firm.c | 19 +++++++------------ source/pin.c | 8 ++++---- source/pin.h | 2 +- source/screen.c | 2 +- 9 files changed, 36 insertions(+), 42 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 188a524..5242309 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -324,9 +324,9 @@ void patchCode(u64 progId, u8 *code, u32 size) static const u8 fpdVerPattern[] = { 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01 }; - + static const u8 mostRecentFpdVer = 0x06; - + u8 *fpdVer = memsearch(code, fpdVerPattern, size, sizeof(fpdVerPattern)); //Allow online access to work with old friends modules, without breaking newer firmwares @@ -399,7 +399,7 @@ void patchCode(u64 progId, u8 *code, u32 size) u32 cpuSetting = CONFIG_NEWCPU; - if(cpuSetting) + if(cpuSetting != 0) { static const u8 cfgN3dsCpuPattern[] = { 0x00, 0x40, 0xA0, 0xE1, 0x07 diff --git a/source/config.c b/source/config.c index 006e253..18f260e 100644 --- a/source/config.c +++ b/source/config.c @@ -31,7 +31,7 @@ bool readConfig(void) { - if(fileRead(&configData, CONFIG_PATH) != sizeof(cfgData) || + if(fileRead(&configData, CONFIG_PATH) != sizeof(CfgData) || memcmp(configData.magic, "CONF", 4) != 0 || configData.formatVersionMajor != CONFIG_VERSIONMAJOR || configData.formatVersionMinor != CONFIG_VERSIONMINOR) @@ -59,7 +59,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) //Merge the new options and new boot configuration configData.config = (configData.config & 0xFFFFFFC0) | (configTemp & 0x3F); - if(!fileWrite(&configData, CONFIG_PATH, sizeof(cfgData))) + if(!fileWrite(&configData, CONFIG_PATH, sizeof(CfgData))) error("Error writing the configuration file"); } } diff --git a/source/config.h b/source/config.h index 425ca76..29c00e7 100644 --- a/source/config.h +++ b/source/config.h @@ -51,7 +51,7 @@ typedef struct __attribute__((packed)) u16 formatVersionMajor, formatVersionMinor; u32 config; -} cfgData; +} CfgData; typedef enum ConfigurationStatus { @@ -60,7 +60,7 @@ typedef enum ConfigurationStatus CREATE_CONFIGURATION = 2 } ConfigurationStatus; -extern cfgData configData; +extern CfgData configData; bool readConfig(void); void writeConfig(ConfigurationStatus needConfig, u32 configTemp); diff --git a/source/emunand.c b/source/emunand.c index 80915af..bd11046 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -25,7 +25,7 @@ #include "fatfs/sdmmc/sdmmc.h" #include "../build/emunandpatch.h" -void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) +void locateEmuNand(u32 *emuHeader, FirmwareSource *nandType) { static u8 temp[0x200]; const u32 nandSize = getMMCDevice(0)->total_size; @@ -43,11 +43,11 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) nandOffset = isN3DS ? 0x26E000 : 0x1D8000; //"Minsize" layout break; default: - nandOffset = *emuNand == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout + nandOffset = *nandType == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout break; } - if(*emuNand != FIRMWARE_EMUNAND) nandOffset *= ((u32)*emuNand - 1); + if(*nandType != FIRMWARE_EMUNAND) nandOffset *= ((u32)*nandType - 1); //Check for RedNAND if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC) @@ -57,7 +57,7 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) found = true; } - //Check for Gateway emuNAND + //Check for Gateway EmuNAND else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC) { emuOffset = nandOffset; @@ -65,19 +65,18 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) found = true; } - if(*emuNand == FIRMWARE_EMUNAND) break; + if(*nandType == FIRMWARE_EMUNAND) break; } - /* Fallback to the first emuNAND if there's no second one, - or to SysNAND if there isn't any */ + //Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any if(!found) { - if(*emuNand != FIRMWARE_EMUNAND) + if(*nandType != FIRMWARE_EMUNAND) { - *emuNand = FIRMWARE_EMUNAND; - locateEmuNand(emuHeader, emuNand); + *nandType = FIRMWARE_EMUNAND; + locateEmuNand(emuHeader, nandType); } - else *emuNand = FIRMWARE_SYSNAND; + else *nandType = FIRMWARE_SYSNAND; } } @@ -130,11 +129,11 @@ static inline void patchMpu(u8 *pos, u32 size) void patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32 process9Size, u32 emuHeader, u32 branchAdditive) { - //Copy emuNAND code + //Copy EmuNAND code u8 *freeK9Space = getFreeK9Space(arm9Section, arm9SectionSize); memcpy(freeK9Space, emunand, emunand_size); - //Add the data of the found emuNAND + //Add the data of the found EmuNAND u32 *posOffset = (u32 *)memsearch(freeK9Space, "NAND", emunand_size, 4), *posHeader = (u32 *)memsearch(freeK9Space, "NCSD", emunand_size, 4); *posOffset = emuOffset; @@ -144,10 +143,10 @@ void patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32 u32 *posSdmmc = (u32 *)memsearch(freeK9Space, "SDMC", emunand_size, 4); *posSdmmc = getSdmmc(process9Offset, process9Size); - //Add emuNAND hooks + //Add EmuNAND hooks u32 branchOffset = (u32)freeK9Space - branchAdditive; patchNandRw(process9Offset, process9Size, branchOffset); - //Set MPU for emu code region + //Set MPU patchMpu(arm9Section, arm9SectionSize); } \ No newline at end of file diff --git a/source/fatfs/sdmmc/sdmmc.c b/source/fatfs/sdmmc/sdmmc.c index 27966a1..23ecd58 100644 --- a/source/fatfs/sdmmc/sdmmc.c +++ b/source/fatfs/sdmmc/sdmmc.c @@ -25,8 +25,8 @@ #include "sdmmc.h" #include "delay.h" -struct mmcdevice handleNAND; -struct mmcdevice handleSD; +static struct mmcdevice handleNAND; +static struct mmcdevice handleSD; static inline u16 sdmmc_read16(u16 reg) { diff --git a/source/firm.c b/source/firm.c index 56719e3..bbdda32 100755 --- a/source/firm.c +++ b/source/firm.c @@ -41,21 +41,17 @@ static firmHeader *const firm = (firmHeader *)0x24000000; static const firmSectionHeader *section; u32 emuOffset; - bool isN3DS, isDevUnit, isFirmlaunch; - -cfgData configData; +CfgData configData; FirmwareSource firmSource; void main(void) { bool isA9lh; - u32 configTemp, emuHeader; - FirmwareType firmType; FirmwareSource nandType; ConfigurationStatus needConfig; @@ -186,8 +182,7 @@ void main(void) firmSource = nandType; } - /* If we're booting emuNAND the second emuNAND is set as default and B isn't pressed, - or vice-versa, boot the second emuNAND */ + //If we're booting EmuNAND, determine which one from the directional pad buttons, or otherwise from the config if(nandType == FIRMWARE_EMUNAND) switch(pressed & EMUNAND_BUTTONS) { @@ -210,14 +205,14 @@ void main(void) } } - //If we need to boot emuNAND, make sure it exists + //If we need to boot EmuNAND, make sure it exists if(nandType != FIRMWARE_SYSNAND) { locateEmuNand(&emuHeader, &nandType); if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND; } - //Same if we're using emuNAND as the FIRM source + //Same if we're using EmuNAND as the FIRM source else if(firmSource != FIRMWARE_SYSNAND) locateEmuNand(&emuHeader, &firmSource); @@ -285,8 +280,8 @@ static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource) static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh) { - u8 *arm9Section = (u8 *)firm + section[2].offset; - u8 *arm11Section1 = (u8 *)firm + section[1].offset; + u8 *arm9Section = (u8 *)firm + section[2].offset, + *arm11Section1 = (u8 *)firm + section[1].offset; if(isN3DS) { @@ -310,7 +305,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 //Apply signature patches patchSignatureChecks(process9Offset, process9Size); - //Apply emuNAND patches + //Apply EmuNAND patches if(nandType != FIRMWARE_SYSNAND) { u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address; diff --git a/source/pin.c b/source/pin.c index 5e7b7dc..4d3e1f2 100644 --- a/source/pin.c +++ b/source/pin.c @@ -83,7 +83,7 @@ void newPin(bool allowSkipping) charDrawPos += 2 * SPACING_X; } - PINData pin; + PinData pin; memcpy(pin.magic, "PINF", 4); pin.formatVersionMajor = PIN_VERSIONMAJOR; @@ -99,7 +99,7 @@ void newPin(bool allowSkipping) computePinHash(tmp, enteredPassword); memcpy(pin.hash, tmp, sizeof(tmp)); - if(!fileWrite(&pin, PIN_PATH, sizeof(PINData))) + if(!fileWrite(&pin, PIN_PATH, sizeof(PinData))) error("Error writing the PIN file"); } @@ -107,9 +107,9 @@ bool verifyPin(void) { initScreens(); - PINData pin; + PinData pin; - if(fileRead(&pin, PIN_PATH) != sizeof(PINData) || + if(fileRead(&pin, PIN_PATH) != sizeof(PinData) || memcmp(pin.magic, "PINF", 4) != 0 || pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMinor != PIN_VERSIONMINOR || diff --git a/source/pin.h b/source/pin.h index 462094c..cf502ff 100644 --- a/source/pin.h +++ b/source/pin.h @@ -42,7 +42,7 @@ typedef struct __attribute__((packed)) u8 length; u8 testHash[32]; u8 hash[32]; -} PINData; +} PinData; void newPin(bool allowSkipping); bool verifyPin(void); \ No newline at end of file diff --git a/source/screen.c b/source/screen.c index fc06222..1707d37 100644 --- a/source/screen.c +++ b/source/screen.c @@ -242,7 +242,7 @@ void initScreens(void) if(PDN_GPU_CNT == 1) { - flushDCacheRange(&configData, sizeof(cfgData)); + flushDCacheRange(&configData, sizeof(CfgData)); flushDCacheRange((void *)fb, sizeof(struct fb)); invokeArm11Function(ARM11);