-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
142 lines (119 loc) · 3.48 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
BINARY_S = secure.elf
BINARY_LIB_S = cmse_import.o
BINARY_NS = nonsecure.elf
BINARY_ALL = image_s_ns.elf
MACHINE_NAME := mps2-an505
CMSIS_PATH ?= ./CMSIS_5
QEMU_PATH ?= ./qemu/build/arm-softmmu/qemu-system-arm
TOOLCHAIN_PATH ?= ./gcc-arm-none-eabi-8-2019-q3-update/bin
CROSS_COMPILE = $(TOOLCHAIN_PATH)/arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
GDB = $(CROSS_COMPILE)gdb
OBJ = $(CROSS_COMPILE)objdump
NM = $(CROSS_COMPILE)nm
READELF = $(CROSS_COMPILE)readelf
LINKER_SCRIPT_NS = non_secure/gcc_arm_ns.ld
# Must match the same value in the NS linker script where the vector table is.
TZ_VTOR_TABLE_ADDR = 0x00200000
LINKER_SCRIPT = secure/gcc_arm.ld
# From $(CMSIS_PATH)/Device/ARM/ARMCM33/Source/GCC/startup_ARMCM33.S
SRC_ASM = secure/startup_ARMCM33.S
# From $(CMSIS_PATH)/Device/ARM/ARMCM33/Source/system_ARMCM33.c
SRC_C = \
secure/system_ARMCM33.c \
secure/main.c \
secure/main_mpu.c \
common/logPrint.c \
common/uart.c
INCLUDE_FLAGS = \
-I$(CMSIS_PATH)/Device/ARM/ARMCM33/Include \
-I$(CMSIS_PATH)/CMSIS/Core/Include \
-I./secure \
-I./non_secure \
-I./common
COMMON_CFLAGS = \
-mcpu=cortex-m33 \
-g \
$(INCLUDE_FLAGS) \
-nostartfiles -ffreestanding \
-mthumb
CFLAGS = \
$(COMMON_CFLAGS) \
-DARMCM33_DSP_FP_TZ \
-mcmse \
-DTZ_VTOR_TABLE_ADDR=$(TZ_VTOR_TABLE_ADDR) \
-specs=nano.specs -specs=nosys.specs \
-ffunction-sections \
-Wl,--gc-sections \
-DC_SECURE_CODE
CFLAGS_NS = \
$(COMMON_CFLAGS) \
--specs=nosys.specs -DARMCM33 \
-DC_NON_SECURE_CODE
SECURE_LINKER_ARGS = \
-Xlinker --sort-section=alignment \
-Xlinker --cmse-implib \
-Xlinker --out-implib=$(BINARY_LIB_S) \
-Xlinker -Map=output.map
OBJS = \
common/logPrint.o \
secure/system_ARMCM33.o \
secure/boot.o \
secure/main.o \
common/uart.o
OBJS_NS = \
non_secure/main_ns.o \
non_secure/system_ARMCM33_ns.o \
non_secure/boot_ns.o \
common/uart.o \
$(BINARY_LIB_S)
all: $(BINARY_S) $(BINARY_NS)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
secure/boot.o: $(SRC_ASM)
$(CC) $(CFLAGS) -c $^ -o $@
non_secure/boot_ns.o: non_secure/boot_ns.S
$(CC) $(CFLAGS_NS) -c $^ -o $@
# Generate two separate images (one for Non-Secure and another for Secure) with
# different linker scripts (as they will have different addresses to locate the code).
# This is to make sure that there is no clash with the symbols.
$(BINARY_S): $(OBJS)
$(CC) $(CFLAGS) $(SECURE_LINKER_ARGS) $^ -T $(LINKER_SCRIPT) -o $@
$(NM) $@ > secure/nm_s.out
$(OBJ) -D $@ > secure/objdump_s.out
$(READELF) -a $@ > secure/readelf_s.out
$(BINARY_NS): $(OBJS_NS)
$(CC) $^ $(CFLAGS_NS) -T $(LINKER_SCRIPT_NS) -o $@
$(NM) $@ > non_secure/nm_ns.out
$(OBJ) -D $@ > non_secure/objdump_ns.out
$(READELF) -a $@ > non_secure/readelf_ns.out
# Select the subsystem an505, specify the cortex-m33
# Ctrl-A, then X to quit
run: $(BINARY_S) $(BINARY_NS)
$(QEMU_PATH) \
-machine $(MACHINE_NAME) \
-cpu cortex-m33 \
-m 16M \
-nographic \
-semihosting \
-d int,cpu_reset \
-device loader,file=$(BINARY_NS) \
-device loader,file=$(BINARY_S)
gdbserver: $(BINARY_S) $(BINARY_NS)
$(QEMU_PATH) \
-machine $(MACHINE_NAME) \
-cpu cortex-m33 \
-m 16M \
-nographic \
-semihosting \
-device loader,file=$(BINARY_NS) \
-device loader,file=$(BINARY_S) \
-d int,cpu_reset \
-S -s
gdb: $(BINARY)
$(GDB) $(BINARY_S) -ex "target remote:1234"
help:
$(QEMU_PATH) --machine help
clean:
rm -f *.o *.elf *.out secure/*.out non_secure/*.out $(OBJS)