xref: /rk3399_ARM-atf/plat/st/stm32mp1/platform.mk (revision 351f9cd8897fd3ea52db2421721a152494b16328)
1#
2# Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7ARM_CORTEX_A7		:=	yes
8ARM_WITH_NEON		:=	yes
9BL2_AT_EL3		:=	1
10USE_COHERENT_MEM	:=	0
11
12STM32MP_EARLY_CONSOLE	?=	0
13STM32MP_UART_BAUDRATE	?=	115200
14
15# Allow TF-A to concatenate BL2 & BL32 binaries in a single file,
16# share DTB file between BL2 and BL32
17# If it is set to 0, then FIP is used
18STM32MP_USE_STM32IMAGE	?=	0
19
20# Please don't increment this value without good understanding of
21# the monotonic counter
22STM32_TF_VERSION	?=	0
23
24# Enable dynamic memory mapping
25PLAT_XLAT_TABLES_DYNAMIC :=	1
26
27# Default Device tree
28DTB_FILE_NAME		?=	stm32mp157c-ev1.dtb
29
30STM32MP13		?=	0
31STM32MP15		?=	0
32
33ifeq ($(STM32MP13),1)
34ifeq ($(STM32MP15),1)
35$(error Cannot enable both flags STM32MP13 and STM32MP15)
36endif
37STM32MP13		:=	1
38STM32MP15		:=	0
39else ifeq ($(STM32MP15),1)
40STM32MP13		:=	0
41STM32MP15		:=	1
42else ifneq ($(findstring stm32mp13,$(DTB_FILE_NAME)),)
43STM32MP13		:=	1
44STM32MP15		:=	0
45else ifneq ($(findstring stm32mp15,$(DTB_FILE_NAME)),)
46STM32MP13		:=	0
47STM32MP15		:=	1
48endif
49
50ifeq ($(STM32MP13),1)
51# DDR controller with single AXI port and 16-bit interface
52STM32MP_DDR_DUAL_AXI_PORT:=	0
53STM32MP_DDR_32BIT_INTERFACE:=	0
54
55# STM32 image header version v2.0
56STM32_HEADER_VERSION_MAJOR:=	2
57STM32_HEADER_VERSION_MINOR:=	0
58endif
59
60ifeq ($(STM32MP15),1)
61# DDR controller with dual AXI port and 32-bit interface
62STM32MP_DDR_DUAL_AXI_PORT:=	1
63STM32MP_DDR_32BIT_INTERFACE:=	1
64
65# STM32 image header version v1.0
66STM32_HEADER_VERSION_MAJOR:=	1
67STM32_HEADER_VERSION_MINOR:=	0
68
69# Add OP-TEE reserved shared memory area in mapping
70STM32MP15_OPTEE_RSV_SHM	:=	1
71$(eval $(call add_defines,STM32MP15_OPTEE_RSV_SHM))
72endif
73
74# STM32 image header binary type for BL2
75STM32_HEADER_BL2_BINARY_TYPE:=	0x10
76
77ifeq ($(AARCH32_SP),sp_min)
78# Disable Neon support: sp_min runtime may conflict with non-secure world
79TF_CFLAGS		+=	-mfloat-abi=soft
80endif
81
82TF_CFLAGS		+=	-Wsign-compare
83TF_CFLAGS		+=	-Wformat-signedness
84
85# Not needed for Cortex-A7
86WORKAROUND_CVE_2017_5715:=	0
87WORKAROUND_CVE_2022_23960:=	0
88
89# Number of TF-A copies in the device
90STM32_TF_A_COPIES		:=	2
91
92# PLAT_PARTITION_MAX_ENTRIES must take care of STM32_TF-A_COPIES and other partitions
93# such as metadata (2) to find all the FIP partitions (default is 2).
94PLAT_PARTITION_MAX_ENTRIES	:=	$(shell echo $$(($(STM32_TF_A_COPIES) + 4)))
95
96ifeq (${PSA_FWU_SUPPORT},1)
97ifneq (${STM32MP_USE_STM32IMAGE},1)
98# Number of banks of updatable firmware
99NR_OF_FW_BANKS			:=	2
100NR_OF_IMAGES_IN_FW_BANK		:=	1
101
102FWU_MAX_PART = $(shell echo $$(($(STM32_TF_A_COPIES) + 2 + $(NR_OF_FW_BANKS))))
103ifeq ($(shell test $(FWU_MAX_PART) -gt $(PLAT_PARTITION_MAX_ENTRIES); echo $$?),0)
104$(error "Required partition number is $(FWU_MAX_PART) where PLAT_PARTITION_MAX_ENTRIES is only \
105$(PLAT_PARTITION_MAX_ENTRIES)")
106endif
107else
108$(error FWU Feature enabled only with FIP images)
109endif
110endif
111
112# Boot devices
113STM32MP_EMMC		?=	0
114STM32MP_SDMMC		?=	0
115STM32MP_RAW_NAND	?=	0
116STM32MP_SPI_NAND	?=	0
117STM32MP_SPI_NOR		?=	0
118STM32MP_EMMC_BOOT	?=	0
119
120# Serial boot devices
121STM32MP_USB_PROGRAMMER	?=	0
122STM32MP_UART_PROGRAMMER	?=	0
123
124# Device tree
125ifeq ($(STM32MP13),1)
126BL2_DTSI		:=	stm32mp13-bl2.dtsi
127FDT_SOURCES		:=	$(addprefix ${BUILD_PLAT}/fdts/, $(patsubst %.dtb,%-bl2.dts,$(DTB_FILE_NAME)))
128else
129ifeq ($(STM32MP_USE_STM32IMAGE),1)
130ifeq ($(AARCH32_SP),optee)
131BL2_DTSI		:=	stm32mp15-bl2.dtsi
132FDT_SOURCES		:=	$(addprefix ${BUILD_PLAT}/fdts/, $(patsubst %.dtb,%-bl2.dts,$(DTB_FILE_NAME)))
133else
134FDT_SOURCES		:=	$(addprefix fdts/, $(patsubst %.dtb,%.dts,$(DTB_FILE_NAME)))
135endif
136else
137BL2_DTSI		:=	stm32mp15-bl2.dtsi
138FDT_SOURCES		:=	$(addprefix ${BUILD_PLAT}/fdts/, $(patsubst %.dtb,%-bl2.dts,$(DTB_FILE_NAME)))
139ifeq ($(AARCH32_SP),sp_min)
140BL32_DTSI		:=	stm32mp15-bl32.dtsi
141FDT_SOURCES		+=	$(addprefix ${BUILD_PLAT}/fdts/, $(patsubst %.dtb,%-bl32.dts,$(DTB_FILE_NAME)))
142endif
143endif
144endif
145
146$(eval DTC_V = $(shell $(DTC) -v | awk '{print $$NF}'))
147$(eval DTC_VERSION = $(shell printf "%d" $(shell echo ${DTC_V} | cut -d- -f1 | sed "s/\./0/g" | grep -o "[0-9]*")))
148DTC_CPPFLAGS		+=	${INCLUDES}
149DTC_FLAGS		+=	-Wno-unit_address_vs_reg
150ifeq ($(shell test $(DTC_VERSION) -ge 10601; echo $$?),0)
151DTC_FLAGS		+=	-Wno-interrupt_provider
152endif
153
154# Macros and rules to build TF binary
155STM32_TF_ELF_LDFLAGS	:=	--hash-style=gnu --as-needed
156STM32_TF_STM32		:=	$(addprefix ${BUILD_PLAT}/tf-a-, $(patsubst %.dtb,%.stm32,$(DTB_FILE_NAME)))
157STM32_TF_LINKERFILE	:=	${BUILD_PLAT}/stm32mp1.ld
158
159ASFLAGS			+= -DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\"
160ifeq ($(AARCH32_SP),sp_min)
161# BL32 is built only if using SP_MIN
162BL32_DEP		:= bl32
163ASFLAGS			+= -DBL32_BIN_PATH=\"${BUILD_PLAT}/bl32.bin\"
164endif
165
166# Variables for use with stm32image
167STM32IMAGEPATH		?= tools/stm32image
168STM32IMAGE		?= ${STM32IMAGEPATH}/stm32image${BIN_EXT}
169STM32IMAGE_SRC		:= ${STM32IMAGEPATH}/stm32image.c
170
171ifneq (${STM32MP_USE_STM32IMAGE},1)
172FIP_DEPS		+=	dtbs
173STM32MP_HW_CONFIG	:=	${BL33_CFG}
174STM32MP_FW_CONFIG_NAME	:=	$(patsubst %.dtb,%-fw-config.dtb,$(DTB_FILE_NAME))
175STM32MP_FW_CONFIG	:=	${BUILD_PLAT}/fdts/$(STM32MP_FW_CONFIG_NAME)
176ifneq (${AARCH32_SP},none)
177FDT_SOURCES		+=	$(addprefix fdts/, $(patsubst %.dtb,%.dts,$(STM32MP_FW_CONFIG_NAME)))
178endif
179# Add the FW_CONFIG to FIP and specify the same to certtool
180$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_FW_CONFIG},--fw-config))
181# Add the HW_CONFIG to FIP and specify the same to certtool
182$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_HW_CONFIG},--hw-config))
183ifeq ($(AARCH32_SP),sp_min)
184STM32MP_TOS_FW_CONFIG	:= $(addprefix ${BUILD_PLAT}/fdts/, $(patsubst %.dtb,%-bl32.dtb,$(DTB_FILE_NAME)))
185$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_TOS_FW_CONFIG},--tos-fw-config))
186else
187# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images
188# in the FIP if the platform requires.
189ifneq ($(BL32_EXTRA1),)
190$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1))
191endif
192ifneq ($(BL32_EXTRA2),)
193$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2))
194endif
195endif
196endif
197
198# Enable flags for C files
199$(eval $(call assert_booleans,\
200	$(sort \
201		PLAT_XLAT_TABLES_DYNAMIC \
202		STM32MP_DDR_32BIT_INTERFACE \
203		STM32MP_DDR_DUAL_AXI_PORT \
204		STM32MP_EARLY_CONSOLE \
205		STM32MP_EMMC \
206		STM32MP_EMMC_BOOT \
207		STM32MP_RAW_NAND \
208		STM32MP_SDMMC \
209		STM32MP_SPI_NAND \
210		STM32MP_SPI_NOR \
211		STM32MP_UART_PROGRAMMER \
212		STM32MP_USB_PROGRAMMER \
213		STM32MP_USE_STM32IMAGE \
214		STM32MP13 \
215		STM32MP15 \
216)))
217
218$(eval $(call assert_numerics,\
219	$(sort \
220		PLAT_PARTITION_MAX_ENTRIES \
221		STM32_TF_A_COPIES \
222		STM32_TF_VERSION \
223		STM32MP_UART_BAUDRATE \
224)))
225
226$(eval $(call add_defines,\
227	$(sort \
228		PLAT_PARTITION_MAX_ENTRIES \
229		PLAT_XLAT_TABLES_DYNAMIC \
230		STM32_TF_A_COPIES \
231		STM32_TF_VERSION \
232		STM32MP_DDR_32BIT_INTERFACE \
233		STM32MP_DDR_DUAL_AXI_PORT \
234		STM32MP_EARLY_CONSOLE \
235		STM32MP_EMMC \
236		STM32MP_EMMC_BOOT \
237		STM32MP_RAW_NAND \
238		STM32MP_SDMMC \
239		STM32MP_SPI_NAND \
240		STM32MP_SPI_NOR \
241		STM32MP_UART_BAUDRATE \
242		STM32MP_UART_PROGRAMMER \
243		STM32MP_USB_PROGRAMMER \
244		STM32MP_USE_STM32IMAGE \
245		STM32MP13 \
246		STM32MP15 \
247)))
248
249# Include paths and source files
250PLAT_INCLUDES		:=	-Iplat/st/common/include/
251PLAT_INCLUDES		+=	-Iplat/st/stm32mp1/include/
252
253ifeq (${STM32MP_USE_STM32IMAGE},1)
254include common/fdt_wrappers.mk
255else
256include lib/fconf/fconf.mk
257endif
258include lib/libfdt/libfdt.mk
259
260PLAT_BL_COMMON_SOURCES	:=	common/uuid.c						\
261				plat/st/common/stm32mp_common.c				\
262				plat/st/stm32mp1/stm32mp1_private.c
263
264PLAT_BL_COMMON_SOURCES	+=	drivers/st/uart/aarch32/stm32_console.S
265
266ifneq (${ENABLE_STACK_PROTECTOR},0)
267PLAT_BL_COMMON_SOURCES	+=	plat/st/stm32mp1/stm32mp1_stack_protector.c
268endif
269
270include lib/xlat_tables_v2/xlat_tables.mk
271PLAT_BL_COMMON_SOURCES	+=	${XLAT_TABLES_LIB_SRCS}
272
273PLAT_BL_COMMON_SOURCES	+=	lib/cpus/aarch32/cortex_a7.S
274
275PLAT_BL_COMMON_SOURCES	+=	drivers/arm/tzc/tzc400.c				\
276				drivers/clk/clk.c					\
277				drivers/delay_timer/delay_timer.c			\
278				drivers/delay_timer/generic_delay_timer.c		\
279				drivers/st/bsec/bsec2.c					\
280				drivers/st/clk/stm32mp_clkfunc.c			\
281				drivers/st/ddr/stm32mp_ddr.c				\
282				drivers/st/ddr/stm32mp1_ddr_helpers.c			\
283				drivers/st/gpio/stm32_gpio.c				\
284				drivers/st/i2c/stm32_i2c.c				\
285				drivers/st/iwdg/stm32_iwdg.c				\
286				drivers/st/pmic/stm32mp_pmic.c				\
287				drivers/st/pmic/stpmic1.c				\
288				drivers/st/regulator/regulator_core.c			\
289				drivers/st/regulator/regulator_fixed.c			\
290				drivers/st/reset/stm32mp1_reset.c			\
291				plat/st/common/stm32mp_dt.c				\
292				plat/st/stm32mp1/stm32mp1_dbgmcu.c			\
293				plat/st/stm32mp1/stm32mp1_helper.S			\
294				plat/st/stm32mp1/stm32mp1_syscfg.c
295
296ifeq ($(STM32MP13),1)
297PLAT_BL_COMMON_SOURCES	+=	drivers/st/clk/clk-stm32-core.c				\
298				drivers/st/clk/clk-stm32mp13.c
299else
300PLAT_BL_COMMON_SOURCES	+=	drivers/st/clk/stm32mp1_clk.c
301endif
302
303ifneq (${STM32MP_USE_STM32IMAGE},1)
304BL2_SOURCES		+=	${FCONF_SOURCES} ${FCONF_DYN_SOURCES}
305
306BL2_SOURCES		+=	drivers/io/io_fip.c					\
307				plat/st/common/bl2_io_storage.c				\
308				plat/st/common/stm32mp_fconf_io.c			\
309				plat/st/stm32mp1/plat_bl2_mem_params_desc.c		\
310				plat/st/stm32mp1/stm32mp1_fconf_firewall.c
311else
312BL2_SOURCES		+=	${FDT_WRAPPERS_SOURCES}
313
314BL2_SOURCES		+=	drivers/io/io_dummy.c					\
315				drivers/st/io/io_stm32image.c				\
316				plat/st/common/bl2_stm32_io_storage.c			\
317				plat/st/stm32mp1/plat_bl2_stm32_mem_params_desc.c	\
318				plat/st/stm32mp1/stm32mp1_security.c
319endif
320
321include lib/zlib/zlib.mk
322
323ifeq (${PSA_FWU_SUPPORT},1)
324include drivers/fwu/fwu.mk
325endif
326
327
328BL2_SOURCES		+=	$(ZLIB_SOURCES)
329
330BL2_SOURCES		+=	drivers/io/io_block.c					\
331				drivers/io/io_mtd.c					\
332				drivers/io/io_storage.c					\
333				drivers/st/crypto/stm32_hash.c				\
334				plat/st/stm32mp1/bl2_plat_setup.c
335
336
337ifeq ($(STM32MP15),1)
338BL2_SOURCES		+=	plat/st/common/stm32mp_auth.c
339endif
340
341ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),)
342BL2_SOURCES		+=	drivers/mmc/mmc.c					\
343				drivers/partition/gpt.c					\
344				drivers/partition/partition.c				\
345				drivers/st/io/io_mmc.c					\
346				drivers/st/mmc/stm32_sdmmc2.c
347endif
348
349ifeq (${STM32MP_RAW_NAND},1)
350$(eval $(call add_define_val,NAND_ONFI_DETECT,1))
351BL2_SOURCES		+=	drivers/mtd/nand/raw_nand.c				\
352				drivers/st/fmc/stm32_fmc2_nand.c
353endif
354
355ifeq (${STM32MP_SPI_NAND},1)
356BL2_SOURCES		+=	drivers/mtd/nand/spi_nand.c
357endif
358
359ifeq (${STM32MP_SPI_NOR},1)
360BL2_SOURCES		+=	drivers/mtd/nor/spi_nor.c
361endif
362
363ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
364BL2_SOURCES		+=	drivers/mtd/spi-mem/spi_mem.c				\
365				drivers/st/spi/stm32_qspi.c
366endif
367
368ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),)
369BL2_SOURCES		+=	drivers/mtd/nand/core.c
370endif
371
372ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
373BL2_SOURCES		+=	plat/st/stm32mp1/stm32mp1_boot_device.c
374endif
375
376ifneq ($(filter 1,${STM32MP_UART_PROGRAMMER} ${STM32MP_USB_PROGRAMMER}),)
377BL2_SOURCES		+=	drivers/io/io_memmap.c
378endif
379
380ifeq (${STM32MP_UART_PROGRAMMER},1)
381BL2_SOURCES		+=	drivers/st/uart/stm32_uart.c				\
382				plat/st/common/stm32cubeprogrammer_uart.c
383endif
384
385ifeq (${STM32MP_USB_PROGRAMMER},1)
386#The DFU stack uses only one end point, reduce the USB stack footprint
387$(eval $(call add_define_val,CONFIG_USBD_EP_NB,1U))
388BL2_SOURCES		+=	drivers/st/usb/stm32mp1_usb.c				\
389				drivers/usb/usb_device.c				\
390				plat/st/common/stm32cubeprogrammer_usb.c		\
391				plat/st/common/usb_dfu.c					\
392				plat/st/stm32mp1/stm32mp1_usb_dfu.c
393endif
394
395BL2_SOURCES		+=	drivers/st/ddr/stm32mp_ddr_test.c			\
396				drivers/st/ddr/stm32mp_ram.c				\
397				drivers/st/ddr/stm32mp1_ddr.c				\
398				drivers/st/ddr/stm32mp1_ram.c
399
400BL2_SOURCES		+=	common/desc_image_load.c				\
401				plat/st/stm32mp1/plat_image_load.c
402
403BL2_SOURCES		+=	lib/optee/optee_utils.c
404
405# Compilation rules
406.PHONY: check_dtc_version stm32image clean_stm32image check_boot_device
407.SUFFIXES:
408
409all: check_dtc_version stm32image ${STM32_TF_STM32}
410
411distclean realclean clean: clean_stm32image
412
413bl2: check_boot_device
414
415check_boot_device:
416	@if [ ${STM32MP_EMMC} != 1 ] && \
417	    [ ${STM32MP_SDMMC} != 1 ] && \
418	    [ ${STM32MP_RAW_NAND} != 1 ] && \
419	    [ ${STM32MP_SPI_NAND} != 1 ] && \
420	    [ ${STM32MP_SPI_NOR} != 1 ] && \
421	    [ ${STM32MP_UART_PROGRAMMER} != 1 ] && \
422	    [ ${STM32MP_USB_PROGRAMMER} != 1 ]; then \
423		echo "No boot device driver is enabled"; \
424		false; \
425	fi
426
427stm32image: ${STM32IMAGE}
428
429${STM32IMAGE}: ${STM32IMAGE_SRC}
430	${Q}${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}
431
432clean_stm32image:
433	${Q}${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean
434
435check_dtc_version:
436	@if [ ${DTC_VERSION} -lt 10404 ]; then \
437		echo "dtc version too old (${DTC_V}), you need at least version 1.4.4"; \
438		false; \
439	fi
440
441ifeq ($(STM32MP_USE_STM32IMAGE)-$(AARCH32_SP),1-sp_min)
442${BUILD_PLAT}/stm32mp1-%.o: ${BUILD_PLAT}/fdts/%.dtb plat/st/stm32mp1/stm32mp1.S bl2 ${BL32_DEP}
443	@echo "  AS      stm32mp1.S"
444	${Q}${AS} ${ASFLAGS} ${TF_CFLAGS} \
445		-DDTB_BIN_PATH=\"$<\" \
446		-c $(word 2,$^) -o $@
447else
448# Create DTB file for BL2
449${BUILD_PLAT}/fdts/%-bl2.dts: fdts/%.dts fdts/${BL2_DTSI} | ${BUILD_PLAT} fdt_dirs
450	@echo '#include "$(patsubst fdts/%,%,$<)"' > $@
451	@echo '#include "${BL2_DTSI}"' >> $@
452
453${BUILD_PLAT}/fdts/%-bl2.dtb: ${BUILD_PLAT}/fdts/%-bl2.dts
454
455ifeq ($(AARCH32_SP),sp_min)
456# Create DTB file for BL32
457${BUILD_PLAT}/fdts/%-bl32.dts: fdts/%.dts fdts/${BL32_DTSI} | ${BUILD_PLAT} fdt_dirs
458	@echo '#include "$(patsubst fdts/%,%,$<)"' > $@
459	@echo '#include "${BL32_DTSI}"' >> $@
460
461${BUILD_PLAT}/fdts/%-bl32.dtb: ${BUILD_PLAT}/fdts/%-bl32.dts
462endif
463
464${BUILD_PLAT}/stm32mp1-%.o: ${BUILD_PLAT}/fdts/%-bl2.dtb plat/st/stm32mp1/stm32mp1.S bl2
465	@echo "  AS      stm32mp1.S"
466	${Q}${AS} ${ASFLAGS} ${TF_CFLAGS} \
467		-DDTB_BIN_PATH=\"$<\" \
468		-c plat/st/stm32mp1/stm32mp1.S -o $@
469endif
470
471$(eval $(call MAKE_LD,${STM32_TF_LINKERFILE},plat/st/stm32mp1/stm32mp1.ld.S,bl2))
472
473tf-a-%.elf: stm32mp1-%.o ${STM32_TF_LINKERFILE}
474	@echo "  LDS     $<"
475	${Q}${LD} -o $@ ${STM32_TF_ELF_LDFLAGS} -Map=$(@:.elf=.map) --script ${STM32_TF_LINKERFILE} $<
476
477tf-a-%.bin: tf-a-%.elf
478	${Q}${OC} -O binary $< $@
479	@echo
480	@echo "Built $@ successfully"
481	@echo
482
483tf-a-%.stm32: ${STM32IMAGE} tf-a-%.bin
484	@echo
485	@echo "Generate $@"
486	$(eval LOADADDR = $(shell cat $(@:.stm32=.map) | grep RAM | awk '{print $$2}'))
487	$(eval ENTRY = $(shell cat $(@:.stm32=.map) | grep "__BL2_IMAGE_START" | awk '{print $$1}'))
488	${Q}${STM32IMAGE} -s $(word 2,$^) -d $@ \
489		-l $(LOADADDR) -e ${ENTRY} \
490		-v ${STM32_TF_VERSION} \
491		-m ${STM32_HEADER_VERSION_MAJOR} \
492		-n ${STM32_HEADER_VERSION_MINOR} \
493		-b ${STM32_HEADER_BL2_BINARY_TYPE}
494	@echo
495