Fix console id retrieval under ntrboot

This commit is contained in:
Edoardo Lolletti 2024-04-25 17:07:58 +02:00
parent e8956ae02e
commit c00569d5c5
2 changed files with 16 additions and 7 deletions

View File

@ -119,17 +119,16 @@ int main()
if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/) 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 // 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! // The console id registers are readable, so use them!
memcpy(out, (uint8_t *)0x04004D00, 8); memcpy(out, (vu8*)0x04004D00, 8);
} else }
#endif if(out[0] == 0 || out[1] == 0) {
{
// For getting ConsoleID without reading from 0x4004D00... // For getting ConsoleID without reading from 0x4004D00...
u8 base[16]={0}; u8 base[16]={0};
u8 in[16]={0}; u8 in[16]={0};

View File

@ -57,8 +57,17 @@ void getConsoleID(u8 *consoleID)
u8 key[16]; //key3 normalkey - keyslot 3 is used for DSi/twln NAND crypto 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 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 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 F_XY_reverse(key, key_x); //work backwards from the normalkey to get key_x that has the consoleID
u128_xor(key_x, DSi_NAND_KEY_Y); u128_xor(key_x, DSi_NAND_KEY_Y);
@ -87,6 +96,7 @@ bool nandio_startup()
{ {
consoleIDfixed[i] = consoleID[7-i]; consoleIDfixed[i] = consoleID[7-i];
} }
// iprintf("sector 0 is %s\n", is3DS ? "3DS" : "DSi"); // iprintf("sector 0 is %s\n", is3DS ? "3DS" : "DSi");
dsi_crypt_init((const u8*)consoleIDfixed, (const u8*)0x2FFD7BC, is3DS); dsi_crypt_init((const u8*)consoleIDfixed, (const u8*)0x2FFD7BC, is3DS);
dsi_nand_crypt(sector_buf, sector_buf, 0, SECTOR_SIZE / AES_BLOCK_SIZE); dsi_nand_crypt(sector_buf, sector_buf, 0, SECTOR_SIZE / AES_BLOCK_SIZE);