Support additional EmuNAND layouts.

Fixes compatibility with a second EmuNAND placed after an EmuNAND
created with either the 'default' or 'minimum' setup sizes with EmuNAND9
/ 3DS Multi EmuNAND Creator.
This commit is contained in:
Pablo Curiel 2016-09-06 22:26:48 -04:00
parent 98cdbe0784
commit 5b6318ee3a
2 changed files with 46 additions and 23 deletions

View File

@ -25,37 +25,59 @@
#include "fatfs/sdmmc/sdmmc.h" #include "fatfs/sdmmc/sdmmc.h"
#include "../build/emunandpatch.h" #include "../build/emunandpatch.h"
#define O3DS_LEGACY_FAT 0x200000
#define O3DS_DEFAULT_FAT 0x1DE000
#define O3DS_MINIMUM_FAT 0x1D8000
#define N3DS_LEGACY_FAT 0x400000
#define N3DS_DEFAULT_FAT 0x3B2000
#define N3DS_MINIMUM_FAT 0x26E000
void locateEmuNand(u32 *off, u32 *head, FirmwareSource *emuNand) void locateEmuNand(u32 *off, u32 *head, FirmwareSource *emuNand)
{ {
static u8 temp[0x200]; static u8 temp[0x200];
const u32 nandSize = getMMCDevice(0)->total_size; const u32 nandSize = getMMCDevice(0)->total_size;
u32 nandOffset = *emuNand == FIRMWARE_EMUNAND ? 0 : const u32 nandLayoutO3DS[3] = { O3DS_LEGACY_FAT, O3DS_DEFAULT_FAT, O3DS_MINIMUM_FAT }; // Legacy, Default, Minimum
(nandSize > 0x200000 ? 0x400000 : 0x200000); const u32 nandLayoutN3DS[3] = { N3DS_LEGACY_FAT, N3DS_DEFAULT_FAT, N3DS_MINIMUM_FAT }; // Legacy, Default, Minimum
//Check for RedNAND u8 i;
if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && u32 nandOffset;
*(u32 *)(temp + 0x100) == NCSD_MAGIC) bool found = false;
{
*off = nandOffset + 1; for (i = 0; i < 3; i++)
*head = nandOffset + 1; {
} if (i > 0 && *emuNand != FIRMWARE_EMUNAND2) break;
//Check for Gateway emuNAND // Check for 'Legacy', 'Default' and 'Minimum' partition layouts when checking for the 2nd EmuNAND
else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && nandOffset = (*emuNand == FIRMWARE_EMUNAND ? 0 : (isN3DS ? nandLayoutN3DS[i] : nandLayoutO3DS[i]));
*(u32 *)(temp + 0x100) == NCSD_MAGIC)
{ //Check for RedNAND
*off = nandOffset; if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC)
*head = nandOffset + nandSize; {
} *off = nandOffset + 1;
*head = nandOffset + 1;
found = true;
break;
}
//Check for Gateway emuNAND
else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC)
{
*off = nandOffset;
*head = nandOffset + nandSize;
found = true;
break;
}
}
/* Fallback to the first emuNAND if there's no second one, /* Fallback to the first emuNAND if there's no second one,
or to SysNAND if there isn't any */ or to SysNAND if there isn't any */
else if (!found)
{ {
*emuNand = (*emuNand == FIRMWARE_EMUNAND2) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND; *emuNand = (*emuNand == FIRMWARE_EMUNAND2) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND;
if(*emuNand) locateEmuNand(off, head, emuNand); if(*emuNand) locateEmuNand(off, head, emuNand);
} }
} }
static inline u8 *getFreeK9Space(u8 *pos, u32 size) static inline u8 *getFreeK9Space(u8 *pos, u32 size)

View File

@ -27,6 +27,7 @@
#define NCSD_MAGIC 0x4453434E #define NCSD_MAGIC 0x4453434E
extern u32 emuOffset; extern u32 emuOffset;
extern bool isN3DS;
void locateEmuNand(u32 *off, u32 *head, FirmwareSource *emuNand); void locateEmuNand(u32 *off, u32 *head, FirmwareSource *emuNand);
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);