Merge branch 'master' into developer

This commit is contained in:
Aurora 2016-09-08 03:11:06 +02:00
commit 6e178e2069
9 changed files with 36 additions and 42 deletions

View File

@ -399,7 +399,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
u32 cpuSetting = CONFIG_NEWCPU; u32 cpuSetting = CONFIG_NEWCPU;
if(cpuSetting) if(cpuSetting != 0)
{ {
static const u8 cfgN3dsCpuPattern[] = { static const u8 cfgN3dsCpuPattern[] = {
0x00, 0x40, 0xA0, 0xE1, 0x07 0x00, 0x40, 0xA0, 0xE1, 0x07

View File

@ -31,7 +31,7 @@
bool readConfig(void) bool readConfig(void)
{ {
if(fileRead(&configData, CONFIG_PATH) != sizeof(cfgData) || if(fileRead(&configData, CONFIG_PATH) != sizeof(CfgData) ||
memcmp(configData.magic, "CONF", 4) != 0 || memcmp(configData.magic, "CONF", 4) != 0 ||
configData.formatVersionMajor != CONFIG_VERSIONMAJOR || configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
configData.formatVersionMinor != CONFIG_VERSIONMINOR) configData.formatVersionMinor != CONFIG_VERSIONMINOR)
@ -59,7 +59,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp)
//Merge the new options and new boot configuration //Merge the new options and new boot configuration
configData.config = (configData.config & 0xFFFFFFC0) | (configTemp & 0x3F); 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"); error("Error writing the configuration file");
} }
} }

View File

@ -53,7 +53,7 @@ typedef struct __attribute__((packed))
u16 formatVersionMajor, formatVersionMinor; u16 formatVersionMajor, formatVersionMinor;
u32 config; u32 config;
} cfgData; } CfgData;
typedef enum ConfigurationStatus typedef enum ConfigurationStatus
{ {
@ -62,7 +62,7 @@ typedef enum ConfigurationStatus
CREATE_CONFIGURATION = 2 CREATE_CONFIGURATION = 2
} ConfigurationStatus; } ConfigurationStatus;
extern cfgData configData; extern CfgData configData;
bool readConfig(void); bool readConfig(void);
void writeConfig(ConfigurationStatus needConfig, u32 configTemp); void writeConfig(ConfigurationStatus needConfig, u32 configTemp);

View File

@ -25,7 +25,7 @@
#include "fatfs/sdmmc/sdmmc.h" #include "fatfs/sdmmc/sdmmc.h"
#include "../build/emunandpatch.h" #include "../build/emunandpatch.h"
void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) void locateEmuNand(u32 *emuHeader, FirmwareSource *nandType)
{ {
static u8 temp[0x200]; static u8 temp[0x200];
const u32 nandSize = getMMCDevice(0)->total_size; const u32 nandSize = getMMCDevice(0)->total_size;
@ -43,11 +43,11 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand)
nandOffset = isN3DS ? 0x26E000 : 0x1D8000; //"Minsize" layout nandOffset = isN3DS ? 0x26E000 : 0x1D8000; //"Minsize" layout
break; break;
default: default:
nandOffset = *emuNand == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout nandOffset = *nandType == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout
break; break;
} }
if(*emuNand != FIRMWARE_EMUNAND) nandOffset *= ((u32)*emuNand - 1); if(*nandType != FIRMWARE_EMUNAND) nandOffset *= ((u32)*nandType - 1);
//Check for RedNAND //Check for RedNAND
if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC) 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; found = true;
} }
//Check for Gateway emuNAND //Check for Gateway EmuNAND
else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC) else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC)
{ {
emuOffset = nandOffset; emuOffset = nandOffset;
@ -65,19 +65,18 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand)
found = true; found = true;
} }
if(*emuNand == FIRMWARE_EMUNAND) break; if(*nandType == FIRMWARE_EMUNAND) break;
} }
/* Fallback to the first emuNAND if there's no second one, //Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any
or to SysNAND if there isn't any */
if(!found) if(!found)
{ {
if(*emuNand != FIRMWARE_EMUNAND) if(*nandType != FIRMWARE_EMUNAND)
{ {
*emuNand = FIRMWARE_EMUNAND; *nandType = FIRMWARE_EMUNAND;
locateEmuNand(emuHeader, 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) 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); u8 *freeK9Space = getFreeK9Space(arm9Section, arm9SectionSize);
memcpy(freeK9Space, emunand, emunand_size); 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), u32 *posOffset = (u32 *)memsearch(freeK9Space, "NAND", emunand_size, 4),
*posHeader = (u32 *)memsearch(freeK9Space, "NCSD", emunand_size, 4); *posHeader = (u32 *)memsearch(freeK9Space, "NCSD", emunand_size, 4);
*posOffset = emuOffset; *posOffset = emuOffset;
@ -144,10 +143,10 @@ void patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32
u32 *posSdmmc = (u32 *)memsearch(freeK9Space, "SDMC", emunand_size, 4); u32 *posSdmmc = (u32 *)memsearch(freeK9Space, "SDMC", emunand_size, 4);
*posSdmmc = getSdmmc(process9Offset, process9Size); *posSdmmc = getSdmmc(process9Offset, process9Size);
//Add emuNAND hooks //Add EmuNAND hooks
u32 branchOffset = (u32)freeK9Space - branchAdditive; u32 branchOffset = (u32)freeK9Space - branchAdditive;
patchNandRw(process9Offset, process9Size, branchOffset); patchNandRw(process9Offset, process9Size, branchOffset);
//Set MPU for emu code region //Set MPU
patchMpu(arm9Section, arm9SectionSize); patchMpu(arm9Section, arm9SectionSize);
} }

View File

@ -25,8 +25,8 @@
#include "sdmmc.h" #include "sdmmc.h"
#include "delay.h" #include "delay.h"
struct mmcdevice handleNAND; static struct mmcdevice handleNAND;
struct mmcdevice handleSD; static struct mmcdevice handleSD;
static inline u16 sdmmc_read16(u16 reg) static inline u16 sdmmc_read16(u16 reg)
{ {
@ -107,8 +107,8 @@ static void __attribute__ ((noinline)) sdmmc_send_command(struct mmcdevice *ctx,
u8 *rDataPtr = ctx->rData; u8 *rDataPtr = ctx->rData;
const u8 *tDataPtr = ctx->tData; const u8 *tDataPtr = ctx->tData;
int rUseBuf = NULL != rDataPtr; bool rUseBuf = rDataPtr != NULL;
int tUseBuf = NULL != tDataPtr; bool tUseBuf = tDataPtr != NULL;
u16 status0 = 0; u16 status0 = 0;
while(true) while(true)

View File

@ -43,21 +43,17 @@ static firmHeader *const firm = (firmHeader *)0x24000000;
static const firmSectionHeader *section; static const firmSectionHeader *section;
u32 emuOffset; u32 emuOffset;
bool isN3DS, bool isN3DS,
isDevUnit, isDevUnit,
isFirmlaunch; isFirmlaunch;
CfgData configData;
cfgData configData;
FirmwareSource firmSource; FirmwareSource firmSource;
void main(void) void main(void)
{ {
bool isA9lh; bool isA9lh;
u32 configTemp, u32 configTemp,
emuHeader; emuHeader;
FirmwareType firmType; FirmwareType firmType;
FirmwareSource nandType; FirmwareSource nandType;
ConfigurationStatus needConfig; ConfigurationStatus needConfig;
@ -194,8 +190,7 @@ void main(void)
firmSource = nandType; firmSource = nandType;
} }
/* If we're booting emuNAND the second emuNAND is set as default and B isn't pressed, //If we're booting EmuNAND, determine which one from the directional pad buttons, or otherwise from the config
or vice-versa, boot the second emuNAND */
if(nandType == FIRMWARE_EMUNAND) if(nandType == FIRMWARE_EMUNAND)
switch(pressed & EMUNAND_BUTTONS) switch(pressed & EMUNAND_BUTTONS)
{ {
@ -218,14 +213,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) if(nandType != FIRMWARE_SYSNAND)
{ {
locateEmuNand(&emuHeader, &nandType); locateEmuNand(&emuHeader, &nandType);
if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND; 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) else if(firmSource != FIRMWARE_SYSNAND)
locateEmuNand(&emuHeader, &firmSource); locateEmuNand(&emuHeader, &firmSource);
@ -329,7 +324,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
//Apply signature patches //Apply signature patches
patchSignatureChecks(process9Offset, process9Size); patchSignatureChecks(process9Offset, process9Size);
//Apply emuNAND patches //Apply EmuNAND patches
if(nandType != FIRMWARE_SYSNAND) if(nandType != FIRMWARE_SYSNAND)
{ {
u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address; u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address;

View File

@ -83,7 +83,7 @@ void newPin(bool allowSkipping)
charDrawPos += 2 * SPACING_X; charDrawPos += 2 * SPACING_X;
} }
PINData pin; PinData pin;
memcpy(pin.magic, "PINF", 4); memcpy(pin.magic, "PINF", 4);
pin.formatVersionMajor = PIN_VERSIONMAJOR; pin.formatVersionMajor = PIN_VERSIONMAJOR;
@ -99,7 +99,7 @@ void newPin(bool allowSkipping)
computePinHash(tmp, enteredPassword); computePinHash(tmp, enteredPassword);
memcpy(pin.hash, tmp, sizeof(tmp)); 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"); error("Error writing the PIN file");
} }
@ -107,9 +107,9 @@ bool verifyPin(void)
{ {
initScreens(); 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 || memcmp(pin.magic, "PINF", 4) != 0 ||
pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMajor != PIN_VERSIONMAJOR ||
pin.formatVersionMinor != PIN_VERSIONMINOR || pin.formatVersionMinor != PIN_VERSIONMINOR ||

View File

@ -42,7 +42,7 @@ typedef struct __attribute__((packed))
u8 length; u8 length;
u8 testHash[32]; u8 testHash[32];
u8 hash[32]; u8 hash[32];
} PINData; } PinData;
void newPin(bool allowSkipping); void newPin(bool allowSkipping);
bool verifyPin(void); bool verifyPin(void);

View File

@ -242,7 +242,7 @@ void initScreens(void)
if(PDN_GPU_CNT == 1) if(PDN_GPU_CNT == 1)
{ {
flushDCacheRange(&configData, sizeof(cfgData)); flushDCacheRange(&configData, sizeof(CfgData));
flushDCacheRange((void *)fb, sizeof(struct fb)); flushDCacheRange((void *)fb, sizeof(struct fb));
invokeArm11Function(ARM11); invokeArm11Function(ARM11);