From 684b10b1680dc9bc0dda3cbf1634655e128dec4e Mon Sep 17 00:00:00 2001 From: SciresM Date: Wed, 24 Aug 2016 13:16:08 -0700 Subject: [PATCH] Prefer OTP from memory to OTP from file Prevents using wrong OTP.bin by mistake/leftovers/sd card re-use. --- source/installer.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/installer.c b/source/installer.c index 54e5613..d0b8c0e 100755 --- a/source/installer.c +++ b/source/installer.c @@ -68,14 +68,20 @@ static inline void installer(u32 a9lhBoot) //If making a first install, we need the OTP if(!a9lhBoot) { - //Read OTP + // Prefer OTP from memory if available + const u8 zeroes[256] = {0}; path = "a9lh/otp.bin"; - if(fileRead((void *)OTP_OFFSET, path) != 256) + if(memcmp((void *)OTP_FROM_MEM, zeroes, 256) == 0) { - const u8 zeroes[256] = {0}; - if(memcmp((void *)OTP_FROM_MEM, zeroes, 256) == 0) - shutdown(1, "Error: otp.bin doesn't exist and can't be dumped"); - + // Read OTP from file + if(fileRead((void *)OTP_OFFSET, path) != 256) + { + shutdown(1, "Error: otp.bin doesn't exist and can't be dumped"); + } + } + else + { + // Write OTP from memory to file fileWrite((void *)OTP_FROM_MEM, path, 256); memcpy((void *)OTP_OFFSET, (void *)OTP_FROM_MEM, 256); } @@ -232,4 +238,4 @@ static inline void uninstaller(void) sdmmc_nand_writesectors(0x5C000, MAX_STAGE2_SIZE / 0x200, (vu8 *)STAGE2_OFFSET); shutdown(2, "Uninstall: success!"); -} \ No newline at end of file +}