Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
005855dccb | ||
|
|
723dd542ee | ||
|
|
30b3af634c | ||
|
|
38995d3231 | ||
|
|
5167c66127 |
18
Makefile
18
Makefile
@@ -42,7 +42,7 @@ launcher: $(dir_out)/$(name).dat
|
|||||||
a9lh: $(dir_out)/arm9loaderhax.bin
|
a9lh: $(dir_out)/arm9loaderhax.bin
|
||||||
|
|
||||||
.PHONY: emunand
|
.PHONY: emunand
|
||||||
emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin $(dir_out)/rei-n3ds/emunand/emunand90.bin
|
emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin
|
||||||
|
|
||||||
.PHONY: emunando3ds
|
.PHONY: emunando3ds
|
||||||
emunando3ds: $(dir_out)/rei-o3ds/emunand/emunand.bin
|
emunando3ds: $(dir_out)/rei-o3ds/emunand/emunand.bin
|
||||||
@@ -75,26 +75,20 @@ $(dir_out)/3ds/$(name):
|
|||||||
@mv $(dir_out)/$(name).3dsx $@
|
@mv $(dir_out)/$(name).3dsx $@
|
||||||
@mv $(dir_out)/$(name).smdh $@
|
@mv $(dir_out)/$(name).smdh $@
|
||||||
|
|
||||||
$(dir_out)/rei-n3ds/: $(dir_data)/firmware.bin
|
$(dir_out)/rei-n3ds/:
|
||||||
@mkdir -p "$(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"
|
@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
|
$(dir_out)/rei-n3ds/emunand/emunand.bin: $(dir_emu)/emuCode.s
|
||||||
@armips $<
|
@armips $<
|
||||||
@mkdir -p "$(dir_out)/rei-n3ds/emunand"
|
@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
|
$(dir_out)/rei-o3ds/emunand/emunand.bin: emunand.bin
|
||||||
@armips $<
|
|
||||||
@mkdir -p "$(dir_out)/rei-o3ds/emunand"
|
@mkdir -p "$(dir_out)/rei-o3ds/emunand"
|
||||||
@cp -av emunand.bin $(dir_out)/rei-o3ds/emunand
|
@mv emunand.bin $(dir_out)/rei-o3ds/emunand
|
||||||
|
|
||||||
$(dir_out)/rei-n3ds/emunand/emunand90.bin: $(dir_out)/rei-o3ds/emunand/emunand.bin
|
|
||||||
@mv emunand.bin $(dir_out)/rei-n3ds/emunand/emunand90.bin
|
|
||||||
|
|
||||||
$(dir_out)/rei-o3ds/reboot/reboot1.bin: $(dir_reboot)/rebootCode.s
|
$(dir_out)/rei-o3ds/reboot/reboot1.bin: $(dir_reboot)/rebootCode.s
|
||||||
@armips $<
|
@armips $<
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ See https://github.com/Reisyukaku/ReiNand and http://gbatemp.net/threads/reinand
|
|||||||
|
|
||||||
The FIRMs you need are here:
|
The FIRMs you need are here:
|
||||||
|
|
||||||
http://www12.zippyshare.com/v/JNkWUhDd/file.html
|
http://www99.zippyshare.com/v/kEIiQl0x/file.html
|
||||||
|
|
||||||
**Credits:**
|
**Credits:**
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -23,8 +23,8 @@ void getEmunandSect(u32 *off, u32 *head){
|
|||||||
|
|
||||||
void getSDMMC(void *pos, u32 *off, u32 size){
|
void getSDMMC(void *pos, u32 *off, u32 size){
|
||||||
//Look for struct code
|
//Look for struct code
|
||||||
unsigned char pattern[] = {0x01, 0x21, 0x20, 0x18, 0x20};
|
unsigned char pattern[] = {0x21, 0x20, 0x18, 0x20};
|
||||||
*off = (u32)memsearch(pos, pattern, size, 5);
|
*off = (u32)memsearch(pos, pattern, size, 4) - 1;
|
||||||
|
|
||||||
//Get DCD values
|
//Get DCD values
|
||||||
unsigned char buf[4];
|
unsigned char buf[4];
|
||||||
@@ -42,15 +42,15 @@ void getSDMMC(void *pos, u32 *off, u32 size){
|
|||||||
|
|
||||||
void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){
|
void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){
|
||||||
//Look for read/write code
|
//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);
|
*writeOff = (u32)memsearch(pos, pattern, size, 4) - 6;
|
||||||
*readOff = (u32)memsearch((void *)(*writeOff - 0x1000), pattern, 0x1000, 10);
|
*readOff = (u32)memsearch((void *)(*writeOff - 0x1000), pattern, 0x1000, 4) - 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMPU(void *pos, u32 *off, u32 size){
|
void getMPU(void *pos, u32 *off, u32 size){
|
||||||
//Look for MPU pattern
|
//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);
|
*off = (u32)memsearch(pos, pattern, size, 4);
|
||||||
}
|
}
|
||||||
@@ -28,18 +28,18 @@ u8 loadFirm(u8 a9lhBoot){
|
|||||||
//Get pressed buttons
|
//Get pressed buttons
|
||||||
pressed = HID_PAD;
|
pressed = HID_PAD;
|
||||||
//Determine if A9LH is installed
|
//Determine if A9LH is installed
|
||||||
if(a9lhBoot || fileSize("/rei/installeda9lh")){
|
if(a9lhBoot || fileExists("/rei/installeda9lh")){
|
||||||
a9lhSetup = 1;
|
a9lhSetup = 1;
|
||||||
//Check flag for > 9.2 SysNAND
|
//Check flag for > 9.2 SysNAND
|
||||||
if(fileSize("/rei/updatedsysnand")) updatedSys = 1;
|
if(fileExists("/rei/updatedsysnand")) updatedSys = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
section = firmLocation->section;
|
section = firmLocation->section;
|
||||||
|
|
||||||
/* If L and R are pressed on a 9.0/2 SysNAND, or L on an updated
|
/* If L and R are pressed on a 9.0/2 SysNAND, or L on an updated
|
||||||
SysNAND, boot 9.0 FIRM */
|
SysNAND, boot 9.0 FIRM */
|
||||||
if((!updatedSys & ((pressed & BUTTON_L1R1) == BUTTON_L1R1)) |
|
if((!updatedSys && (pressed & BUTTON_L1R1) == BUTTON_L1R1) ||
|
||||||
(updatedSys & (pressed == BUTTON_L1))) mode = 0;
|
(updatedSys && (pressed & BUTTON_L1))) mode = 0;
|
||||||
|
|
||||||
//If not using an A9LH setup, do so by decrypting FIRM0
|
//If not using an A9LH setup, do so by decrypting FIRM0
|
||||||
if(!a9lhSetup && !mode){
|
if(!a9lhSetup && !mode){
|
||||||
@@ -77,15 +77,14 @@ u8 loadEmu(void){
|
|||||||
|
|
||||||
//Read emunand code from SD
|
//Read emunand code from SD
|
||||||
char path[] = "/rei/emunand/emunand.bin";
|
char path[] = "/rei/emunand/emunand.bin";
|
||||||
char path2[] = "/rei/emunand/emunand90.bin";
|
u32 size = fileSize(path);
|
||||||
char *pathPtr = ((!mode) & console) ? path2 : path;
|
|
||||||
u32 size = fileSize(pathPtr);
|
|
||||||
if (!size) return 1;
|
if (!size) return 1;
|
||||||
if(!console | !mode) nandRedir[5] = 0xA4;
|
if(!console || !mode) nandRedir[5] = 0xA4;
|
||||||
|
//Find offset for emuNAND code from the offset in nandRedir
|
||||||
u8 *emuCodeTmp = &nandRedir[4];
|
u8 *emuCodeTmp = &nandRedir[4];
|
||||||
emuCodeOffset = *(u32*)emuCodeTmp - (u32)section[2].address +
|
emuCodeOffset = *(u32*)emuCodeTmp - (u32)section[2].address +
|
||||||
section[2].offset + (u32)firmLocation;
|
section[2].offset + (u32)firmLocation;
|
||||||
fileRead((u8*)emuCodeOffset, pathPtr, size);
|
fileRead((u8*)emuCodeOffset, path, size);
|
||||||
|
|
||||||
//Find and patch emunand related offsets
|
//Find and patch emunand related offsets
|
||||||
u32 *pos_sdmmc = memsearch((u32*)emuCodeOffset, "SDMC", size, 4);
|
u32 *pos_sdmmc = memsearch((u32*)emuCodeOffset, "SDMC", size, 4);
|
||||||
@@ -98,6 +97,11 @@ u8 loadEmu(void){
|
|||||||
*pos_sdmmc = sdmmcOffset;
|
*pos_sdmmc = sdmmcOffset;
|
||||||
*pos_offset = emuOffset;
|
*pos_offset = emuOffset;
|
||||||
*pos_header = emuHeader;
|
*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
|
//Add emunand hooks
|
||||||
memcpy((u8*)emuRead, nandRedir, sizeof(nandRedir));
|
memcpy((u8*)emuRead, nandRedir, sizeof(nandRedir));
|
||||||
@@ -114,11 +118,11 @@ u8 patchFirm(void){
|
|||||||
|
|
||||||
/* If L is pressed on a 9.0/9.2 SysNAND, or L+R on a > 9.2 SysNAND,
|
/* If L is pressed on a 9.0/9.2 SysNAND, or L+R on a > 9.2 SysNAND,
|
||||||
or the 9.0 FIRM is loaded on a > 9.2 SysNAND, boot emuNAND */
|
or the 9.0 FIRM is loaded on a > 9.2 SysNAND, boot emuNAND */
|
||||||
if((updatedSys & (!mode | (pressed == BUTTON_L1R1))) |
|
if((updatedSys && (!mode || ((pressed & BUTTON_L1R1) == BUTTON_L1R1 &&
|
||||||
((!updatedSys) & mode & !(pressed & BUTTON_L1))){
|
pressed != SAFEMODE))) || (!updatedSys && mode && !(pressed & BUTTON_L1))){
|
||||||
if (loadEmu()) return 1;
|
if (loadEmu()) return 1;
|
||||||
}
|
}
|
||||||
else if (a9lhSetup){
|
else if(a9lhSetup){
|
||||||
//Patch FIRM partitions writes on SysNAND to protect A9LH
|
//Patch FIRM partitions writes on SysNAND to protect A9LH
|
||||||
u32 writeOffset = 0;
|
u32 writeOffset = 0;
|
||||||
getFIRMWrite(firmLocation, firmSize, &writeOffset);
|
getFIRMWrite(firmLocation, firmSize, &writeOffset);
|
||||||
@@ -133,9 +137,9 @@ u8 patchFirm(void){
|
|||||||
memcpy((u8*)sigOffset, sigPat1, sizeof(sigPat1));
|
memcpy((u8*)sigOffset, sigPat1, sizeof(sigPat1));
|
||||||
memcpy((u8*)sigOffset2, sigPat2, sizeof(sigPat2));
|
memcpy((u8*)sigOffset2, sigPat2, sizeof(sigPat2));
|
||||||
|
|
||||||
//Apply FIRM reboot patch. Not needed with A9LH and N3DS
|
//Apply FIRM reboot patch. Not needed on N3DS
|
||||||
if(!console && !a9lhSetup && mode &&
|
if(!console && mode && pressed != SAFEMODE &&
|
||||||
((fileSize("/rei/reversereboot") > 0) == (pressed & BUTTON_A))){
|
fileExists("/rei/reversereboot") == (pressed & BUTTON_A)){
|
||||||
u32 rebootOffset = 0,
|
u32 rebootOffset = 0,
|
||||||
rebootOffset2 = 0;
|
rebootOffset2 = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#define BUTTON_L1R1 (3 << 8)
|
#define BUTTON_L1R1 (3 << 8)
|
||||||
#define BUTTON_L1 (1 << 9)
|
#define BUTTON_L1 (1 << 9)
|
||||||
#define BUTTON_A 1
|
#define BUTTON_A 1
|
||||||
|
#define SAFEMODE (BUTTON_L1R1 | BUTTON_A | (1 << 6))
|
||||||
#define PATCHED_FIRM_PATH "/rei/patched_firmware.bin"
|
#define PATCHED_FIRM_PATH "/rei/patched_firmware.bin"
|
||||||
|
|
||||||
u8 loadFirm(u8 a9lh);
|
u8 loadFirm(u8 a9lh);
|
||||||
|
|||||||
11
source/fs.c
11
source/fs.c
@@ -63,6 +63,7 @@ int fileWrite(const u8 *buffer, const char *path, u32 size){
|
|||||||
FIL fp;
|
FIL fp;
|
||||||
unsigned int br = 0;
|
unsigned int br = 0;
|
||||||
|
|
||||||
|
f_unlink(path);
|
||||||
if(f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS) == FR_OK){
|
if(f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS) == FR_OK){
|
||||||
fr = f_write(&fp, buffer, size, &br);
|
fr = f_write(&fp, buffer, size, &br);
|
||||||
f_close(&fp);
|
f_close(&fp);
|
||||||
@@ -83,4 +84,14 @@ int fileSize(const char* path){
|
|||||||
error:
|
error:
|
||||||
f_close(&fp);
|
f_close(&fp);
|
||||||
return size;
|
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;
|
||||||
}
|
}
|
||||||
@@ -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 fileRead(u8 *dest, const char *path, u32 size);
|
||||||
int fileWrite(const u8 *buffer, const char *path, u32 size);
|
int fileWrite(const u8 *buffer, const char *path, u32 size);
|
||||||
int fileSize(const char* path);
|
int fileSize(const char* path);
|
||||||
|
int fileExists(const char* path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ u8 nandRedir[0x08] = {0x00, 0x4C, 0xA0, 0x47, 0xC0, 0xA5, 0x01, 0x08}; //Bran
|
|||||||
u8 sigPat1[2] = {0x00, 0x20};
|
u8 sigPat1[2] = {0x00, 0x20};
|
||||||
u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47};
|
u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47};
|
||||||
u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46};
|
u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46};
|
||||||
|
u8 emuInstr[5] = {0xA5, 0x01, 0x08, 0x30, 0xA5};
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
* Functions
|
* Functions
|
||||||
@@ -36,10 +37,10 @@ u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46};
|
|||||||
void getSignatures(void *pos, u32 size, u32 *off, u32 *off2){
|
void getSignatures(void *pos, u32 size, u32 *off, u32 *off2){
|
||||||
//Look for signature checks
|
//Look for signature checks
|
||||||
unsigned char pattern[] = {0xC0, 0x1C, 0x76, 0xE7};
|
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);
|
*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){
|
void getReboot(void *pos, u32 size, u32 *off, u32 *off2){
|
||||||
@@ -53,7 +54,7 @@ void getReboot(void *pos, u32 size, u32 *off, u32 *off2){
|
|||||||
|
|
||||||
void getFIRMWrite(void *pos, u32 size, u32 *off){
|
void getFIRMWrite(void *pos, u32 size, u32 *off){
|
||||||
//Look for FIRM writing code
|
//Look for FIRM writing code
|
||||||
void *firmwrite = memsearch(pos, "exe:/", size, 5);
|
void *firmwrite = memsearch(pos, "exe:", size, 4);
|
||||||
unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA};
|
unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA};
|
||||||
|
|
||||||
*off = (u32)memsearch(firmwrite - 0x100, pattern, 0x100, 4);
|
*off = (u32)memsearch(firmwrite - 0x100, pattern, 0x100, 4);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ u8 nandRedir[0x08];
|
|||||||
u8 sigPat1[2];
|
u8 sigPat1[2];
|
||||||
u8 sigPat2[4];
|
u8 sigPat2[4];
|
||||||
u8 FIRMblock[4];
|
u8 FIRMblock[4];
|
||||||
|
u8 emuInstr[5];
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
* Functions
|
* Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user