Add delays when using the MCU, move screen init routines after OTPless install completes

This commit is contained in:
Aurora 2016-11-14 17:27:10 +01:00
parent 3d477d3565
commit 9898020267
4 changed files with 56 additions and 21 deletions

View File

@ -64,14 +64,19 @@ static const u8 sectorHashRetail[SHA_256_HASH_SIZE] = {
u32 posY; u32 posY;
void main(void) static void drawTitle(void)
{ {
bool isOtpless = ISA9LH && magic == 0xDEADCAFE;
initScreens(); initScreens();
posY = drawString(TITLE, 10, 10, COLOR_TITLE); posY = drawString(TITLE, 10, 10, COLOR_TITLE);
posY = drawString("Thanks to delebile, #cakey and StandardBus", 10, posY + SPACING_Y, COLOR_WHITE); posY = drawString("Thanks to delebile, #cakey and StandardBus", 10, posY + SPACING_Y, COLOR_WHITE);
}
void main(void)
{
bool isOtpless = ISA9LH && magic == 0xDEADCAFE;
if(!isOtpless) drawTitle();
if(!sdmmc_sdcard_init(isOtpless)) if(!sdmmc_sdcard_init(isOtpless))
shutdown(1, "Error: failed to initialize SD and NAND"); shutdown(1, "Error: failed to initialize SD and NAND");
@ -84,11 +89,6 @@ void main(void)
posY = drawString("Press any other button to shutdown", 10, posY, COLOR_WHITE); posY = drawString("Press any other button to shutdown", 10, posY, COLOR_WHITE);
pressed = waitInput(); pressed = waitInput();
} }
else
{
posY = drawString("Finalizing install...", 10, posY + SPACING_Y, COLOR_WHITE);
pressed = 0;
}
if(isOtpless || pressed == BUTTON_SELECT) installer(isOtpless); if(isOtpless || pressed == BUTTON_SELECT) installer(isOtpless);
if(pressed == BUTTON_START && ISA9LH) uninstaller(); if(pressed == BUTTON_START && ISA9LH) uninstaller();
@ -289,6 +289,8 @@ static inline void installer(bool isOtpless)
writeFirm((u8 *)FIRM0_OFFSET, false, FIRM0_SIZE); writeFirm((u8 *)FIRM0_OFFSET, false, FIRM0_SIZE);
if(isOtpless) drawTitle();
shutdown(2, ISA9LH && !isOtpless ? "Update: success!" : "Full install: success!"); shutdown(2, ISA9LH && !isOtpless ? "Update: success!" : "Full install: success!");
} }

View File

@ -36,6 +36,7 @@
#include "screen.h" #include "screen.h"
#include "cache.h" #include "cache.h"
#include "utils.h"
#include "i2c.h" #include "i2c.h"
vu32 *arm11Entry = (vu32 *)BRAHMA_ARM11_ENTRY; vu32 *arm11Entry = (vu32 *)BRAHMA_ARM11_ENTRY;
@ -183,6 +184,8 @@ void initScreens(void)
{ {
invokeArm11Function(initSequence); invokeArm11Function(initSequence);
wait(3ULL);
//Turn on backlight //Turn on backlight
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A); i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
} }

View File

@ -8,33 +8,56 @@
#include "cache.h" #include "cache.h"
#include "i2c.h" #include "i2c.h"
static void startChrono(void)
{
REG_TIMER_CNT(0) = 0; //67MHz
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up
for(u32 i = 0; i < 4; i++) REG_TIMER_VAL(i) = 0;
REG_TIMER_CNT(0) = 0x80; //67MHz; enabled
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
}
static u64 chrono(void)
{
u64 res;
for(u32 i = 0; i < 4; i++) res |= REG_TIMER_VAL(i) << (16 * i);
res /= (TICKS_PER_SEC / 1000);
return res;
}
u32 waitInput(void) u32 waitInput(void)
{ {
bool pressedKey = false; bool pressedKey = false;
u32 key; u32 key,
oldKey = HID_PAD;
//Wait for no keys to be pressed while(!pressedKey)
while(HID_PAD);
do
{ {
//Wait for a key to be pressed
while(!HID_PAD);
key = HID_PAD; key = HID_PAD;
//Make sure it's pressed if(!key) oldKey = key;
for(u32 i = 0x13000; i > 0; i--) else if(key != oldKey)
{ {
if(key != HID_PAD) break; //Make sure the key is pressed
if(i == 1) pressedKey = true; u32 i;
for(i = 0; i < 0x13000 && key == HID_PAD; i++);
if(i == 0x13000) pressedKey = true;
} }
} }
while(!pressedKey);
return key; return key;
} }
void wait(u64 amount)
{
startChrono();
while(chrono() < amount);
}
void mcuReboot(void) void mcuReboot(void)
{ {
clearScreens(); clearScreens();
@ -42,6 +65,8 @@ void mcuReboot(void)
//Ensure that all memory transfers have completed and that the data cache has been flushed //Ensure that all memory transfers have completed and that the data cache has been flushed
flushEntireDCache(); flushEntireDCache();
wait(3ULL);
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
while(true); while(true);
} }

View File

@ -21,9 +21,14 @@
#define COLOR_RED 0x0000FF #define COLOR_RED 0x0000FF
#define COLOR_GREEN 0x00FF00 #define COLOR_GREEN 0x00FF00
#define TICKS_PER_SEC 67027964ULL
#define REG_TIMER_CNT(i) *(vu16 *)(0x10003002 + 4 * i)
#define REG_TIMER_VAL(i) *(vu16 *)(0x10003000 + 4 * i)
extern u32 posY; extern u32 posY;
u32 waitInput(void); u32 waitInput(void);
void wait(u64 amount);
void mcuReboot(void); void mcuReboot(void);
void inputSequence(void); void inputSequence(void);
void shutdown(u32 mode, const char *message); void shutdown(u32 mode, const char *message);