dccloader/makefile

275 lines
7.3 KiB
Makefile
Raw Permalink Normal View History

2025-04-05 14:25:46 +07:00
##############################################################################################
# Start of default section
#
2026-03-22 19:22:22 +07:00
# Tools
2025-04-05 14:25:46 +07:00
TRGT = arm-none-eabi-
2025-04-19 14:08:45 +07:00
CC = $(TRGT)gcc
2025-04-05 14:25:46 +07:00
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
OBJDUMP = $(TRGT)objdump
2026-03-22 19:22:22 +07:00
PYTHON = python
2025-04-05 14:25:46 +07:00
# List all default C defines here, like -D_DEBUG=1
DDEFS =
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
# List all default directories to look for include files here
DINCDIR =
# List the default directory to look for the libraries here
DLIBDIR =
# List all default libraries here
DLIBS =
#
# End of default section
##############################################################################################
##############################################################################################
# Start of user section
#
# Define project name here
PROJECT = dumpnow
2026-03-22 19:22:22 +07:00
# Auto LD script stuff
LOADER_LOAD_START = 0x00000000
LOADER_LOAD_SIZE_KB = 512
2025-04-05 14:25:46 +07:00
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
2026-03-22 19:22:22 +07:00
# CPU type
MCU = arm7tdmi
# Target platform
PLATFORM = default
# Storage devices for the target platform
LOADER_DEVICES = default
# Define optimisation level here
OPT = -O2
# Dependencies
2025-04-14 20:16:43 +07:00
DEVICES = flash/mmap/mmap.c
CONTROLLERS =
ADD_DEPS =
2026-03-22 19:22:22 +07:00
# Optional dependencies
2025-04-14 20:16:43 +07:00
ifeq ($(LZ4), 1)
2026-07-21 19:58:13 +07:00
ADD_DEPS += extdeps/lz4/lz4_fs.c
2025-04-14 20:16:43 +07:00
DDEFS += -DHAVE_LZ4=1
endif
2026-07-21 19:58:13 +07:00
ifeq ($(ZLIB), 1)
ADD_DEPS += extdeps/miniz/miniz.c
DDEFS += -DHAVE_ZLIB=1
endif
2026-03-22 19:22:22 +07:00
# Storage devices
2025-04-14 20:16:43 +07:00
ifeq ($(CFI), 1)
DEVICES += flash/cfi/cfi.c
endif
ifdef NAND_CONTROLLER
DEVICES += flash/nand/nand.c
CONTROLLERS += flash/nand/controller/$(NAND_CONTROLLER).c
endif
ifdef ONENAND_CONTROLLER
DEVICES += flash/onenand/onenand.c
CONTROLLERS += flash/onenand/controller/$(ONENAND_CONTROLLER).c
endif
ifdef SUPERAND_CONTROLLER
DEVICES += flash/superand/superand.c
CONTROLLERS += flash/superand/controller/$(SUPERAND_CONTROLLER).c
endif
2026-03-22 19:22:22 +07:00
# Loader configuration
2025-04-19 11:15:42 +07:00
ifeq ($(MCU), xscale)
DDEFS += -DCPU_XSCALE
DADEFS += -DCPU_XSCALE
endif
2025-05-30 19:40:25 +07:00
ifeq ($(ICACHE), 1)
2025-04-22 21:28:22 +07:00
DADEFS += -DUSE_ICACHE=1
endif
2025-04-26 16:45:19 +07:00
ifeq ($(BP_LOADER), 1)
DADEFS += -DUSE_BREAKPOINTS=1
DDEFS += -DUSE_BREAKPOINTS=1
endif
2025-05-24 21:25:11 +07:00
ifdef BUFFER_SIZE
DDEFS += -DDCC_BUFFER_SIZE=${BUFFER_SIZE}
else
2026-03-22 11:47:18 +07:00
DDEFS += -DDCC_BUFFER_SIZE=0x4000
2025-05-24 21:25:11 +07:00
endif
2025-06-01 06:59:50 +07:00
ifeq ($(NO_COMPRESS), 1)
DDEFS += -DDISABLE_COMPRESS=1
endif
2026-03-22 16:32:06 +07:00
ifeq ($(PIC), 1)
DADEFS += -DUSE_PIC
ADD_DEPS += dcc/pic.c
2025-05-26 22:25:45 +07:00
endif
2026-07-21 22:35:01 +07:00
ifeq ($(DEBUG_LOG), 1)
DDEFS += -DDEBUG_PORT=1
endif
2026-07-24 22:27:43 +07:00
ifeq ($(TCC_EABI), 1)
ADD_DEPS += dcc/arm_eabi_tcc.c
endif
2026-03-22 19:22:22 +07:00
# List C source files here
SRC = main.c dcc/memory.c dcc/dn_dcc_proto.c dcc/bitutils.c dcc/lwprintf.c plat/$(PLATFORM).c devices/$(LOADER_DEVICES).c $(DEVICES) $(CONTROLLERS) $(ADD_DEPS)
2025-04-05 14:25:46 +07:00
# List ASM source files here
ASRC = crt.s
# List all user directories here
UINCDIR =
# List the user directory to look for the libraries here
ULIBDIR =
# List all user libraries here
ULIBS =
#
# End of user defines
##############################################################################################
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
2025-05-31 10:58:14 +07:00
DEFS = $(DDEFS) $(UDEFS) -DCDEFS="\"FLAGS=$(DDEFS) $(UDEFS) CPU=$(MCU) PLATFORM=$(PLATFORM) LOADER_DEVICES=$(LOADER_DEVICES) DEVICES=$(DEVICES) CONTROLLERS=$(CONTROLLERS)\""
2026-08-05 22:31:57 +07:00
ADEFS = $(DADEFS) $(UADEFS) -DADEFS="\"FLAGS=$(DADEFS) $(UADEFS) CPU=$(MCU)\"" -DLOADER_MIN_RAM=$(shell echo ${LOADER_LOAD_SIZE_KB}*1024 | bc)
2026-03-22 19:22:22 +07:00
OBJS = $(ASRC:%.s=.out/%.o) $(SRC:%.c=.out/%.o)
2025-04-05 14:25:46 +07:00
LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)
2026-03-22 16:32:06 +07:00
CC_PIC =
AS_PIC =
2025-04-05 14:25:46 +07:00
2025-05-31 22:04:02 +07:00
ifeq ($(BIG_ENDIAN), 1)
MCFLAGS += -mbig-endian -mbe32
endif
2026-03-22 16:32:06 +07:00
ifeq ($(PIC), 1)
CC_PIC += -fPIC -mpic-register=r9 -mpic-data-is-text-relative -msingle-pic-base -fPIE
AS_PIC += -fPIC -mpic-register=r9 -mpic-data-is-text-relative -msingle-pic-base -fPIE -pie
endif
2025-04-05 14:25:46 +07:00
2026-07-24 22:27:43 +07:00
ifeq ($(TCC_EABI), 1)
MCFLAGS += -nostdlib
endif
2026-03-22 19:36:24 +07:00
ASFLAGS = $(MCFLAGS) $(CC_PIC) -g -gdwarf-2 -Wa,-amhls=$(@:.o=.lst) $(ADEFS) -c
2026-03-22 16:32:06 +07:00
#CPFLAGS = $(MCFLAGS) $(CC_PIC) -I . $(OPT) -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS) -c
2026-03-22 19:36:24 +07:00
CPFLAGS = $(MCFLAGS) $(CC_PIC) -I . $(OPT) -g -gdwarf-2 -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(@:.o=.lst) $(DEFS) -c
2026-03-22 16:32:06 +07:00
LDFLAGS = $(MCFLAGS) $(AS_PIC) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=build/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
2025-04-05 14:25:46 +07:00
# Generate dependency information
#CPFLAGS += -MD -MP -MF .dep/$(@F).d
#
# makefile rules
#
2025-05-26 07:44:09 +07:00
ifeq ($(PLATFORM), default)
2025-12-30 14:01:09 +07:00
$(warning Building without platform specific routines, specify PLATFORM to change that)
2025-05-26 07:44:09 +07:00
endif
2026-03-22 19:22:22 +07:00
ifndef LDSCRIPT
2026-03-22 19:33:22 +07:00
LDSCRIPT = .out/linker/script.ld
all: ldscript $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst
ldscript:
$(info Generating linker script with offset: $(LOADER_LOAD_START); size: $(LOADER_LOAD_SIZE_KB)k)
@mkdir -p .out/linker
$(PYTHON) "utils/substitute.py" linker/linker.ld.tl .out/linker/script.ld $(LOADER_LOAD_START) $(LOADER_LOAD_SIZE_KB)
2026-03-22 19:22:22 +07:00
else
2025-04-05 14:25:46 +07:00
all: $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst
2026-03-22 19:22:22 +07:00
endif
.out/%.o : %.c
@mkdir -p $(@D)
2025-04-05 14:25:46 +07:00
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
2026-03-22 19:22:22 +07:00
.out/%.o : %.s
@mkdir -p $(@D)
2025-04-05 14:25:46 +07:00
$(AS) -c $(ASFLAGS) $< -o $@
%elf: $(OBJS)
2026-03-22 19:38:15 +07:00
@mkdir -p build
2025-04-25 16:40:37 +07:00
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o build/$@
2025-04-05 14:25:46 +07:00
%hex: %elf
2025-04-25 16:40:37 +07:00
$(HEX) build/$< build/$@
2025-04-05 14:25:46 +07:00
%bin: %elf
2025-04-25 16:40:37 +07:00
$(BIN) build/$< build/$@
2025-04-05 14:25:46 +07:00
%.lst: %.elf
2025-04-25 16:40:37 +07:00
$(OBJDUMP) -h -S build/$< > build/$@
2025-04-05 14:25:46 +07:00
clean:
2025-04-25 16:43:06 +07:00
-rm -f build/$(PROJECT).elf
-rm -f build/$(PROJECT).map
-rm -f build/$(PROJECT).hex
-rm -f build/$(PROJECT).bin
-rm -f build/$(PROJECT).lst
2026-03-22 19:33:22 +07:00
-rm -fR .out
2025-04-05 14:25:46 +07:00
-rm -fR .dep
2025-04-14 20:16:43 +07:00
help:
2025-05-26 07:44:09 +07:00
ifeq ($(OS),Windows_NT)
@echo > NUL
else
@echo > /dev/null
endif
$(info Dumpnow DCC Loader)
2025-12-30 14:01:09 +07:00
$(info Optional libraries:)
$(info $(NULL) LZ4=1 = Enable LZ4 Compression)
2026-07-21 19:58:13 +07:00
$(info $(NULL) ZLIB=1 = Enable ZLIB Compression)
2025-12-30 14:01:09 +07:00
$(info Target configuration:)
$(info $(NULL) PLATFORM=(name) Select chipset platform)
$(info $(NULL) MCU=(MCU) = Select CPU architecture)
$(info $(NULL) ICACHE=1 = Use instruction cache (ARM9 and later))
$(info $(NULL) BP_LOADER=1 = If the chipset have broken DCC Support, compiling as Breakpoint-based loader might help)
2026-03-22 19:22:22 +07:00
$(info $(NULL) BUFFER_SIZE=(Buffer Size) = DCC Buffer Size (Default: 0x4000))
2025-12-30 14:01:09 +07:00
$(info $(NULL) PROJECT=(name) = Output name)
$(info $(NULL) LDSCRIPT=(ld) = Linker script)
$(info $(NULL) NO_COMPRESS=1 = Disable RLE compression, used if using with RIFF says failed to unpack received data.)
$(info $(NULL) BIG_ENDIAN=1 = Big endian format)
2026-03-22 16:32:06 +07:00
$(info $(NULL) PIC=1 = Use PIC code)
2026-03-22 19:22:22 +07:00
$(info $(NULL) LOADER_LOAD_START=(LOAD_OFFSET_IN_HEX) = With LDSCRIPT unset, set loader start offset)
$(info $(NULL) LOADER_LOAD_SIZE_KB=(LOAD_SIZE_IN_KB) = With LDSCRIPT unset, set RAM size for the loader)
2026-07-21 22:35:01 +07:00
$(info $(NULL) DEBUG_LOG=1 = Enable debug logs (only useful during development))
2026-07-24 22:27:43 +07:00
$(info $(NULL) TCC_EABI=1 = Use ARM EABI from TCC)
2025-12-30 14:01:09 +07:00
$(info Flash devices:)
$(info $(NULL) CFI=1 = Enable CFI interface)
$(info $(NULL) NAND_CONTROLLER=(name) = Enable NAND controller)
$(info $(NULL) ONENAND_CONTROLLER=(name) = Enable OneNAND controller)
$(info $(NULL) SUPERAND_CONTROLLER=(name) = Enable SuperAND controller)
$(info $(NULL) LOADER_DEVICES=(name) = Select which memory combination to use)
2025-04-14 20:16:43 +07:00
2025-04-05 14:25:46 +07:00
#
# Include the dependency files, should be the last of the makefile
#
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# *** EOF ***