mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Prepare for NAND reading in DS mode with SCFG unlocked
TODO: Replace SWI SHA1 functions with custom implementation
This commit is contained in:
parent
2b850a957c
commit
e7257819f5
@ -360,7 +360,7 @@ void driveMenu (void) {
|
|||||||
chdir("ram:/");
|
chdir("ram:/");
|
||||||
screenMode = 1;
|
screenMode = 1;
|
||||||
break;
|
break;
|
||||||
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::sysNand && isDSiMode() && nandMounted) {
|
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::sysNand && nandMounted) {
|
||||||
currentDrive = Drive::nand;
|
currentDrive = Drive::nand;
|
||||||
chdir("nand:/");
|
chdir("nand:/");
|
||||||
screenMode = 1;
|
screenMode = 1;
|
||||||
|
|||||||
@ -101,7 +101,7 @@ bool imgFound(void) {
|
|||||||
return (access("img:/", F_OK) == 0);
|
return (access("img:/", F_OK) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TWL_CODE bool nandMount(void) {
|
bool nandMount(void) {
|
||||||
fatMountSimple("nand", &io_dsi_nand);
|
fatMountSimple("nand", &io_dsi_nand);
|
||||||
if (nandFound()) {
|
if (nandFound()) {
|
||||||
struct statvfs st;
|
struct statvfs st;
|
||||||
@ -113,7 +113,7 @@ TWL_CODE bool nandMount(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TWL_CODE void nandUnmount(void) {
|
void nandUnmount(void) {
|
||||||
fatUnmount("nand");
|
fatUnmount("nand");
|
||||||
nandSize = 0;
|
nandSize = 0;
|
||||||
nandMounted = false;
|
nandMounted = false;
|
||||||
|
|||||||
@ -154,13 +154,13 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (isDSiMode()) {
|
if (isDSiMode()) {
|
||||||
if (!arm7SCFGLocked) {
|
if (!arm7SCFGLocked) {
|
||||||
font->print(-2, -4, false, " Held - Disable NAND access", Alignment::right);
|
//font->print(-2, -4, false, " Held - Disable NAND access", Alignment::right);
|
||||||
font->print(-2, -3, false, " Held - Disable cart access", Alignment::right);
|
font->print(-2, -3, false, " Held - Disable cart access", Alignment::right);
|
||||||
font->print(-2, -2, false, "Do these if it crashes here", Alignment::right);
|
font->print(-2, -2, false, "Do this if it crashes here", Alignment::right);
|
||||||
} else {
|
} /*else {
|
||||||
font->print(-2, -3, false, " Held - Disable NAND access", Alignment::right);
|
font->print(-2, -3, false, " Held - Disable NAND access", Alignment::right);
|
||||||
font->print(-2, -2, false, "Do this if it crashes here", Alignment::right);
|
font->print(-2, -2, false, "Do this if it crashes here", Alignment::right);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display for 2 seconds
|
// Display for 2 seconds
|
||||||
@ -193,9 +193,9 @@ int main(int argc, char **argv) {
|
|||||||
if (ram32MB) {
|
if (ram32MB) {
|
||||||
is3DS = fifoGetValue32(FIFO_USER_05) != 0xD2;
|
is3DS = fifoGetValue32(FIFO_USER_05) != 0xD2;
|
||||||
}
|
}
|
||||||
if (!(keysHeld() & KEY_X)) {
|
//if (!(keysHeld() & KEY_X)) {
|
||||||
nandMounted = nandMount();
|
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");
|
/*FILE* cidFile = fopen("sd:/gm9i/CID.bin", "wb");
|
||||||
fwrite((void*)0x2FFD7BC, 1, 16, cidFile);
|
fwrite((void*)0x2FFD7BC, 1, 16, cidFile);
|
||||||
@ -210,6 +210,7 @@ int main(int argc, char **argv) {
|
|||||||
if (ram32MB) {
|
if (ram32MB) {
|
||||||
is3DS = fifoGetValue32(FIFO_USER_05) != 0xD2;
|
is3DS = fifoGetValue32(FIFO_USER_05) != 0xD2;
|
||||||
}
|
}
|
||||||
|
//nandMounted = nandMount();
|
||||||
} else if (isRegularDS && (io_dldi_data->ioInterface.features & FEATURE_SLOT_NDS)) {
|
} else if (isRegularDS && (io_dldi_data->ioInterface.features & FEATURE_SLOT_NDS)) {
|
||||||
ramdriveMount(false);
|
ramdriveMount(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
#include <nds.h>
|
#include <nds.h>
|
||||||
|
#include <nds/fifocommon.h>
|
||||||
|
#include <nds/fifomessages.h>
|
||||||
#include <nds/disc_io.h>
|
#include <nds/disc_io.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -11,8 +13,6 @@
|
|||||||
//#define SECTOR_SIZE 512
|
//#define SECTOR_SIZE 512
|
||||||
#define CRYPT_BUF_LEN 64
|
#define CRYPT_BUF_LEN 64
|
||||||
|
|
||||||
extern bool nand_Startup();
|
|
||||||
|
|
||||||
static u8* crypt_buf = 0;
|
static u8* crypt_buf = 0;
|
||||||
|
|
||||||
static u32 fat_sig_fix_offset = 0;
|
static u32 fat_sig_fix_offset = 0;
|
||||||
@ -43,10 +43,49 @@ void getConsoleID(u8 *consoleID){
|
|||||||
tonccpy(&consoleID[4], &key_x[0xC], 4);
|
tonccpy(&consoleID[4], &key_x[0xC], 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nandio_startup() {
|
//---------------------------------------------------------------------------------
|
||||||
if (!nand_Startup()) return false;
|
bool my_nand_Startup() {
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
fifoSendValue32(FIFO_SDMMC,SDMMC_HAVE_SD);
|
||||||
|
while(!fifoCheckValue32(FIFO_SDMMC));
|
||||||
|
int result = fifoGetValue32(FIFO_SDMMC);
|
||||||
|
|
||||||
nand_ReadSectors(0, 1, sector_buf);
|
if(result==0) return false;
|
||||||
|
|
||||||
|
fifoSendValue32(FIFO_SDMMC,SDMMC_NAND_START);
|
||||||
|
|
||||||
|
fifoWaitValue32(FIFO_SDMMC);
|
||||||
|
|
||||||
|
result = fifoGetValue32(FIFO_SDMMC);
|
||||||
|
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
bool my_nand_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) {
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
FifoMessage msg;
|
||||||
|
|
||||||
|
DC_FlushRange(buffer,numSectors * 512);
|
||||||
|
|
||||||
|
msg.type = SDMMC_NAND_READ_SECTORS;
|
||||||
|
msg.sdParams.startsector = sector;
|
||||||
|
msg.sdParams.numsectors = numSectors;
|
||||||
|
msg.sdParams.buffer = buffer;
|
||||||
|
|
||||||
|
fifoSendDatamsg(FIFO_SDMMC, sizeof(msg), (u8*)&msg);
|
||||||
|
|
||||||
|
fifoWaitValue32(FIFO_SDMMC);
|
||||||
|
|
||||||
|
int result = fifoGetValue32(FIFO_SDMMC);
|
||||||
|
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nandio_startup() {
|
||||||
|
if (!my_nand_Startup()) return false;
|
||||||
|
|
||||||
|
my_nand_ReadSectors(0, 1, sector_buf);
|
||||||
bool isDSi = parse_ncsd(sector_buf, 0) != 0;
|
bool isDSi = parse_ncsd(sector_buf, 0) != 0;
|
||||||
//if (!isDSi) return false;
|
//if (!isDSi) return false;
|
||||||
|
|
||||||
@ -97,7 +136,7 @@ bool nandio_is_inserted() {
|
|||||||
|
|
||||||
// len is guaranteed <= CRYPT_BUF_LEN
|
// len is guaranteed <= CRYPT_BUF_LEN
|
||||||
static bool read_sectors(sec_t start, sec_t len, void *buffer) {
|
static bool read_sectors(sec_t start, sec_t len, void *buffer) {
|
||||||
if (nand_ReadSectors(start, len, crypt_buf)) {
|
if (my_nand_ReadSectors(start, len, crypt_buf)) {
|
||||||
dsi_nand_crypt(buffer, crypt_buf, start * SECTOR_SIZE / AES_BLOCK_SIZE, len * SECTOR_SIZE / AES_BLOCK_SIZE);
|
dsi_nand_crypt(buffer, crypt_buf, start * SECTOR_SIZE / AES_BLOCK_SIZE, len * SECTOR_SIZE / AES_BLOCK_SIZE);
|
||||||
if (fat_sig_fix_offset &&
|
if (fat_sig_fix_offset &&
|
||||||
start == fat_sig_fix_offset
|
start == fat_sig_fix_offset
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user