From 0b41ed04d5d306e51ebd93fa41eb862d4b501aad Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Fri, 9 Feb 2018 05:03:22 +0100 Subject: [PATCH] Simplify loadNintendoFirm after the previous commit --- source/firm.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/source/firm.c b/source/firm.c index 52488d2..285e66f 100755 --- a/source/firm.c +++ b/source/firm.c @@ -123,7 +123,7 @@ static inline u32 loadFirmFromStorage(FirmwareType firmType) "cetk_sysupdater" }; - u32 firmSize = fileRead(firm, firmType == NATIVE_FIRM1X2X ? firmwareFiles[0] : firmwareFiles[(u32)firmType], 0x400000 + sizeof(Cxi) + 0x200); + u32 firmSize = fileRead(firm, firmwareFiles[(u32)firmType], 0x400000 + sizeof(Cxi) + 0x200); if(!firmSize) return 0; @@ -137,7 +137,7 @@ static inline u32 loadFirmFromStorage(FirmwareType firmType) u8 cetk[0xA50]; - if(fileRead(cetk, firmType == NATIVE_FIRM1X2X ? cetkFiles[0] : cetkFiles[(u32)firmType], sizeof(cetk)) != sizeof(cetk)) + if(fileRead(cetk, cetkFiles[(u32)firmType], sizeof(cetk)) != sizeof(cetk)) error("The cetk is missing or corrupted."); firmSize = decryptNusFirm((Ticket *)(cetk + 0x140), (Cxi *)firm, firmSize); @@ -150,19 +150,6 @@ static inline u32 loadFirmFromStorage(FirmwareType firmType) return firmSize; } -static void check1x2xFirm(FirmwareType *firmType, FirmwareSource nandType, bool isSafeMode) -{ - if(!ISN3DS && *firmType == NATIVE_FIRM && firm->section[0].address == (u8 *)0x1FF80000) - { - //We can't boot < 3.x EmuNANDs - if(nandType != FIRMWARE_SYSNAND) error("An old unsupported EmuNAND has been detected.\nLuma3DS is unable to boot it."); - - if(isSafeMode) error("SAFE_MODE is not supported on 1.x/2.x FIRM."); - - *firmType = NATIVE_FIRM1X2X; - } -} - u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode) { u32 firmVersion, @@ -180,12 +167,7 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadF { firmSize = decryptExeFs((Cxi *)firm); - if(!firmSize) ctrNandError = true; - else - { - if(!checkFirm(firmSize)) ctrNandError = true; - else check1x2xFirm(firmType, nandType, isSafeMode); - } + if(!firmSize || !checkFirm(firmSize)) ctrNandError = true; } } @@ -197,7 +179,6 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadF if(result != 0) { - if(ctrNandError) check1x2xFirm(firmType, nandType, isSafeMode); loadedFromStorage = true; firmSize = result; } @@ -208,6 +189,16 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadF if((firm->section[3].offset != 0 ? firm->section[3].address : firm->section[2].address) != (ISN3DS ? (u8 *)0x8006000 : (u8 *)0x8006800)) error("The %s FIRM is not for this console.", loadedFromStorage ? "external" : "CTRNAND"); + if(!ISN3DS && *firmType == NATIVE_FIRM && firm->section[0].address == (u8 *)0x1FF80000) + { + //We can't boot < 3.x EmuNANDs + if(nandType != FIRMWARE_SYSNAND) error("An old unsupported EmuNAND has been detected.\nLuma3DS is unable to boot it."); + + if(isSafeMode) error("SAFE_MODE is not supported on 1.x/2.x FIRM."); + + *firmType = NATIVE_FIRM1X2X; + } + if(loadedFromStorage || ISDEVUNIT) { firmVersion = 0xFFFFFFFF;