Compare commits

..

13 Commits
v3.4 ... v3.5.3

Author SHA1 Message Date
Aurora
b6b309140b Fixed typo 2016-02-20 23:57:59 +01:00
Aurora
af83d31e8d New button combos
No more complaints about triggering the cameras!
2016-02-20 23:25:00 +01:00
Aurora
9b58208c12 Fix booting emuNAND with a > 9.6 FIRM
Hoping this is the last derp...
2016-02-20 22:15:37 +01:00
Aurora
005855dccb Fix derps, improved readability
Thanks xorhash for noticing
2016-02-20 17:55:58 +01:00
Aurora
723dd542ee Forgot useless stuff 2016-02-20 15:32:52 +01:00
Aurora
30b3af634c Merge branch 'master' of https://github.com/AuroraWright/AuReiNand 2016-02-20 15:30:02 +01:00
Aurora
38995d3231 Re-added reboot patch on A9LH, optimizations
O3DS and N3DS now share the same emuNAND patch, shorter patching patterns, patched_firmware does not keep garbage from larger loaded FIRMs, flags can be empty files
2016-02-20 15:29:32 +01:00
AuroraWright
5167c66127 Update README.md 2016-02-19 22:48:34 +01:00
Aurora
b4d94da531 Added "updated sysNAND" mode, FIRM writes patch, propered emuNAND code location
Thanks to delebile for the patch!
2016-02-19 21:32:07 +01:00
Aurora
8872a243fc Better commenting
Everyone loves that!
2016-02-19 04:53:19 +01:00
Aurora
02bed5d37d Merge branch 'master' of https://github.com/AuroraWright/AuReiNand 2016-02-19 04:40:28 +01:00
Aurora
7c70cc2c36 Reboot patch is not needed at all with A9LH
Thanks Apache_Thunder for letting me know, no more choosing!
2016-02-19 04:39:42 +01:00
AuroraWright
9f3178afec Update README.md 2016-02-19 01:42:14 +01:00
12 changed files with 101 additions and 116 deletions

View File

@@ -33,7 +33,7 @@ objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
.PHONY: all
all: launcher a9lh emunand emunando3ds reboot reboot2 rebootntr ninjhax
all: launcher a9lh emunand emunando3ds reboot rebootntr ninjhax
.PHONY: launcher
launcher: $(dir_out)/$(name).dat
@@ -48,10 +48,7 @@ emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin
emunando3ds: $(dir_out)/rei-o3ds/emunand/emunand.bin
.PHONY: reboot
reboot: $(dir_out)/rei-o3ds/reboot/reboot1.bin
.PHONY: reboot2
reboot2: $(dir_out)/rei-o3ds/reboot/reboot2.bin
reboot: $(dir_out)/rei-o3ds/reboot/reboot1.bin $(dir_out)/rei-o3ds/reboot/reboot2.bin
.PHONY: rebootntr
rebootntr: $(dir_out)/ntr-o3ds/reboot/reboot1.bin $(dir_out)/ntr-o3ds/reboot/reboot2.bin
@@ -70,7 +67,7 @@ $(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/rei-n3ds/ $(dir_out)/re
dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)/rei-n3ds/ $(dir_out)/rei-o3ds/
@cp $(dir_build)/main.bin $(dir_out)/arm9loaderhax.bin
@cp -av $(dir_build)/main.bin $(dir_out)/arm9loaderhax.bin
$(dir_out)/3ds/$(name):
@mkdir -p "$(dir_out)/3ds/$(name)"
@@ -78,21 +75,18 @@ $(dir_out)/3ds/$(name):
@mv $(dir_out)/$(name).3dsx $@
@mv $(dir_out)/$(name).smdh $@
$(dir_out)/rei-n3ds/: $(dir_data)/firmware.bin
$(dir_out)/rei-n3ds/:
@mkdir -p "$(dir_out)/rei-n3ds"
@cp -av $(dir_data)/firmware.bin $@
$(dir_out)/rei-o3ds/: $(dir_data)/firmwareo3ds.bin
$(dir_out)/rei-o3ds/:
@mkdir -p "$(dir_out)/rei-o3ds"
@cp -av $(dir_data)/firmwareo3ds.bin $(dir_out)/rei-o3ds/firmware.bin
$(dir_out)/rei-n3ds/emunand/emunand.bin: $(dir_emu)/emuCode.s
@armips $<
@mkdir -p "$(dir_out)/rei-n3ds/emunand"
@mv emunand.bin $(dir_out)/rei-n3ds/emunand
@cp -av emunand.bin $(dir_out)/rei-n3ds/emunand
$(dir_out)/rei-o3ds/emunand/emunand.bin: $(dir_emu)/emuCodeo3ds.s
@armips $<
$(dir_out)/rei-o3ds/emunand/emunand.bin: emunand.bin
@mkdir -p "$(dir_out)/rei-o3ds/emunand"
@mv emunand.bin $(dir_out)/rei-o3ds/emunand

View File

@@ -15,9 +15,7 @@ See https://github.com/Reisyukaku/ReiNand and http://gbatemp.net/threads/reinand
The FIRMs you need are here:
Latest (10.4): http://www95.zippyshare.com/v/78942FBa/file.html
NTR-compatible (10.2 for N3DS, 9.6 for O3DS): http://www66.zippyshare.com/v/gUbSYGfE/file.html
http://www99.zippyshare.com/v/kEIiQl0x/file.html
**Credits:**

View File

@@ -1,50 +0,0 @@
.nds
sdmmc equ 0x434D4453 ;dummy
.create "emunand.bin", 0x0801A4C0
.org 0x0801A4C0
.arm
nand_sd:
; Original code that still needs to be executed.
mov r4, r0
mov r5, r1
mov r7, r2
mov r6, r3
; End.
; If we're already trying to access the SD, return.
ldr r2, [r0, #4]
ldr r1, =sdmmc
cmp r2, r1
beq nand_sd_ret
str r1, [r0, #4] ; Set object to be SD
ldr r2, [r0, #8] ; Get sector to read
cmp r2, #0 ; For GW compatibility, see if we're trying to read the ncsd header (sector 0)
ldr r3, =nand_offset
ldr r3, [r3]
add r2, r3 ; Add the offset to the NAND in the SD.
ldreq r3, =ncsd_header_offset
ldreq r3, [r3]
addeq r2, r3 ; If we're reading the ncsd header, add the offset of that sector.
str r2, [r0, #8] ; Store sector to read
nand_sd_ret:
; Restore registers.
mov r1, r5
mov r2, r7
mov r3, r6
; Return 4 bytes behind where we got called,
; due to the offset of this function being stored there.
mov r0, lr
add r0, #4
bx r0
.pool
nand_offset: .ascii "NAND" ; for rednand this should be 1
ncsd_header_offset: .ascii "NCSD" ; depends on nand manufacturer + emunand type (GW/RED)
.close

View File

@@ -23,8 +23,8 @@ void getEmunandSect(u32 *off, u32 *head){
void getSDMMC(void *pos, u32 *off, u32 size){
//Look for struct code
unsigned char pattern[] = {0x01, 0x21, 0x20, 0x18, 0x20};
*off = (u32)memsearch(pos, pattern, size, 5);
unsigned char pattern[] = {0x21, 0x20, 0x18, 0x20};
*off = (u32)memsearch(pos, pattern, size, 4) - 1;
//Get DCD values
unsigned char buf[4];
@@ -42,23 +42,15 @@ void getSDMMC(void *pos, u32 *off, u32 size){
void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){
//Look for read/write code
unsigned char pattern[] = {0x04, 0x00, 0x0D, 0x00, 0x17, 0x00, 0x1E, 0x00, 0xC8, 0x05};
unsigned char pattern[] = {0x1E, 0x00, 0xC8, 0x05};
*writeOff = (u32)memsearch(pos, pattern, size, 10);
*readOff = (u32)memsearch((void *)(*writeOff - 0x1000), pattern, 0x1000, 10);
*writeOff = (u32)memsearch(pos, pattern, size, 4) - 6;
*readOff = (u32)memsearch((void *)(*writeOff - 0x1000), pattern, 0x1000, 4) - 6;
}
void getMPU(void *pos, u32 *off, u32 size){
//Look for MPU pattern
unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00, 0x00};
unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00};
*off = (u32)memsearch(pos, pattern, size, 5);
}
void getEmuCode(void *pos, u32 *off, u32 size){
void *proc9 = memsearch(pos, "Process9", size, 8);
unsigned char pattern[] = {0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF};
//Looking for the last spot before Process9
*off = (u32)memsearch(pos, pattern, size - (size - (u32)(proc9 - pos)), 6) + 0xF;
*off = (u32)memsearch(pos, pattern, size, 4);
}

View File

@@ -15,6 +15,5 @@ void getEmunandSect(u32 *off, u32 *head);
void getSDMMC(void *pos, u32 *off, u32 size);
void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff);
void getMPU(void *pos, u32 *off, u32 size);
void getEmuCode(void *pos, u32 *off, u32 size);
#endif

View File

@@ -15,40 +15,46 @@ firmHeader *firmLocation = (firmHeader *)0x24000000;
firmSectionHeader *section;
u32 firmSize = 0;
u8 mode = 1,
console = 1;
console = 1,
a9lhSetup = 0,
updatedSys = 0;
u16 pressed;
//Load firm into FCRAM
u8 loadFirm(u8 a9lh){
u8 loadFirm(u8 a9lhBoot){
//Detect the console being used
if(PDN_MPCORE_CFG == 1) console = 0;
if(!a9lh && fileSize("/rei/installeda9lh")) a9lh = 1;
//Get pressed buttons
pressed = HID_PAD;
//Determine if A9LH is installed
if(a9lhBoot || fileExists("/rei/installeda9lh")){
a9lhSetup = 1;
//Check flag for > 9.2 SysNAND
if(fileExists("/rei/updatedsysnand")) updatedSys = 1;
}
section = firmLocation->section;
if((pressed & BUTTON_L1R1) == BUTTON_L1R1) mode = 0;
/* If L is pressed, and on an updated SysNAND setup the SAFE MODE combo
is not pressed, boot 9.0 FIRM */
if((pressed & BUTTON_L1) && !(updatedSys && pressed == SAFEMODE)) mode = 0;
//If L and R are pressed, boot SysNAND with the NAND FIRM
if(!a9lh && !mode){
//If not using an A9LH setup, do so by decrypting FIRM0
if(!a9lhSetup && !mode){
//Read FIRM from NAND and write to FCRAM
firmSize = console ? 0xF2000 : 0xE9000;
nandFirm0((u8*)firmLocation, firmSize, console);
if(memcmp((u8*)firmLocation, "FIRM", 4) != 0) return 1;
}
//Load FIRM from SDCard
//Load FIRM from SD
else{
if (a9lh && !mode){
char firmPath[] = "/rei/firmware90.bin";
firmSize = fileSize(firmPath);
if (!firmSize) return 1;
fileRead((u8*)firmLocation, firmPath, firmSize);
}
else {
char firmPath[] = "/rei/firmware.bin";
firmSize = fileSize(firmPath);
if (!firmSize) return 1;
fileRead((u8*)firmLocation, firmPath, firmSize);
}
char firmPath[] = "/rei/firmware.bin";
char firmPath2[] = "/rei/firmware90.bin";
char *pathPtr = mode ? firmPath : firmPath2;
firmSize = fileSize(pathPtr);
if (!firmSize) return 1;
fileRead((u8*)firmLocation, pathPtr, firmSize);
}
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 1;
@@ -69,10 +75,14 @@ u8 loadEmu(void){
emuCodeOffset = 0;
//Read emunand code from SD
const char path[] = "/rei/emunand/emunand.bin";
char path[] = "/rei/emunand/emunand.bin";
u32 size = fileSize(path);
if (!size) return 1;
getEmuCode(firmLocation, &emuCodeOffset, firmSize);
if(!console || !mode) nandRedir[5] = 0xA4;
//Find offset for emuNAND code from the offset in nandRedir
u8 *emuCodeTmp = &nandRedir[4];
emuCodeOffset = *(u32*)emuCodeTmp - (u32)section[2].address +
section[2].offset + (u32)firmLocation;
fileRead((u8*)emuCodeOffset, path, size);
//Find and patch emunand related offsets
@@ -86,9 +96,13 @@ u8 loadEmu(void){
*pos_sdmmc = sdmmcOffset;
*pos_offset = emuOffset;
*pos_header = emuHeader;
//Patch emuNAND code in memory for O3DS and 9.0 N3DS
if(!console || !mode){
u32 *pos_instr = memsearch((u32*)emuCodeOffset, "\xA6\x01\x08\x30", size, 4);
memcpy((u8*)pos_instr, emuInstr, sizeof(emuInstr));
}
//Add emunand hooks
if(!console) nandRedir[5] = 0xA4;
memcpy((u8*)emuRead, nandRedir, sizeof(nandRedir));
memcpy((u8*)emuWrite, nandRedir, sizeof(nandRedir));
@@ -101,8 +115,18 @@ u8 loadEmu(void){
//Patches
u8 patchFirm(void){
//If L is pressed, boot SysNAND with the SDCard FIRM
if(mode && !(pressed & BUTTON_L1)) if (loadEmu()) return 1;
/* If L or R aren't pressed on a 9.0/9.2 SysNAND, or the 9.0 FIRM is selected
or R is pressed on a > 9.2 SysNAND, boot emuNAND */
if((updatedSys && (!mode || ((pressed & BUTTON_R1) && pressed != SAFEMODE))) ||
(!updatedSys && mode && !(pressed & (BUTTON_L1 | BUTTON_R1)))){
if (loadEmu()) return 1;
}
else if(a9lhSetup){
//Patch FIRM partitions writes on SysNAND to protect A9LH
u32 writeOffset = 0;
getFIRMWrite(firmLocation, firmSize, &writeOffset);
memcpy((u8*)writeOffset, FIRMblock, sizeof(FIRMblock));
}
u32 sigOffset = 0,
sigOffset2 = 0;
@@ -112,8 +136,9 @@ u8 patchFirm(void){
memcpy((u8*)sigOffset, sigPat1, sizeof(sigPat1));
memcpy((u8*)sigOffset2, sigPat2, sizeof(sigPat2));
if(!console && mode &&
((fileSize("/rei/reversereboot") > 0) == (pressed & BUTTON_A))){
//Apply FIRM reboot patch. Not needed on N3DS
if(!console && mode && pressed != SAFEMODE &&
fileExists("/rei/reversereboot") == (pressed & BUTTON_A)){
u32 rebootOffset = 0,
rebootOffset2 = 0;
@@ -130,7 +155,7 @@ u8 patchFirm(void){
if (!size) return 1;
fileRead((u8*)rebootOffset2, path, size);
//Write patched FIRM to SDCard
//Write patched FIRM to SD
if (fileWrite((u8*)firmLocation, PATCHED_FIRM_PATH, firmSize) != 0) return 1;
}

View File

@@ -10,12 +10,13 @@
#define PDN_MPCORE_CFG (*(u8*)0x10140FFC)
#define HID_PAD ((~*(u16*)0x10146000) & 0xFFF)
#define BUTTON_L1R1 (3 << 8)
#define BUTTON_R1 (1 << 8)
#define BUTTON_L1 (1 << 9)
#define BUTTON_A 1
#define SAFEMODE (BUTTON_L1 | BUTTON_R1 | BUTTON_A | (1 << 6))
#define PATCHED_FIRM_PATH "/rei/patched_firmware.bin"
u8 loadFirm(u8 a9lh);
u8 loadFirm(u8 a9lhBoot);
u8 loadEmu(void);
u8 patchFirm(void);
void launchFirm(void);

View File

@@ -63,6 +63,7 @@ int fileWrite(const u8 *buffer, const char *path, u32 size){
FIL fp;
unsigned int br = 0;
f_unlink(path);
if(f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS) == FR_OK){
fr = f_write(&fp, buffer, size, &br);
f_close(&fp);
@@ -83,4 +84,14 @@ int fileSize(const char* path){
error:
f_close(&fp);
return size;
}
int fileExists(const char* path){
FRESULT fr;
FIL fp;
int exists = 1;
fr = f_open(&fp, path, FA_READ);
if (fr != FR_OK)exists = 0;
f_close(&fp);
return exists;
}

View File

@@ -13,5 +13,6 @@ int fileReadOffset(u8 *dest, const char *path, u32 size, u32 offset);
int fileRead(u8 *dest, const char *path, u32 size);
int fileWrite(const u8 *buffer, const char *path, u32 size);
int fileSize(const char* path);
int fileExists(const char* path);
#endif

View File

@@ -10,13 +10,14 @@
#include "firm.h"
#include "draw.h"
u8 a9lh = 0;
u8 a9lhBoot = 0;
u8 main(){
mountSD();
if (!*((u32*)0x10141204)) a9lh = 1;
//Detect an A9LH boot checking PDN_GPU_CNT register
if (*((u8*)0x10141200) == 0x1) a9lhBoot = 1;
else loadSplash();
if (loadFirm(a9lh)) return 1;
if (loadFirm(a9lhBoot)) return 1;
if (patchFirm()) return 1;
launchFirm();
return 0;

View File

@@ -27,6 +27,8 @@ u8 nandRedir[0x08] = {0x00, 0x4C, 0xA0, 0x47, 0xC0, 0xA5, 0x01, 0x08}; //Bran
*/
u8 sigPat1[2] = {0x00, 0x20};
u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47};
u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46};
u8 emuInstr[5] = {0xA5, 0x01, 0x08, 0x30, 0xA5};
/**************************************************
* Functions
@@ -35,10 +37,10 @@ u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47};
void getSignatures(void *pos, u32 size, u32 *off, u32 *off2){
//Look for signature checks
unsigned char pattern[] = {0xC0, 0x1C, 0x76, 0xE7};
unsigned char pattern2[] = {0x70, 0xB5, 0x22, 0x4D, 0x0C};
unsigned char pattern2[] = {0xB5, 0x22, 0x4D, 0x0C};
*off = (u32)memsearch(pos, pattern, size, 4);
*off2 = (u32)memsearch(pos, pattern2, size, 5);
*off2 = (u32)memsearch(pos, pattern2, size, 4) - 1;
}
void getReboot(void *pos, u32 size, u32 *off, u32 *off2){
@@ -48,4 +50,12 @@ void getReboot(void *pos, u32 size, u32 *off, u32 *off2){
*off = (u32)memsearch(pos, pattern, size, 5) + 2;
*off2 = (u32)memsearch(pos, pattern2, size, 5);
}
void getFIRMWrite(void *pos, u32 size, u32 *off){
//Look for FIRM writing code
void *firmwrite = memsearch(pos, "exe:", size, 4);
unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA};
*off = (u32)memsearch(firmwrite - 0x100, pattern, 0x100, 4);
}

View File

@@ -15,11 +15,14 @@ u8 mpu[0x2C];
u8 nandRedir[0x08];
u8 sigPat1[2];
u8 sigPat2[4];
u8 FIRMblock[4];
u8 emuInstr[5];
/**************************************************
* Functions
**************************************************/
void getSignatures(void *pos, u32 size, u32 *off, u32 *off2);
void getReboot(void *pos, u32 size, u32 *off, u32 *off2);
void getFIRMWrite(void *pos, u32 size, u32 *off);
#endif