From 279f39bc13b5d32b31b97327e36351441a63f561 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 23 Mar 2016 03:45:32 +0100 Subject: [PATCH] Added error messages, moved emunand and reboot.bin to aurei/patches --- Makefile | 13 ++++++----- source/firm.c | 44 ++++++++++++++++-------------------- source/firm.h | 4 ++-- source/main.c | 9 ++------ source/start.s | 2 -- source/{config.c => utils.c} | 31 +++++++++++++++++++------ source/{config.h => utils.h} | 5 ++-- 7 files changed, 57 insertions(+), 51 deletions(-) rename source/{config.c => utils.c} (79%) rename source/{config.h => utils.h} (60%) diff --git a/Makefile b/Makefile index 0e22ac2..67d658b 100644 --- a/Makefile +++ b/Makefile @@ -43,10 +43,10 @@ launcher: $(dir_out)/$(name).dat a9lh: $(dir_out)/arm9loaderhax.bin .PHONY: emunand -emunand: $(dir_out)/aurei/emunand/emunand.bin +emunand: $(dir_out)/aurei/patches/emunand.bin .PHONY: reboot -reboot: $(dir_out)/aurei/reboot/reboot.bin +reboot: $(dir_out)/aurei/patches/reboot.bin .PHONY: ninjhax ninjhax: $(dir_out)/3ds/$(name) @@ -77,14 +77,15 @@ $(dir_out)/3ds/$(name): $(dir_out)/aurei: @mkdir -p "$(dir_out)/aurei" -$(dir_out)/aurei/emunand/emunand.bin: $(dir_emu)/emuCode.s +$(dir_out)/aurei/patches: + @mkdir -p "$(dir_out)/aurei/patches" + +$(dir_out)/aurei/patches/emunand.bin: $(dir_emu)/emuCode.s $(dir_out)/aurei/patches @armips $< - @mkdir -p "$(dir_out)/aurei/emunand" @mv emunand.bin $@ -$(dir_out)/aurei/reboot/reboot.bin: $(dir_reboot)/rebootCode.s +$(dir_out)/aurei/patches/reboot.bin: $(dir_reboot)/rebootCode.s $(dir_out)/aurei/patches @armips $< - @mkdir -p "$(dir_out)/aurei/reboot" @mv reboot.bin $@ $(dir_out)/aurei/loader.bin: $(dir_out)/aurei $(dir_loader)/Makefile diff --git a/source/firm.c b/source/firm.c index a536229..052f3b2 100755 --- a/source/firm.c +++ b/source/firm.c @@ -13,7 +13,7 @@ #include "draw.h" #include "screeninit.h" #include "loader.h" -#include "config.h" +#include "utils.h" #include "buttons.h" //FIRM patches version @@ -79,10 +79,8 @@ void setupCFW(void){ if(a9lhBoot && (pressed & BUTTON_L1R1) == BUTTON_L1R1) loadPayload(); //If no configuration file exists or SELECT is held, load configuration menu - if(needConfig == 2 || (pressed & BUTTON_SELECT)){ - if(PDN_GPU_CNT == 0x1) initScreens(); + if(needConfig == 2 || (pressed & BUTTON_SELECT)) configureCFW(configPath); - } //If screens are inited, load splash screen if(PDN_GPU_CNT != 0x1) loadSplash(); @@ -128,7 +126,7 @@ void setupCFW(void){ } //Load FIRM into FCRAM -u32 loadFirm(void){ +void loadFirm(void){ //If not using an A9LH setup or the patched FIRM, load 9.0 FIRM from NAND if(!usePatchedFirm && !a9lhSetup && !mode){ @@ -136,31 +134,31 @@ u32 loadFirm(void){ firmSize = console ? 0xF2000 : 0xE9000; nandFirm0((u8 *)firmLocation, firmSize, console); //Check for correct decryption - if(memcmp(firmLocation, "FIRM", 4) != 0) return 0; + if(memcmp(firmLocation, "FIRM", 4) != 0) + error("Couldn't decrypt FIRM0 from NAND"); } //Load FIRM from SD else{ const char *path = usePatchedFirm ? patchedFirms[selectedFirm - 1] : (mode ? "/aurei/firmware.bin" : "/aurei/firmware90.bin"); firmSize = fileSize(path); - if(!firmSize) return 0; + if(!firmSize) error("firmware(90).bin doesn't exist"); fileRead((u8 *)firmLocation, path, firmSize); } section = firmLocation->section; //Check that the loaded FIRM matches the console - if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 0; + if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) + error("firmware(90).bin doesn't match the console"); arm9Section = (u8 *)firmLocation + section[2].offset; if(console && !usePatchedFirm) decryptArm9Bin(arm9Section, mode); - - return 1; } //NAND redirection -static u32 loadEmu(u8 *proc9Offset){ +static void loadEmu(u8 *proc9Offset){ u32 emuOffset = 1, emuHeader = 1, @@ -168,9 +166,9 @@ static u32 loadEmu(u8 *proc9Offset){ emuWrite; //Read emunand code from SD - const char path[] = "/aurei/emunand/emunand.bin"; + const char path[] = "/aurei/patches/emunand.bin"; u32 size = fileSize(path); - if(!size) return 0; + if(!size) error("emunand.bin doesn't exist"); u8 *emuCodeOffset = getEmuCode(arm9Section, section[2].size, proc9Offset); fileRead(emuCodeOffset, path, size); @@ -178,7 +176,7 @@ static u32 loadEmu(u8 *proc9Offset){ getEmunandSect(&emuOffset, &emuHeader, emuNAND); //No emuNAND detected - if(!emuHeader) return 0; + if(!emuHeader) error("No emuNAND has been detected"); //Place emuNAND data u32 *pos_offset = (u32 *)memsearch(emuCodeOffset, "NAND", size, 4); @@ -202,30 +200,27 @@ static u32 loadEmu(u8 *proc9Offset){ //Set MPU for emu code region void *mpuOffset = getMPU(arm9Section, section[2].size); memcpy(mpuOffset, mpu, sizeof(mpu)); - - return 1; } //Patches -u32 patchFirm(void){ +void patchFirm(void){ //Skip patching - if(usePatchedFirm) return 1; + if(usePatchedFirm) return; if(mode || emuNAND){ //Find the Process9 NCCH location u8 *proc9Offset = getProc9(arm9Section, section[2].size); //Apply emuNAND patches - if(emuNAND) - if(!loadEmu(proc9Offset)) return 0; + if(emuNAND) loadEmu(proc9Offset); //Patch FIRM reboots, not on 9.0 FIRM as it breaks firmlaunchhax if(mode){ //Read reboot code from SD - const char path[] = "/aurei/reboot/reboot.bin"; + const char path[] = "/aurei/patches/reboot.bin"; u32 size = fileSize(path); - if(!size) return 0; + if(!size) error("reboot.bin doesn't exist"); u8 *rebootOffset = getReboot(arm9Section, section[2].size); fileRead(rebootOffset, path, size); @@ -261,9 +256,8 @@ u32 patchFirm(void){ //Write patched FIRM to SD if needed if(selectedFirm) - if(!fileWrite((u8 *)firmLocation, patchedFirms[selectedFirm - 1], firmSize)) return 0; - - return 1; + if(!fileWrite((u8 *)firmLocation, patchedFirms[selectedFirm - 1], firmSize)) + error("Couldn't write the patched FIRM (no free space?)"); } void launchFirm(void){ diff --git a/source/firm.h b/source/firm.h index b09cca9..3dd8ffa 100644 --- a/source/firm.h +++ b/source/firm.h @@ -31,6 +31,6 @@ typedef struct firmHeader { } firmHeader; void setupCFW(void); -u32 loadFirm(void); -u32 patchFirm(void); +void loadFirm(void); +void patchFirm(void); void launchFirm(void); \ No newline at end of file diff --git a/source/main.c b/source/main.c index 88b2941..9d785ea 100644 --- a/source/main.c +++ b/source/main.c @@ -8,16 +8,11 @@ #include "fs.h" #include "firm.h" -#include "i2c.h" void main(void){ mountSD(); setupCFW(); - if(!loadFirm()) return; - if(!patchFirm()) return; + loadFirm(); + patchFirm(); launchFirm(); -} - -void shutdown(void){ - i2cWriteRegister(I2C_DEV_MCU, 0x20, 1); } \ No newline at end of file diff --git a/source/start.s b/source/start.s index 7d2b461..729f02c 100644 --- a/source/start.s +++ b/source/start.s @@ -52,7 +52,5 @@ _start: bl main - bl shutdown - .die: b .die diff --git a/source/config.c b/source/utils.c similarity index 79% rename from source/config.c rename to source/utils.c index e27c4fb..4ad2e1c 100644 --- a/source/config.c +++ b/source/utils.c @@ -1,10 +1,11 @@ /* -* config.c +* utils.c * by Aurora Wright * Copyright (c) 2016 All Rights Reserved */ -#include "config.h" +#include "utils.h" +#include "screeninit.h" #include "draw.h" #include "fs.h" #include "i2c.h" @@ -14,8 +15,8 @@ #define OPTIONS 3 #define COLOR_TITLE 0xFF9900 -#define COLOR_NORMAL 0xFFFFFF -#define COLOR_SELECTED 0x0000FF +#define COLOR_WHITE 0xFFFFFF +#define COLOR_RED 0x0000FF #define COLOR_BLACK 0x000000 struct options { @@ -55,10 +56,11 @@ void configureCFW(const char *configPath){ options.text[1] = "( ) Use pre-patched FIRMs"; options.text[2] = "( ) Force A9LH detection"; + if(PDN_GPU_CNT == 0x1) initScreens(); clearScreens(); drawString("AuReiNand configuration", 10, 10, COLOR_TITLE); - drawString("Press A to select, START to save and reboot", 10, 30, COLOR_NORMAL); + drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE); //Read and parse the existing configuration u16 tempConfig = 0; @@ -75,8 +77,8 @@ void configureCFW(const char *configPath){ do{ for(u32 i = 0; i < OPTIONS; i++){ - options.pos_y[i] = drawString(options.text[i], 10, !i ? 60 : options.pos_y[i - 1] + SPACING_VERT, options.selected == i ? COLOR_SELECTED : COLOR_NORMAL); - drawCharacter('x', 10 + SPACING_HORIZ, options.pos_y[i], options.enabled[i] ? (options.selected == i ? COLOR_SELECTED : COLOR_NORMAL) : COLOR_BLACK); + options.pos_y[i] = drawString(options.text[i], 10, !i ? 60 : options.pos_y[i - 1] + SPACING_VERT, options.selected == i ? COLOR_RED : COLOR_WHITE); + drawCharacter('x', 10 + SPACING_HORIZ, options.pos_y[i], options.enabled[i] ? (options.selected == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK); } pressed = waitInput(); } while(!(pressed & (BUTTON_UP | BUTTON_DOWN | BUTTON_A | BUTTON_START))); @@ -105,4 +107,19 @@ void deleteFirms(const char *firmPaths[], u32 firms){ fileDelete(firmPaths[firms - 1]); firms--; } +} + +void error(const char *message){ + if(PDN_GPU_CNT == 0x1) initScreens(); + clearScreens(); + + drawString("An error has occurred:", 10, 10, COLOR_RED); + int pos_y = drawString(message, 10, 30, COLOR_WHITE); + drawString("Press any button to shutdown", 10, pos_y + 2 * SPACING_VERT, COLOR_WHITE); + + waitInput(); + + //Shutdown + i2cWriteRegister(I2C_DEV_MCU, 0x20, 1); + while(1); } \ No newline at end of file diff --git a/source/config.h b/source/utils.h similarity index 60% rename from source/config.h rename to source/utils.h index 42bb342..f9536c6 100644 --- a/source/config.h +++ b/source/utils.h @@ -1,5 +1,5 @@ /* -* config.h +* utils.h * by Aurora Wright * Copyright (c) 2016 All Rights Reserved */ @@ -9,4 +9,5 @@ #include "types.h" void configureCFW(const char *configPath); -void deleteFirms(const char *firmPaths[], u32 firms); \ No newline at end of file +void deleteFirms(const char *firmPaths[], u32 firms); +void error(const char *message); \ No newline at end of file