From c00569d5c553990b30d75d24a1ef47c4f57acb3e Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Thu, 25 Apr 2024 17:07:58 +0200 Subject: [PATCH] Fix console id retrieval under ntrboot --- arm7/src/main.c | 13 ++++++------- arm9/src/nand/nandio.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arm7/src/main.c b/arm7/src/main.c index 0d47176..4105204 100644 --- a/arm7/src/main.c +++ b/arm7/src/main.c @@ -119,17 +119,16 @@ int main() if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/) { - u8 *out=(u8*)0x02300000; + vu8 *out=(vu8*)0x02300000; + memset(out, 0, 16); -#if USENATIVECONSOLEID // first check whether we can read the console ID directly and it was not hidden by SCFG - if (((*(volatile uint16_t *)0x04004000) & (1u << 10)) == 0) + if (((*(vu16*)0x04004000) & (1u << 10)) == 0 && ((*(vu8*)0x04004D08) & 0x1) == 0) { // The console id registers are readable, so use them! - memcpy(out, (uint8_t *)0x04004D00, 8); - } else -#endif - { + memcpy(out, (vu8*)0x04004D00, 8); + } + if(out[0] == 0 || out[1] == 0) { // For getting ConsoleID without reading from 0x4004D00... u8 base[16]={0}; u8 in[16]={0}; diff --git a/arm9/src/nand/nandio.c b/arm9/src/nand/nandio.c index 8a9f2a0..e63cafe 100644 --- a/arm9/src/nand/nandio.c +++ b/arm9/src/nand/nandio.c @@ -57,7 +57,16 @@ void getConsoleID(u8 *consoleID) u8 key[16]; //key3 normalkey - keyslot 3 is used for DSi/twln NAND crypto u8 key_x[16];////key3_x - contains a DSi console id (which just happens to be the LFCS on 3ds) + u8 empty_buff[8] = {0}; + memcpy(key, fifo, 16); //receive the goods from arm7 + + if(memcmp(key + 8, empty_buff, 8) == 0) + { + //we got the consoleid directly or nothing at all, don't treat this as key3 output + memcpy(consoleID, key, 8); + return; + } F_XY_reverse(key, key_x); //work backwards from the normalkey to get key_x that has the consoleID @@ -87,6 +96,7 @@ bool nandio_startup() { consoleIDfixed[i] = consoleID[7-i]; } + // iprintf("sector 0 is %s\n", is3DS ? "3DS" : "DSi"); dsi_crypt_init((const u8*)consoleIDfixed, (const u8*)0x2FFD7BC, is3DS); dsi_nand_crypt(sector_buf, sector_buf, 0, SECTOR_SIZE / AES_BLOCK_SIZE);