From 229bc3cb44185122cd16519d78cb4b3260ab3a27 Mon Sep 17 00:00:00 2001 From: shchmue Date: Wed, 15 Sep 2021 17:46:14 -0600 Subject: [PATCH] Add embedded payload version --- Makefile | 7 ++++--- bdk/utils/types.h | 8 ++++++++ loader/Makefile | 6 +++--- loader/link.ld | 1 + loader/loader.c | 6 ++++++ source/link.ld | 1 + source/main.c | 6 ++++++ 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1fdc863..efb9df7 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ include $(DEVKITARM)/base_rules ################################################################################ IPL_LOAD_ADDR := 0x40008000 +MAGIC = 0x4B434F4C #"LOCK" include ./Versions.inc ################################################################################ @@ -37,8 +38,8 @@ FFCFG_INC := '"../$(SOURCEDIR)/libs/fatfs/ffconf.h"' ################################################################################ -CUSTOMDEFINES := -DIPL_LOAD_ADDR=$(IPL_LOAD_ADDR) -CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) +CUSTOMDEFINES := -DIPL_LOAD_ADDR=$(IPL_LOAD_ADDR) -DLP_MAGIC=$(MAGIC) +CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) -DLP_RESERVED=$(LPVERSION_RSVD) CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC) #CUSTOMDEFINES += -DDEBUG @@ -51,7 +52,7 @@ CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC) WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overread -Wno-stringop-overflow ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork -CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES) +CFLAGS = $(ARCH) -O2 -g -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES) LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=IPL_LOAD_ADDR=$(IPL_LOAD_ADDR) LDRDIR := $(wildcard loader) diff --git a/bdk/utils/types.h b/bdk/utils/types.h index a56b202..b9c269e 100644 --- a/bdk/utils/types.h +++ b/bdk/utils/types.h @@ -109,6 +109,14 @@ typedef struct __attribute__((__packed__)) _boot_cfg_t static_assert(sizeof(boot_cfg_t) == 0x84, "Boot CFG size is wrong!"); +typedef struct __attribute__((__packed__)) _ipl_ver_meta_t +{ + u32 magic; + u32 version; + u16 rsvd0; + u16 rsvd1; +} ipl_ver_meta_t; + typedef struct __attribute__((__packed__)) _reloc_meta_t { u32 start; diff --git a/loader/Makefile b/loader/Makefile index d59ed08..06f46e4 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -7,7 +7,7 @@ include $(DEVKITARM)/base_rules ################################################################################ LDR_LOAD_ADDR := 0x40007000 -IPL_MAGIC := 0x43544349 #"ICTC" +MAGIC := 0x4B434F4C #"LOCK" include ../Versions.inc ################################################################################ @@ -26,8 +26,8 @@ OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ ################################################################################ -CUSTOMDEFINES := -DBL_MAGIC=$(IPL_MAGIC) -CUSTOMDEFINES += -DBL_VER_MJ=$(BLVERSION_MAJOR) -DBL_VER_MN=$(BLVERSION_MINOR) -DBL_VER_HF=$(BLVERSION_HOTFX) -DBL_RESERVED=$(BLVERSION_RSVD) +CUSTOMDEFINES := -DLP_MAGIC=$(MAGIC) +CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) -DLP_RESERVED=$(LPVERSION_RSVD) #TODO: Considering reinstating some of these when pointer warnings have been fixed. WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overflow diff --git a/loader/link.ld b/loader/link.ld index cf5cb17..ae0b3d1 100644 --- a/loader/link.ld +++ b/loader/link.ld @@ -6,6 +6,7 @@ SECTIONS { .text : { *(.text._start); KEEP(*(._boot_cfg)); + KEEP(*(._ipl_version)); *(.text*); } .data : { diff --git a/loader/loader.c b/loader/loader.c index 11e6018..b202efe 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -30,6 +30,12 @@ #define IPL_PATCHED_RELOC_SZ 0x94 boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg; +const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = { + .magic = LP_MAGIC, + .version = (LP_VER_MJ + '0') | ((LP_VER_MN + '0') << 8) | ((LP_VER_BF + '0') << 16), + .rsvd0 = 0, + .rsvd1 = 0 +}; void loader_main() { diff --git a/source/link.ld b/source/link.ld index fe49b0c..335be02 100644 --- a/source/link.ld +++ b/source/link.ld @@ -6,6 +6,7 @@ SECTIONS { .text : { *(.text._start); KEEP(*(._boot_cfg)); + KEEP(*(._ipl_version)); *(.text._irq_setup); *(.text*); } diff --git a/source/main.c b/source/main.c index a920f70..8e6e8ab 100644 --- a/source/main.c +++ b/source/main.c @@ -46,6 +46,12 @@ hekate_config h_cfg; boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg; +const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = { + .magic = LP_MAGIC, + .version = (LP_VER_MJ + '0') | ((LP_VER_MN + '0') << 8) | ((LP_VER_BF + '0') << 16), + .rsvd0 = 0, + .rsvd1 = 0 +}; volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;