xref: /rk3399_ARM-atf/plat/st/common/common.mk (revision b47dddd061e92054c3b2096fc8aa9688bfef68d6)
1#
2# Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
3# Copyright (c) 2025, Arm Limited and Contributors. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8RESET_TO_BL2			:=	1
9
10STM32MP_RECONFIGURE_CONSOLE	?=	0
11STM32MP_UART_BAUDRATE		?=	115200
12
13TRUSTED_BOARD_BOOT		?=	0
14STM32MP_USE_EXTERNAL_HEAP	?=	0
15
16# Use secure library from the ROM code for authentication
17STM32MP_CRYPTO_ROM_LIB		?=	0
18
19# Please don't increment this value without good understanding of
20# the monotonic counter
21STM32_TF_VERSION		?=	0
22
23# Enable dynamic memory mapping
24PLAT_XLAT_TABLES_DYNAMIC	:=	1
25
26# STM32 image header binary type for BL2
27STM32_HEADER_BL2_BINARY_TYPE	:=	0x10
28
29TF_CFLAGS			+=	-Wsign-compare
30TF_CFLAGS			+=	-Wformat-signedness
31
32# Number of TF-A copies in the device
33STM32_TF_A_COPIES		:=	2
34
35# PLAT_PARTITION_MAX_ENTRIES must take care of STM32_TF-A_COPIES and other partitions
36PLAT_PARTITION_MAX_ENTRIES	:=	$(shell echo $$(($(STM32_TF_A_COPIES) + $(STM32_EXTRA_PARTS))))
37
38ifeq (${PSA_FWU_SUPPORT},1)
39# Number of banks of updatable firmware
40NR_OF_FW_BANKS			:=	2
41NR_OF_IMAGES_IN_FW_BANK		:=	1
42
43FWU_MAX_PART = $(shell echo $$(($(STM32_TF_A_COPIES) + 2 + $(NR_OF_FW_BANKS))))
44ifeq ($(shell test $(FWU_MAX_PART) -gt $(PLAT_PARTITION_MAX_ENTRIES); echo $$?),0)
45$(error "Required partition number is $(FWU_MAX_PART) where PLAT_PARTITION_MAX_ENTRIES is only \
46$(PLAT_PARTITION_MAX_ENTRIES)")
47endif
48endif
49
50# Boot devices
51STM32MP_EMMC			?=	0
52STM32MP_SDMMC			?=	0
53STM32MP_RAW_NAND		?=	0
54STM32MP_SPI_NAND		?=	0
55STM32MP_SPI_NOR			?=	0
56
57# Put both BL2 and FIP in eMMC boot partition
58STM32MP_EMMC_BOOT		?=	0
59
60# Serial boot devices
61STM32MP_UART_PROGRAMMER		?=	0
62STM32MP_USB_PROGRAMMER		?=	0
63
64$(eval DTC_V = $(shell $($(ARCH)-dtc) -v | awk '{print $$NF}'))
65$(eval DTC_VERSION = $(shell printf "%d" $(shell echo ${DTC_V} | cut -d- -f1 | sed "s/\./0/g" | grep -o "[0-9]*")))
66DTC_CPPFLAGS			+=	${INCLUDES}
67DTC_FLAGS			+=	-Wno-unit_address_vs_reg
68ifeq ($(shell test $(DTC_VERSION) -ge 10601; echo $$?),0)
69DTC_FLAGS			+=	-Wno-interrupt_provider
70endif
71
72# Macros and rules to build TF binary
73STM32_TF_ELF_LDFLAGS		:=	--hash-style=gnu --as-needed
74STM32_TF_LINKERFILE		:=	${BUILD_PLAT}/${PLAT}.ld
75
76ASFLAGS				+=	-DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\"
77
78# Variables for use with stm32image
79STM32IMAGEPATH			?=	tools/stm32image
80STM32IMAGE			?=	${STM32IMAGEPATH}/stm32image$(.exe)
81STM32IMAGE_SRC			:=	${STM32IMAGEPATH}/stm32image.c
82STM32_DEPS			+=	${STM32IMAGE}
83
84FIP_DEPS			+=	dtbs
85STM32MP_HW_CONFIG		:=	${BL33_CFG}
86
87# Add the HW_CONFIG to FIP and specify the same to certtool
88$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_HW_CONFIG},--hw-config))
89
90# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images
91# in the FIP if the platform requires.
92ifneq ($(BL32_EXTRA1),)
93$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1,,$(ENCRYPT_BL32)))
94endif
95ifneq ($(BL32_EXTRA2),)
96$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2,,$(ENCRYPT_BL32)))
97endif
98
99# Enable flags for C files
100$(eval $(call assert_booleans,\
101	$(sort \
102		PLAT_XLAT_TABLES_DYNAMIC \
103		STM32MP_EMMC \
104		STM32MP_EMMC_BOOT \
105		STM32MP_RAW_NAND \
106		STM32MP_RECONFIGURE_CONSOLE \
107		STM32MP_SDMMC \
108		STM32MP_SPI_NAND \
109		STM32MP_SPI_NOR \
110		STM32MP_UART_PROGRAMMER \
111		STM32MP_USB_PROGRAMMER \
112)))
113
114$(eval $(call assert_numerics,\
115	$(sort \
116		STM32_TF_VERSION \
117		STM32MP_UART_BAUDRATE \
118)))
119
120$(eval $(call add_defines,\
121	$(sort \
122		PLAT_XLAT_TABLES_DYNAMIC \
123		STM32_TF_VERSION \
124		STM32MP_EMMC \
125		STM32MP_EMMC_BOOT \
126		STM32MP_RAW_NAND \
127		STM32MP_RECONFIGURE_CONSOLE \
128		STM32MP_SDMMC \
129		STM32MP_SPI_NAND \
130		STM32MP_SPI_NOR \
131		STM32MP_UART_BAUDRATE \
132		STM32MP_UART_PROGRAMMER \
133		STM32MP_USB_PROGRAMMER \
134)))
135
136# Include paths and source files
137PLAT_INCLUDES			+=	-Iplat/st/common/include/
138
139include lib/fconf/fconf.mk
140include lib/libfdt/libfdt.mk
141include lib/zlib/zlib.mk
142ifeq (${PSA_FWU_SUPPORT},1)
143include drivers/fwu/fwu.mk
144endif
145
146PLAT_BL_COMMON_SOURCES		+=	common/uuid.c					\
147					plat/st/common/stm32mp_common.c
148
149
150include lib/xlat_tables_v2/xlat_tables.mk
151PLAT_BL_COMMON_SOURCES		+=	${XLAT_TABLES_LIB_SRCS}
152
153PLAT_BL_COMMON_SOURCES		+=	drivers/clk/clk.c				\
154					drivers/delay_timer/delay_timer.c		\
155					drivers/delay_timer/generic_delay_timer.c	\
156					drivers/st/clk/stm32mp_clkfunc.c		\
157					drivers/st/ddr/stm32mp_ddr.c			\
158					drivers/st/gpio/stm32_gpio.c			\
159					drivers/st/regulator/regulator_core.c		\
160					drivers/st/regulator/regulator_fixed.c		\
161					plat/st/common/stm32mp_dt.c
162
163BL2_SOURCES			+=	${FCONF_SOURCES} ${FCONF_DYN_SOURCES}
164BL2_SOURCES			+=	$(ZLIB_SOURCES)
165
166BL2_SOURCES			+=	drivers/io/io_fip.c				\
167					plat/st/common/bl2_io_storage.c			\
168					plat/st/common/plat_image_load.c		\
169					plat/st/common/stm32mp_fconf_io.c
170
171BL2_SOURCES			+=	drivers/io/io_block.c				\
172					drivers/io/io_mtd.c				\
173					drivers/io/io_storage.c
174
175ifneq (${DECRYPTION_SUPPORT},none)
176BL2_SOURCES			+=	drivers/io/io_encrypted.c
177endif
178
179ifeq (${TRUSTED_BOARD_BOOT},1)
180AUTH_SOURCES			:=	drivers/auth/auth_mod.c				\
181					drivers/auth/crypto_mod.c			\
182					drivers/auth/img_parser_mod.c
183
184ifeq (${GENERATE_COT},1)
185TFW_NVCTR_VAL			:=	0
186NTFW_NVCTR_VAL			:=	0
187KEY_ALG				:=	ecdsa
188HASH_ALG			:=	sha256
189
190ifeq (${SAVE_KEYS},1)
191TRUSTED_WORLD_KEY		?=	${BUILD_PLAT}/trusted.pem
192NON_TRUSTED_WORLD_KEY		?=	${BUILD_PLAT}/non-trusted.pem
193BL32_KEY			?=	${BUILD_PLAT}/trusted_os.pem
194BL33_KEY			?=	${BUILD_PLAT}/non-trusted_os.pem
195endif
196
197endif
198TF_MBEDTLS_KEY_ALG		:=	ecdsa
199KEY_SIZE			:=	256
200
201ifneq (${MBEDTLS_DIR},)
202MBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" \
203${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')
204
205ifeq (${MBEDTLS_MAJOR}, 3)
206MBEDTLS_CONFIG_FILE		?=	"<stm32mp_mbedtls_config-3.h>"
207else
208$(error Error: TF-A only supports MbedTLS versions > 3.x)
209endif
210endif
211
212include drivers/auth/mbedtls/mbedtls_x509.mk
213
214COT_DESC_IN_DTB			:=	1
215AUTH_SOURCES			+=	lib/fconf/fconf_cot_getter.c			\
216					lib/fconf/fconf_tbbr_getter.c			\
217					plat/st/common/stm32mp_crypto_lib.c
218
219BL2_SOURCES			+=	$(AUTH_SOURCES)					\
220					plat/st/common/stm32mp_trusted_boot.c
221endif
222
223ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),)
224BL2_SOURCES			+=	drivers/mmc/mmc.c				\
225					drivers/partition/gpt.c				\
226					drivers/partition/partition.c
227endif
228
229ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
230BL2_SOURCES			+=	drivers/mtd/spi-mem/spi_mem.c
231endif
232
233ifeq (${STM32MP_RAW_NAND},1)
234$(eval $(call add_define_val,NAND_ONFI_DETECT,1))
235BL2_SOURCES			+=	drivers/mtd/nand/raw_nand.c
236endif
237
238ifeq (${STM32MP_SPI_NAND},1)
239BL2_SOURCES			+=	drivers/mtd/nand/spi_nand.c
240endif
241
242ifeq (${STM32MP_SPI_NOR},1)
243ifneq (${STM32MP_FORCE_MTD_START_OFFSET},)
244$(eval $(call add_define_val,STM32MP_NOR_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET}))
245endif
246BL2_SOURCES			+=	drivers/mtd/nor/spi_nor.c
247endif
248
249ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),)
250ifneq (${STM32MP_FORCE_MTD_START_OFFSET},)
251$(eval $(call add_define_val,STM32MP_NAND_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET}))
252endif
253BL2_SOURCES			+=	drivers/mtd/nand/core.c
254endif
255
256ifneq ($(filter 1,${STM32MP_UART_PROGRAMMER} ${STM32MP_USB_PROGRAMMER}),)
257BL2_SOURCES			+=	drivers/io/io_memmap.c
258endif
259
260ifeq (${STM32MP_UART_PROGRAMMER},1)
261BL2_SOURCES			+=	plat/st/common/stm32cubeprogrammer_uart.c
262endif
263
264ifeq (${STM32MP_USB_PROGRAMMER},1)
265BL2_SOURCES			+=	drivers/usb/usb_device.c			\
266					plat/st/common/stm32cubeprogrammer_usb.c	\
267					plat/st/common/usb_dfu.c
268endif
269
270BL2_SOURCES			+=	drivers/st/ddr/stm32mp_ddr_test.c		\
271					drivers/st/ddr/stm32mp_ram.c
272
273BL2_SOURCES			+=	common/desc_image_load.c
274
275BL2_SOURCES			+=	lib/optee/optee_utils.c
276