2022-03-09 11:47:42 +00:00
|
|
|
RUSTARCH ?= aarch64-unknown-none-softfloat
|
2021-11-08 04:52:59 +00:00
|
|
|
|
|
|
|
ifeq ($(shell uname),Darwin)
|
|
|
|
USE_CLANG ?= 1
|
|
|
|
$(info INFO: Building on Darwin)
|
|
|
|
ifeq ($(shell uname -p),arm)
|
|
|
|
TOOLCHAIN ?= /opt/homebrew/opt/llvm/bin/
|
|
|
|
else
|
|
|
|
TOOLCHAIN ?= /usr/local/opt/llvm/bin/
|
|
|
|
endif
|
|
|
|
$(info INFO: Toolchain path: $(TOOLCHAIN))
|
|
|
|
endif
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-08-29 08:02:00 +00:00
|
|
|
ifeq ($(shell uname -m),aarch64)
|
|
|
|
ARCH ?=
|
|
|
|
else
|
|
|
|
ARCH ?= aarch64-linux-gnu-
|
|
|
|
endif
|
|
|
|
|
2021-03-07 16:31:14 +00:00
|
|
|
ifeq ($(USE_CLANG),1)
|
2021-11-08 04:52:59 +00:00
|
|
|
CC := $(TOOLCHAIN)clang --target=$(ARCH)
|
|
|
|
AS := $(TOOLCHAIN)clang --target=$(ARCH)
|
|
|
|
LD := $(TOOLCHAIN)ld.lld
|
|
|
|
OBJCOPY := $(TOOLCHAIN)llvm-objcopy
|
|
|
|
CLANG_FORMAT := $(TOOLCHAIN)clang-format
|
|
|
|
EXTRA_CFLAGS ?=
|
2021-03-07 16:31:14 +00:00
|
|
|
else
|
2021-11-08 04:52:59 +00:00
|
|
|
CC := $(TOOLCHAIN)$(ARCH)gcc
|
|
|
|
AS := $(TOOLCHAIN)$(ARCH)gcc
|
|
|
|
LD := $(TOOLCHAIN)$(ARCH)ld
|
|
|
|
OBJCOPY := $(TOOLCHAIN)$(ARCH)objcopy
|
|
|
|
CLANG_FORMAT := clang-format
|
|
|
|
EXTRA_CFLAGS ?= -Wstack-usage=1024
|
2021-03-07 16:31:14 +00:00
|
|
|
endif
|
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
BASE_CFLAGS := -O2 -Wall -g -Wundef -Werror=strict-prototypes -fno-common -fno-PIE \
|
2021-01-14 11:10:42 +00:00
|
|
|
-Werror=implicit-function-declaration -Werror=implicit-int \
|
2021-02-06 06:08:15 +00:00
|
|
|
-Wsign-compare -Wunused-parameter -Wno-multichar \
|
2021-01-16 19:40:46 +00:00
|
|
|
-ffreestanding -fpic -ffunction-sections -fdata-sections \
|
2021-03-07 16:31:14 +00:00
|
|
|
-nostdinc -isystem $(shell $(CC) -print-file-name=include) -isystem sysinc \
|
2022-11-30 08:28:25 +00:00
|
|
|
-fno-stack-protector -mstrict-align -march=armv8.2-a \
|
2021-11-08 04:52:59 +00:00
|
|
|
$(EXTRA_CFLAGS)
|
2021-01-14 11:10:42 +00:00
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
CFLAGS := $(BASE_CFLAGS) -mgeneral-regs-only
|
|
|
|
|
2022-03-09 11:47:42 +00:00
|
|
|
CFG :=
|
2022-02-21 07:07:01 +00:00
|
|
|
ifeq ($(RELEASE),1)
|
2022-03-09 13:15:09 +00:00
|
|
|
CFG += RELEASE
|
2022-03-09 11:47:42 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Required for no_std + alloc for now
|
|
|
|
export RUSTUP_TOOLCHAIN=nightly
|
|
|
|
RUST_LIB := librust.a
|
|
|
|
RUST_LIBS :=
|
|
|
|
ifeq ($(CHAINLOADING),1)
|
2022-03-09 13:15:09 +00:00
|
|
|
CFG += CHAINLOADING
|
2022-03-09 11:47:42 +00:00
|
|
|
RUST_LIBS += $(RUST_LIB)
|
2022-02-21 07:07:01 +00:00
|
|
|
endif
|
|
|
|
|
2021-12-17 12:31:36 +00:00
|
|
|
LDFLAGS := -EL -maarch64elf --no-undefined -X -Bsymbolic \
|
2021-09-21 06:36:56 +00:00
|
|
|
-z notext --no-apply-dynamic-relocs --orphan-handling=warn \
|
2021-01-14 11:10:42 +00:00
|
|
|
-z nocopyreloc --gc-sections -pie
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-01-23 13:25:34 +00:00
|
|
|
MINILZLIB_OBJECTS := $(patsubst %,minilzlib/%, \
|
|
|
|
dictbuf.o inputbuf.o lzma2dec.o lzmadec.o rangedec.o xzstream.o)
|
|
|
|
|
|
|
|
TINF_OBJECTS := $(patsubst %,tinf/%, \
|
|
|
|
adler32.o crc32.o tinfgzip.o tinflate.o tinfzlib.o)
|
|
|
|
|
2021-01-29 06:19:34 +00:00
|
|
|
DLMALLOC_OBJECTS := dlmalloc/malloc.o
|
|
|
|
|
2021-01-29 10:54:39 +00:00
|
|
|
LIBFDT_OBJECTS := $(patsubst %,libfdt/%, \
|
2021-03-07 16:31:14 +00:00
|
|
|
fdt_addresses.o fdt_empty_tree.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o \
|
2021-01-29 10:54:39 +00:00
|
|
|
fdt_wip.o fdt.o)
|
|
|
|
|
2021-04-14 08:51:41 +00:00
|
|
|
OBJECTS := \
|
|
|
|
adt.o \
|
2022-01-16 19:29:16 +00:00
|
|
|
afk.o \
|
2021-08-23 08:01:33 +00:00
|
|
|
aic.o \
|
2022-01-10 17:16:55 +00:00
|
|
|
asc.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
bootlogo_128.o bootlogo_256.o \
|
2022-03-09 11:44:33 +00:00
|
|
|
chainload.o \
|
|
|
|
chainload_asm.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
chickens.o \
|
2022-06-27 09:15:38 +00:00
|
|
|
chickens_avalanche.o \
|
|
|
|
chickens_blizzard.o \
|
2022-06-27 09:15:12 +00:00
|
|
|
chickens_firestorm.o \
|
|
|
|
chickens_icestorm.o \
|
2022-03-07 14:57:48 +00:00
|
|
|
clk.o \
|
2021-10-18 08:34:40 +00:00
|
|
|
cpufreq.o \
|
2022-07-03 14:27:30 +00:00
|
|
|
dapf.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
dart.o \
|
2022-01-16 19:29:36 +00:00
|
|
|
dcp.o \
|
|
|
|
dcp_iboot.o \
|
2022-10-11 20:20:41 +00:00
|
|
|
devicetree.o \
|
2022-01-16 19:29:51 +00:00
|
|
|
display.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
exception.o exception_asm.o \
|
2021-02-12 21:27:39 +00:00
|
|
|
fb.o font.o font_retina.o \
|
2022-12-04 06:40:09 +00:00
|
|
|
firmware.o \
|
2021-05-08 12:54:07 +00:00
|
|
|
gxf.o gxf_asm.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
heapblock.o \
|
2021-06-05 20:05:17 +00:00
|
|
|
hv.o hv_vm.o hv_exc.o hv_vuart.o hv_wdt.o hv_asm.o hv_aic.o \
|
2021-05-29 12:34:41 +00:00
|
|
|
i2c.o \
|
2021-04-15 13:47:33 +00:00
|
|
|
iodev.o \
|
2022-01-10 17:16:57 +00:00
|
|
|
iova.o \
|
2022-11-30 08:31:00 +00:00
|
|
|
kboot.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
main.o \
|
2021-11-16 12:09:48 +00:00
|
|
|
mcc.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
memory.o memory_asm.o \
|
2022-01-10 17:16:58 +00:00
|
|
|
nvme.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
payload.o \
|
2021-04-11 13:44:23 +00:00
|
|
|
pcie.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
pmgr.o \
|
|
|
|
proxy.o \
|
2021-03-13 19:16:21 +00:00
|
|
|
ringbuffer.o \
|
2022-01-10 17:16:57 +00:00
|
|
|
rtkit.o \
|
2022-01-10 17:16:56 +00:00
|
|
|
sart.o \
|
2022-03-18 15:59:51 +00:00
|
|
|
sep.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
smp.o \
|
|
|
|
start.o \
|
|
|
|
startup.o \
|
|
|
|
string.o \
|
2022-09-26 21:01:36 +00:00
|
|
|
tunables.o tunables_static.o \
|
2021-05-29 12:35:00 +00:00
|
|
|
tps6598x.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
uart.o \
|
|
|
|
uartproxy.o \
|
2021-03-14 12:03:13 +00:00
|
|
|
usb.o usb_dwc3.o \
|
2021-04-14 08:51:41 +00:00
|
|
|
utils.o utils_asm.o \
|
|
|
|
vsprintf.o \
|
|
|
|
wdt.o \
|
2022-03-09 11:47:42 +00:00
|
|
|
$(MINILZLIB_OBJECTS) $(TINF_OBJECTS) $(DLMALLOC_OBJECTS) $(LIBFDT_OBJECTS) $(RUST_LIBS)
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
FP_OBJECTS := \
|
2022-11-30 08:31:00 +00:00
|
|
|
kboot_gpu.o \
|
2022-11-30 08:28:25 +00:00
|
|
|
math/expf.o \
|
|
|
|
math/exp2f_data.o \
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
BUILD_OBJS := $(patsubst %,build/%,$(OBJECTS))
|
2022-11-30 08:28:25 +00:00
|
|
|
BUILD_FP_OBJS := $(patsubst %,build/%,$(FP_OBJECTS))
|
|
|
|
BUILD_ALL_OBJS := $(BUILD_OBJS) $(BUILD_FP_OBJS)
|
2021-01-12 18:22:11 +00:00
|
|
|
NAME := m1n1
|
|
|
|
TARGET := m1n1.macho
|
2021-12-17 12:31:36 +00:00
|
|
|
TARGET_RAW := m1n1.bin
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
DEPDIR := build/.deps
|
|
|
|
|
2022-03-13 21:42:52 +00:00
|
|
|
.PHONY: all clean format update_tag update_cfg invoke_cc
|
2022-03-09 12:40:12 +00:00
|
|
|
all: update_tag update_cfg build/$(TARGET) build/$(TARGET_RAW)
|
2021-01-12 18:22:11 +00:00
|
|
|
clean:
|
|
|
|
rm -rf build/*
|
|
|
|
format:
|
2022-11-30 08:28:25 +00:00
|
|
|
$(CLANG_FORMAT) -i src/*.c src/math/*.c src/*.h src/math/*.h sysinc/*.h
|
2021-04-06 10:18:56 +00:00
|
|
|
format-check:
|
2021-11-08 04:52:59 +00:00
|
|
|
$(CLANG_FORMAT) --dry-run --Werror src/*.c src/*.h sysinc/*.h
|
2022-03-09 11:47:42 +00:00
|
|
|
rustfmt:
|
|
|
|
cd rust && cargo fmt
|
|
|
|
rustfmt-check:
|
|
|
|
cd rust && cargo fmt --check
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-03-09 11:47:42 +00:00
|
|
|
build/$(RUST_LIB): rust/src/* rust/*
|
|
|
|
@echo " RS $@"
|
|
|
|
@mkdir -p $(DEPDIR)
|
|
|
|
@mkdir -p "$(dir $@)"
|
|
|
|
@cargo build --target $(RUSTARCH) --lib --release --manifest-path rust/Cargo.toml --target-dir build
|
|
|
|
@cp "build/$(RUSTARCH)/release/${RUST_LIB}" "$@"
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
build/%.o: src/%.S
|
|
|
|
@echo " AS $@"
|
|
|
|
@mkdir -p $(DEPDIR)
|
2021-01-23 13:36:17 +00:00
|
|
|
@mkdir -p "$(dir $@)"
|
2021-11-08 04:50:45 +00:00
|
|
|
@$(AS) -c $(CFLAGS) -MMD -MF $(DEPDIR)/$(*F).d -MQ "$@" -MP -o $@ $<
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
$(BUILD_FP_OBJS): build/%.o: src/%.c
|
2022-12-04 06:07:16 +00:00
|
|
|
@echo " CC FP $@"
|
2022-11-30 08:28:25 +00:00
|
|
|
@mkdir -p $(DEPDIR)
|
|
|
|
@mkdir -p "$(dir $@)"
|
|
|
|
@$(CC) -c $(BASE_CFLAGS) -MMD -MF $(DEPDIR)/$(*F).d -MQ "$@" -MP -o $@ $<
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
build/%.o: src/%.c
|
|
|
|
@echo " CC $@"
|
|
|
|
@mkdir -p $(DEPDIR)
|
2021-01-23 13:36:17 +00:00
|
|
|
@mkdir -p "$(dir $@)"
|
2021-11-08 04:50:45 +00:00
|
|
|
@$(CC) -c $(CFLAGS) -MMD -MF $(DEPDIR)/$(*F).d -MQ "$@" -MP -o $@ $<
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-03-13 21:42:52 +00:00
|
|
|
# special target for usage by m1n1.loadobjs
|
|
|
|
invoke_cc:
|
|
|
|
@$(CC) -c $(CFLAGS) -Isrc -o $(OBJFILE) $(CFILE)
|
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
build/$(NAME).elf: $(BUILD_ALL_OBJS) m1n1.ld
|
2021-01-12 18:22:11 +00:00
|
|
|
@echo " LD $@"
|
2022-11-30 08:28:25 +00:00
|
|
|
@$(LD) -T m1n1.ld $(LDFLAGS) -o $@ $(BUILD_ALL_OBJS)
|
2021-12-17 12:31:36 +00:00
|
|
|
|
2022-11-30 08:28:25 +00:00
|
|
|
build/$(NAME)-raw.elf: $(BUILD_ALL_OBJS) m1n1-raw.ld
|
2021-12-17 12:31:36 +00:00
|
|
|
@echo " LDRAW $@"
|
2022-11-30 08:28:25 +00:00
|
|
|
@$(LD) -T m1n1-raw.ld $(LDFLAGS) -o $@ $(BUILD_ALL_OBJS)
|
2021-01-16 15:45:10 +00:00
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
build/$(NAME).macho: build/$(NAME).elf
|
|
|
|
@echo " MACHO $@"
|
2021-09-21 06:36:56 +00:00
|
|
|
@$(OBJCOPY) -O binary --strip-debug $< $@
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-12-17 12:31:36 +00:00
|
|
|
build/$(NAME).bin: build/$(NAME)-raw.elf
|
|
|
|
@echo " RAW $@"
|
|
|
|
@$(OBJCOPY) -O binary --strip-debug $< $@
|
|
|
|
|
2021-08-31 14:09:28 +00:00
|
|
|
update_tag:
|
2022-03-09 12:45:25 +00:00
|
|
|
@mkdir -p build
|
2022-12-04 05:59:47 +00:00
|
|
|
@./version.sh > build/build_tag.tmp
|
2021-08-31 14:09:28 +00:00
|
|
|
@cmp -s build/build_tag.h build/build_tag.tmp 2>/dev/null || \
|
|
|
|
( mv -f build/build_tag.tmp build/build_tag.h && echo " TAG build/build_tag.h" )
|
|
|
|
|
2022-03-09 11:47:42 +00:00
|
|
|
update_cfg:
|
2022-03-09 12:45:25 +00:00
|
|
|
@mkdir -p build
|
2022-03-09 13:15:09 +00:00
|
|
|
@for i in $(CFG); do echo "#define $$i"; done > build/build_cfg.tmp
|
2022-03-09 11:47:42 +00:00
|
|
|
@cmp -s build/build_cfg.h build/build_cfg.tmp 2>/dev/null || \
|
|
|
|
( mv -f build/build_cfg.tmp build/build_cfg.h && echo " CFG build/build_cfg.h" )
|
|
|
|
|
2021-08-31 14:09:28 +00:00
|
|
|
build/build_tag.h: update_tag
|
2022-03-09 11:47:42 +00:00
|
|
|
build/build_cfg.h: update_cfg
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2022-05-05 04:30:43 +00:00
|
|
|
build/%.bin: data/%.bin
|
2021-01-12 18:22:11 +00:00
|
|
|
@echo " IMG $@"
|
2022-03-09 12:45:25 +00:00
|
|
|
@mkdir -p "$(dir $@)"
|
2022-05-05 04:30:43 +00:00
|
|
|
@cp $< $@
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
build/%.o: build/%.bin
|
|
|
|
@echo " BIN $@"
|
2022-03-09 12:45:25 +00:00
|
|
|
@mkdir -p "$(dir $@)"
|
2021-01-15 21:39:32 +00:00
|
|
|
@$(OBJCOPY) -I binary -B aarch64 -O elf64-littleaarch64 $< $@
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-02-12 21:27:39 +00:00
|
|
|
build/%.bin: font/%.bin
|
|
|
|
@echo " CP $@"
|
2022-03-09 12:45:25 +00:00
|
|
|
@mkdir -p "$(dir $@)"
|
2021-02-12 21:27:39 +00:00
|
|
|
@cp $< $@
|
|
|
|
|
2022-03-09 11:47:42 +00:00
|
|
|
build/main.o: build/build_tag.h build/build_cfg.h src/main.c
|
2021-08-31 14:09:28 +00:00
|
|
|
build/usb_dwc3.o: build/build_tag.h src/usb_dwc3.c
|
2022-03-09 11:47:42 +00:00
|
|
|
build/chainload.o: build/build_cfg.h src/usb_dwc3.c
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
-include $(DEPDIR)/*
|