rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | CC := ${CROSS_COMPILE}gcc |
| 2 | AR := ${CROSS_COMPILE}ar |
| 3 | LD := ${CROSS_COMPILE}ld |
| 4 | OBJCOPY := ${CROSS_COMPILE}objcopy |
| 5 | |
| 6 | LDS = tllink.lds |
| 7 | |
| 8 | DIR_INC = ./include |
| 9 | DIR_SRC = ./src |
| 10 | DIR_PREBUILT = ./prebuild |
| 11 | DIR_OBJ = ${TL_RAW_OUT}/obj |
| 12 | DIR_BIN = ${TL_RAW_OUT}/bin |
| 13 | |
| 14 | ASRCS = $(wildcard $(DIR_SRC)/*.s) |
| 15 | CSRCS = $(wildcard $(DIR_SRC)/*.c) |
| 16 | CSRCS += \ |
| 17 | $(DIR_SRC)/drivers/tz_emi_mpu.c |
| 18 | |
| 19 | VPATH = $(DIR_SRC):$(DIR_SRC)/drivers |
| 20 | SRCS = $(ASRCS) $(CSRCS) |
| 21 | AOBJS = $(patsubst %.s, $(DIR_OBJ)/%.o, $(notdir $(ASRCS))) |
| 22 | COBJS = $(patsubst %.c, $(DIR_OBJ)/%.o, $(notdir $(CSRCS))) |
| 23 | SOBJS = $(wildcard $(DIR_PREBUILT)/*.a) |
| 24 | OBJS = $(AOBJS) $(COBJS) $(SOBJS) |
| 25 | |
| 26 | TARGET = teeloader |
| 27 | BIN_TARGET = $(DIR_BIN)/$(TARGET) |
| 28 | |
| 29 | all: $(OBJS) |
| 30 | @if [ ! -d `dirname $(BIN_TARGET).elf` ] ; then \ |
| 31 | mkdir -p `dirname $(BIN_TARGET).elf`; \ |
| 32 | fi |
| 33 | sed "s/%BASE_ADDR%/${BASE_ADDR}/g" $(LDS) > $(DIR_OBJ)/$(LDS) |
| 34 | $(LD) --start-group $^ --end-group -T$(DIR_OBJ)/$(LDS) -o $(BIN_TARGET).elf |
| 35 | -echo "teeloader binary created" |
| 36 | $(OBJCOPY) -O binary $(BIN_TARGET).elf $(BIN_TARGET).bin |
| 37 | ./zero_padding.sh $(BIN_TARGET).bin ${TL_ALIGN_SIZE} |
| 38 | |
| 39 | $(DIR_OBJ)/%.o: %.c |
| 40 | @if [ ! -d `dirname $@` ] ; then \ |
| 41 | mkdir -p `dirname $@`; \ |
| 42 | fi |
| 43 | $(CC) -I$(DIR_INC) -DBASE_ADDR=${BASE_ADDR} -DTL_ALIGN_SIZE=${TL_ALIGN_SIZE} -DTRUSTEDOS_ENTRYPOINT=${TRUSTEDOS_ENTRYPOINT} -c $(filter %$(patsubst %.o,%.c,$(notdir $@)),$(CSRCS)) -o $@ |
| 44 | |
| 45 | $(DIR_OBJ)/%.o: %.s |
| 46 | @if [ ! -d `dirname $@` ] ; then \ |
| 47 | mkdir -p `dirname $@`; \ |
| 48 | fi |
| 49 | $(CC) -c $^ -o $@ |
| 50 | |
| 51 | .PHONY: clean |
| 52 | clean: |
| 53 | -@rm -rf $(DIR_OBJ)/* $(DIR_BIN)/* |