1
0
Fork 0
mirror of https://github.com/s1204IT/Lockpick_RCM.git synced 2024-11-25 03:02:02 +00:00
Lockpick_RCM/Makefile

131 lines
4.7 KiB
Makefile
Raw Permalink Normal View History

rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
2019-03-04 23:05:42 +00:00
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/base_rules
2019-05-11 22:51:44 +01:00
################################################################################
2019-03-04 23:05:42 +00:00
2021-05-12 23:47:06 +01:00
IPL_LOAD_ADDR := 0x40008000
2021-09-16 00:46:14 +01:00
MAGIC = 0x4B434F4C #"LOCK"
2021-05-12 23:47:06 +01:00
include ./Versions.inc
2019-04-19 18:03:11 +01:00
2019-05-11 22:51:44 +01:00
################################################################################
TARGET := Lockpick_RCM
BUILDDIR := build
OUTPUTDIR := output
SOURCEDIR := source
2020-06-26 21:17:06 +01:00
BDKDIR := bdk
BDKINC := -I./$(BDKDIR)
KEYGENDIR := keygen
KEYGEN := tsec_keygen
KEYGENH := tsec_keygen.h
2020-06-26 21:17:06 +01:00
VPATH = $(dir ./$(SOURCEDIR)/) $(dir $(wildcard ./$(SOURCEDIR)/*/)) $(dir $(wildcard ./$(SOURCEDIR)/*/*/))
VPATH += $(dir $(wildcard ./$(BDKDIR)/)) $(dir $(wildcard ./$(BDKDIR)/*/)) $(dir $(wildcard ./$(BDKDIR)/*/*/))
OBJS = $(patsubst $(SOURCEDIR)/%.S, $(BUILDDIR)/$(TARGET)/%.o, \
$(patsubst $(SOURCEDIR)/%.c, $(BUILDDIR)/$(TARGET)/%.o, \
$(call rwildcard, $(SOURCEDIR), *.S *.c)))
2020-06-26 21:17:06 +01:00
OBJS += $(patsubst $(BDKDIR)/%.S, $(BUILDDIR)/$(TARGET)/%.o, \
$(patsubst $(BDKDIR)/%.c, $(BUILDDIR)/$(TARGET)/%.o, \
$(call rwildcard, $(BDKDIR), *.S *.c)))
GFX_INC := '"../$(SOURCEDIR)/gfx/gfx.h"'
FFCFG_INC := '"../$(SOURCEDIR)/libs/fatfs/ffconf.h"'
2019-03-04 23:05:42 +00:00
2019-05-11 22:51:44 +01:00
################################################################################
2021-09-16 00:46:14 +01:00
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)
2020-06-26 21:17:06 +01:00
CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC)
2019-03-04 23:05:42 +00:00
#CUSTOMDEFINES += -DDEBUG
2021-05-12 23:47:06 +01:00
# UART Logging: Max baudrate 12.5M.
# DEBUG_UART_PORT - 0: UART_A, 1: UART_B, 2: UART_C.
#CUSTOMDEFINES += -DDEBUG_UART_BAUDRATE=115200 -DDEBUG_UART_INVERT=0 -DDEBUG_UART_PORT=0
2021-05-12 22:38:34 +01:00
#TODO: Considering reinstating some of these when pointer warnings have been fixed.
WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overread -Wno-stringop-overflow
2019-10-22 18:22:55 +01:00
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
2021-09-16 00:46:14 +01:00
CFLAGS = $(ARCH) -O2 -g -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES)
2019-03-04 23:05:42 +00:00
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=IPL_LOAD_ADDR=$(IPL_LOAD_ADDR)
2021-05-12 23:47:06 +01:00
LDRDIR := $(wildcard loader)
TOOLSLZ := $(wildcard tools/lz)
TOOLSB2C := $(wildcard tools/bin2c)
TOOLS := $(TOOLSLZ) $(TOOLSB2C)
2019-05-11 22:51:44 +01:00
################################################################################
2021-05-12 23:47:06 +01:00
.PHONY: all clean $(LDRDIR) $(TOOLS)
2019-03-04 23:05:42 +00:00
2021-05-12 23:47:06 +01:00
all: $(OUTPUTDIR)/$(TARGET).bin $(LDRDIR)
@echo "--------------------------------------"
@echo -n "Uncompr size: "
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(TARGET)_unc.bin))
@echo $(BIN_SIZE)" Bytes"
@echo "Uncompr Max: 140288 Bytes + 3 KiB BSS"
@if [ ${BIN_SIZE} -gt 140288 ]; then echo "\e[1;33mUncompr size exceeds limit!\e[0m"; fi
@echo -n "Payload size: "
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(TARGET).bin))
2021-05-12 23:47:06 +01:00
@echo $(BIN_SIZE)" Bytes"
@echo "Payload Max: 126296 Bytes"
@if [ ${BIN_SIZE} -gt 126296 ]; then echo "\e[1;33mPayload size exceeds limit!\e[0m"; fi
2021-05-12 23:47:06 +01:00
@echo "--------------------------------------"
2019-03-04 23:05:42 +00:00
2021-05-12 23:47:06 +01:00
clean: $(TOOLS)
2019-05-11 22:51:44 +01:00
@rm -rf $(BUILDDIR)
@rm -rf $(OUTPUTDIR)
2019-03-04 23:05:42 +00:00
2021-05-12 23:47:06 +01:00
$(LDRDIR): $(OUTPUTDIR)/$(TARGET).bin
@$(TOOLSLZ)/lz77 $(OUTPUTDIR)/$(TARGET).bin
mv $(OUTPUTDIR)/$(TARGET).bin $(OUTPUTDIR)/$(TARGET)_unc.bin
@mv $(OUTPUTDIR)/$(TARGET).bin.00.lz payload_00
@mv $(OUTPUTDIR)/$(TARGET).bin.01.lz payload_01
@$(TOOLSB2C)/bin2c payload_00 > $(LDRDIR)/payload_00.h
@$(TOOLSB2C)/bin2c payload_01 > $(LDRDIR)/payload_01.h
@rm payload_00
@rm payload_01
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS) -$(MAKEFLAGS) PAYLOAD_NAME=$(TARGET)
$(TOOLS):
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS) -$(MAKEFLAGS)
$(OUTPUTDIR)/$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf $(TOOLS)
@mkdir -p "$(@D)"
$(OBJCOPY) -S -O binary $< $@
2019-03-04 23:05:42 +00:00
2019-05-11 22:51:44 +01:00
$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS)
2021-05-12 23:47:06 +01:00
@$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@
@echo "Lockpick_RCM was built with the following flags:\nCFLAGS: "$(CFLAGS)"\nLDFLAGS: "$(LDFLAGS)
2019-03-04 23:05:42 +00:00
$(OBJS): | $(KEYGENDIR)
$(KEYGENDIR): $(TOOLS)
@cd $(KEYGENDIR) && ../$(TOOLSB2C)/bin2c $(KEYGEN) > $(KEYGENH)
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.c
@mkdir -p "$(@D)"
2021-05-12 23:47:06 +01:00
@echo Building $@
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
2019-03-04 23:05:42 +00:00
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.S
@mkdir -p "$(@D)"
2021-05-12 23:47:06 +01:00
@echo Building $@
@$(CC) $(CFLAGS) -c $< -o $@
2020-06-26 21:17:06 +01:00
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.c
@mkdir -p "$(@D)"
2021-05-12 23:47:06 +01:00
@echo Building $@
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
2020-06-26 21:17:06 +01:00
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.S
@mkdir -p "$(@D)"
2021-05-12 23:47:06 +01:00
@echo Building $@
@$(CC) $(CFLAGS) -c $< -o $@