diff --git a/include/arm9/main.h b/include/arm9/main.h index 6154168..d5fe05e 100644 --- a/include/arm9/main.h +++ b/include/arm9/main.h @@ -31,3 +31,4 @@ void unmount_nand_fs(); u8 rng_get_byte(); void power_off_safe(); +void reboot_safe(); diff --git a/include/pxi.h b/include/pxi.h index 1fb382e..33e3367 100644 --- a/include/pxi.h +++ b/include/pxi.h @@ -42,6 +42,7 @@ // Custom PXI Command/Reply Definitions #define PXI_CMD_ENABLE_LCDS 0x4C434453 #define PXI_CMD_POWER_OFF 0x504F4646 +#define PXI_CMD_REBOOT 0x48326482 #define PXI_CMD_ALLOW_POWER_OFF 0x504F4F4B #define PXI_CMD_FORBID_POWER_OFF 0x504F4E4F #define PXI_CMD_FIRM_LAUNCH 0x544F4F42 diff --git a/source/arm11/main.c b/source/arm11/main.c index 8787374..6014f76 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -5,18 +5,9 @@ #include "gfx.h" #include "pxi.h" - - -void turn_off(void) -{ - i2cmcu_lcd_poweroff(); - i2cmcu_lcd_backlight_poweroff(); - for(;;) - { - i2c_writeregdata(3, 0x20, 0xff); - wait(0x200000); - } -} +extern bool battery_ok(void); +extern void power_off(void); +extern void power_reboot(void); int main(void) { @@ -48,7 +39,10 @@ poweroff_allowed = false; break; case PXI_CMD_POWER_OFF: - turn_off(); + power_off(); + break; + case PXI_CMD_REBOOT: + power_reboot(); break; case PXI_CMD_FIRM_LAUNCH: goto start_firmlaunch; diff --git a/source/arm9/firmwriter.c b/source/arm9/firmwriter.c index 0824bd5..2441806 100644 --- a/source/arm9/firmwriter.c +++ b/source/arm9/firmwriter.c @@ -15,10 +15,11 @@ static size_t totalToWrite; static size_t totalWritten; static size_t curSector; +// static size_t blockSize; static bool protectSig; static bool failure; -void firmwriterInit(size_t sector, size_t sectorCount, bool preserveSignature) +void firmwriterInit(size_t sector, size_t sectorCount, /*size_t blockSize,*/ bool preserveSignature) { if(sectorCount < 2) panic(); diff --git a/source/arm9/main.c b/source/arm9/main.c index 4e50960..b997d80 100644 --- a/source/arm9/main.c +++ b/source/arm9/main.c @@ -40,16 +40,16 @@ consoleSelect(&con_top); - printf("\x1B[32mGood morning\nHello !\e[0m\n\n"); + uiPrintInfo("\x1B[32mGood morning\nHello !\e[0m\n\n"); PXI_sendWord(PXI_CMD_FORBID_POWER_OFF); - printf("Early filesystem init...\n"); + uiPrintInfo("Early filesystem init...\n"); /* Try to read the settings file ASAP. */ if(fs_early_init()) { - printf("Loading settings...\n"); + uiPrintInfo("Loading settings...\n"); if(loadSettings(&mode)) { @@ -73,27 +73,27 @@ else screen_init(); } - printf("Initializing devices...\n"); + uiPrintInfo("Initializing devices...\n"); if(!devs_init()) screen_init(); - printf("Mounting filesystems...\n"); + uiPrintInfo("Mounting filesystems...\n"); if(!mount_fs()) screen_init(); - printf("Detecting unit...\n"); + uiPrintInfo("Detecting unit...\n"); unit_detect(); - printf("Detecting boot environment...\n"); + uiPrintInfo("Detecting boot environment...\n"); boot_env_detect(); - printf("Detecting firmware...\n"); + uiPrintInfo("Detecting firmware...\n"); fw_detect(); - printf("Entering menu...\n"); + uiPrintInfo("Entering menu...\n"); TIMER_sleep(1000); @@ -104,11 +104,11 @@ finish_firmlaunch: - printf("Unmounting FS...\n"); + uiPrintInfo("Unmounting FS...\n"); unmount_fs(); - printf("Closing devices...\n"); + uiPrintInfo("Closing devices...\n"); devs_close(); @@ -120,12 +120,12 @@ const char *res_str[2] = {"\x1B[31mFailed!", "\x1B[32mOK!"}; bool sdRes, nandRes, wifiRes; - printf(" Initializing SD card... "); - printf("%s\e[0m\n", res_str[sdRes = dev_sdcard->init()]); - printf(" Initializing raw NAND... "); - printf("%s\e[0m\n", res_str[nandRes = dev_rawnand->init()]); - printf(" Initializing Wifi flash... "); - printf("%s\e[0m\n", res_str[wifiRes = dev_flash->init()]); + uiPrintInfo(" Initializing SD card... "); + uiPrintInfo("%s\e[0m\n", res_str[sdRes = dev_sdcard->init()]); + uiPrintInfo(" Initializing raw NAND... "); + uiPrintInfo("%s\e[0m\n", res_str[nandRes = dev_rawnand->init()]); + uiPrintInfo(" Initializing Wifi flash... "); + uiPrintInfo("%s\e[0m\n", res_str[wifiRes = dev_flash->init()]); bootInfo.sd_status = sdRes; bootInfo.nand_status = nandRes; @@ -170,7 +170,7 @@ res = f_mount(&sd_fs, "sdmc:", 1); - printf("%s\e[0m\n", res_str[res == FR_OK]); + uiPrintInfo("%s\e[0m\n", res_str[res == FR_OK]); return res == FR_OK; } @@ -183,30 +183,30 @@ if(bootInfo.sd_status) { - printf("Mounting SD card FAT FS... "); + uiPrintInfo("Mounting SD card FAT FS... "); res[0] = f_mount(&sd_fs, "sdmc:", 1); - if(res[0] == FR_OK) printf("%s\e[0m\n", res_str[1]); - else printf("%s ERROR 0x%d\e[0m\n", res_str[0], res[0]); + if(res[0] == FR_OK) uiPrintInfo("%s\e[0m\n", res_str[1]); + //else uiPrintInfo("%s ERROR 0x%d\e[0m\n", res_str[0], res[0]); finalRes &= res[0] == FR_OK; } else finalRes = false; if(bootInfo.nand_status) { - printf("Mounting twln FS... "); + uiPrintInfo("Mounting twln FS... "); res[1] = f_mount(&nand_twlnfs, "twln:", 1); - if(res[1] == FR_OK) printf("%s\e[0m\n", res_str[1]); - else printf("%s ERROR 0x%d\e[0m\n", res_str[0], res[1]); + if(res[1] == FR_OK) uiPrintInfo("%s\e[0m\n", res_str[1]); + else uiPrintInfo("%s ERROR 0x%d\e[0m\n", res_str[0], res[1]); - printf("Mounting twlp FS... "); + uiPrintInfo("Mounting twlp FS... "); res[2] = f_mount(&nand_twlpfs, "twlp:", 1); - if(res[2] == FR_OK) printf("%s\e[0m\n", res_str[1]); - else printf("%s ERROR 0x%d\e[0m\n", res_str[0], res[2]); + if(res[2] == FR_OK) uiPrintInfo("%s\e[0m\n", res_str[1]); + else uiPrintInfo("%s ERROR 0x%d\e[0m\n", res_str[0], res[2]); - printf("Mounting CTR NAND FAT FS... "); + uiPrintInfo("Mounting CTR NAND FAT FS... "); res[3] = f_mount(&nand_fs, "nand:", 1); - if(res[3] == FR_OK) printf("%s\e[0m\n", res_str[1]); - else printf("%s ERROR 0x%d\e[0m\n", res_str[0], res[3]); + if(res[3] == FR_OK) uiPrintInfo("%s\e[0m\n", res_str[1]); + else uiPrintInfo("%s ERROR 0x%d\e[0m\n", res_str[0], res[3]); finalRes &= res[3] == res[2] == res[1] == FR_OK; } @@ -266,7 +266,7 @@ sprintf(bootInfo.model, "%s 3DS", bootInfo.unit_is_new3ds ? "New" : "Original"); - printf("%s detected!\n", bootInfo.model); + uiPrintInfo("%s detected!\n", bootInfo.model); } #define CFG_REGS_BASE (IO_MEM_ARM9_ONLY) @@ -294,7 +294,7 @@ u8 *nand_sector = (u8*)malloc(0x200); if(!bootInfo.nand_status) - printf("\x1B[31mFailed!\e[0m\n"); + uiPrintInfo("\x1B[31mFailed!\e[0m\n"); else { dev_decnand->read_sector(0x0B130000 >> 9, 1, nand_sector); @@ -311,7 +311,7 @@ const char *res_str[2] = {"\x1B[31mFailed!", "\x1B[32mOK!"}; bool success = loadConfigFile(); - printf("%s\e[0m\n", res_str[success]); + uiPrintInfo("%s\e[0m\n", res_str[success]); if(success) { @@ -340,7 +340,7 @@ { uiClearConsoles(); - printf("Attempting to turn off...\n"); + uiPrintInfo("Attempting to turn off...\n"); unmount_fs(); devs_close(); @@ -349,3 +349,19 @@ for(;;); } + +void reboot_safe() +{ + wait(0x100000); + + uiClearConsoles(); + + uiPrintInfo("Attempting to reboot...\n"); + + unmount_fs(); + devs_close(); + + PXI_sendWord(PXI_CMD_REBOOT); + + for(;;); +} \ No newline at end of file diff --git a/source/arm9/menu_update.c b/source/arm9/menu_update.c index bd8d76d..a38436d 100644 --- a/source/arm9/menu_update.c +++ b/source/arm9/menu_update.c @@ -120,13 +120,12 @@ /* We should be done now... */ - - - uiPrintInfo("Press any key to reboot..."); menuWaitForAnyPadkey(); - panic(); + reboot_safe(); + + return true; fail: