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