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