Merge emunand.bin, reboot.bin and loader.bin in the main executable
Less SD accesses, more noob-proof
This commit is contained in:
parent
b42f9ffb41
commit
03a6e343db
42
Makefile
42
Makefile
@ -34,7 +34,7 @@ objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
|||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: launcher a9lh emunand reboot ninjhax loader
|
all: loader launcher a9lh ninjhax
|
||||||
|
|
||||||
.PHONY: launcher
|
.PHONY: launcher
|
||||||
launcher: $(dir_out)/$(name).dat
|
launcher: $(dir_out)/$(name).dat
|
||||||
@ -42,18 +42,9 @@ launcher: $(dir_out)/$(name).dat
|
|||||||
.PHONY: a9lh
|
.PHONY: a9lh
|
||||||
a9lh: $(dir_out)/arm9loaderhax.bin
|
a9lh: $(dir_out)/arm9loaderhax.bin
|
||||||
|
|
||||||
.PHONY: emunand
|
|
||||||
emunand: $(dir_out)/aurei/patches/emunand.bin
|
|
||||||
|
|
||||||
.PHONY: reboot
|
|
||||||
reboot: $(dir_out)/aurei/patches/reboot.bin
|
|
||||||
|
|
||||||
.PHONY: ninjhax
|
.PHONY: ninjhax
|
||||||
ninjhax: $(dir_out)/3ds/$(name)
|
ninjhax: $(dir_out)/3ds/$(name)
|
||||||
|
|
||||||
.PHONY: loader
|
|
||||||
loader: $(dir_out)/aurei/loader.bin
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_mset) clean
|
@$(MAKE) $(FLAGS) -C $(dir_mset) clean
|
||||||
@ -61,36 +52,33 @@ clean:
|
|||||||
@rm -rf $(dir_out) $(dir_build)
|
@rm -rf $(dir_out) $(dir_build)
|
||||||
@$(MAKE) -C $(dir_loader) clean
|
@$(MAKE) -C $(dir_loader) clean
|
||||||
|
|
||||||
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/aurei
|
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
|
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
|
||||||
dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144
|
dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144
|
||||||
|
|
||||||
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)/aurei
|
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)
|
||||||
@cp -av $(dir_build)/main.bin $@
|
@cp -av $(dir_build)/main.bin $@
|
||||||
|
|
||||||
$(dir_out)/3ds/$(name):
|
$(dir_out)/3ds/$(name): $(dir_out)
|
||||||
@mkdir -p "$(dir_out)/3ds/$(name)"
|
@mkdir -p "$(dir_out)/3ds/$(name)"
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_ninjhax)
|
@$(MAKE) $(FLAGS) -C $(dir_ninjhax)
|
||||||
@mv $(dir_out)/$(name).3dsx $@
|
@mv $(dir_out)/$(name).3dsx $@
|
||||||
@mv $(dir_out)/$(name).smdh $@
|
@mv $(dir_out)/$(name).smdh $@
|
||||||
|
|
||||||
$(dir_out)/aurei:
|
$(dir_out):
|
||||||
@mkdir -p "$(dir_out)/aurei"
|
@mkdir -p "$(dir_out)/aurei/payloads"
|
||||||
|
|
||||||
$(dir_out)/aurei/patches:
|
$(dir_build)/patches.h: $(dir_emu)/emuCode.s $(dir_reboot)/rebootCode.s
|
||||||
@mkdir -p "$(dir_out)/aurei/patches"
|
@mkdir -p "$(dir_build)"
|
||||||
|
|
||||||
$(dir_out)/aurei/patches/emunand.bin: $(dir_emu)/emuCode.s $(dir_out)/aurei/patches
|
|
||||||
@armips $<
|
@armips $<
|
||||||
@mv emunand.bin $@
|
@mv emunand.bin $(dir_build)
|
||||||
|
@armips $(word 2,$^)
|
||||||
|
@mv reboot.bin $(dir_build)
|
||||||
|
@bin2c -o $@ -n emunand $(dir_build)/emunand.bin -n reboot $(dir_build)/reboot.bin
|
||||||
|
|
||||||
$(dir_out)/aurei/patches/reboot.bin: $(dir_reboot)/rebootCode.s $(dir_out)/aurei/patches
|
$(dir_build)/loader.h: $(dir_loader)/Makefile
|
||||||
@armips $<
|
|
||||||
@mv reboot.bin $@
|
|
||||||
|
|
||||||
$(dir_out)/aurei/loader.bin: $(dir_out)/aurei $(dir_loader)/Makefile
|
|
||||||
@$(MAKE) -C $(dir_loader)
|
@$(MAKE) -C $(dir_loader)
|
||||||
@mv $(dir_loader)/loader.bin $@
|
@bin2c -o $@ -n loader $(dir_loader)/loader.bin
|
||||||
|
|
||||||
$(dir_build)/main.bin: $(dir_build)/main.elf
|
$(dir_build)/main.bin: $(dir_build)/main.elf
|
||||||
$(OC) -S -O binary $< $@
|
$(OC) -S -O binary $< $@
|
||||||
@ -99,7 +87,7 @@ $(dir_build)/main.elf: $(objects_cfw)
|
|||||||
# FatFs requires libgcc for __aeabi_uidiv
|
# FatFs requires libgcc for __aeabi_uidiv
|
||||||
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
$(dir_build)/%.o: $(dir_source)/%.c
|
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h
|
||||||
@mkdir -p "$(@D)"
|
@mkdir -p "$(@D)"
|
||||||
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
#include "../build/patches.h"
|
||||||
|
|
||||||
//FIRM patches version
|
//FIRM patches version
|
||||||
#define PATCH_VER 1
|
#define PATCH_VER 1
|
||||||
@ -100,14 +101,14 @@ void setupCFW(void){
|
|||||||
|
|
||||||
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
||||||
and "Use pre-patched FIRMs" is set, delete all patched FIRMs */
|
and "Use pre-patched FIRMs" is set, delete all patched FIRMs */
|
||||||
u16 bootConfig = (PATCH_VER << 11) | (!a9lhSetup << 10);
|
u16 bootConfig = (PATCH_VER << 11) | (a9lhSetup << 10);
|
||||||
if ((config >> 1) & 0x1 && bootConfig != (config & 0xFC00))
|
if ((config >> 1) & 0x1 && bootConfig != (config & 0xFC00))
|
||||||
deleteFirms(patchedFirms, sizeof(patchedFirms) / sizeof(char *));
|
deleteFirms(patchedFirms, sizeof(patchedFirms) / sizeof(char *));
|
||||||
|
|
||||||
//We also need to remember the used boot mode on A9LH
|
//We also need to remember the used boot mode on A9LH
|
||||||
if(a9lhBoot) bootConfig |= (mode << 8) | (emuNAND << 9);
|
if(a9lhBoot) bootConfig |= (mode << 8) | (emuNAND << 9);
|
||||||
|
|
||||||
//If boot configuration is different from previously, overwrite it
|
//If the boot configuration is different from previously, overwrite it
|
||||||
if(bootConfig != (config & 0xFF00)){
|
if(bootConfig != (config & 0xFF00)){
|
||||||
//Preserve user settings (first byte)
|
//Preserve user settings (first byte)
|
||||||
u16 tempConfig = ((config & 0xFF) | bootConfig);
|
u16 tempConfig = ((config & 0xFF) | bootConfig);
|
||||||
@ -165,12 +166,8 @@ static void loadEmu(u8 *proc9Offset){
|
|||||||
emuRead,
|
emuRead,
|
||||||
emuWrite;
|
emuWrite;
|
||||||
|
|
||||||
//Read emunand code from SD
|
|
||||||
const char path[] = "/aurei/patches/emunand.bin";
|
|
||||||
u32 size = fileSize(path);
|
|
||||||
if(!size) error("aurei/patches/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);
|
memcpy(emuCodeOffset, emunand, emunand_size);
|
||||||
|
|
||||||
//Look for emuNAND
|
//Look for emuNAND
|
||||||
getEmunandSect(&emuOffset, &emuHeader, emuNAND);
|
getEmunandSect(&emuOffset, &emuHeader, emuNAND);
|
||||||
@ -179,13 +176,13 @@ static void loadEmu(u8 *proc9Offset){
|
|||||||
if(!emuHeader) error("No emuNAND has been detected");
|
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", emunand_size, 4);
|
||||||
u32 *pos_header = (u32 *)memsearch(emuCodeOffset, "NCSD", size, 4);
|
u32 *pos_header = (u32 *)memsearch(emuCodeOffset, "NCSD", emunand_size, 4);
|
||||||
*pos_offset = emuOffset;
|
*pos_offset = emuOffset;
|
||||||
*pos_header = emuHeader;
|
*pos_header = emuHeader;
|
||||||
|
|
||||||
//Find and place the SDMMC struct
|
//Find and place the SDMMC struct
|
||||||
u32 *pos_sdmmc = (u32 *)memsearch(emuCodeOffset, "SDMC", size, 4);
|
u32 *pos_sdmmc = (u32 *)memsearch(emuCodeOffset, "SDMC", emunand_size, 4);
|
||||||
*pos_sdmmc = getSDMMC(arm9Section, section[2].size);
|
*pos_sdmmc = getSDMMC(arm9Section, section[2].size);
|
||||||
|
|
||||||
//Calculate offset for the hooks
|
//Calculate offset for the hooks
|
||||||
@ -218,19 +215,16 @@ void patchFirm(void){
|
|||||||
//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/patches/reboot.bin";
|
|
||||||
u32 size = fileSize(path);
|
|
||||||
if(!size) error("aurei/patches/reboot.bin doesn't exist");
|
|
||||||
u8 *rebootOffset = getReboot(arm9Section, section[2].size);
|
u8 *rebootOffset = getReboot(arm9Section, section[2].size);
|
||||||
fileRead(rebootOffset, path, size);
|
memcpy(rebootOffset, reboot, reboot_size);
|
||||||
|
|
||||||
//Calculate the fOpen offset and put it in the right location
|
//Calculate the fOpen offset and put it in the right location
|
||||||
u32 *pos_fopen = (u32 *)memsearch(rebootOffset, "OPEN", size, 4);
|
u32 *pos_fopen = (u32 *)memsearch(rebootOffset, "OPEN", reboot_size, 4);
|
||||||
*pos_fopen = getfOpen(arm9Section, section[2].size, proc9Offset);
|
*pos_fopen = getfOpen(arm9Section, section[2].size, proc9Offset);
|
||||||
|
|
||||||
//Patch path for emuNAND-patched FIRM
|
//Patch path for emuNAND-patched FIRM
|
||||||
if(emuNAND){
|
if(emuNAND){
|
||||||
void *pos_path = memsearch(rebootOffset, L"sy", size, 4);
|
void *pos_path = memsearch(rebootOffset, L"sy", reboot_size, 4);
|
||||||
memcpy(pos_path, emuNAND == 1 ? L"emu" : L"em2", 5);
|
memcpy(pos_path, emuNAND == 1 ? L"emu" : L"em2", 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,20 @@
|
|||||||
|
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "screeninit.h"
|
#include "screeninit.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
|
#include "../build/loader.h"
|
||||||
|
|
||||||
#define PAYLOAD_ADDRESS 0x24F00000
|
#define PAYLOAD_ADDRESS 0x24F00000
|
||||||
|
|
||||||
void loadPayload(void){
|
void loadPayload(void){
|
||||||
if(fileExists("aurei/payloads/default.bin") &&
|
if(fileExists("aurei/payloads/default.bin")){
|
||||||
fileRead((u8 *)PAYLOAD_ADDRESS, "aurei/loader.bin", 0)){
|
|
||||||
if(PDN_GPU_CNT == 0x1){
|
if(PDN_GPU_CNT == 0x1){
|
||||||
initScreens();
|
initScreens();
|
||||||
clearScreens();
|
clearScreens();
|
||||||
}
|
}
|
||||||
|
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);
|
||||||
((void (*)())PAYLOAD_ADDRESS)();
|
((void (*)())PAYLOAD_ADDRESS)();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user