Got rid of the bin2c dependency

This commit is contained in:
Aurora 2016-09-23 02:06:04 +02:00
parent 4f11162fae
commit a36556d7e4
7 changed files with 74 additions and 82 deletions

View File

@ -22,7 +22,7 @@ dir_injector := injector
dir_exceptions := exceptions
dir_arm9_exceptions := $(dir_exceptions)/arm9
dir_arm11_exceptions := $(dir_exceptions)/arm11
dir_ninjhax := CakeBrah
dir_cakebrah := CakeBrah
dir_diffs := diffs
dir_build := build
dir_out := out
@ -36,8 +36,14 @@ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
$(call rwildcard, $(dir_source), *.s *.c)))
bundled = $(dir_build)/rebootpatch.h $(dir_build)/emunandpatch.h $(dir_build)/svcGetCFWInfopatch.h $(dir_build)/injector.h $(dir_build)/loader.h \
$(dir_build)/k11modulespatch.h $(dir_build)/arm9_exceptions.h $(dir_build)/arm11_exceptions.h
bundled = $(dir_build)/reboot.bin.o $(dir_build)/emunand.bin.o $(dir_build)/svcGetCFWInfo.bin.o $(dir_build)/injector.bin.o $(dir_build)/loader.bin.o \
$(dir_build)/k11modules.bin.o $(dir_build)/arm9_exceptions.bin.o $(dir_build)/arm11_exceptions.bin.o
define bin2o
bin2s $< | $(AS) -o $(@)
echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> $(dir_build)/bundled.h
echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> $(dir_build)/bundled.h
endef
.PHONY: all
all: a9lh ninjhax menuhax
@ -56,75 +62,64 @@ release: $(dir_out)/$(name)$(revision).7z
.PHONY: clean
clean:
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) clean
@$(MAKE) $(FLAGS) -C $(dir_cakebrah) clean
@$(MAKE) -C $(dir_loader) clean
@$(MAKE) -C $(dir_arm9_exceptions) clean
@$(MAKE) -C $(dir_arm11_exceptions) clean
@$(MAKE) -C $(dir_injector) clean
@rm -rf $(dir_out) $(dir_build)
.PRECIOUS: $(dir_build)/%.bin
$(dir_out):
@mkdir -p "$(dir_out)"
$(dir_out)/menuhax/boot.3dsx: $(dir_diffs) $(dir_out)
@mkdir -p "$(@D)"
@cd $(dir_ninjhax); patch -p1 < ../$(dir_diffs)/1.diff; patch -p1 < ../$(dir_diffs)/2.diff; $(MAKE) $(FLAGS); git reset --hard
@mv $(dir_out)/$(name).3dsx $@
@rm $(dir_out)/$(name).smdh
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)
@cp -a $(dir_build)/main.bin $@
$(dir_out)/3ds/$(name): $(dir_diffs) $(dir_out)
@mkdir -p "$@"
@cd $(dir_ninjhax); patch -p1 < ../$(dir_diffs)/1.diff; $(MAKE) $(FLAGS); git reset --hard
@mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@
$(dir_out)/$(name)$(revision).7z: all
@7z a -mx $@ ./$(@D)/* ./$(dir_exceptions)/exception_dump_parser.py
$(dir_out)/menuhax/boot.3dsx: $(dir_diffs) $(dir_out)
@mkdir -p "$(@D)"
@cd $(dir_cakebrah); patch -p1 < ../$(dir_diffs)/1.diff; patch -p1 < ../$(dir_diffs)/2.diff; $(MAKE) $(FLAGS); git reset --hard
@mv $(dir_out)/$(name).3dsx $@
@rm $(dir_out)/$(name).smdh
$(dir_out)/3ds/$(name): $(dir_diffs) $(dir_out)
@mkdir -p "$@"
@cd $(dir_cakebrah); patch -p1 < ../$(dir_diffs)/1.diff; $(MAKE) $(FLAGS); git reset --hard
@mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)
@cp -a $(dir_build)/main.bin $@
$(dir_build)/main.bin: $(dir_build)/main.elf
$(OC) -S -O binary $< $@
$(dir_build)/main.elf: $(objects)
$(dir_build)/main.elf: $(bundled) $(objects)
$(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
$(dir_build)/emunandpatch.h: $(dir_patches)/emunand.s
$(dir_build)/%.bin.o: $(dir_build)/%.bin
@mkdir -p "$(@D)"
@armips $<
@bin2c -o $@ -n emunand $(@D)/emunand.bin
@$(bin2o)
$(dir_build)/rebootpatch.h: $(dir_patches)/reboot.s
@mkdir -p "$(@D)"
@armips $<
@bin2c -o $@ -n reboot $(@D)/reboot.bin
$(dir_build)/svcGetCFWInfopatch.h: $(dir_patches)/svcGetCFWInfo.s
@mkdir -p "$(@D)"
@armips $<
@bin2c -o $@ -n svcGetCFWInfo $(@D)/svcGetCFWInfo.bin
$(dir_build)/injector.h: $(dir_injector)/Makefile
$(dir_build)/injector.bin: $(dir_injector)/Makefile
@mkdir -p "$(@D)"
@$(MAKE) -C $(dir_injector)
@bin2c -o $@ -n injector $(@D)/injector.cxi
$(dir_build)/loader.h: $(dir_loader)/Makefile
$(dir_build)/loader.bin: $(dir_loader)/Makefile
@mkdir -p "$(@D)"
@$(MAKE) -C $(dir_loader)
@bin2c -o $@ -n loader $(@D)/loader.bin
$(dir_build)/k11modulespatch.h: $(dir_patches)/k11modules.s
$(dir_build)/arm9_exceptions.bin: $(dir_arm9_exceptions)/Makefile
@mkdir -p "$(@D)"
@$(MAKE) -C $(dir_arm9_exceptions)
$(dir_build)/arm11_exceptions.bin: $(dir_arm11_exceptions)/Makefile
@mkdir -p "$(@D)"
@$(MAKE) -C $(dir_arm11_exceptions)
$(dir_build)/%.bin: $(dir_patches)/%.s
@mkdir -p "$(@D)"
@armips $<
@bin2c -o $@ -n k11modules $(@D)/k11modules.bin
$(dir_build)/arm9_exceptions.h: $(dir_arm9_exceptions)/Makefile
@$(MAKE) -C $(dir_arm9_exceptions)
@bin2c -o $@ -n arm9_exceptions $(@D)/arm9_exceptions.bin
$(dir_build)/arm11_exceptions.h: $(dir_arm11_exceptions)/Makefile
@$(MAKE) -C $(dir_arm11_exceptions)
@bin2c -o $@ -n arm11_exceptions $(@D)/arm11_exceptions.bin
$(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3
$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\""

View File

@ -31,13 +31,13 @@ objects = $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
$(call rwildcard, $(dir_source), *.s *.c))
.PHONY: all
all: ../$(dir_build)/$(name).cxi
all: ../$(dir_build)/$(name).bin
.PHONY: clean
clean:
@rm -rf $(dir_build)
../$(dir_build)/$(name).cxi: $(dir_build)/$(name).elf
../$(dir_build)/$(name).bin: $(dir_build)/$(name).elf
@makerom -f ncch -rsf loader.rsf -nocodepadding -o $@ -elf $<
$(dir_build)/$(name).elf: $(objects)

View File

@ -23,7 +23,7 @@
#include "emunand.h"
#include "memory.h"
#include "fatfs/sdmmc/sdmmc.h"
#include "../build/emunandpatch.h"
#include "../build/bundled.h"
void locateEmuNand(u32 *emuHeader, FirmwareSource *nandType)
{
@ -144,16 +144,16 @@ void patchEmuNand(u8 *arm9Section, u32 arm9SectionSize, u8 *process9Offset, u32
{
//Copy EmuNAND code
u8 *freeK9Space = getFreeK9Space(arm9Section, arm9SectionSize);
memcpy(freeK9Space, emunand, emunand_size);
memcpy(freeK9Space, emunand_bin, emunand_bin_size);
//Add the data of the found EmuNAND
u32 *posOffset = (u32 *)memsearch(freeK9Space, "NAND", emunand_size, 4),
*posHeader = (u32 *)memsearch(freeK9Space, "NCSD", emunand_size, 4);
u32 *posOffset = (u32 *)memsearch(freeK9Space, "NAND", emunand_bin_size, 4),
*posHeader = (u32 *)memsearch(freeK9Space, "NCSD", emunand_bin_size, 4);
*posOffset = emuOffset;
*posHeader = emuHeader;
//Find and add the SDMMC struct
u32 *posSdmmc = (u32 *)memsearch(freeK9Space, "SDMC", emunand_size, 4);
u32 *posSdmmc = (u32 *)memsearch(freeK9Space, "SDMC", emunand_bin_size, 4);
*posSdmmc = getSdmmc(process9Offset, process9Size);
//Add EmuNAND hooks

View File

@ -27,12 +27,11 @@
#include "screen.h"
#include "draw.h"
#include "utils.h"
#include "../build/arm9_exceptions.h"
#include "../build/arm11_exceptions.h"
#include "../build/bundled.h"
void installArm9Handlers(void)
{
memcpy((void *)0x01FF8000, arm9_exceptions + 32, arm9_exceptions_size - 32);
memcpy((void *)0x01FF8000, arm9_exceptions_bin + 32, arm9_exceptions_bin_size - 32);
/* IRQHandler is at 0x08000000, but we won't handle it for some reasons
svcHandler is at 0x08000010, but we won't handle svc either */
@ -42,7 +41,7 @@ void installArm9Handlers(void)
for(u32 i = 0; i < 4; i++)
{
*(vu32 *)(0x08000000 + offsets[i]) = 0xE51FF004;
*(vu32 *)(0x08000000 + offsets[i] + 4) = *((u32 *)arm9_exceptions + 1 + i);
*(vu32 *)(0x08000000 + offsets[i] + 4) = *((u32 *)arm9_exceptions_bin + 1 + i);
}
}
@ -58,14 +57,14 @@ void installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffs
u32 *freeSpace;
for(freeSpace = initFPU; freeSpace < (exceptionsPage + 0x400) && (freeSpace[0] != 0xFFFFFFFF || freeSpace[1] != 0xFFFFFFFF); freeSpace++);
memcpy(freeSpace, arm11_exceptions + 32, arm11_exceptions_size - 32);
memcpy(freeSpace, arm11_exceptions_bin + 32, arm11_exceptions_bin_size - 32);
exceptionsPage[1] = MAKE_BRANCH(exceptionsPage + 1, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 8) - 32); //Undefined Instruction
exceptionsPage[3] = MAKE_BRANCH(exceptionsPage + 3, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 12) - 32); //Prefetch Abort
exceptionsPage[4] = MAKE_BRANCH(exceptionsPage + 4, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 16) - 32); //Data Abort
exceptionsPage[7] = MAKE_BRANCH(exceptionsPage + 7, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 4) - 32); //FIQ
exceptionsPage[1] = MAKE_BRANCH(exceptionsPage + 1, (u8 *)freeSpace + *(u32 *)(arm11_exceptions_bin + 8) - 32); //Undefined Instruction
exceptionsPage[3] = MAKE_BRANCH(exceptionsPage + 3, (u8 *)freeSpace + *(u32 *)(arm11_exceptions_bin + 12) - 32); //Prefetch Abort
exceptionsPage[4] = MAKE_BRANCH(exceptionsPage + 4, (u8 *)freeSpace + *(u32 *)(arm11_exceptions_bin + 16) - 32); //Data Abort
exceptionsPage[7] = MAKE_BRANCH(exceptionsPage + 7, (u8 *)freeSpace + *(u32 *)(arm11_exceptions_bin + 4) - 32); //FIQ
for(u32 *pos = freeSpace; pos < (u32 *)((u8 *)freeSpace + arm11_exceptions_size - 32); pos++)
for(u32 *pos = freeSpace; pos < (u32 *)((u8 *)freeSpace + arm11_exceptions_bin_size - 32); pos++)
{
switch(*pos) //Perform relocations
{

View File

@ -35,7 +35,7 @@
#include "screen.h"
#include "buttons.h"
#include "pin.h"
#include "../build/injector.h"
#include "../build/bundled.h"
extern u16 launchedFirmTidLow[8]; //Defined in start.s
@ -492,8 +492,8 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType, boo
if(firmType == NATIVE_FIRM && memcmp(moduleName, "loader", 6) == 0)
{
module = injector;
dstModuleSize = injector_size;
module = injector_bin;
dstModuleSize = injector_bin_size;
}
else
{

View File

@ -28,7 +28,7 @@
#include "screen.h"
#include "fatfs/ff.h"
#include "buttons.h"
#include "../build/loader.h"
#include "../build/bundled.h"
static FATFS sdFs,
nandFs;
@ -128,7 +128,7 @@ void loadPayload(u32 pressed)
u32 *loaderAddress = (u32 *)0x24FFFF00;
u8 *payloadAddress = (u8 *)0x24F00000;
memcpy(loaderAddress, loader, loader_size);
memcpy(loaderAddress, loader_bin, loader_bin_size);
concatenateStrings(path, "/");
concatenateStrings(path, info.altname);
@ -142,8 +142,8 @@ void loadPayload(u32 pressed)
restoreShaHashBackup();
initScreens();
flushDCacheRange(loaderAddress, loader_size);
flushICacheRange(loaderAddress, loader_size);
flushDCacheRange(loaderAddress, loader_bin_size);
flushICacheRange(loaderAddress, loader_bin_size);
((void (*)())loaderAddress)();
}

View File

@ -28,9 +28,7 @@
#include "fs.h"
#include "memory.h"
#include "config.h"
#include "../build/rebootpatch.h"
#include "../build/svcGetCFWInfopatch.h"
#include "../build/k11modulespatch.h"
#include "../build/bundled.h"
u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr)
{
@ -90,10 +88,10 @@ void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr)
u32 fOpenOffset = (u32)(off + 9 - (-((*(u32 *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - pos + process9MemAddr);
//Copy firmlaunch code
memcpy(off, reboot, reboot_size);
memcpy(off, reboot_bin, reboot_bin_size);
//Put the fOpen offset in the right location
u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_size, 4);
u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_bin_size, 4);
*pos_fopen = fOpenOffset;
if(CONFIG(USECUSTOMPATH))
@ -116,7 +114,7 @@ void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr)
finalPath[i] = (u16)path[i];
finalPath[pathSize] = 0;
u8 *pos_path = memsearch(off, u"sd", reboot_size, 4) + 0xA;
u8 *pos_path = memsearch(off, u"sd", reboot_bin_size, 4) + 0xA;
memcpy(pos_path, finalPath, (pathSize + 1) * 2);
}
}
@ -171,9 +169,9 @@ void reimplementSvcBackdoor(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **fre
void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **freeK11Space)
{
memcpy(*freeK11Space, svcGetCFWInfo, svcGetCFWInfo_size);
memcpy(*freeK11Space, svcGetCFWInfo_bin, svcGetCFWInfo_bin_size);
CFWInfo *info = (CFWInfo *)memsearch(*freeK11Space, "LUMA", svcGetCFWInfo_size, 4);
CFWInfo *info = (CFWInfo *)memsearch(*freeK11Space, "LUMA", svcGetCFWInfo_bin_size, 4);
const char *rev = REVISION;
@ -194,7 +192,7 @@ void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **fre
info->flags = isRelease ? 1 : 0;
arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc
*freeK11Space += svcGetCFWInfo_size;
*freeK11Space += svcGetCFWInfo_bin_size;
}
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size)
@ -344,10 +342,10 @@ void patchK11ModuleChecks(u8 *pos, u32 size, u8 **freeK11Space)
are compressed in memory and are only decompressed at runtime */
//Check that we have enough free space
if(*(u32 *)(*freeK11Space + k11modules_size - 4) == 0xFFFFFFFF)
if(*(u32 *)(*freeK11Space + k11modules_bin_size - 4) == 0xFFFFFFFF)
{
//Inject our code into the free space
memcpy(*freeK11Space, k11modules, k11modules_size);
memcpy(*freeK11Space, k11modules_bin, k11modules_bin_size);
//Look for the code that decompresses the .code section of the builtin modules
const u8 pattern[] = {0xE5, 0x48, 0x00, 0x9D};
@ -357,7 +355,7 @@ void patchK11ModuleChecks(u8 *pos, u32 size, u8 **freeK11Space)
//Inject a jump (BL) instruction to our code at the offset we found
*off = 0xEB000000 | (((((u32)*freeK11Space) - ((u32)off + 8)) >> 2) & 0xFFFFFF);
*freeK11Space += k11modules_size;
*freeK11Space += k11modules_bin_size;
}
}