Various changes/cleanups, removed useless code, simplified chronometer functions
This commit is contained in:
parent
75acdc8a98
commit
aa7c2c0009
@ -311,11 +311,8 @@ void ctrNandInit(void)
|
|||||||
|
|
||||||
if(isN3DS)
|
if(isN3DS)
|
||||||
{
|
{
|
||||||
if(!isDevUnit)
|
u8 __attribute__((aligned(4))) keyY0x5[0x10] = {0x4D, 0x80, 0x4F, 0x4E, 0x99, 0x90, 0x19, 0x46, 0x13, 0xA2, 0x04, 0xAC, 0x58, 0x44, 0x60, 0xBE};
|
||||||
{
|
aes_setkey(0x05, keyY0x5, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
u8 __attribute__((aligned(4))) keyY0x5[0x10] = {0x4D, 0x80, 0x4F, 0x4E, 0x99, 0x90, 0x19, 0x46, 0x13, 0xA2, 0x04, 0xAC, 0x58, 0x44, 0x60, 0xBE};
|
|
||||||
aes_setkey(0x05, keyY0x5, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
nandSlot = 0x05;
|
nandSlot = 0x05;
|
||||||
fatStart = 0x5CAD7;
|
fatStart = 0x5CAD7;
|
||||||
@ -361,11 +358,10 @@ void setRSAMod0DerivedKeys(void)
|
|||||||
|
|
||||||
aes_setkey(0x25, keyX0x25, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(0x25, keyX0x25, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
aes_setkey(0x2F, keyY0x2F, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(0x2F, keyY0x2F, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
|
|
||||||
/* [3dbrew] The first 0x10-bytes are checked by the v6.0/v7.0 NATIVE_FIRM keyinit function,
|
/* [3dbrew] The first 0x10-bytes are checked by the v6.0/v7.0 NATIVE_FIRM keyinit function,
|
||||||
when non-zero it clears this block and continues to do the key generation.
|
when non-zero it clears this block and continues to do the key generation.
|
||||||
Otherwise when this block was already all-zero, it immediately returns.
|
Otherwise when this block was already all-zero, it immediately returns. */
|
||||||
*/
|
|
||||||
memset32((void *)0x01FFCD00, 0, 0x10);
|
memset32((void *)0x01FFCD00, 0, 0x10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,7 +404,7 @@ void arm9Loader(u8 *arm9Section)
|
|||||||
|
|
||||||
//Firm keys
|
//Firm keys
|
||||||
u8 __attribute__((aligned(4))) keyY[0x10];
|
u8 __attribute__((aligned(4))) keyY[0x10];
|
||||||
u8 __attribute__((aligned(4))) arm9BinCTR[0x10];
|
u8 __attribute__((aligned(4))) arm9BinCTR[0x10];
|
||||||
u8 arm9BinSlot = a9lVersion ? 0x16 : 0x15;
|
u8 arm9BinSlot = a9lVersion ? 0x16 : 0x15;
|
||||||
|
|
||||||
//Setup keys needed for arm9bin decryption
|
//Setup keys needed for arm9bin decryption
|
||||||
@ -424,7 +420,7 @@ void arm9Loader(u8 *arm9Section)
|
|||||||
if(a9lVersion)
|
if(a9lVersion)
|
||||||
{
|
{
|
||||||
u8 __attribute__((aligned(4))) keyX[0x10];
|
u8 __attribute__((aligned(4))) keyX[0x10];
|
||||||
|
|
||||||
if(!isDevUnit)
|
if(!isDevUnit)
|
||||||
{
|
{
|
||||||
const u8 __attribute__((aligned(4))) key1[0x10] = {0x07, 0x29, 0x44, 0x38, 0xF8, 0xC9, 0x75, 0x93, 0xAA, 0x0E, 0x4A, 0xB4, 0xAE, 0x84, 0xC1, 0xD8};
|
const u8 __attribute__((aligned(4))) key1[0x10] = {0x07, 0x29, 0x44, 0x38, 0xF8, 0xC9, 0x75, 0x93, 0xAA, 0x0E, 0x4A, 0xB4, 0xAE, 0x84, 0xC1, 0xD8};
|
||||||
@ -453,11 +449,10 @@ void arm9Loader(u8 *arm9Section)
|
|||||||
|
|
||||||
//Set keys 0x19..0x1F keyXs
|
//Set keys 0x19..0x1F keyXs
|
||||||
aes_use_keyslot(0x11);
|
aes_use_keyslot(0x11);
|
||||||
for(u8 slot = 0x19; slot < 0x20; slot++)
|
for(u8 slot = 0x19; slot < 0x20; slot++, keyData[0xF]++)
|
||||||
{
|
{
|
||||||
aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||||
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
keyData[0xF] += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,7 @@ void main(void)
|
|||||||
isA9lh;
|
isA9lh;
|
||||||
|
|
||||||
u32 newConfig,
|
u32 newConfig,
|
||||||
emuHeader,
|
emuHeader;
|
||||||
nbChronoStarted = 0;
|
|
||||||
|
|
||||||
FirmwareType firmType;
|
FirmwareType firmType;
|
||||||
FirmwareSource nandType;
|
FirmwareSource nandType;
|
||||||
@ -135,12 +134,12 @@ void main(void)
|
|||||||
if(needConfig != DONT_CONFIGURE)
|
if(needConfig != DONT_CONFIGURE)
|
||||||
{
|
{
|
||||||
//If no configuration file exists or SELECT is held, load configuration menu
|
//If no configuration file exists or SELECT is held, load configuration menu
|
||||||
bool shouldLoadConfigurationMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
|
bool shouldLoadConfigurationMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)),
|
||||||
bool pinExists = CONFIG(7) && readPin(&pin);
|
pinExists = CONFIG(7) && readPin(&pin);
|
||||||
|
|
||||||
if(pinExists || shouldLoadConfigurationMenu)
|
if(pinExists || shouldLoadConfigurationMenu)
|
||||||
{
|
{
|
||||||
bool needToDeinit = initScreens();
|
initScreens();
|
||||||
|
|
||||||
//If we get here we should check the PIN (if it exists) in all cases
|
//If we get here we should check the PIN (if it exists) in all cases
|
||||||
if(pinExists) verifyPin(&pin, true);
|
if(pinExists) verifyPin(&pin, true);
|
||||||
@ -154,21 +153,11 @@ void main(void)
|
|||||||
//Zero the last booted FIRM flag
|
//Zero the last booted FIRM flag
|
||||||
CFG_BOOTENV = 0;
|
CFG_BOOTENV = 0;
|
||||||
|
|
||||||
nbChronoStarted = 1;
|
|
||||||
chrono(0);
|
|
||||||
chrono(2);
|
chrono(2);
|
||||||
|
|
||||||
//Update pressed buttons
|
//Update pressed buttons
|
||||||
pressed = HID_PAD;
|
pressed = HID_PAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(needToDeinit)
|
|
||||||
{
|
|
||||||
//Turn off backlight
|
|
||||||
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x16);
|
|
||||||
deinitScreens();
|
|
||||||
PDN_GPU_CNT = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isA9lh && !CFG_BOOTENV && pressed == SAFE_MODE)
|
if(isA9lh && !CFG_BOOTENV && pressed == SAFE_MODE)
|
||||||
@ -183,22 +172,19 @@ void main(void)
|
|||||||
|
|
||||||
if(CONFIG(6) && loadSplash())
|
if(CONFIG(6) && loadSplash())
|
||||||
{
|
{
|
||||||
nbChronoStarted = 2;
|
|
||||||
chrono(0);
|
|
||||||
chrono(3);
|
chrono(3);
|
||||||
nbChronoStarted = 0;
|
|
||||||
|
//Update pressed buttons
|
||||||
pressed = HID_PAD;
|
pressed = HID_PAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldLoadPayload = (pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS));
|
bool shouldLoadPayload = (pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS));
|
||||||
|
|
||||||
if(shouldLoadPayload)
|
if(shouldLoadPayload) loadPayload(pressed);
|
||||||
loadPayload(pressed, nbChronoStarted != 2);
|
|
||||||
|
|
||||||
if(!CONFIG(6) && loadSplash())
|
if(!CONFIG(6) && loadSplash())
|
||||||
{
|
{
|
||||||
nbChronoStarted = 2;
|
chrono(3);
|
||||||
chrono(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
|
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
|
||||||
@ -266,12 +252,6 @@ void main(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nbChronoStarted)
|
|
||||||
{
|
|
||||||
if(nbChronoStarted == 2) chrono(3);
|
|
||||||
stopChrono();
|
|
||||||
}
|
|
||||||
|
|
||||||
launchFirm(firmType, isFirmlaunch);
|
launchFirm(firmType, isFirmlaunch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ void createDirectory(const char *path)
|
|||||||
f_mkdir(path);
|
f_mkdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadPayload(u32 pressed, bool needToInitScreens)
|
void loadPayload(u32 pressed)
|
||||||
{
|
{
|
||||||
const char *pattern;
|
const char *pattern;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ void loadPayload(u32 pressed, bool needToInitScreens)
|
|||||||
|
|
||||||
if(result == FR_OK && info.fname[0])
|
if(result == FR_OK && info.fname[0])
|
||||||
{
|
{
|
||||||
if(needToInitScreens) initScreens();
|
initScreens();
|
||||||
|
|
||||||
u32 *const loaderAddress = (u32 *)0x24FFFF00;
|
u32 *const loaderAddress = (u32 *)0x24FFFF00;
|
||||||
|
|
||||||
|
@ -33,5 +33,5 @@ u32 fileRead(void *dest, const char *path);
|
|||||||
u32 getFileSize(const char *path);
|
u32 getFileSize(const char *path);
|
||||||
bool fileWrite(const void *buffer, const char *path, u32 size);
|
bool fileWrite(const void *buffer, const char *path, u32 size);
|
||||||
void createDirectory(const char *path);
|
void createDirectory(const char *path);
|
||||||
void loadPayload(u32 pressed, bool needToInitScreens);
|
void loadPayload(u32 pressed);
|
||||||
u32 firmRead(void *dest, u32 firmType);
|
u32 firmRead(void *dest, u32 firmType);
|
@ -185,7 +185,7 @@ u32 getLoader(u8 *pos, u32 *loaderSize)
|
|||||||
u8 *off = pos;
|
u8 *off = pos;
|
||||||
u32 size;
|
u32 size;
|
||||||
|
|
||||||
while(1)
|
while(true)
|
||||||
{
|
{
|
||||||
size = *(u32 *)(off + 0x104) * 0x200;
|
size = *(u32 *)(off + 0x104) * 0x200;
|
||||||
if(*(u32 *)(off + 0x200) == 0x64616F6C) break;
|
if(*(u32 *)(off + 0x200) == 0x64616F6C) break;
|
||||||
|
35
source/pin.c
35
source/pin.c
@ -39,9 +39,10 @@ bool readPin(PINData *out)
|
|||||||
{
|
{
|
||||||
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
||||||
u8 __attribute__((aligned(4))) tmp[32] = {0};
|
u8 __attribute__((aligned(4))) tmp[32] = {0};
|
||||||
|
|
||||||
if(fileRead(out, "/luma/pin.bin") != sizeof(PINData)) return false;
|
if(fileRead(out, "/luma/pin.bin") != sizeof(PINData)) return false;
|
||||||
else if(memcmp(out->magic, "PINF", 4) != 0) return false;
|
if(memcmp(out->magic, "PINF", 4) != 0) return false;
|
||||||
|
|
||||||
computePINHash(tmp, zeroes, 1);
|
computePINHash(tmp, zeroes, 1);
|
||||||
return memcmp(out->testHash, tmp, 32) == 0; //test vector verification (SD card has (or hasn't) been used on another console)
|
return memcmp(out->testHash, tmp, 32) == 0; //test vector verification (SD card has (or hasn't) been used on another console)
|
||||||
}
|
}
|
||||||
@ -62,16 +63,15 @@ PINData newPin(void)
|
|||||||
|
|
||||||
drawString("Enter your NEW PIN: ", 10, 10, COLOR_WHITE);
|
drawString("Enter your NEW PIN: ", 10, 10, COLOR_WHITE);
|
||||||
|
|
||||||
u32 pressed = 0;
|
|
||||||
|
|
||||||
// Set the default value as 0x00 so we can check if there are any unentered characters.
|
// Set the default value as 0x00 so we can check if there are any unentered characters.
|
||||||
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; // pad to AES block length
|
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; // pad to AES block length
|
||||||
|
|
||||||
|
u32 cnt = 0;
|
||||||
int charDrawPos = 20 * SPACING_X;
|
int charDrawPos = 20 * SPACING_X;
|
||||||
int cnt = 0;
|
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
u32 pressed;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pressed = waitInput();
|
pressed = waitInput();
|
||||||
@ -89,9 +89,8 @@ PINData newPin(void)
|
|||||||
charDrawPos += 2 * SPACING_X;
|
charDrawPos += 2 * SPACING_X;
|
||||||
|
|
||||||
// we leave the rest of the array zeroed out.
|
// we leave the rest of the array zeroed out.
|
||||||
if (cnt >= PIN_LENGTH)
|
if(cnt >= PIN_LENGTH)
|
||||||
{
|
{
|
||||||
|
|
||||||
PINData pin = {0};
|
PINData pin = {0};
|
||||||
u8 __attribute__((aligned(4))) tmp[32] = {0};
|
u8 __attribute__((aligned(4))) tmp[32] = {0};
|
||||||
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
||||||
@ -119,16 +118,16 @@ void verifyPin(PINData *in, bool allowQuit)
|
|||||||
drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE);
|
drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE);
|
||||||
drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
||||||
|
|
||||||
u32 pressed = 0;
|
|
||||||
|
|
||||||
// Set the default characters as 0x00 so we can check if there are any unentered characters.
|
// Set the default characters as 0x00 so we can check if there are any unentered characters.
|
||||||
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
|
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
|
||||||
|
|
||||||
|
u32 cnt = 0;
|
||||||
bool unlock;
|
bool unlock;
|
||||||
int charDrawPos = 5 * SPACING_X, cnt = 0;
|
int charDrawPos = 5 * SPACING_X;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
u32 pressed;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pressed = waitInput();
|
pressed = waitInput();
|
||||||
@ -159,22 +158,18 @@ void verifyPin(PINData *in, bool allowQuit)
|
|||||||
computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
||||||
unlock = memcmp(in->hash, tmp, 32) == 0;
|
unlock = memcmp(in->hash, tmp, 32) == 0;
|
||||||
|
|
||||||
if (!unlock)
|
if(!unlock)
|
||||||
{
|
{
|
||||||
// re zero out all 16 just in case.
|
|
||||||
memset32(enteredPassword, 0, 16);
|
|
||||||
|
|
||||||
pressed = 0;
|
|
||||||
charDrawPos = 5 * SPACING_X;
|
charDrawPos = 5 * SPACING_X;
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
|
|
||||||
clearScreens();
|
clearScreens();
|
||||||
|
|
||||||
drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE);
|
drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE);
|
||||||
drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
||||||
drawString("Wrong pin! Try again!", 10, 10 + 3 * SPACING_Y, COLOR_RED);
|
drawString("Wrong pin! Try again!", 10, 10 + 3 * SPACING_Y, COLOR_RED);
|
||||||
}
|
}
|
||||||
else return;
|
else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -140,10 +140,8 @@ void clearScreens(void)
|
|||||||
invokeArm11Function(ARM11);
|
invokeArm11Function(ARM11);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initScreens(void)
|
void initScreens(void)
|
||||||
{
|
{
|
||||||
bool needToInit = PDN_GPU_CNT == 1;
|
|
||||||
|
|
||||||
void __attribute__((naked)) ARM11(void)
|
void __attribute__((naked)) ARM11(void)
|
||||||
{
|
{
|
||||||
//Disable interrupts
|
//Disable interrupts
|
||||||
@ -242,7 +240,7 @@ bool initScreens(void)
|
|||||||
WAIT_FOR_ARM9();
|
WAIT_FOR_ARM9();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(needToInit)
|
if(PDN_GPU_CNT == 1)
|
||||||
{
|
{
|
||||||
flushDCacheRange(&config, 4);
|
flushDCacheRange(&config, 4);
|
||||||
flushDCacheRange((void *)fb, sizeof(struct fb));
|
flushDCacheRange((void *)fb, sizeof(struct fb));
|
||||||
@ -254,6 +252,4 @@ bool initScreens(void)
|
|||||||
else updateBrightness(MULTICONFIG(0));
|
else updateBrightness(MULTICONFIG(0));
|
||||||
|
|
||||||
clearScreens();
|
clearScreens();
|
||||||
|
|
||||||
return needToInit;
|
|
||||||
}
|
}
|
@ -42,4 +42,4 @@ static volatile struct fb {
|
|||||||
void deinitScreens(void);
|
void deinitScreens(void);
|
||||||
void updateBrightness(u32 brightnessIndex);
|
void updateBrightness(u32 brightnessIndex);
|
||||||
void clearScreens(void);
|
void clearScreens(void);
|
||||||
bool initScreens(void);
|
void initScreens(void);
|
@ -84,14 +84,19 @@ static inline void startChrono(u64 initialTicks)
|
|||||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void stopChrono(void)
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < 4; i++) REG_TIMER_CNT(i) &= ~0x80;
|
||||||
|
}
|
||||||
|
|
||||||
void chrono(u32 seconds)
|
void chrono(u32 seconds)
|
||||||
{
|
{
|
||||||
static u64 startingTicks = 0;
|
startChrono(0);
|
||||||
|
|
||||||
if(!startingTicks) startChrono(0);
|
u64 startingTicks = 0;
|
||||||
|
for(u32 i = 0; i < 4; i++) startingTicks |= REG_TIMER_VAL(i) << (16 * i);
|
||||||
|
|
||||||
u64 res;
|
u64 res;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -99,12 +104,7 @@ void chrono(u32 seconds)
|
|||||||
}
|
}
|
||||||
while(res - startingTicks < seconds * TICKS_PER_SEC);
|
while(res - startingTicks < seconds * TICKS_PER_SEC);
|
||||||
|
|
||||||
if(!seconds) startingTicks = res;
|
stopChrono();
|
||||||
}
|
|
||||||
|
|
||||||
void stopChrono(void)
|
|
||||||
{
|
|
||||||
for(u32 i = 0; i < 4; i++) REG_TIMER_CNT(i) &= ~0x80;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(const char *message)
|
void error(const char *message)
|
||||||
|
@ -31,7 +31,5 @@
|
|||||||
u32 waitInput(void);
|
u32 waitInput(void);
|
||||||
void mcuReboot(void);
|
void mcuReboot(void);
|
||||||
void mcuPowerOff(void);
|
void mcuPowerOff(void);
|
||||||
|
|
||||||
void chrono(u32 seconds);
|
void chrono(u32 seconds);
|
||||||
void stopChrono(void);
|
|
||||||
void error(const char *message);
|
void error(const char *message);
|
Reference in New Issue
Block a user