platform.mk 7.11 KB
Newer Older
1
#
Yann Gautier's avatar
Yann Gautier committed
2
# Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
#
# SPDX-License-Identifier: BSD-3-Clause
#

ARM_CORTEX_A7		:=	yes
ARM_WITH_NEON		:=	yes
BL2_AT_EL3		:=	1
USE_COHERENT_MEM	:=	0

Yann Gautier's avatar
Yann Gautier committed
12
13
ENABLE_PIE		:=	1

14
15
STM32_TF_VERSION	?=	0

16
17
18
# Enable dynamic memory mapping
PLAT_XLAT_TABLES_DYNAMIC :=	1

19
20
ifeq ($(AARCH32_SP),sp_min)
# Disable Neon support: sp_min runtime may conflict with non-secure world
21
TF_CFLAGS		+=	-mfloat-abi=soft
22
23
endif

24
25
26
# Not needed for Cortex-A7
WORKAROUND_CVE_2017_5715:=	0

27
28
# Number of TF-A copies in the device
STM32_TF_A_COPIES		:=	2
29
STM32_BL33_PARTS_NUM		:=	1
Yann Gautier's avatar
Yann Gautier committed
30
ifeq ($(AARCH32_SP),optee)
31
STM32_RUNTIME_PARTS_NUM		:=	3
Yann Gautier's avatar
Yann Gautier committed
32
else
33
STM32_RUNTIME_PARTS_NUM		:=	0
Yann Gautier's avatar
Yann Gautier committed
34
endif
35
36
37
PLAT_PARTITION_MAX_ENTRIES	:=	$(shell echo $$(($(STM32_TF_A_COPIES) + \
							 $(STM32_BL33_PARTS_NUM) + \
							 $(STM32_RUNTIME_PARTS_NUM))))
38

39
40
41
# Boot devices
STM32MP_EMMC		?=	0
STM32MP_SDMMC		?=	0
42
STM32MP_RAW_NAND	?=	0
43
STM32MP_SPI_NAND	?=	0
44
STM32MP_SPI_NOR		?=	0
45
STM32MP_EMMC_BOOT	?=	0
46

Yann Gautier's avatar
Yann Gautier committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Device tree
DTB_FILE_NAME		?=	stm32mp157c-ev1.dtb
FDT_SOURCES		:=	$(addprefix fdts/, $(patsubst %.dtb,%.dts,$(DTB_FILE_NAME)))
DTC_FLAGS		+=	-Wno-unit_address_vs_reg

# Macros and rules to build TF binary
STM32_TF_ELF_LDFLAGS	:=	--hash-style=gnu --as-needed
STM32_TF_STM32		:=	$(addprefix ${BUILD_PLAT}/tf-a-, $(patsubst %.dtb,%.stm32,$(DTB_FILE_NAME)))
STM32_TF_LINKERFILE	:=	${BUILD_PLAT}/stm32mp1.ld

ASFLAGS			+= -DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\"
ifeq ($(AARCH32_SP),sp_min)
# BL32 is built only if using SP_MIN
BL32_DEP		:= bl32
ASFLAGS			+= -DBL32_BIN_PATH=\"${BUILD_PLAT}/bl32.bin\"
endif

# Variables for use with stm32image
STM32IMAGEPATH		?= tools/stm32image
STM32IMAGE		?= ${STM32IMAGEPATH}/stm32image${BIN_EXT}
67
STM32IMAGE_SRC		:= ${STM32IMAGEPATH}/stm32image.c
Yann Gautier's avatar
Yann Gautier committed
68
69

# Enable flags for C files
70
$(eval $(call assert_booleans,\
Yann Gautier's avatar
Yann Gautier committed
71
72
73
74
75
76
	$(sort \
		STM32MP_EMMC \
		STM32MP_SDMMC \
		STM32MP_RAW_NAND \
		STM32MP_SPI_NAND \
		STM32MP_SPI_NOR \
77
		STM32MP_EMMC_BOOT \
Yann Gautier's avatar
Yann Gautier committed
78
79
80
81
82
83
84
		PLAT_XLAT_TABLES_DYNAMIC \
)))

$(eval $(call assert_numerics,\
	$(sort \
		STM32_TF_A_COPIES \
		PLAT_PARTITION_MAX_ENTRIES \
85
86
87
)))

$(eval $(call add_defines,\
Yann Gautier's avatar
Yann Gautier committed
88
89
90
91
92
93
	$(sort \
		STM32MP_EMMC \
		STM32MP_SDMMC \
		STM32MP_RAW_NAND \
		STM32MP_SPI_NAND \
		STM32MP_SPI_NOR \
94
		STM32MP_EMMC_BOOT \
Yann Gautier's avatar
Yann Gautier committed
95
96
97
		PLAT_XLAT_TABLES_DYNAMIC \
		STM32_TF_A_COPIES \
		PLAT_PARTITION_MAX_ENTRIES \
98
)))
99

Yann Gautier's avatar
Yann Gautier committed
100
# Include paths and source files
101
102
PLAT_INCLUDES		:=	-Iplat/st/common/include/
PLAT_INCLUDES		+=	-Iplat/st/stm32mp1/include/
103
104
105

include lib/libfdt/libfdt.mk

106
107
PLAT_BL_COMMON_SOURCES	:=	common/fdt_wrappers.c					\
				plat/st/common/stm32mp_common.c				\
108
				plat/st/stm32mp1/stm32mp1_private.c
109

110
PLAT_BL_COMMON_SOURCES	+=	drivers/st/uart/aarch32/stm32_console.S
111
112
113
114
115
116
117
118
119
120

ifneq (${ENABLE_STACK_PROTECTOR},0)
PLAT_BL_COMMON_SOURCES	+=	plat/st/stm32mp1/stm32mp1_stack_protector.c
endif

include lib/xlat_tables_v2/xlat_tables.mk
PLAT_BL_COMMON_SOURCES	+=	${XLAT_TABLES_LIB_SRCS}

PLAT_BL_COMMON_SOURCES	+=	lib/cpus/aarch32/cortex_a7.S

121
PLAT_BL_COMMON_SOURCES	+=	drivers/arm/tzc/tzc400.c				\
122
123
				drivers/delay_timer/delay_timer.c			\
				drivers/delay_timer/generic_delay_timer.c		\
Yann Gautier's avatar
Yann Gautier committed
124
				drivers/st/bsec/bsec.c					\
Yann Gautier's avatar
Yann Gautier committed
125
				drivers/st/clk/stm32mp_clkfunc.c			\
126
				drivers/st/clk/stm32mp1_clk.c				\
127
				drivers/st/ddr/stm32mp1_ddr_helpers.c			\
Yann Gautier's avatar
Yann Gautier committed
128
				drivers/st/gpio/stm32_gpio.c				\
129
				drivers/st/i2c/stm32_i2c.c				\
Yann Gautier's avatar
Yann Gautier committed
130
				drivers/st/iwdg/stm32_iwdg.c				\
131
132
				drivers/st/pmic/stm32mp_pmic.c				\
				drivers/st/pmic/stpmic1.c				\
133
				drivers/st/reset/stm32mp1_reset.c			\
134
				plat/st/common/stm32mp_dt.c				\
135
				plat/st/stm32mp1/stm32mp1_context.c			\
Yann Gautier's avatar
Yann Gautier committed
136
				plat/st/stm32mp1/stm32mp1_dbgmcu.c			\
137
				plat/st/stm32mp1/stm32mp1_helper.S			\
138
139
				plat/st/stm32mp1/stm32mp1_security.c			\
				plat/st/stm32mp1/stm32mp1_syscfg.c
140

141
142
BL2_SOURCES		+=	drivers/io/io_block.c					\
				drivers/io/io_dummy.c					\
143
				drivers/io/io_mtd.c					\
144
				drivers/io/io_storage.c					\
145
				drivers/st/crypto/stm32_hash.c				\
146
				drivers/st/io/io_stm32image.c				\
147
				plat/st/common/stm32mp_auth.c				\
148
				plat/st/common/bl2_io_storage.c				\
149
150
				plat/st/stm32mp1/bl2_plat_setup.c

151
ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),)
152
153
154
155
156
BL2_SOURCES		+=	drivers/mmc/mmc.c					\
				drivers/partition/gpt.c					\
				drivers/partition/partition.c				\
				drivers/st/io/io_mmc.c					\
				drivers/st/mmc/stm32_sdmmc2.c
157
endif
158

159
160
161
162
163
164
ifeq (${STM32MP_RAW_NAND},1)
$(eval $(call add_define_val,NAND_ONFI_DETECT,1))
BL2_SOURCES		+=	drivers/mtd/nand/raw_nand.c				\
				drivers/st/fmc/stm32_fmc2_nand.c
endif

165
166
167
168
ifeq (${STM32MP_SPI_NAND},1)
BL2_SOURCES		+=	drivers/mtd/nand/spi_nand.c
endif

169
170
171
172
173
ifeq (${STM32MP_SPI_NOR},1)
BL2_SOURCES		+=	drivers/mtd/nor/spi_nor.c
endif

ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
174
175
176
177
178
BL2_SOURCES		+=	drivers/mtd/spi-mem/spi_mem.c				\
				drivers/st/spi/stm32_qspi.c
endif

ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),)
179
180
181
182
183
BL2_SOURCES		+=	drivers/mtd/nand/core.c
endif

ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
BL2_SOURCES		+=	plat/st/stm32mp1/stm32mp1_boot_device.c
184
185
endif

186
187
188
BL2_SOURCES		+=	drivers/st/ddr/stm32mp1_ddr.c				\
				drivers/st/ddr/stm32mp1_ram.c

189
190
191
192
BL2_SOURCES		+=	common/desc_image_load.c				\
				plat/st/stm32mp1/plat_bl2_mem_params_desc.c		\
				plat/st/stm32mp1/plat_image_load.c

Yann Gautier's avatar
Yann Gautier committed
193
194
195
196
ifeq ($(AARCH32_SP),optee)
BL2_SOURCES		+=	lib/optee/optee_utils.c
endif

Yann Gautier's avatar
Yann Gautier committed
197
# Compilation rules
198
.PHONY: check_dtc_version stm32image clean_stm32image check_boot_device
199
200
.SUFFIXES:

201
all: check_dtc_version stm32image ${STM32_TF_STM32}
202
203
204

distclean realclean clean: clean_stm32image

205
206
207
208
209
210
211
212
213
214
215
216
bl2: check_boot_device

check_boot_device:
	@if [ ${STM32MP_EMMC} != 1 ] && \
	    [ ${STM32MP_SDMMC} != 1 ] && \
	    [ ${STM32MP_RAW_NAND} != 1 ] && \
	    [ ${STM32MP_SPI_NAND} != 1 ] && \
	    [ ${STM32MP_SPI_NOR} != 1 ]; then \
		echo "No boot device driver is enabled"; \
		false; \
	fi

217
218
219
stm32image: ${STM32IMAGE}

${STM32IMAGE}: ${STM32IMAGE_SRC}
220
221
222
223
224
225
226
227
228
229
230
231
232
233
	${Q}${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}

clean_stm32image:
	${Q}${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean

check_dtc_version:
	$(eval DTC_V = $(shell $(DTC) -v | awk '{print $$NF}'))
	$(eval DTC_VERSION = $(shell printf "%d" $(shell echo ${DTC_V} | cut -d- -f1 | sed "s/\./0/g")))
	@if [ ${DTC_VERSION} -lt 10404 ]; then \
		echo "dtc version too old (${DTC_V}), you need at least version 1.4.4"; \
		false; \
	fi


234
235
236
237
238
${BUILD_PLAT}/stm32mp1-%.o: ${BUILD_PLAT}/fdts/%.dtb plat/st/stm32mp1/stm32mp1.S bl2 ${BL32_DEP}
	@echo "  AS      stm32mp1.S"
	${Q}${AS} ${ASFLAGS} ${TF_CFLAGS} \
		-DDTB_BIN_PATH=\"$<\" \
		-c plat/st/stm32mp1/stm32mp1.S -o $@
239

240
$(eval $(call MAKE_LD,${STM32_TF_LINKERFILE},plat/st/stm32mp1/stm32mp1.ld.S,2))
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
tf-a-%.elf: stm32mp1-%.o ${STM32_TF_LINKERFILE}
	@echo "  LDS     $<"
	${Q}${LD} -o $@ ${STM32_TF_ELF_LDFLAGS} -Map=$(@:.elf=.map) --script ${STM32_TF_LINKERFILE} $<

tf-a-%.bin: tf-a-%.elf
	${Q}${OC} -O binary $< $@
	@echo
	@echo "Built $@ successfully"
	@echo

tf-a-%.stm32: ${STM32IMAGE} tf-a-%.bin
	@echo
	@echo "Generate $@"
	$(eval LOADADDR = $(shell cat $(@:.stm32=.map) | grep RAM | awk '{print $$2}'))
	$(eval ENTRY = $(shell cat $(@:.stm32=.map) | grep "__BL2_IMAGE_START" | awk '{print $$1}'))
	${Q}${STM32IMAGE} -s $(word 2,$^) -d $@ \
		-l $(LOADADDR) -e ${ENTRY} \
		-v ${STM32_TF_VERSION}
	@echo