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