]> Chaos Git - corbenik/corbenik.git/commitdiff
Port corbenik to autotools
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 18 Jul 2016 03:37:19 +0000 (23:37 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 18 Jul 2016 16:26:42 +0000 (12:26 -0400)
35 files changed:
.gitignore
Makefile [deleted file]
Makefile.am
autogen.sh [new file with mode: 0755]
common.mk
configure.ac
contrib/Makefile
external/Makefile [deleted file]
external/Makefile.am [new file with mode: 0644]
external/bits/Makefile
external/loader/Makefile
external/loader/source/interp.c
external/loader/source/logger.c
external/loader/source/memory.c
external/loader/source/patcher.c
external/screeninit/Makefile
external/screeninit/source/main.c
host/Makefile [new file with mode: 0644]
host/copy.sh
include/Makefile.am [new file with mode: 0644]
include/common.h
include/config.h.in [new file with mode: 0644]
include/corbconf.h [new file with mode: 0644]
include/firm/firm.h
include/option.h [moved from include/config.h with 100% similarity]
include/patch_format.h
include/std/unused.h
patch/Makefile
source/Makefile.am [new file with mode: 0644]
source/chain.c
source/linker.ld [moved from linker.ld with 100% similarity]
source/main.c
source/menu.c
source/option.c [moved from source/config.c with 100% similarity]
source/screeninit.c

index 5040b3f62720dad83f9037414d9706bab25d6597..45056366286fcebaf04ec4535e644021d8249f5c 100644 (file)
@@ -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 (file)
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)
index 4491836e66fde1b44148b4b4f0fb8b9deb19ce64..e8b7e9477df8c4bebe39e49fcca06998fe4b6831 100644 (file)
@@ -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 (executable)
index 0000000..fad27d8
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+mkdir -p m4
+autoreconf -fi
index 36cc9bcc28ec877cfc7f56512bb0e4d5c5b6a08a..4a8028ec900770f0a5ec2745dbb8ba7db047821e 100644 (file)
--- 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
index e64afe5492474052374f297592e2bb7e67ad4b64..5af4adcef0cbb02bcce4a457dbb9cca3b4c61825 100644 (file)
@@ -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
index 9ed7fba958be8a0d84aade1adb4f023048dea47d..3dc0cfc5d51b50422929e3b5f09b37d0914466f3 100644 (file)
@@ -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 (file)
index 5cac09e..0000000
+++ /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 (file)
index 0000000..a88f86e
--- /dev/null
@@ -0,0 +1,3 @@
+SUBDIRS = libctr9 loader bits screeninit
+
+install:
index a7e39f113947c89ec6280a1ffb61391e041ea86a..814e965d6c60055241d2449781f09ce598831c34 100644 (file)
@@ -17,3 +17,6 @@ all: $(OBJECTS)
 .PHONY: clean
 clean:
        rm -f *.bin *.elf *.o
+
+.PHONY: install
+install:
index c014baf3b94ae37a77693851c482b317e245e7d0..81f1a7fe461ca0bf6462041d4ba336d9022ae32c 100644 (file)
@@ -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:
index 59aa1f3fcb903ac9ee55cf1ba65bd515a7d4f451..5344affdbf4047d4a18747eb6ae4f17c146972d7 100644 (file)
@@ -13,8 +13,8 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "../../../source/config.h"
-#include "../../../source/patch_format.h"
+#include <option.h>
+#include <patch_format.h>
 
 // Patches must consist of fewer bytes than this.
 // 16K is reasonable, IMO, and doesn't cause issues.
index 76a883617b8243eb97cd581f4bb4b55271f17a63..41c41104e3ca5ebbb9e5216fec1a964462cdab98 100644 (file)
@@ -8,8 +8,8 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "../../../source/config.h"
-#include "../../../source/patch_format.h"
+#include <option.h>
+#include <patch_format.h>
 
 Handle log_file_hdl;
 int logger_is_initd = 0;
index 82c07f96cce0b7c50bfd73b37474e59ab019569e..ab3d93159caf2b42c63602c6f85665d1b6f66ede 100644 (file)
@@ -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 <option.h>
+#include <patch_format.h>
 
 // Quick Search algorithm, adapted from
 // http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
index 9a519ec700c67b54a372b2096dfa635c54687cc5..9950b278ec304cd6a371f41d8d6799dee18132c0 100644 (file)
@@ -6,15 +6,15 @@
 #include "internal.h"
 #include "memory.h"
 #include "logger.h"
-#include "../../../source/patch_format.h"
-#include "../../../source/std/unused.h"
+#include <patch_format.h>
+#include <std/unused.h>
 #include "interp.h"
 
 #ifndef PATH_MAX
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "../../../source/config.h"
+#include <option.h>
 
 #define TEXT_PATH PATH_EXEFS_TEXT "/0000000000000000"
 #define DATA_PATH PATH_EXEFS_DATA "/0000000000000000"
index fdb5d25090b63756e3fc2e09e94f73ee8a2a2570..b986b31ca0522aa530188d26a2c1ed275fd9e04f 100755 (executable)
@@ -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:
index 932cb7e62c77511c51aeefa0fe3e6bcc12a3acea..d4f3898803601257606962bd5ca7339b9ebba64f 100755 (executable)
@@ -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 (file)
index 0000000..1f10798
--- /dev/null
@@ -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
index 38d6fa91e63dc26ef290289174156525fcd043fd..4295a173220d3b40c24d3336cea08a365fdcf5a8 100755 (executable)
@@ -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 (file)
index 0000000..7fd9bb1
--- /dev/null
@@ -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
index c8a46a529829703b431e52efbb240e2b0160568c..d120c7d9ed49fd9aa53f27039353a8f870f46fa2 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __COMMON_H
 #define __COMMON_H
 
+#include <corbconf.h>
+
 #include <std/unused.h>
 #include <std/abort.h>
 
@@ -19,7 +21,7 @@
 
 #include <screeninit.h>
 #include <interrupt.h>
-#include <config.h>
+#include <option.h>
 #include <input.h>
 #include <interp.h>
 #include <patcher.h>
diff --git a/include/config.h.in b/include/config.h.in
new file mode 100644 (file)
index 0000000..15cd6ad
--- /dev/null
@@ -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 (file)
index 0000000..419b3f7
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __CORBENIK_CONF
+#define __CORBENIK_CONF
+
+#include <config.h>
+
+#ifndef ROOT
+#define ROOT "/corbenik"
+#endif
+
+#ifndef DATA
+#define DATA ROOT
+#endif
+
+#endif
index d6259b9d68b7bf504a4fc0c8baa5a3bb2861f8a6..a29d7030fd9c22e028d9ca960627cb18aaaade15 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef __FIRM_H
+#define __FIRM_H
 
 #include <stdint.h>
 
similarity index 100%
rename from include/config.h
rename to include/option.h
index 7d02c206eb9d190aef6c68f038d806c4c225136a..b46da7c6fde54d3d75684550d6bec27d9f42d18d 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __PATCH_FORMAT_H
 #define __PATCH_FORMAT_H
 
+#include <corbconf.h>
+
 // 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
 #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.
index b66bf0ea508e4363e6af6be2aebfc15c330fff6a..93f287d565b7dbfa39a9cf861525aa1877cbed67 100644 (file)
@@ -1 +1,6 @@
+#ifndef __UNUSED_H
+#define __UNUSED_H
+
 #define _UNUSED __attribute__((unused))
+
+#endif
index b6c1b9a906d78aef94e6cad1c16526ce1d7d6f23..3dc0cfc5d51b50422929e3b5f09b37d0914466f3 100644 (file)
@@ -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 (file)
index 0000000..fa375a1
--- /dev/null
@@ -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
index 10d52665bdf2b708c944766860721d2919ba1350..3fb99a0cf0deeefebd372024fecb525dafdce05b 100644 (file)
@@ -1,4 +1,5 @@
-#if defined(CHAINLOADER) && CHAINLOADER == 1
+#include <corbconf.h>
+#ifdef CHAINLOADER
 
 #include <common.h>
 #include <screeninit.h>
similarity index 100%
rename from linker.ld
rename to source/linker.ld
index 852a30f9802d9a6dd05bbb9b80784f19034d329d..fc4886fe5cfd21e9d9520bae4fefc74226e714c0 100644 (file)
@@ -1,4 +1,7 @@
 #include <ctr9/ctr_hid.h>
+#include <ctr9/io.h>
+#include <ctr9/ctr_screen.h>
+#include <ctr9/i2c.h>
 
 #include <common.h>
 
@@ -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.
index d0111c0ba865f7341d9d0446e1d4f86582af2a1a..a140bd89ff578bbd8c27080614d83ca870d39517 100644 (file)
@@ -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 },
similarity index 100%
rename from source/config.c
rename to source/option.c
index 22e14ac4f3653a084486a59a6f8edd30a7785c39..2348aafcdda8cbc2b6a40330ac46a138d14ed979 100644 (file)
@@ -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);
 }