diff --git a/include/arm9/menu_firmloader.h b/include/arm9/menu_firmloader.h index edc1a1d..293c621 100644 --- a/include/arm9/menu_firmloader.h +++ b/include/arm9/menu_firmloader.h @@ -2,6 +2,5 @@ bool isFirmLoaded(void); bool menuLaunchFirm(const char *filePath, bool quick); -bool menuTryLoadFirmwareFromSettings(void); -bool TryLoadFirmwareFromSettings(void); +bool tryLoadFirmwareFromSettings(bool fromMenu); bool tryLoadFirmware(const char *filepath, bool skipHashCheck, bool printInfo); diff --git a/include/arm9/ui.h b/include/arm9/ui.h index d14eb32..b508d83 100644 --- a/include/arm9/ui.h +++ b/include/arm9/ui.h @@ -16,7 +16,8 @@ void uiDrawConsoleWindow(); void uiClearConsoles(); void clearConsole(int which); -void uiSetVerbose(bool verb); +void uiSetVerboseMode(bool verb); +bool uiGetVerboseMode(); bool uiDialogYesNo(const char *textYes, const char *textNo, const char *const format, ...); void uiPrintIfVerbose(const char *const format, ...); void uiPrint(const char *const format, unsigned int color, bool centered, ...); diff --git a/include/hid.h b/include/hid.h index 11ae9bf..53a5089 100644 --- a/include/hid.h +++ b/include/hid.h @@ -4,7 +4,7 @@ #define HID_KEY_MASK_ALL ((KEY_Y << 1) - 1) - +#define HID_VERBOSE_MODE_BUTTONS (KEY_SELECT | KEY_START) enum { diff --git a/source/arm9/config.c b/source/arm9/config.c index 26ef923..4e4e929 100644 --- a/source/arm9/config.c +++ b/source/arm9/config.c @@ -18,8 +18,8 @@ #define MAX_FILE_SIZE 0x4000 - 1 -static const char *SdmcFilepath = "sdmc:\\loadercfg.txt"; -// static const char *NandFilepath = "nand:\\loader\\loadercfg.txt"; +static const char *SdmcFilepath = "sdmc:\\fastbootcfg.txt"; +// static const char *NandFilepath = "nand:\\loader\\fastbootcfg.txt"; static const char *filepath; diff --git a/source/arm9/firm.c b/source/arm9/firm.c index 18a1f43..240aee4 100644 --- a/source/arm9/firm.c +++ b/source/arm9/firm.c @@ -9,6 +9,7 @@ #include "arm9/firm.h" #include "arm9/crypto.h" #include "arm9/ndma.h" +#include "arm9/ui.h" #include "cache.h" #include "util.h" #include "pxi.h" @@ -167,8 +168,8 @@ if(printInfo) { - printf("ARM9 entry: 0x%"PRIX32"\n", firm_hdr->entrypointarm9); - printf("ARM11 entry: 0x%"PRIX32"\n", firm_hdr->entrypointarm11); + uiPrintInfo("ARM9 entry: 0x%"PRIX32"\n", firm_hdr->entrypointarm9); + uiPrintInfo("ARM11 entry: 0x%"PRIX32"\n", firm_hdr->entrypointarm11); } for(u32 i=0; i<4; i++) @@ -179,20 +180,20 @@ continue; if(printInfo) - printf("Section %i:\noffset: 0x%"PRIX32", addr: 0x%"PRIX32", size: 0x%"PRIX32"\n", (int)i, + uiPrintInfo("Section %i:\noffset: 0x%"PRIX32", addr: 0x%"PRIX32", size: 0x%"PRIX32"\n", (int)i, section->offset, section->address, section->size); if(section->offset >= fwSize || section->offset < sizeof(firm_header)) { if(printInfo) - printf("\x1B[31mBad section offset!\e[0m\n"); + uiPrintInfo("\x1B[31mBad section offset!\e[0m\n"); return false; } if((section->size >= fwSize) || (section->size + section->offset > fwSize)) { if(printInfo) - printf("\x1B[31mBad section size!\e[0m\n"); + uiPrintInfo("\x1B[31mBad section size!\e[0m\n"); return false; } @@ -220,7 +221,7 @@ if(!isValid) { if(printInfo) - printf("\x1B[31mUnallowed section:\n0x%"PRIX32" - 0x%"PRIX32"\e[0m\n", start, end); + uiPrintInfo("\x1B[31mUnallowed section:\n0x%"PRIX32" - 0x%"PRIX32"\e[0m\n", start, end); retval = false; break; } @@ -233,7 +234,7 @@ isValid = memcmp(hash, section->hash, 32) == 0; if(printInfo) - printf("Hash: %s\e[0m\n", res[isValid]); + uiPrintInfo("Hash: %s\e[0m\n", res[isValid]); retval &= isValid; } @@ -253,7 +254,7 @@ //printf("Relocating FIRM launch stub...\n"); NDMA_copy((u32*)A9_STUB_ENTRY, (u32*)firmLaunchStub, A9_STUB_SIZE>>2); - printf("Starting firm launch...\n"); + //printf("Starting firm launch...\n"); void (*stub)(void) = (void (*)(void))A9_STUB_ENTRY; stub(); while(1); diff --git a/source/arm9/firmwriter.c b/source/arm9/firmwriter.c index 2ed2534..e1b6cdb 100644 --- a/source/arm9/firmwriter.c +++ b/source/arm9/firmwriter.c @@ -95,7 +95,7 @@ if(!firmwriterIsDone()) { - printf("firmwriter is not done yet.\n"); + // printf("firmwriter is not done yet.\n"); return false; } diff --git a/source/arm9/main.c b/source/arm9/main.c index 912cf6c..bc41849 100644 --- a/source/arm9/main.c +++ b/source/arm9/main.c @@ -23,6 +23,7 @@ static void boot_env_detect(); static void fw_detect(); static bool loadSettings(int *mode); +static void checkSetVerboseMode(); int main(void) { @@ -36,9 +37,11 @@ uiInit(); + checkSetVerboseMode(); + uiDrawSplashScreen(); - consoleSelect(&con_top); + consoleSelect(&con_bottom); uiPrintIfVerbose("\x1B[32mGood morning\nHello !\e[0m\n\n"); @@ -59,7 +62,7 @@ screen_init(); /* fallthrough */ case BootModeQuiet: - TryLoadFirmwareFromSettings(); + tryLoadFirmwareFromSettings(false); if(isFirmLoaded()) goto finish_firmlaunch; /* else fallthrough */ @@ -212,7 +215,7 @@ } else finalRes = false; - if(!finalRes) + if(!finalRes && uiGetVerboseMode()) TIMER_sleep(2000); return finalRes; @@ -327,6 +330,16 @@ return false; } +static void checkSetVerboseMode() +{ + u32 keys; + + hidScanInput(); + keys = hidKeysDown() & HID_KEY_MASK_ALL; + if(keys == HID_VERBOSE_MODE_BUTTONS) + uiSetVerboseMode(true); +} + #define PRNG_REGS_BASE (IO_MEM_ARM9_ONLY + 0x11000) #define REG_PRNG ((vu32*)(PRNG_REGS_BASE)) diff --git a/source/arm9/menu.c b/source/arm9/menu.c index d632be3..e5029d9 100644 --- a/source/arm9/menu.c +++ b/source/arm9/menu.c @@ -23,9 +23,9 @@ 5, { {"Continue boot", MENU_STATE_FIRM_LAUNCH_SETTINGS}, + {"Launch Firmware...", MENU_STATE_BROWSER}, {"NAND tools...", MENU_STATE_NAND_MENU}, {"Options...", MENU_STATE_OPTIONS_MENU}, - {"Browse FIRM...", MENU_STATE_BROWSER}, {"Update", MENU_STATE_UPDATE}, } }; @@ -184,7 +184,7 @@ break; case MENU_STATE_FIRM_LAUNCH_SETTINGS: - if(!menuTryLoadFirmwareFromSettings()) + if(!tryLoadFirmwareFromSettings(true)) uiClearConsoles(); break; @@ -237,7 +237,7 @@ switch(state) { case MENU_STATE_FIRM_LAUNCH_SETTINGS: - if(!menuTryLoadFirmwareFromSettings()) + if(!tryLoadFirmwareFromSettings(true)) uiClearConsoles(); break; @@ -380,68 +380,9 @@ menu_event_state = MENU_EVENT_NONE; } -/* -static char *menuNormalizeText(const char *text) -{ - size_t curLineLen; - const char *p = text; - - char *q = (char *) malloc((strlen(text) + 1) * 3); - if(!q) - return NULL; - - while(*p) - { - if(p[0] == '\\' && p[1] == 'n') - { - - } - } -} - -void menuCalcWindowMetrics(const char *text, int *x, int *y, int *width, int *height) -{ - const char *p = text; - size_t longestLineLen = 0; - size_t curLineLen; - size_t lines = 0; - - while(*p) - { - // Note: text shouldn't be malformed. - if(p[0] == '\n') - { - lines ++; - if(curLineLen > longestLineLen) - longestLineLen = curLineLen; - p += 2; - } - else - { - curLineLen++; - p++; - } - } - - if(curLineLen > longestLineLen) - longestLineLen = curLineLen; - - -} -*/ void menuPrintPrompt(const char *text) { - /* - const char *p = text; - size_t lines = 0; - - - while(*p) - { - - }*/ - printf(text); } diff --git a/source/arm9/menu_firmloader.c b/source/arm9/menu_firmloader.c index e215258..f2907df 100644 --- a/source/arm9/menu_firmloader.c +++ b/source/arm9/menu_firmloader.c @@ -90,90 +90,13 @@ return true; } + else if(strncmp(filePath, "firm1:", 5) == 0) + return true; // this is always available // unknown mountpoint return false; } -bool menuTryLoadFirmwareFromSettings(void) -{ - const char *path; - int keyBootOption, keyPad; - int i; - u32 padValue, expectedPadValue; - - uiClearConsoles(); - consoleSelect(&con_top); - - printf("Loading FIRM from settings\n\n"); - - // No Boot Option set up? - if(!configDataExist(KBootOption1) && - !configDataExist(KBootOption2) && - !configDataExist(KBootOption3)) - { - menuPrintPrompt("No Boot-Option set up yet.\nGo to 'Options' to choose a file.\n"); - menuWaitForAnyPadkey(); - menuSetReturnToState(STATE_PREVIOUS); - return false; - } - - keyBootOption = KBootOption1; - keyPad = KBootOption1Buttons; - - for(i=0; i<3; i++, keyBootOption++, keyPad++) - { - path = (const char *)configGetData(keyBootOption); - if(path) - { - printf("\nBoot Option #%i:\n%s\n", i + 1, path); - - // check if fw still exists - if(!statFirmware(path)) - { - printf("Couldn't find firmware...\n"); - continue; - } - - // check pad value - const u32 *temp; - temp = (const u32 *)configGetData(keyPad); - if(temp) - { - expectedPadValue = *temp; - hidScanInput(); - padValue = HID_KEY_MASK_ALL & hidKeysHeld(); - if(padValue != expectedPadValue) - { - printf("Skipping, right buttons are not pressed.\n"); - printf("%" PRIX32 " %" PRIX32 "\n", padValue, expectedPadValue); - continue; - } - } - - if(menuLaunchFirm(path, false)) - break; - else - { - uiClearConsoles(); - consoleSelect(&con_top); - } - } - - // ... we failed, try next one - } - - if(i >= 3) - { - menuSetReturnToState(STATE_PREVIOUS); - return false; - } - - menuSetReturnToState(MENU_STATE_EXIT); - - return true; -} - static bool checkForHIDAbort() { bool successFlag; @@ -196,13 +119,16 @@ return false; } -bool TryLoadFirmwareFromSettings(void) +bool tryLoadFirmwareFromSettings(bool fromMenu) { const char *path; int keyBootOption, keyBootMode, keyPad; int i; u32 padValue, expectedPadValue; + if(fromMenu) + uiClearConsoles(); + consoleSelect(&con_top); firmLoaded = 0; @@ -214,6 +140,12 @@ !configDataExist(KBootOption2) && !configDataExist(KBootOption3)) { + if(fromMenu) + { + menuPrintPrompt("No Boot-Option set up yet.\nGo to 'Options' to choose a file.\n"); + menuWaitForAnyPadkey(); + menuSetReturnToState(STATE_PREVIOUS); + } return false; } @@ -256,11 +188,24 @@ } } - if(tryLoadFirmware(path, false, false)) - break; + if(fromMenu) + { + if(menuLaunchFirm(path, false)) + break; + else + { + uiClearConsoles(); + consoleSelect(&con_top); + } + } else { - printf("Bad firmware, trying next one...\n"); + if(tryLoadFirmware(path, false, false)) + break; + else + { + printf("Bad firmware, trying next one...\n"); + } } } else @@ -276,6 +221,8 @@ if(i >= 3) { + if(fromMenu) + menuSetReturnToState(STATE_PREVIOUS); return false; } @@ -283,6 +230,9 @@ return false; firmLoaded = 1; + + if(fromMenu) + menuSetReturnToState(MENU_STATE_EXIT); return true; } @@ -364,11 +314,16 @@ if(!filepath) return false; + + if(!statFirmware(filepath)) + return false; // printf("Loading firmware:\n%s\n\n", filepath); + /* SD card */ if(strncmp(filepath, "sdmc:", 5) == 0) fw_size = loadFirmSd(filepath); + /* NAND */ else if(strncmp(filepath, "firm1:", 5) == 0) fw_size = loadFirmNandPartition(filepath); else diff --git a/source/arm9/ui.c b/source/arm9/ui.c index 52c7130..c2ae7ac 100644 --- a/source/arm9/ui.c +++ b/source/arm9/ui.c @@ -77,11 +77,16 @@ consoleClear(); } -void uiSetVerbose(bool verb) +void uiSetVerboseMode(bool verb) { verbose = verb; } +bool uiGetVerboseMode() +{ + return verbose; +} + /* TODO: Should look similar to uiShowMessageWindow */ bool uiDialogYesNo(const char *textYes, const char *textNo, const char *const format, ...) { @@ -112,16 +117,14 @@ { if(verbose) { - const unsigned int width = (unsigned int)consoleGet()->consoleWidth; - char tmp[width + 1]; + char tmp[256]; va_list args; va_start(args, format); - vsnprintf(tmp, width + 1, format, args); + vsnprintf(tmp, 256, format, args); va_end(args); - - size_t len = strlen(tmp); - printf("\x1B[0m%*s%s\n", (width - len) / 2, "", tmp); + + printf(tmp); } }