Compare commits

...

9 Commits
v3.3 ... v3.5

Author SHA1 Message Date
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
Aurora
6c25ed4607 Arm9LoaderHax support, cleaned Makefile 2016-02-19 01:29:53 +01:00
Aurora
e34ca44715 Reduced pattern size, fixed N3DS NAND0 FIRM size
It's actually a little smaller
2016-02-11 00:45:24 +01:00
Aurora
899a6853a9 Add data folder to gitignore 2016-02-09 00:15:56 +01:00
Aurora
1131589c19 Minor code style/comment changes
To match official build
2016-02-08 23:46:01 +01:00
13 changed files with 153 additions and 176 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@ out
CakeHax
CakeBrah
build
data
*.bin
*.3dsx
*.smdh

View File

@@ -24,7 +24,7 @@ dir_reboot := reboot
dir_ninjhax := CakeBrah
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) --no-print-directory
objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
@@ -33,28 +33,25 @@ objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
.PHONY: all
all: launcher emunand emunando3ds reboot reboot2 rebootntr reboot2ntr ninjhax
all: launcher a9lh emunand emunando3ds reboot rebootntr ninjhax
.PHONY: launcher
launcher: $(dir_out)/$(name).dat
.PHONY: a9lh
a9lh: $(dir_out)/arm9loaderhax.bin
.PHONY: emunand
emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin
emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin $(dir_out)/rei-n3ds/emunand/emunand90.bin
.PHONY: emunando3ds
emunand: $(dir_out)/rei-o3ds/emunand/emunand.bin
emunando3ds: $(dir_out)/rei-o3ds/emunand/emunand.bin
.PHONY: reboot
reboot: $(dir_out)/rei-o3ds/reboot/reboot1.bin
.PHONY: reboot2
reboot: $(dir_out)/rei-o3ds/reboot/reboot2.bin
reboot: $(dir_out)/rei-o3ds/reboot/reboot1.bin $(dir_out)/rei-o3ds/reboot/reboot2.bin
.PHONY: rebootntr
reboot: $(dir_out)/ntr-o3ds/reboot/reboot1.bin
.PHONY: reboot2ntr
reboot: $(dir_out)/ntr-o3ds/reboot/reboot2.bin
rebootntr: $(dir_out)/ntr-o3ds/reboot/reboot1.bin $(dir_out)/ntr-o3ds/reboot/reboot2.bin
.PHONY: ninjhax
ninjhax: $(dir_out)/3ds/$(name)
@@ -65,11 +62,13 @@ clean:
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) clean
rm -rf $(dir_out) $(dir_build)
.PHONY: $(dir_out)/$(name).dat
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/rei-n3ds/ $(dir_out)/rei-o3ds/
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
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 -av $(dir_build)/main.bin $(dir_out)/arm9loaderhax.bin
$(dir_out)/3ds/$(name):
@mkdir -p "$(dir_out)/3ds/$(name)"
@$(MAKE) $(FLAGS) -C $(dir_ninjhax)
@@ -92,22 +91,25 @@ $(dir_out)/rei-n3ds/emunand/emunand.bin: $(dir_emu)/emuCode.s
$(dir_out)/rei-o3ds/emunand/emunand.bin: $(dir_emu)/emuCodeo3ds.s
@armips $<
@mkdir -p "$(dir_out)/rei-o3ds/emunand"
@mv emunand.bin $(dir_out)/rei-o3ds/emunand
@cp -av 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
@armips $<
@mkdir -p "$(dir_out)/rei-o3ds/reboot"
@mv reboot1.bin $(dir_out)/rei-o3ds/reboot
$(dir_out)/rei-o3ds/reboot/reboot2.bin: $(dir_reboot)/rebootCode.s
@mv reboot2.bin $(dir_out)/rei-o3ds/reboot
$(dir_out)/rei-o3ds/reboot/reboot2.bin: reboot2.bin
@cp -av reboot2.bin $(dir_out)/rei-o3ds/reboot
$(dir_out)/ntr-o3ds/reboot/reboot1.bin: $(dir_reboot)/rebootCodeNtr.s
@armips $<
@mkdir -p "$(dir_out)/ntr-o3ds/reboot"
@mv reboot1.bin $(dir_out)/ntr-o3ds/reboot
$(dir_out)/ntr-o3ds/reboot/reboot2.bin: $(dir_reboot)/rebootCodeNtr.s
$(dir_out)/ntr-o3ds/reboot/reboot2.bin: reboot2.bin
@mv reboot2.bin $(dir_out)/ntr-o3ds/reboot
$(dir_build)/main.bin: $(dir_build)/main.elf

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://www12.zippyshare.com/v/JNkWUhDd/file.html
**Credits:**

View File

@@ -57,103 +57,3 @@ patch005:
.pool
firm_fname:
.close
.create "reboot2.bin", 0x08094454
.org 0x08094454
.arm
stmfd sp!, {r4-r11,lr}
sub sp, sp, #0x3C
mrc p15, 0, r0, c2, c0, 0 ; dcacheable
mrc p15, 0, r12, c2, c0, 1 ; icacheable
mrc p15, 0, r1, c3, c0, 0 ; write bufferable
mrc p15, 0, r2, c5, c0, 2 ; daccess
mrc p15, 0, r3, c5, c0, 3 ; iaccess
ldr r4, =0x18000035 ; 0x18000000 128M
bic r2, r2, #0xF0000 ; unprotect region 4
bic r3, r3, #0xF0000 ; unprotect region 4
orr r0, r0, #0x10 ; dcacheable region 4
orr r2, r2, #0x30000 ; region 4 r/w
orr r3, r3, #0x30000 ; region 4 r/w
orr r12, r12, #0x10 ; icacheable region 4
orr r1, r1, #0x10 ; write bufferable region 4
mcr p15, 0, r0, c2, c0, 0
mcr p15, 0, r12, c2, c0, 1
mcr p15, 0, r1, c3, c0, 0 ; write bufferable
mcr p15, 0, r2, c5, c0, 2 ; daccess
mcr p15, 0, r3, c5, c0, 3 ; iaccess
mcr p15, 0, r4, c6, c4, 0 ; region 4 (hmmm)
mrc p15, 0, r0, c2, c0, 0 ; dcacheable
mrc p15, 0, r1, c2, c0, 1 ; icacheable
mrc p15, 0, r2, c3, c0, 0 ; write bufferable
orr r0, r0, #0x20 ; dcacheable region 5
orr r1, r1, #0x20 ; icacheable region 5
orr r2, r2, #0x20 ; write bufferable region 5
mcr p15, 0, r0, c2, c0, 0 ; dcacheable
mcr p15, 0, r1, c2, c0, 1 ; icacheable
mcr p15, 0, r2, c3, c0, 0 ; write bufferable
mov r4, #firm_addr
add r3, r4, #0x40
ldr r0, [r3] ; offset
add r0, r0, r4 ; src
ldr r1, [r3,#4] ; dst
ldr r2, [r3,#8] ; size
bl memcpy32
add r3, r4, #0x70
ldr r0, [r3]
add r0, r0, r4 ; src
ldr r1, [r3,#4] ; dst
ldr r2, [r3,#8] ; size
bl memcpy32
add r3, r4, #0xA0
ldr r0, [r3]
add r0, r0, r4 ; src
ldr r1, [r3,#4] ; dst
ldr r2, [r3,#8] ; size
bl memcpy32
mov r2, #0
mov r1, r2
@flush_cache:
mov r0, #0
mov r3, r2, lsl#30
@flush_cache_inner_loop:
orr r12, r3, r0, lsl#5
mcr p15, 0, r1, c7, c10, 4 ; drain write buffer
mcr p15, 0, r12, c7, c14, 2 ; clean and flush dcache entry (index and segment)
add r0, r0, #1
cmp r0, #0x20
bcc @flush_cache_inner_loop
add r2, r2, #1
cmp r2, #4
bcc @flush_cache
mcr p15, 0, r1, c7, c10, 4 ; drain write buffer
@mpu_enable:
ldr r0, =0x42078 ; alt vector select, enable itcm
mcr p15, 0, r0, c1, c0, 0
mcr p15, 0, r1, c7, c5, 0 ; flush dcache
mcr p15, 0, r1, c7, c6, 0 ; flush icache
mcr p15, 0, r1, c7, c10, 4 ; drain write buffer
mov r0, #firm_addr
mov r1, 0X1FFFFFFC
ldr r2, [r0,#8] ; arm11 entry
str r2, [r1]
ldr r0, [r0,#0xC] ; arm9 entry
add sp, sp, #0x3C
ldmfd sp!, {r4-r11,lr}
bx r0
.pool
memcpy32: ; memcpy32(void *src, void *dst, unsigned int size)
mov r12, lr
stmfd sp!, {r0-r4}
add r2, r2, r0
@memcpy_loop:
ldr r3, [r0], #4
str r3, [r1], #4
cmp r0, r2
blt @memcpy_loop
ldmfd sp!, {r0-r4}
mov lr, r12
bx lr
.pool
.close

View File

@@ -23,14 +23,14 @@ 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, 0x30};
*off = (u32)memsearch(pos, pattern, size, 6);
unsigned char pattern[] = {0x01, 0x21, 0x20, 0x18, 0x20};
*off = (u32)memsearch(pos, pattern, size, 5);
//Get DCD values
unsigned char buf[4];
int p;
u32 addr = 0;
u32 additive = 0;
u32 addr = 0,
additive = 0;
memcpy((void*)buf, (void*)(*off+0x0A), 4);
for (p = 0; p < 4; p++) addr |= ((u32) buf[p]) << (8 * p);
memcpy((void*)buf, (void*)(*off+0x0E), 4);
@@ -49,16 +49,8 @@ void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){
}
void getMPU(void *pos, u32 *off, u32 size){
//Look for MPU code
unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00, 0x00, 0x00, 0x10};
//Look for MPU pattern
unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00, 0x00};
*off = (u32)memsearch(pos, pattern, size, 7);
}
void getEmuCode(void *pos, u32 *off, u32 size){
void *proc9 = memsearch(pos, "Process9", size, 8);
unsigned char pattern[] = {0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF};
//We're 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, 5);
}

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,32 +15,49 @@ 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(void){
u8 loadFirm(u8 a9lhBoot){
//Detect the console being used
if(PDN_MPCORE_CFG == 1) console = 0;
//Get pressed buttons
pressed = HID_PAD;
//Determine if A9LH is installed
if(a9lhBoot || fileSize("/rei/installeda9lh")){
a9lhSetup = 1;
//Check flag for > 9.2 SysNAND
if(fileSize("/rei/updatedsysnand")) updatedSys = 1;
}
section = firmLocation->section;
//If L and R are pressed, boot SysNAND with the NAND FIRM
if((pressed & BUTTON_L1R1) == BUTTON_L1R1){
mode = 0;
/* If L and R are pressed on a 9.0/2 SysNAND, or L on an updated
SysNAND, boot 9.0 FIRM */
if((!updatedSys & ((pressed & BUTTON_L1R1) == BUTTON_L1R1)) |
(updatedSys & (pressed == BUTTON_L1))) mode = 0;
//If not using an A9LH setup, do so by decrypting FIRM0
if(!a9lhSetup && !mode){
//Read FIRM from NAND and write to FCRAM
firmSize = console ? 0xF2C00 : 0xE9000;
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{
const char firmPath[] = "/rei/firmware.bin";
firmSize = fileSize(firmPath);
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, firmPath, firmSize);
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 1;
fileRead((u8*)firmLocation, pathPtr, firmSize);
}
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 1;
if(console) arm9loader((u8*)firmLocation + section[2].offset, mode);
@@ -51,19 +68,24 @@ u8 loadFirm(void){
u8 loadEmu(void){
u32 emuOffset = 0,
emuHeader = 0,
emuRead = 0,
emuWrite = 0,
sdmmcOffset = 0,
mpuOffset = 0,
emuCodeOffset = 0;
emuHeader = 0,
emuRead = 0,
emuWrite = 0,
sdmmcOffset = 0,
mpuOffset = 0,
emuCodeOffset = 0;
//Read emunand code from SD
getEmuCode(firmLocation, &emuCodeOffset, firmSize);
const char path[] = "/rei/emunand/emunand.bin";
u32 size = fileSize(path);
char path[] = "/rei/emunand/emunand.bin";
char path2[] = "/rei/emunand/emunand90.bin";
char *pathPtr = ((!mode) & console) ? path2 : path;
u32 size = fileSize(pathPtr);
if (!size) return 1;
fileRead((u8*)emuCodeOffset, path, size);
if(!console | !mode) nandRedir[5] = 0xA4;
u8 *emuCodeTmp = &nandRedir[4];
emuCodeOffset = *(u32*)emuCodeTmp - (u32)section[2].address +
section[2].offset + (u32)firmLocation;
fileRead((u8*)emuCodeOffset, pathPtr, size);
//Find and patch emunand related offsets
u32 *pos_sdmmc = memsearch((u32*)emuCodeOffset, "SDMC", size, 4);
@@ -78,7 +100,6 @@ u8 loadEmu(void){
*pos_header = emuHeader;
//Add emunand hooks
if(!console) nandRedir[5] = 0xA4;
memcpy((u8*)emuRead, nandRedir, sizeof(nandRedir));
memcpy((u8*)emuWrite, nandRedir, sizeof(nandRedir));
@@ -91,25 +112,38 @@ 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 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 */
if((updatedSys & (!mode | (pressed == BUTTON_L1R1))) |
((!updatedSys) & mode & !(pressed & BUTTON_L1))){
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;
//Disable signature checks
u32 sigOffset = 0,
sigOffset2 = 0;
getSignatures(firmLocation, firmSize, &sigOffset, &sigOffset2);
memcpy((u8*)sigOffset, sigPat1, sizeof(sigPat1));
memcpy((u8*)sigOffset2, sigPat2, sizeof(sigPat2));
//Apply reboot patch and write patched FIRM
if(!console && mode &&
//Apply FIRM reboot patch. Not needed with A9LH and N3DS
if(!console && !a9lhSetup && mode &&
((fileSize("/rei/reversereboot") > 0) == (pressed & BUTTON_A))){
u32 rebootOffset = 0,
rebootOffset2 = 0;
getReboot(firmLocation, firmSize, &rebootOffset, &rebootOffset2);
rebootOffset2 = 0;
//Read reboot code from SD and write patched FIRM path in memory
char path[] = "/rei/reboot/reboot1.bin";
u32 size = fileSize(path);
if (!size) return 1;
getReboot(firmLocation, firmSize, &rebootOffset, &rebootOffset2);
fileRead((u8*)rebootOffset, path, size);
memcpy((u8*)rebootOffset + size, L"sdmc:", 10);
memcpy((u8*)rebootOffset + size + 10, L"" PATCHED_FIRM_PATH, sizeof(PATCHED_FIRM_PATH) * 2);
@@ -117,6 +151,8 @@ u8 patchFirm(void){
size = fileSize(path);
if (!size) return 1;
fileRead((u8*)rebootOffset2, path, size);
//Write patched FIRM to SD
if (fileWrite((u8*)firmLocation, PATCHED_FIRM_PATH, firmSize) != 0) return 1;
}

View File

@@ -15,7 +15,7 @@
#define BUTTON_A 1
#define PATCHED_FIRM_PATH "/rei/patched_firmware.bin"
u8 loadFirm(void);
u8 loadFirm(u8 a9lh);
u8 loadEmu(void);
u8 patchFirm(void);
void launchFirm(void);

View File

@@ -59,7 +59,7 @@ int fileRead(u8 *dest, const char *path, u32 size){
}
int fileWrite(const u8 *buffer, const char *path, u32 size){
FRESULT fr;
FRESULT fr = 1;
FIL fp;
unsigned int br = 0;

View File

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

View File

@@ -27,6 +27,7 @@ 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};
/**************************************************
* Functions
@@ -34,18 +35,26 @@ 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, 0x20};
unsigned char pattern[] = {0xC0, 0x1C, 0x76, 0xE7};
unsigned char pattern2[] = {0x70, 0xB5, 0x22, 0x4D, 0x0C};
*off = (u32)memsearch(pos, pattern, size, 5);
*off = (u32)memsearch(pos, pattern, size, 4);
*off2 = (u32)memsearch(pos, pattern2, size, 5);
}
void getReboot(void *pos, u32 size, u32 *off, u32 *off2){
//Look for FIRM reboot code
unsigned char pattern[] = {0x8D, 0xE5, 0x00, 0xC0, 0x91, 0xE5};
unsigned char pattern[] = {0x8D, 0xE5, 0x00, 0xC0, 0x91};
unsigned char pattern2[] = {0xF0, 0x4F, 0x2D, 0xE9, 0x3C};
*off = (u32)memsearch(pos, pattern, size, 6) + 2;
*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, 5);
unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA};
*off = (u32)memsearch(firmwrite - 0x100, pattern, 0x100, 4);
}

View File

@@ -15,11 +15,13 @@ u8 mpu[0x2C];
u8 nandRedir[0x08];
u8 sigPat1[2];
u8 sigPat2[4];
u8 FIRMblock[4];
/**************************************************
* 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

34
source/start.s.a9lh Normal file
View File

@@ -0,0 +1,34 @@
.section .text.start
.align 4
.global _start
_start:
@ Change the stack pointer
mov sp, #0x27000000
@ Give read/write access to all the memory regions
ldr r5, =0x33333333
mcr p15, 0, r5, c5, c0, 2 @ write data access
mcr p15, 0, r5, c5, c0, 3 @ write instruction access
@ Enable caches
mrc p15, 0, r4, c1, c0, 0 @ read control register
orr r4, r4, #(1<<12) @ - instruction cache enable
orr r4, r4, #(1<<2) @ - data cache enable
orr r4, r4, #(1<<0) @ - mpu enable
mcr p15, 0, r4, c1, c0, 0 @ write control register
@ Flush caches
mov r5, #0
mcr p15, 0, r5, c7, c5, 0 @ flush I-cache
mcr p15, 0, r5, c7, c6, 0 @ flush D-cache
mcr p15, 0, r5, c7, c10, 4 @ drain write buffer
@ Fixes mounting of SDMC
ldr r0, =0x10000020
mov r1, #0x340
str r1, [r0]
bl main
.die:
b .die