2021-11-08 04:52:59 +00:00
|
|
|
ARCH ?= aarch64-linux-gnu-
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2021-09-21 06:36:56 +00:00
|
|
|
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 \
|
2021-09-15 12:58:14 +00:00
|
|
|
-fno-stack-protector -mgeneral-regs-only -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-02-21 07:07:01 +00:00
|
|
|
ifeq ($(RELEASE),1)
|
|
|
|
CFLAGS += -DRELEASE
|
|
|
|
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 \
|
|
|
|
chickens.o \
|
2022-03-07 14:57:48 +00:00
|
|
|
clk.o \
|
2021-10-18 08:34:40 +00:00
|
|
|
cpufreq.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-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 \
|
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 \
|
2021-04-14 08:51:41 +00:00
|
|
|
kboot.o \
|
|
|
|
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 \
|
2021-04-14 08:51:41 +00:00
|
|
|
smp.o \
|
|
|
|
start.o \
|
|
|
|
startup.o \
|
|
|
|
string.o \
|
|
|
|
tunables.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 \
|
|
|
|
$(MINILZLIB_OBJECTS) $(TINF_OBJECTS) $(DLMALLOC_OBJECTS) $(LIBFDT_OBJECTS)
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-03-14 17:26:31 +00:00
|
|
|
DTS := t8103-j274.dts
|
2021-01-23 13:36:17 +00:00
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
BUILD_OBJS := $(patsubst %,build/%,$(OBJECTS))
|
2021-01-23 13:36:17 +00:00
|
|
|
DTBS := $(patsubst %.dts,build/dtb/%.dtb,$(DTS))
|
|
|
|
|
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
|
|
|
|
|
2021-08-31 14:09:28 +00:00
|
|
|
.PHONY: all clean format update_tag
|
2021-12-17 12:31:36 +00:00
|
|
|
all: build/$(TARGET) build/$(TARGET_RAW) $(DTBS)
|
2021-01-12 18:22:11 +00:00
|
|
|
clean:
|
|
|
|
rm -rf build/*
|
|
|
|
format:
|
2021-11-08 04:52:59 +00:00
|
|
|
$(CLANG_FORMAT) -i src/*.c src/*.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
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-03-14 17:26:31 +00:00
|
|
|
build/dtb/%.dts: dts/%.dts
|
|
|
|
@echo " DTCPP $@"
|
|
|
|
@mkdir -p "$(dir $@)"
|
|
|
|
@$(CC) -E -nostdinc -I dts -x assembler-with-cpp -o $@ $<
|
|
|
|
|
|
|
|
build/dtb/%.dtb: build/dtb/%.dts
|
2021-01-23 13:36:17 +00:00
|
|
|
@echo " DTC $@"
|
|
|
|
@mkdir -p "$(dir $@)"
|
2021-03-14 17:26:31 +00:00
|
|
|
@dtc -I dts -i dts $< -o $@
|
2021-01-23 13:36:17 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
build/$(NAME).elf: $(BUILD_OBJS) m1n1.ld
|
|
|
|
@echo " LD $@"
|
2021-12-17 12:31:36 +00:00
|
|
|
@$(LD) -T m1n1.ld $(LDFLAGS) -o $@ $(BUILD_OBJS)
|
|
|
|
|
|
|
|
build/$(NAME)-raw.elf: $(BUILD_OBJS) m1n1-raw.ld
|
|
|
|
@echo " LDRAW $@"
|
|
|
|
@$(LD) -T m1n1-raw.ld $(LDFLAGS) -o $@ $(BUILD_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:
|
|
|
|
@echo "#define BUILD_TAG \"$$(git describe --always --dirty)\"" > build/build_tag.tmp
|
|
|
|
@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" )
|
|
|
|
|
|
|
|
build/build_tag.h: update_tag
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
build/%.bin: data/%.png
|
|
|
|
@echo " IMG $@"
|
|
|
|
@convert $< -background black -flatten -depth 8 rgba:$@
|
|
|
|
|
|
|
|
build/%.o: build/%.bin
|
|
|
|
@echo " BIN $@"
|
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 $@"
|
|
|
|
@cp $< $@
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
build/main.o: build/build_tag.h src/main.c
|
2021-08-31 14:09:28 +00:00
|
|
|
build/usb_dwc3.o: build/build_tag.h src/usb_dwc3.c
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
-include $(DEPDIR)/*
|