diff --git a/include/arm9/main.h b/include/arm9/main.h index 7217ecb..3cfb8cb 100644 --- a/include/arm9/main.h +++ b/include/arm9/main.h @@ -4,13 +4,22 @@ #include "fatfs/ff.h" #include "arm9/ui.h" +enum bootOptionResultTypes { + BO_NOT_ATTEMPTED = 0, + BO_NOT_FOUND, + BO_FAILED, + BO_SKIPPED +}; + typedef struct { char model[0x10]; - bool unit_is_new3ds; - char boot_env[0x20]; + bool unitIsNew3DS; + char bootEnv[0x20]; char mode[7]; char fw_ver1[10]; char fw_ver2[10]; + u32 numBootOptionsAttempted; + u32 bootOptionResults[3]; bool wififlash_status; u32 nand_status; // Bit 0: twln, bit 1: twlp, bit 2: nand u32 sd_status; // 0: Not inserted, 1: FS init failed, 2: OK diff --git a/include/arm9/menu.h b/include/arm9/menu.h index fc0fd80..939f86f 100644 --- a/include/arm9/menu.h +++ b/include/arm9/menu.h @@ -11,6 +11,7 @@ enum menu_state_type { MENU_STATE_MAIN = 0, MENU_STATE_NAND_MENU, + MENU_STATE_LOAD_FIRM, MENU_STATE_OPTIONS_MENU, MENU_STATE_OPTIONS_MODE, MENU_STATE_FIRM_LAUNCH_SETTINGS, diff --git a/source/arm9/debug.c b/source/arm9/debug.c index 140073a..1fb3a5e 100644 --- a/source/arm9/debug.c +++ b/source/arm9/debug.c @@ -136,6 +136,8 @@ return; f_write(&file, mem, size, &bytesWritten); + + f_sync(&file); f_close(&file); } diff --git a/source/arm9/dev.c b/source/arm9/dev.c index b4a8965..4bfa259 100644 --- a/source/arm9/dev.c +++ b/source/arm9/dev.c @@ -280,7 +280,7 @@ } else if(i == 4) // CTR NAND partition { - if(bootInfo.unit_is_new3ds) + if(bootInfo.unitIsNew3DS) partitionSetKeyslot(index, 0x05); else partitionSetKeyslot(index, 0x04); diff --git a/source/arm9/fsutils.c b/source/arm9/fsutils.c index dbb91ff..c877dbc 100644 --- a/source/arm9/fsutils.c +++ b/source/arm9/fsutils.c @@ -139,7 +139,7 @@ goto fail; /* touch file */ - res = f_open(&tempFile, filepath, FA_CREATE_NEW); + res = f_open(&tempFile, filepath, FA_CREATE_ALWAYS); if(res != FR_OK && res != FR_EXIST) goto fail; diff --git a/source/arm9/main.c b/source/arm9/main.c index 686c26a..93ee530 100644 --- a/source/arm9/main.c +++ b/source/arm9/main.c @@ -191,9 +191,9 @@ static void unit_detect() { - bootInfo.unit_is_new3ds = REG_PDN_MPCORE_CFG & 2; + bootInfo.unitIsNew3DS = REG_PDN_MPCORE_CFG & 2; - sprintf(bootInfo.model, "%s 3DS", bootInfo.unit_is_new3ds ? "New" : "Original"); + sprintf(bootInfo.model, "%s 3DS", bootInfo.unitIsNew3DS ? "New" : "Original"); uiPrintIfVerbose("%s detected!\n", bootInfo.model); } @@ -211,7 +211,7 @@ sprintf(bootInfo.mode, "%s", CFG_UNITINFO != 0 ? "Dev" : "Retail"); - strcpy(bootInfo.boot_env, boot_environment[boot_env]); + strcpy(bootInfo.bootEnv, boot_environment[boot_env]); } static void fw_detect() diff --git a/source/arm9/menu.c b/source/arm9/menu.c index 4fccfd3..525d7c2 100644 --- a/source/arm9/menu.c +++ b/source/arm9/menu.c @@ -40,11 +40,11 @@ } }; -const menu_state_options menu_load_firmware = { +const menu_state_options menu_loadfw = { 2, { - {"Load from SD card", MENU_STATE_NAND_BACKUP}, - {"Load firm1", MENU_STATE_NAND_RESTORE}, + {"Load from SD card", MENU_STATE_BROWSER}, + {"Load firm1", 0}, } }; @@ -52,6 +52,7 @@ const menu_state_options *options_lookup[] = { &menu_main, // STATE_MAIN &menu_nand, // STATE_NAND_MENU + &menu_loadfw, // MENU_STATE_LOAD_FIRM }; enum menu_state_type menu_state; @@ -70,13 +71,14 @@ const char *const sd_res[3] = {"\x1B[33mNot inserted ", "\x1B[31mFS init failed", "\x1B[32mOK "}; const char *const nand_res[2] = {"\x1B[31mInit failed: ", "\x1B[32mOK "}; const char *const nand_drives[3] = {"twln ", "twlp ", "nand"}; + const char *const boot_res[4] = {"Not attempted", "Not found", "Failed", "Skipped"}; consoleSelect(&con_top); uiPrintCenteredInLine(1, "fastboot 3DS " VER_STRING); uiPrintTextAt(1, 4, "Model: %s", bootInfo.model); - uiPrintTextAt(1, 5, "\x1B[33m%s\e[0m", bootInfo.boot_env); + uiPrintTextAt(1, 5, "\x1B[33m%s\e[0m", bootInfo.bootEnv); uiPrintTextAt(1, 6, "\x1B[32m(%s Mode)\x1B[0m", bootInfo.mode); uiPrintTextAt(1, 8, "SD card status: %s\x1B[0m", sd_res[bootInfo.sd_status]); uiPrintTextAt(1, 9, "NAND status: %s\x1B[0m", nand_res[bootInfo.nand_status == 7]); @@ -88,6 +90,14 @@ } } uiPrintTextAt(1, 10, "Wifi flash status: %s\e[0m", nand_res[bootInfo.wififlash_status]); + + if(bootInfo.numBootOptionsAttempted != 0) + { + uiPrintTextAt(1, 15, "Firm launch statistics:"); + uiPrintTextAt(1, 16, "[Slot1]: %s", boot_res[bootInfo.bootOptionResults[0]]); + uiPrintTextAt(1, 17, "[Slot2]: %s", boot_res[bootInfo.bootOptionResults[1]]); + uiPrintTextAt(1, 18, "[Slot3]: %s", boot_res[bootInfo.bootOptionResults[2]]); + } } void menuSetVBlank(bool enable) diff --git a/source/arm9/menu_firmloader.c b/source/arm9/menu_firmloader.c index d2dc4d1..dd7033f 100644 --- a/source/arm9/menu_firmloader.c +++ b/source/arm9/menu_firmloader.c @@ -75,7 +75,7 @@ static bool statFirmware(const char *filePath) { FILINFO fileStat; - u32 fileSize; + // u32 fileSize; fsEnsureMounted(filePath); @@ -84,10 +84,12 @@ if(f_stat(filePath, &fileStat) != FR_OK) return false; + /* fileSize = fileStat.fsize; if(fileSize == 0 || fileSize > FIRM_MAX_SIZE) return false; + */ return true; } @@ -117,6 +119,11 @@ consoleSelect(&con_top); firmLoaded = 0; + + bootInfo.numBootOptionsAttempted = 0; + bootInfo.bootOptionResults[0] = BO_NOT_ATTEMPTED; + bootInfo.bootOptionResults[1] = BO_NOT_ATTEMPTED; + bootInfo.bootOptionResults[2] = BO_NOT_ATTEMPTED; if(fromMenu) uiPrintCenteredInLine(1, "Loading FIRM from settings\n"); @@ -146,6 +153,8 @@ if(checkForHIDAbort()) return false; + bootInfo.numBootOptionsAttempted ++; + path = (const char *)configGetData(keyBootOption); if(path) { @@ -157,6 +166,7 @@ { if(fromMenu) uiPrintInfo("Couldn't find firmware...\n"); + bootInfo.bootOptionResults[i] = BO_NOT_FOUND; goto try_next; } @@ -178,6 +188,7 @@ uiPrintInfo("Skipping, right buttons are not pressed.\n"); uiPrintInfo("%" PRIX32 " %" PRIX32 "\n", padValue, expectedPadValue); } + bootInfo.bootOptionResults[i] = BO_SKIPPED; goto try_next; } } @@ -203,6 +214,8 @@ uiPrintBootWarning(); } } + + bootInfo.bootOptionResults[i] = BO_FAILED; } else continue; diff --git a/source/arm9/menu_update.c b/source/arm9/menu_update.c index f8435c4..3023dd8 100644 --- a/source/arm9/menu_update.c +++ b/source/arm9/menu_update.c @@ -76,7 +76,7 @@ goto fail; } - if(!uiDialogYesNo("Update", "Cancel", "Update to v%" PRIu16 ".%" PRIu16, + if(!uiDialogYesNo(1, "Update", "Cancel", "Update to v%" PRIu16 ".%" PRIu16, updateVersion>>16, updateVersion & 0xFFFFu)) { goto fail;