Debian Codegraph @

plat/st/common/common.mk

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