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