Added error messages, moved emunand and reboot.bin to aurei/patches

This commit is contained in:
Aurora 2016-03-23 03:45:32 +01:00
parent b7b734bad1
commit 279f39bc13
7 changed files with 57 additions and 51 deletions

View File

@ -43,10 +43,10 @@ launcher: $(dir_out)/$(name).dat
a9lh: $(dir_out)/arm9loaderhax.bin a9lh: $(dir_out)/arm9loaderhax.bin
.PHONY: emunand .PHONY: emunand
emunand: $(dir_out)/aurei/emunand/emunand.bin emunand: $(dir_out)/aurei/patches/emunand.bin
.PHONY: reboot .PHONY: reboot
reboot: $(dir_out)/aurei/reboot/reboot.bin reboot: $(dir_out)/aurei/patches/reboot.bin
.PHONY: ninjhax .PHONY: ninjhax
ninjhax: $(dir_out)/3ds/$(name) ninjhax: $(dir_out)/3ds/$(name)
@ -77,14 +77,15 @@ $(dir_out)/3ds/$(name):
$(dir_out)/aurei: $(dir_out)/aurei:
@mkdir -p "$(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 $< @armips $<
@mkdir -p "$(dir_out)/aurei/emunand"
@mv emunand.bin $@ @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 $< @armips $<
@mkdir -p "$(dir_out)/aurei/reboot"
@mv reboot.bin $@ @mv reboot.bin $@
$(dir_out)/aurei/loader.bin: $(dir_out)/aurei $(dir_loader)/Makefile $(dir_out)/aurei/loader.bin: $(dir_out)/aurei $(dir_loader)/Makefile

View File

@ -13,7 +13,7 @@
#include "draw.h" #include "draw.h"
#include "screeninit.h" #include "screeninit.h"
#include "loader.h" #include "loader.h"
#include "config.h" #include "utils.h"
#include "buttons.h" #include "buttons.h"
//FIRM patches version //FIRM patches version
@ -79,10 +79,8 @@ void setupCFW(void){
if(a9lhBoot && (pressed & BUTTON_L1R1) == BUTTON_L1R1) loadPayload(); if(a9lhBoot && (pressed & BUTTON_L1R1) == BUTTON_L1R1) loadPayload();
//If no configuration file exists or SELECT is held, load configuration menu //If no configuration file exists or SELECT is held, load configuration menu
if(needConfig == 2 || (pressed & BUTTON_SELECT)){ if(needConfig == 2 || (pressed & BUTTON_SELECT))
if(PDN_GPU_CNT == 0x1) initScreens();
configureCFW(configPath); configureCFW(configPath);
}
//If screens are inited, load splash screen //If screens are inited, load splash screen
if(PDN_GPU_CNT != 0x1) loadSplash(); if(PDN_GPU_CNT != 0x1) loadSplash();
@ -128,7 +126,7 @@ void setupCFW(void){
} }
//Load FIRM into FCRAM //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 not using an A9LH setup or the patched FIRM, load 9.0 FIRM from NAND
if(!usePatchedFirm && !a9lhSetup && !mode){ if(!usePatchedFirm && !a9lhSetup && !mode){
@ -136,31 +134,31 @@ u32 loadFirm(void){
firmSize = console ? 0xF2000 : 0xE9000; firmSize = console ? 0xF2000 : 0xE9000;
nandFirm0((u8 *)firmLocation, firmSize, console); nandFirm0((u8 *)firmLocation, firmSize, console);
//Check for correct decryption //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 //Load FIRM from SD
else{ else{
const char *path = usePatchedFirm ? patchedFirms[selectedFirm - 1] : const char *path = usePatchedFirm ? patchedFirms[selectedFirm - 1] :
(mode ? "/aurei/firmware.bin" : "/aurei/firmware90.bin"); (mode ? "/aurei/firmware.bin" : "/aurei/firmware90.bin");
firmSize = fileSize(path); firmSize = fileSize(path);
if(!firmSize) return 0; if(!firmSize) error("firmware(90).bin doesn't exist");
fileRead((u8 *)firmLocation, path, firmSize); fileRead((u8 *)firmLocation, path, firmSize);
} }
section = firmLocation->section; section = firmLocation->section;
//Check that the loaded FIRM matches the console //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; arm9Section = (u8 *)firmLocation + section[2].offset;
if(console && !usePatchedFirm) decryptArm9Bin(arm9Section, mode); if(console && !usePatchedFirm) decryptArm9Bin(arm9Section, mode);
return 1;
} }
//NAND redirection //NAND redirection
static u32 loadEmu(u8 *proc9Offset){ static void loadEmu(u8 *proc9Offset){
u32 emuOffset = 1, u32 emuOffset = 1,
emuHeader = 1, emuHeader = 1,
@ -168,9 +166,9 @@ static u32 loadEmu(u8 *proc9Offset){
emuWrite; emuWrite;
//Read emunand code from SD //Read emunand code from SD
const char path[] = "/aurei/emunand/emunand.bin"; const char path[] = "/aurei/patches/emunand.bin";
u32 size = fileSize(path); u32 size = fileSize(path);
if(!size) return 0; if(!size) error("emunand.bin doesn't exist");
u8 *emuCodeOffset = getEmuCode(arm9Section, section[2].size, proc9Offset); u8 *emuCodeOffset = getEmuCode(arm9Section, section[2].size, proc9Offset);
fileRead(emuCodeOffset, path, size); fileRead(emuCodeOffset, path, size);
@ -178,7 +176,7 @@ static u32 loadEmu(u8 *proc9Offset){
getEmunandSect(&emuOffset, &emuHeader, emuNAND); getEmunandSect(&emuOffset, &emuHeader, emuNAND);
//No emuNAND detected //No emuNAND detected
if(!emuHeader) return 0; if(!emuHeader) error("No emuNAND has been detected");
//Place emuNAND data //Place emuNAND data
u32 *pos_offset = (u32 *)memsearch(emuCodeOffset, "NAND", size, 4); u32 *pos_offset = (u32 *)memsearch(emuCodeOffset, "NAND", size, 4);
@ -202,30 +200,27 @@ static u32 loadEmu(u8 *proc9Offset){
//Set MPU for emu code region //Set MPU for emu code region
void *mpuOffset = getMPU(arm9Section, section[2].size); void *mpuOffset = getMPU(arm9Section, section[2].size);
memcpy(mpuOffset, mpu, sizeof(mpu)); memcpy(mpuOffset, mpu, sizeof(mpu));
return 1;
} }
//Patches //Patches
u32 patchFirm(void){ void patchFirm(void){
//Skip patching //Skip patching
if(usePatchedFirm) return 1; if(usePatchedFirm) return;
if(mode || emuNAND){ if(mode || emuNAND){
//Find the Process9 NCCH location //Find the Process9 NCCH location
u8 *proc9Offset = getProc9(arm9Section, section[2].size); u8 *proc9Offset = getProc9(arm9Section, section[2].size);
//Apply emuNAND patches //Apply emuNAND patches
if(emuNAND) if(emuNAND) loadEmu(proc9Offset);
if(!loadEmu(proc9Offset)) return 0;
//Patch FIRM reboots, not on 9.0 FIRM as it breaks firmlaunchhax //Patch FIRM reboots, not on 9.0 FIRM as it breaks firmlaunchhax
if(mode){ if(mode){
//Read reboot code from SD //Read reboot code from SD
const char path[] = "/aurei/reboot/reboot.bin"; const char path[] = "/aurei/patches/reboot.bin";
u32 size = fileSize(path); u32 size = fileSize(path);
if(!size) return 0; if(!size) error("reboot.bin doesn't exist");
u8 *rebootOffset = getReboot(arm9Section, section[2].size); u8 *rebootOffset = getReboot(arm9Section, section[2].size);
fileRead(rebootOffset, path, size); fileRead(rebootOffset, path, size);
@ -261,9 +256,8 @@ u32 patchFirm(void){
//Write patched FIRM to SD if needed //Write patched FIRM to SD if needed
if(selectedFirm) if(selectedFirm)
if(!fileWrite((u8 *)firmLocation, patchedFirms[selectedFirm - 1], firmSize)) return 0; if(!fileWrite((u8 *)firmLocation, patchedFirms[selectedFirm - 1], firmSize))
error("Couldn't write the patched FIRM (no free space?)");
return 1;
} }
void launchFirm(void){ void launchFirm(void){

View File

@ -31,6 +31,6 @@ typedef struct firmHeader {
} firmHeader; } firmHeader;
void setupCFW(void); void setupCFW(void);
u32 loadFirm(void); void loadFirm(void);
u32 patchFirm(void); void patchFirm(void);
void launchFirm(void); void launchFirm(void);

View File

@ -8,16 +8,11 @@
#include "fs.h" #include "fs.h"
#include "firm.h" #include "firm.h"
#include "i2c.h"
void main(void){ void main(void){
mountSD(); mountSD();
setupCFW(); setupCFW();
if(!loadFirm()) return; loadFirm();
if(!patchFirm()) return; patchFirm();
launchFirm(); launchFirm();
}
void shutdown(void){
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1);
} }

View File

@ -52,7 +52,5 @@ _start:
bl main bl main
bl shutdown
.die: .die:
b .die b .die

View File

@ -1,10 +1,11 @@
/* /*
* config.c * utils.c
* by Aurora Wright * by Aurora Wright
* Copyright (c) 2016 All Rights Reserved * Copyright (c) 2016 All Rights Reserved
*/ */
#include "config.h" #include "utils.h"
#include "screeninit.h"
#include "draw.h" #include "draw.h"
#include "fs.h" #include "fs.h"
#include "i2c.h" #include "i2c.h"
@ -14,8 +15,8 @@
#define OPTIONS 3 #define OPTIONS 3
#define COLOR_TITLE 0xFF9900 #define COLOR_TITLE 0xFF9900
#define COLOR_NORMAL 0xFFFFFF #define COLOR_WHITE 0xFFFFFF
#define COLOR_SELECTED 0x0000FF #define COLOR_RED 0x0000FF
#define COLOR_BLACK 0x000000 #define COLOR_BLACK 0x000000
struct options { struct options {
@ -55,10 +56,11 @@ void configureCFW(const char *configPath){
options.text[1] = "( ) Use pre-patched FIRMs"; options.text[1] = "( ) Use pre-patched FIRMs";
options.text[2] = "( ) Force A9LH detection"; options.text[2] = "( ) Force A9LH detection";
if(PDN_GPU_CNT == 0x1) initScreens();
clearScreens(); clearScreens();
drawString("AuReiNand configuration", 10, 10, COLOR_TITLE); 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 //Read and parse the existing configuration
u16 tempConfig = 0; u16 tempConfig = 0;
@ -75,8 +77,8 @@ void configureCFW(const char *configPath){
do{ do{
for(u32 i = 0; i < OPTIONS; i++){ 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); 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_SELECTED : COLOR_NORMAL) : COLOR_BLACK); drawCharacter('x', 10 + SPACING_HORIZ, options.pos_y[i], options.enabled[i] ? (options.selected == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
} }
pressed = waitInput(); pressed = waitInput();
} while(!(pressed & (BUTTON_UP | BUTTON_DOWN | BUTTON_A | BUTTON_START))); } 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]); fileDelete(firmPaths[firms - 1]);
firms--; 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);
} }

View File

@ -1,5 +1,5 @@
/* /*
* config.h * utils.h
* by Aurora Wright * by Aurora Wright
* Copyright (c) 2016 All Rights Reserved * Copyright (c) 2016 All Rights Reserved
*/ */
@ -9,4 +9,5 @@
#include "types.h" #include "types.h"
void configureCFW(const char *configPath); void configureCFW(const char *configPath);
void deleteFirms(const char *firmPaths[], u32 firms); void deleteFirms(const char *firmPaths[], u32 firms);
void error(const char *message);