From: chaoskagami Date: Mon, 18 Jul 2016 03:37:19 +0000 (-0400) Subject: Port corbenik to autotools X-Git-Tag: v0.2.0~8^2~8 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=2e721a31f35da8e423099f14faac73d44060a025;p=corbenik%2Fcorbenik.git Port corbenik to autotools --- diff --git a/.gitignore b/.gitignore index 5040b3f..4505636 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,26 @@ build *.vco input host/copy.sh +Makefile.in +aclocal.m4 +autom4te.cache/ +compile +config.guess +config.sub +configure +install-sh +ltmain.sh +missing +.deps +config.log +config.status +libtool +.dirstamp +depcomp +/Makefile +/source/Makefile +/external/Makefile +/source/corbenik +/m4 +/include/config.h +/include/stamp-h1 diff --git a/Makefile b/Makefile deleted file mode 100644 index 3f5cd62..0000000 --- a/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) - -include common.mk - -objects_cfw = $(patsubst %.s, %.o, \ - $(patsubst %.c, %.o, \ - $(call rwildcard, $(dir_source), *.s *.c))) - -.PHONY: all -all: hosttools font ctr9io a9lh patch external - -.PHONY: ctr9io -ctr9io: - cd external/libctr9 && autoreconf -fi && CFLAGS= LDFLAGS= ASFLAGS= ./configure --host arm-none-eabi --prefix=$(shell pwd)/external/libctr9/out && make && make install - -.PHONY: release -release: - rm -rf rel - mkdir -p rel - make clean - make CHAINLOADER=0 REL=$(REL) full - mv out/release.zip rel/release-nochain.zip - cat out/release.zip.sha512 | sed 's/release.zip/release-nochain.zip/' > rel/release-nochain.zip.sha512 - make clean - make CHAINLOADER=1 REL=$(REL) full - mv out/release.zip out/release.zip.sha512 rel/ - -.PHONY: hosttools -hosttools: - make -C host/bdfe dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) - -.PHONY: font -font: hosttools - make -C host/bdfe - mkdir -p $(dir_out)/$(fw_folder)/bits - ./host/bdfe/bdfe -A -n external/tewi-font/tewi-medium-11.bdf > $(dir_out)/$(fw_folder)/bits/termfont.bin - -.PHONY: full -full: all contrib $(dir_out)/$(fw_folder)/locale - cp README.md LICENSE.txt $(dir_out)/ - cd out && zip -r9 release.zip * - cd out && sha512sum -b release.zip > release.zip.sha512 # Security. - -.PHONY: contrib -contrib: - make -C contrib dir_out=$(dir_out) fw_name=$(fw_name) fw_folder=$(fw_folder) root=$(root) - -.PHONY: external -external: - make -C external dir_out=$(dir_out) fw_name=$(fw_name) fw_folder=$(fw_folder) CHAINLOADER=$(CHAINLOADER) root=$(root) - -.PHONY: patch -patch: - make -C patch dir_out=$(dir_out) fw_name=$(fw_name) fw_folder=$(fw_folder) root=$(root) - -.PHONY: a9lh -a9lh: $(dir_out)/main.bin - mkdir -p $(dir_out)/$(fw_folder)/bits - -.PHONY: reformat -reformat: - clang-format -i $(dir_source)/*.{c,h} $(dir_source)/*/*.{c,h} external/loader/source/*.{c,h} - -$(dir_out)/$(fw_folder)/locale: all - echo "Generating langemu data from 3dsdb - may take a bit" - cd out/$(fw_folder) && ../../host/generate_langemu_conf.sh - -.PHONY: clean -clean: - rm -f $(objects_cfw) - cd external/libctr9 && git clean -fxd - make -C external dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean - make -C patch dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean - make -C host/bdfe dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean - rm -rf $(dir_out) $(dir_build) - -out/main.bin: out/main.elf - $(OC) $(OCFLAGS) -S -O binary $< $@ - -out/main.elf: $(objects_cfw) - $(CC) $(LDFLAGS) -T linker.ld -o $@ $< - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -%.o: %.s - $(AS) $(ASFLAGS) -c -o $@ $< - -include $(call rwildcard, $(dir_build), *.d) diff --git a/Makefile.am b/Makefile.am index 4491836..e8b7e94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,16 +1,26 @@ -include common.mk +SUBDIRS = include host external source patch contrib +ACLOCAL_AMFLAGS = -I m4 -corbenik_SOURCES = aes.c ctr_nand_crypto_interface.c ctr_sd_interface.c sha.c \ - ctr_io_interface.c ctr_nand_interface.c sdmmc/delay.s sdmmc/sdmmc.c i2c.c \ - ctr_rtc.c fatfs/diskio.c fatfs/ff.c fatfs/option/unicode.c ctr_system.c \ - ctr_fatfs_interface.c fatfs/ctr_fatfs_disk.c ctr_disks.c \ - fatfs/ctr_fatfs_disk.c ctr_fatfs.c ctr_interrupt.c ctr_system_ARM.c \ - ctr_interrupt_asm.s ctr_screen.c ctr_hid.c ctr_pxi.c gamecart/command_ctr.c\ - gamecart/command_ntr.c gamecart/protocol.c gamecart/protocol_ctr.c \ - gamecart/protocol_ntr.c ctr_cart_interface.c gamecart/delay.s ctr_headers.c \ - ctr_timer.c ctr_irq.c ctr_system_clock.c +install: + @echo "Please don't call the install target directly, it doesn't work." + @exit 1 - -includedirectory = include - -corbenik_HEADERS = $(includedirectory)/ +all-local: + mkdir -p out + mkdir -p out/@prefix@ + mkdir -p out/@libdir@/{module,firmware} + mkdir -p out/@datarootdir@/{keys,locale/emu} + mkdir -p out/@bindir@ + mkdir -p out/@sbindir@ + mkdir -p out/@prefix@/boot + mkdir -p out/@libexecdir@ + mkdir -p out/@sysconfdir@ + mkdir -p out/@localstatedir@ + cp source/corbenik.bin out/arm9loaderhax.bin + cp source/corbenik.bin out/@prefix@/boot/ + cp external/loader/loader.cxi out/@libdir@/module/loader.cxi + cp external/bits/*.bin out/@libexecdir@/ + cp external/screeninit/build/screeninit.bin out/@libexecdir@/ + cp host/termfont.bin out/@libexecdir@/ + cp patch/*.vco out/@sbindir@ + cp contrib/*.vco out/@bindir@ diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..fad27d8 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir -p m4 +autoreconf -fi diff --git a/common.mk b/common.mk index 36cc9bc..4a8028e 100644 --- a/common.mk +++ b/common.mk @@ -1,38 +1,29 @@ -INCPATHS=-I$(top_srcdir)/include +INCPATHS=-I$(top_srcdir)/include -I$(top_srcdir)/external/libctr9/include + C9FLAGS=-mcpu=arm946e-s -march=armv5te -mlittle-endian -mword-relocations SIZE_OPTIMIZATION = -Wl,--gc-sections -ffunction-sections -CFLAGS= -std=gnu11 -O2 -g -fomit-frame-pointer -ffast-math \ +AM_CFLAGS= -std=gnu11 -O2 -g -fomit-frame-pointer -ffast-math \ -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual \ -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \ -Wmissing-declarations -Wmissing-include-dirs -Wredundant-decls \ -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wswitch-default \ -Wundef -Wno-unused $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \ - -I$(shell pwd)/external/libctr9/out/include -I$(shell pwd)/include -Os $(ASFLAGS) \ + -Os $(ASFLAGS) \ -fshort-wchar -fno-builtin -std=gnu11 -DVERSION=\"$(REVISION)\" -DREL=\"$(REL)\" \ -DCHAINLOADER=$(CHAINLOADER) -DPATH_CFW=\"/$(fw_folder)\" -DFW_NAME=\"$(fw_name)\" \ $(PATHARGS) -LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -Wl,-z,defs -lgcc \ - -Wl,-Map,$(dir_out)/link.map -L$(shell pwd)/external/libctr9/out/lib -lctr9 +AM_LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -Wl,-z,defs -lgcc \ + -L$(top_srcdir)/external/libctr9/src OCFLAGS=--set-section-flags .bss=alloc,load,contents # Only cygwin is maybe working on windows. PATH := $(PATH):$(DEVKITARM)/bin -CC := arm-none-eabi-gcc -AS := arm-none-eabi-as -LD := arm-none-eabi-ld -OC := arm-none-eabi-objcopy - -BUILD_CC ?= gcc -BUILD_AS ?= as -BUILD_LD ?= ld -BUILD_OC ?= objcopy - fw_name ?= Corbenik # If unset, the primary folder is /corbenik. @@ -43,21 +34,21 @@ fw_folder ?= corbenik # cruel root ?= clusterfuck -ifeq "$(root)" "clusterfuck" - PATHARGS := -DPATH_ROOT=\"\" - PATHARGS += -DPATH_DATA=\"/$(fw_folder)\" -else ifeq "$(root)" "cruel" - PATHARGS := -DPATH_ROOT=\"/3ds/apps\" - PATHARGS += -DPATH_DATA=\"/3ds/appdata/$(fw_folder)\" -else ifeq "$(root)" "shadowhand" - PATHARGS := -DPATH_ROOT=\"/homebrew/3ds\" - PATHARGS += -DPATH_DATA=\"/homebrew/3ds/$(fw_folder)\" -endif - -dir_source := source -dir_data := data -dir_build := build -dir_out := out +# ifeq "$(root)" "clusterfuck" +# PATHARGS := -DPATH_ROOT=\"\" +# PATHARGS += -DPATH_DATA=\"/$(fw_folder)\" +# else ifeq "$(root)" "cruel" +# PATHARGS := -DPATH_ROOT=\"/3ds/apps\" +# PATHARGS += -DPATH_DATA=\"/3ds/appdata/$(fw_folder)\" +# else ifeq "$(root)" "shadowhand" +# PATHARGS := -DPATH_ROOT=\"/homebrew/3ds\" +# PATHARGS += -DPATH_DATA=\"/homebrew/3ds/$(fw_folder)\" +# endif + +# dir_source := source +# dir_data := data +# dir_build := build +# dir_out := out REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count HEAD) REL ?= master diff --git a/configure.ac b/configure.ac index e64afe5..5af4adc 100644 --- a/configure.ac +++ b/configure.ac @@ -1,15 +1,54 @@ -AC_INIT([libctr9], [0.0.1], [], []) +AC_INIT([corbenik], [0.1.2], [https://github.com/chaoskagami/corbenik], []) AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects]) -#Find AR and RANLIB for lto support before initializing libtool +AC_CONFIG_MACRO_DIRS([m4]) + +# Find AR and RANLIB for lto support before initializing libtool AC_CHECK_TOOL([AR],gcc-ar) AC_CHECK_TOOL([RANLIB],gcc-ranlib) LT_INIT +AC_PROG_SED AC_PROG_CC +AC_PROG_CXX AM_PROG_AS AC_CHECK_TOOL([OBJCOPY],objcopy) -AC_CONFIG_FILES([Makefile src/Makefile test/Makefile examples/Makefile]) +AC_ARG_ENABLE([chainloader], + AS_HELP_STRING([--disable-chainloader], [Disable chainloading of external programs])) + +AC_PREFIX_DEFAULT([/corbenik]) + +if ! "$enable_chainloader" == "no" ; then + CHAINLOADER=1 +else + CHAINLOADER=0 +fi + +AC_DEFINE([CHAINLOADER], [$CHAINLOADER]) + +AC_CONFIG_FILES([Makefile source/Makefile external/Makefile include/Makefile]) + +AC_CONFIG_SUBDIRS([external/libctr9]) + +echo " +Corbenik $VERSION +======================== +Prefix: ${prefix} + +cc: ${CC} +cxx: ${CXX} +ld: ${LD} +oc: ${OBJCOPY} + +sed: ${SED} + +cflags: ${CFLAGS} +cxxflags: ${CXXFLAGS} +ldflags: ${LDFLAGS} +ocflags: ${OCFLAGS} + +Chainloader: ${CHAINLOADER} +" AC_OUTPUT diff --git a/contrib/Makefile b/contrib/Makefile index 9ed7fba..3dc0cfc 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -1,15 +1,11 @@ -out := ../$(dir_out)/$(fw_folder) - .PHONY: all -all: build install +all: build .PHONY: build build: clean $(patsubst %.pco, %.vco, $(wildcard *.pco)) .PHONY: install -install: build - mkdir -p $(out)/contrib - cp *.vco README.md $(out)/contrib/ +install: %.vco: %.pco ../host/bytecode_asm.py $< $@ diff --git a/external/Makefile b/external/Makefile deleted file mode 100644 index 5cac09e..0000000 --- a/external/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -out := ../$(dir_out)/$(fw_folder) - -.PHONY: all -all: loader bits screeninit - mkdir -p $(out)/module - mkdir -p $(out)/bits - cp loader/loader.cxi $(out)/module/loader.cxi - cp bits/backdoor.bin $(out)/bits/backdoor.bin - cp bits/emunand.bin $(out)/bits/emunand.bin -ifeq "$(CHAINLOADER)" "1" - cp bits/chain.bin $(out)/bits/chain.bin -endif - cp bits/reboot_hook.bin $(out)/bits/reboot_hook.bin - cp bits/reboot_code.bin $(out)/bits/reboot_code.bin - cp screeninit/build/screeninit.bin $(out)/bits/screeninit.bin - -.PHONY: clean -clean: clean_loader clean_bits clean_screeninit - rm -rf $(out)/bits - rm -rf $(out)/module - -.PHONY: loader -loader: - make -C loader dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) - -.PHONY: bits -bits: - make -C bits dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) - -.PHONY: screeninit -screeninit: - make -C screeninit dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) - -.PHONY: clean_loader -clean_loader: - make -C loader dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean - -.PHONY: clean_bits -clean_bits: - make -C bits dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean - -.PHONY: clean_screeninit -screeninit_clean: - make -C screeninit dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean diff --git a/external/Makefile.am b/external/Makefile.am new file mode 100644 index 0000000..a88f86e --- /dev/null +++ b/external/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = libctr9 loader bits screeninit + +install: diff --git a/external/bits/Makefile b/external/bits/Makefile index a7e39f1..814e965 100644 --- a/external/bits/Makefile +++ b/external/bits/Makefile @@ -17,3 +17,6 @@ all: $(OBJECTS) .PHONY: clean clean: rm -f *.bin *.elf *.o + +.PHONY: install +install: diff --git a/external/loader/Makefile b/external/loader/Makefile index c014baf..81f1a7f 100644 --- a/external/loader/Makefile +++ b/external/loader/Makefile @@ -47,7 +47,7 @@ CFLAGS := -flto -Wall -Os -mword-relocations $(ERROR) \ -fomit-frame-pointer -ffunction-sections -fdata-sections -fshort-wchar \ $(ARCH) -CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DLOADER=1 -DPATH_CFW=\"/$(fw_folder)\" $(PATHARGS) +CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DLOADER=1 -I../../../include $(PATHARGS) CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu99 @@ -174,3 +174,6 @@ endef #--------------------------------------------------------------------------------------- endif #--------------------------------------------------------------------------------------- + +.PHONY: install +install: diff --git a/external/loader/source/interp.c b/external/loader/source/interp.c index 59aa1f3..5344aff 100644 --- a/external/loader/source/interp.c +++ b/external/loader/source/interp.c @@ -13,8 +13,8 @@ #define PATH_MAX 255 #define _MAX_LFN 255 #endif -#include "../../../source/config.h" -#include "../../../source/patch_format.h" +#include +#include // Patches must consist of fewer bytes than this. // 16K is reasonable, IMO, and doesn't cause issues. diff --git a/external/loader/source/logger.c b/external/loader/source/logger.c index 76a8836..41c4110 100644 --- a/external/loader/source/logger.c +++ b/external/loader/source/logger.c @@ -8,8 +8,8 @@ #define PATH_MAX 255 #define _MAX_LFN 255 #endif -#include "../../../source/config.h" -#include "../../../source/patch_format.h" +#include +#include Handle log_file_hdl; int logger_is_initd = 0; diff --git a/external/loader/source/memory.c b/external/loader/source/memory.c index 82c07f9..ab3d931 100644 --- a/external/loader/source/memory.c +++ b/external/loader/source/memory.c @@ -8,24 +8,8 @@ #define PATH_MAX 255 #define _MAX_LFN 255 #endif -#include "../../../source/config.h" -#include "../../../source/patch_format.h" -/* -int -memcmp(const void *buf1, const void *buf2, u32 size) -{ - const u8 *buf1c = (const u8 *)buf1; - const u8 *buf2c = (const u8 *)buf2; - - for (u32 i = 0; i < size; i++) { - int cmp = buf1c[i] - buf2c[i]; - if (cmp) - return cmp; - } - - return 0; -} -*/ +#include +#include // Quick Search algorithm, adapted from // http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190 diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index 9a519ec..9950b27 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -6,15 +6,15 @@ #include "internal.h" #include "memory.h" #include "logger.h" -#include "../../../source/patch_format.h" -#include "../../../source/std/unused.h" +#include +#include #include "interp.h" #ifndef PATH_MAX #define PATH_MAX 255 #define _MAX_LFN 255 #endif -#include "../../../source/config.h" +#include #define TEXT_PATH PATH_EXEFS_TEXT "/0000000000000000" #define DATA_PATH PATH_EXEFS_DATA "/0000000000000000" diff --git a/external/screeninit/Makefile b/external/screeninit/Makefile index fdb5d25..b986b31 100755 --- a/external/screeninit/Makefile +++ b/external/screeninit/Makefile @@ -45,3 +45,6 @@ $(dir_build)/%.o: $(dir_source)/%.s @mkdir -p "$(@D)" $(COMPILE.s) $(OUTPUT_OPTION) $< include $(call rwildcard, $(dir_build), *.d) + +.PHONY: install +install: diff --git a/external/screeninit/source/main.c b/external/screeninit/source/main.c index 932cb7e..d4f3898 100755 --- a/external/screeninit/source/main.c +++ b/external/screeninit/source/main.c @@ -12,7 +12,7 @@ #define INIT_PARAMS 1 #define INIT_DEINIT 2 -void main(void) { +void __attribute__((naked)) main(void) { // FIXME - We could use some serious macros here... u32 do_init = *(vu32 *)0x24FFFC08; @@ -41,10 +41,15 @@ void main(void) { *(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10202014 = 0x00000001; *(vu32 *)0x1020200C &= 0xFFFEFFFE; + } + *(vu32 *)0x10202240 = brightnessLevel; // Alteration; directly read brightness. *(vu32 *)0x10202A40 = brightnessLevel; + + if (do_init == INIT_FULL) { *(vu32 *)0x10202244 = 0x1023E; *(vu32 *)0x10202A44 = 0x1023E; + } // Top screen *(vu32 *)0x10400400 = 0x000001c2; @@ -101,7 +106,6 @@ void main(void) { *(vu32 *)0x10400540 = 0x01980194; *(vu32 *)0x10400544 = 0x00000000; *(vu32 *)0x10400548 = 0x00000011; - *(vu32 *)0x1040055C = 0x00f00140; *(vu32 *)0x10400560 = 0x01c100d1; *(vu32 *)0x10400564 = 0x01920052; @@ -127,9 +131,6 @@ void main(void) { *((vu32 *)0x23FFFE00) = 0x18300000; *((vu32 *)0x23FFFE04) = 0x18300000; *((vu32 *)0x23FFFE08) = 0x18300000 + (yaw * 400); - } else if (do_init == INIT_DEINIT) { - - } //Clear ARM11 entry offset *arm11 = 0; diff --git a/host/Makefile b/host/Makefile new file mode 100644 index 0000000..1f10798 --- /dev/null +++ b/host/Makefile @@ -0,0 +1,11 @@ +all: bdfe font + +bdfe_dir: + make -C bdfe + +font: bdfe_dir + ./bdfe/bdfe -n -A ../external/tewi-font/tewi-medium-11.bdf > termfont.bin + +clean: + make -C bdfe clean + rm -f termfont.bin diff --git a/host/copy.sh b/host/copy.sh index 38d6fa9..4295a17 100755 --- a/host/copy.sh +++ b/host/copy.sh @@ -12,9 +12,7 @@ mount -t vfat ${dev}1 $mnt || exit 0 rm -rf $mnt/corbenik cp -r out/* $mnt/ || exit 0 cp -r input/* $mnt/ || exit 0 -cp out/arm9loaderhax.bin $mnt/corbenik/chain/Corbenik || exit 0 -cp out/arm9loaderhax.bin $mnt/arm9loaderhax_si.bin || exit 0 -rm -f $mnt/arm9loaderhax.bin || exit 0 +cp out/arm9loaderhax.bin $mnt/corbenik/boot/Corbenik || exit 0 umount $mnt || exit 0 sync || exit 0 eject ${dev} || exit 0 diff --git a/include/Makefile.am b/include/Makefile.am new file mode 100644 index 0000000..7fd9bb1 --- /dev/null +++ b/include/Makefile.am @@ -0,0 +1,14 @@ +all-local: + ${SED} \ + -e "s|%CHAINLOADER%|${CHAINLOADER}|g" \ + -e "s|%PREFIX%|${prefix}|g" \ + -e "s|%LOCALSTATEDIR%|${localstatedir}|g" \ + -e "s|%BINDIR%|${bindir}|g" \ + -e "s|%SBINDIR%|${sbindir}|g" \ + -e "s|%LIBDIR%|${libdir}|g" \ + -e "s|%LIBEXECDIR%|${libexecdir}|g" \ + -e "s|%DATAROOTDIR%|${datarootdir}|g" \ + -e "s|%SYSCONFDIR%|${sysconfdir}|g" \ + -e "s|%PACKAGE%|${PACKAGE}|g" \ + -e "s|%PACKAGE_VERSION%|${PACKAGE_VERSION}|g" \ + config.h.in > config.h diff --git a/include/common.h b/include/common.h index c8a46a5..d120c7d 100644 --- a/include/common.h +++ b/include/common.h @@ -1,6 +1,8 @@ #ifndef __COMMON_H #define __COMMON_H +#include + #include #include @@ -19,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/config.h.in b/include/config.h.in new file mode 100644 index 0000000..15cd6ad --- /dev/null +++ b/include/config.h.in @@ -0,0 +1,22 @@ +/* use chainloader code */ +#define CHAINLOADER %CHAINLOADER% + +/* CFW data dirs */ +#define PREFIX "%PREFIX%" + +#define LOCALSTATEDIR "%LOCALSTATEDIR%" +#define BINDIR "%BINDIR%" +#define SBINDIR "%SBINDIR%" +#define LIBDIR "%LIBDIR%" +#define LIBEXECDIR "%LIBEXECDIR%" +#define SHAREDIR "%DATAROOTDIR%" +#define SYSCONFDIR "%SYSCONFDIR%" + +#define LOCALEDIR SHAREDIR "/locale" + +/* Name of package */ +#define PACKAGE "%PACKAGE%" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "%VERSION%" + diff --git a/include/corbconf.h b/include/corbconf.h new file mode 100644 index 0000000..419b3f7 --- /dev/null +++ b/include/corbconf.h @@ -0,0 +1,14 @@ +#ifndef __CORBENIK_CONF +#define __CORBENIK_CONF + +#include + +#ifndef ROOT +#define ROOT "/corbenik" +#endif + +#ifndef DATA +#define DATA ROOT +#endif + +#endif diff --git a/include/firm/firm.h b/include/firm/firm.h index d6259b9..a29d703 100644 --- a/include/firm/firm.h +++ b/include/firm/firm.h @@ -1,4 +1,5 @@ #ifndef __FIRM_H +#define __FIRM_H #include diff --git a/include/config.h b/include/option.h similarity index 100% rename from include/config.h rename to include/option.h diff --git a/include/patch_format.h b/include/patch_format.h index 7d02c20..b46da7c 100644 --- a/include/patch_format.h +++ b/include/patch_format.h @@ -1,6 +1,8 @@ #ifndef __PATCH_FORMAT_H #define __PATCH_FORMAT_H +#include + // The following are titleids which are handled specially for one reason or // another. // We use titleIDs to be generic; it ensures that patches can share the same @@ -22,77 +24,60 @@ #define PATCH_DISABLED (1 << 2) // Do not allow changing this patch's status. With PATCH_MANDATORY, // this prevents disabling it. -#ifndef PATH_ROOT -#define PATH_ROOT "" // Root "storage" directory. Nothing by default (e.g. root clutter mode) -#endif - -// You can redefine this in the Makefile, if you'd like. -// Recommended names for being silly: -// Windows -// system - -//#ifndef PATH_CFW -//#define PATH_CFW "/corbenik" // CFW root directory. -//#endif - -//#ifndef PATH_DATA -//#define PATH_DATA PATH_ROOT PATH_CFW // Data "storage" directory. Nothing by default (e.g. root clutter mode) -//#endif - -#define PATH_MODULES PATH_ROOT PATH_CFW "/module" // Sysmodule location -#define PATH_PATCHES PATH_ROOT PATH_CFW "/patch" // Patch binary folder. +#define PATH_MODULES LIBDIR "/module" // Sysmodule location +#define PATH_PATCHES SBINDIR // Patch binary folder. -#define PATH_BITS PATH_ROOT PATH_CFW "/bits" // Path to misc bits we need (emunand code, reboot code, etc) +#define PATH_BITS LIBEXECDIR // Path to misc bits we need (emunand code, reboot code, etc) -#define PATH_EMUNAND_CODE PATH_BITS "/emunand.bin" // Emunand hook. -#define PATH_SCREENINIT_CODE PATH_BITS "/screeninit.bin" // Screeninit code (ARM11) -#define PATH_BACKDOOR PATH_BITS "/backdoor.bin" // svcBackdoor -#define PATH_REBOOT_HOOK PATH_BITS "/reboot_hook.bin" // Reboot hook -#define PATH_REBOOT_CODE PATH_BITS "/reboot_code.bin" // Reboot entry code +#define PATH_EMUNAND_CODE PATH_BITS "/emunand.bin" // Emunand hook. +#define PATH_SCREENINIT_CODE PATH_BITS "/screeninit.bin" // Screeninit code (ARM11) +#define PATH_BACKDOOR PATH_BITS "/backdoor.bin" // svcBackdoor +#define PATH_REBOOT_HOOK PATH_BITS "/reboot_hook.bin" // Reboot hook +#define PATH_REBOOT_CODE PATH_BITS "/reboot_code.bin" // Reboot entry code -#define PATH_CHAINS PATH_DATA "/chain" +#define PATH_CHAINS PREFIX "/boot" -#define PATH_TEMP PATH_DATA "/cache" // Files that are transient and used to speed operation -#define PATH_LOADER_CACHE PATH_TEMP "/loader" // Cached patch bytecode for loader. +#define PATH_TEMP LOCALSTATEDIR // Files that are transient and used to speed operation +#define PATH_LOADER_CACHE PATH_TEMP "/loader" // Cached patch bytecode for loader. -#define PATH_LOCEMU PATH_DATA "/locale" // Locale emulation config -#define PATH_FIRMWARES PATH_DATA "/firmware" // Firmware folder. +#define PATH_LOCEMU LOCALEDIR "/emu" // Locale emulation config +#define PATH_FIRMWARES LIBDIR "/firmware" // Firmware folder. -#define PATH_CONFIG_DIR PATH_DATA "/config" // Config file directory. -#define PATH_CONFIG PATH_CONFIG_DIR "/main.conf" // Config file. -#define PATH_CPU_CFG PATH_CONFIG_DIR "/cpu.conf" // CPU settings config +#define PATH_CONFIG_DIR SYSCONFDIR // Config file directory. +#define PATH_CONFIG PATH_CONFIG_DIR "/main.conf" // Config file. +#define PATH_CPU_CFG PATH_CONFIG_DIR "/cpu.conf" // CPU settings config -#define PATH_NATIVE_P PATH_TEMP "/p_native" -#define PATH_AGB_P PATH_TEMP "/p_agb" -#define PATH_TWL_P PATH_TEMP "/p_twl" +#define PATH_NATIVE_P PATH_TEMP "/p_native" +#define PATH_AGB_P PATH_TEMP "/p_agb" +#define PATH_TWL_P PATH_TEMP "/p_twl" -#define PATH_KEYS PATH_DATA "/keys" // Keyfiles will be loaded from this dir, and - // additionally the root if not found. +#define PATH_KEYS SHAREDIR "/keys" // Keyfiles will be loaded from this dir, and + // additionally the root if not found. -#define PATH_EXEFS PATH_DATA "/exe" // ExeFS overrides/dumps, named by titleid -#define PATH_EXEFS_TEXT PATH_EXEFS "/text" // Text segment overrides/dumps, named by titleid -#define PATH_EXEFS_RO PATH_EXEFS "/ro" // RO segment overrides/dumps, named by titleid -#define PATH_EXEFS_DATA PATH_EXEFS "/data" // Data segment overrides/dumps, named by titleid +#define PATH_EXEFS LIBDIR "/exe" // ExeFS overrides/dumps, named by titleid +#define PATH_EXEFS_TEXT PATH_EXEFS "/text" // Text segment overrides/dumps, named by titleid +#define PATH_EXEFS_RO PATH_EXEFS "/ro" // RO segment overrides/dumps, named by titleid +#define PATH_EXEFS_DATA PATH_EXEFS "/data" // Data segment overrides/dumps, named by titleid -#define PATH_NATIVE_F PATH_FIRMWARES "/native" -#define PATH_AGB_F PATH_FIRMWARES "/agb" -#define PATH_TWL_F PATH_FIRMWARES "/twl" +#define PATH_NATIVE_F PATH_FIRMWARES "/native" +#define PATH_AGB_F PATH_FIRMWARES "/agb" +#define PATH_TWL_F PATH_FIRMWARES "/twl" -#define PATH_NATIVE_CETK PATH_KEYS "/native.cetk" -#define PATH_TWL_CETK PATH_KEYS "/twl.cetk" -#define PATH_AGB_CETK PATH_KEYS "/agb.cetk" +#define PATH_NATIVE_CETK PATH_KEYS "/native.cetk" +#define PATH_TWL_CETK PATH_KEYS "/twl.cetk" +#define PATH_AGB_CETK PATH_KEYS "/agb.cetk" -#define PATH_NATIVE_FIRMKEY PATH_KEYS "/native.key" -#define PATH_TWL_FIRMKEY PATH_KEYS "/twl.key" -#define PATH_AGB_FIRMKEY PATH_KEYS "/agb.key" +#define PATH_NATIVE_FIRMKEY PATH_KEYS "/native.key" +#define PATH_TWL_FIRMKEY PATH_KEYS "/twl.key" +#define PATH_AGB_FIRMKEY PATH_KEYS "/agb.key" -#define PATH_SLOT0X11KEY96 PATH_KEYS "/11.key" +#define PATH_SLOT0X11KEY96 PATH_KEYS "/11Key96.key" #define PATH_ALT_SLOT0X11KEY96 "/slot0x11key96.bin" // Hey, your perrogative, buddy. I like cleaned up // paths. -#define PATH_BOOTLOG PATH_DATA "/boot.log" -#define PATH_LOADERLOG PATH_DATA "/loader.log" +#define PATH_BOOTLOG LOCALSTATEDIR "/boot.log" +#define PATH_LOADERLOG LOCALSTATEDIR "/loader.log" #define PATCH_FLAG_REQUIRE (1 << 0) // Force enable patch unless 'Unsafe Options' is checked. #define PATCH_FLAG_DEVMODE (1 << 1) // Require 'Developer Options' to be checked. diff --git a/include/std/unused.h b/include/std/unused.h index b66bf0e..93f287d 100644 --- a/include/std/unused.h +++ b/include/std/unused.h @@ -1 +1,6 @@ +#ifndef __UNUSED_H +#define __UNUSED_H + #define _UNUSED __attribute__((unused)) + +#endif diff --git a/patch/Makefile b/patch/Makefile index b6c1b9a..3dc0cfc 100644 --- a/patch/Makefile +++ b/patch/Makefile @@ -1,15 +1,11 @@ -out := ../$(dir_out)/$(fw_folder) - .PHONY: all -all: build install +all: build .PHONY: build build: clean $(patsubst %.pco, %.vco, $(wildcard *.pco)) .PHONY: install -install: build - mkdir -p $(out)/patch - cp *.vco $(out)/patch/ +install: %.vco: %.pco ../host/bytecode_asm.py $< $@ diff --git a/source/Makefile.am b/source/Makefile.am new file mode 100644 index 0000000..fa375a1 --- /dev/null +++ b/source/Makefile.am @@ -0,0 +1,22 @@ +include $(top_srcdir)/common.mk + +noinst_PROGRAMS = corbenik +corbenik_CFLAGS=$(AM_CFLAGS) -T$(srcdir)/linker.ld -nostartfiles +corbenik_LDFLAGS=$(AM_LDFLAGS) -lctr9 +EXTRA_DIST = linker.ld + +install: + +all-local: corbenik.bin + +clean-local: + rm -f corbenik.bin + +corbenik.bin: + $(OBJCOPY) $(OCFLAGS) -O binary corbenik corbenik.bin + +corbenikdir = $(top_srcdir)/source + +inc_dir = $(top_srcdir)/include + +corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c option.c std/fs.c std/draw.c std/memory.c std/abort.c menu.c chain.c firm/version.c firm/firm.c firm/decryptor.c firm/fcram.c interp.c input.c patcher.c display.c start.s interrupt.c screeninit.c diff --git a/source/chain.c b/source/chain.c index 10d5266..3fb99a0 100644 --- a/source/chain.c +++ b/source/chain.c @@ -1,4 +1,5 @@ -#if defined(CHAINLOADER) && CHAINLOADER == 1 +#include +#ifdef CHAINLOADER #include #include diff --git a/linker.ld b/source/linker.ld similarity index 100% rename from linker.ld rename to source/linker.ld diff --git a/source/main.c b/source/main.c index 852a30f..fc4886f 100644 --- a/source/main.c +++ b/source/main.c @@ -1,4 +1,7 @@ #include +#include +#include +#include #include @@ -17,13 +20,19 @@ main(int argc, char** argv) std_init(); int c = fmount(); - screen_mode(0); + + screen_mode(0); // Use RGBA8 mode. + clear_bg(); - load_bg_top(PATH_BITS "/top.bin"); + + load_bg_top (PATH_BITS "/top.bin"); load_bg_bottom(PATH_BITS "/bottom.bin"); // This is basically a menuhax splash (90deg rotated BGR8 pixel data) + clear_disp(TOP_SCREEN); clear_disp(BOTTOM_SCREEN); + ctr_screen_enable_backlight(CTR_SCREEN_BOTH); + set_font(PATH_BITS "/termfont.bin"); install_interrupts(); // Get some free debug info. diff --git a/source/menu.c b/source/menu.c index d0111c0..a140bd8 100644 --- a/source/menu.c +++ b/source/menu.c @@ -276,7 +276,7 @@ poweroff() ctr_system_poweroff(); } -#if defined(CHAINLOADER) && CHAINLOADER == 1 +#ifdef CHAINLOADER void chainload_menu(); #endif @@ -288,7 +288,7 @@ static struct options_s main_s[] = { { 0, "Reboot", "Reboots the console.", call_fun, (uint32_t)reset, 0 }, { 0, "Power off", "Powers off the console.", call_fun, (uint32_t)poweroff, 0 }, { 0, "Save Configuration", "Save the configuration.\nYou must do this prior to booting,\notherwise the cache will not be (re)generated..", call_fun, (uint32_t)save_config, 0 }, -#if defined(CHAINLOADER) && CHAINLOADER == 1 +#ifdef CHAINLOADER { 0, "Chainload", "Boot another ARM9 payload file.", call_fun, (uint32_t)chainload_menu, 0 }, #endif { 0, "Boot Firmware", "Generates caches, patches the firmware, and boots it.\nMake sure to 'Save Configuration' first if any options changed.", break_menu, 0, 0 }, diff --git a/source/config.c b/source/option.c similarity index 100% rename from source/config.c rename to source/option.c diff --git a/source/screeninit.c b/source/screeninit.c index 22e14ac..2348aaf 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -25,19 +25,18 @@ screen_mode(uint32_t mode) // And no, 3dbrew didn't help. Partial init seems to be a superset of what // I was attempting. -// if (PDN_GPU_CNT == 1) { + screenInitAddress[2] = 1; // Do a partial init. + + if (PDN_GPU_CNT == 1) screenInitAddress[2] = 0; // Do a full init. - screenInitAddress[3] = 0xFF; // Brightness - screenInitAddress[4] = mode; // Mode - *a11_entry = (uint32_t)screenInitAddress; + screenInitAddress[3] = 0xFF; // Brightness + screenInitAddress[4] = mode; // Mode - while (*a11_entry); + *a11_entry = (uint32_t)screenInitAddress; - // Turn on backlight - i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 1); + while (*a11_entry); - // FIXME - Time to yell at Gelex now. :| - ctr_screen_enable_backlight(CTR_SCREEN_BOTH); -// } + // Turn on backlight + i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 1); }