Improve NAND init code

This commit is contained in:
RocketRobz 2020-02-16 15:06:17 -07:00
parent 1eba340882
commit 280b1da282
2 changed files with 24 additions and 8 deletions

View File

@ -206,10 +206,13 @@ int main(int argc, char **argv) {
ramdrive2Mount();
}
nandMounted = nandMount();
is3DS = ((access("sd:/Nintendo 3DS", F_OK) == 0) && (*(vu32*)(0x0DFFFE0C) == 0x474D3969));
//is3DS = ((access("sd:/Nintendo 3DS", F_OK) == 0) && (*(vu32*)(0x0DFFFE0C) == 0x474D3969));
/*FILE* cidFile = fopen("sd:/gm9i/CID.bin", "wb");
fwrite((void*)0x2FFD7BC, 1, 16, cidFile);
fclose(cidFile);*/
/*FILE* cidFile = fopen("sd:/gm9i/ConsoleID.bin", "wb");
fwrite((void*)0x2FFFD00, 1, 8, cidFile);
fclose(cidFile);*/
} /*else if (isRegularDS) {
*(vu32*)(0x08240000) = 1;
expansionPakFound = ((*(vu32*)(0x08240000) == 1) && (io_dldi_data->ioInterface.features & FEATURE_SLOT_NDS));

View File

@ -2,12 +2,15 @@
#include <nds.h>
#include <nds/disc_io.h>
#include <malloc.h>
#include <stdio.h>
#include "crypto.h"
#include "sector0.h"
//#define SECTOR_SIZE 512
#define CRYPT_BUF_LEN 64
extern bool is3DS;
extern bool nand_Startup();
static u8* crypt_buf = 0;
@ -25,19 +28,29 @@ bool nandio_startup() {
if (!nand_Startup()) return false;
nand_ReadSectors(0, 1, sector_buf);
int is3DS = parse_ncsd(sector_buf, 0) == 0;
if (is3DS) return false;
is3DS = parse_ncsd(sector_buf, 0) == 0;
//if (is3DS) return false;
if (*(u32*)(0x2FFD7BC) == 0) {
// Get eMMC CID
*(u32*)(0x2FFFD0C) = 0x454D4D43;
while (*(u32*)(0x2FFFD0C) != 0);
if (is3DS) {
FILE* cidFile = fopen("sd:/gm9/out/nand_cid.mem", "rb");
if (!cidFile) return false;
fread((void*)0x2FFD7BC, 1, 16, cidFile);
fclose(cidFile);
} else {
// Get eMMC CID
*(u32*)(0x2FFFD0C) = 0x454D4D43;
while (*(u32*)(0x2FFFD0C) != 0);
}
}
// iprintf("sector 0 is %s\n", is3DS ? "3DS" : "DSi");
dsi_crypt_init((const u8*)0x2FFFD00, (const u8*)0x2FFD7BC, is3DS);
//dsi_nand_crypt(sector_buf, sector_buf, 0, SECTOR_SIZE / AES_BLOCK_SIZE);
//parse_mbr(sector_buf, is3DS, 0);
dsi_nand_crypt(sector_buf, sector_buf, 0, SECTOR_SIZE / AES_BLOCK_SIZE);
parse_mbr(sector_buf, is3DS, 0);
mbr_t *mbr = (mbr_t*)sector_buf;
nandio_set_fat_sig_fix(is3DS ? 0 : mbr->partitions[0].offset);
if (crypt_buf == 0) {
crypt_buf = (u8*)memalign(32, SECTOR_SIZE * CRYPT_BUF_LEN);