1# 2# Copyright (c) 2023-2025, 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_ELF_LDFLAGS := --hash-style=gnu --as-needed 77STM32_TF_LINKERFILE := ${BUILD_PLAT}/${PLAT}.ld 78 79ASFLAGS += -DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\" 80 81# Variables for use with stm32image 82STM32IMAGEPATH ?= tools/stm32image 83STM32IMAGE ?= ${BUILD_PLAT}/${STM32IMAGEPATH}/stm32image$(.exe) 84STM32IMAGE_SRC := ${STM32IMAGEPATH}/stm32image.c 85STM32_DEPS += ${STM32IMAGE} 86 87FIP_DEPS += dtbs 88STM32MP_HW_CONFIG := ${BL33_CFG} 89 90# Add the HW_CONFIG to FIP and specify the same to certtool 91$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_HW_CONFIG},--hw-config)) 92 93# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 94# in the FIP if the platform requires. 95ifneq ($(BL32_EXTRA1),) 96$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 97endif 98ifneq ($(BL32_EXTRA2),) 99$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 100endif 101 102# Enable flags for C files 103$(eval $(call assert_booleans,\ 104 $(sort \ 105 PLAT_XLAT_TABLES_DYNAMIC \ 106 STM32MP_EMMC \ 107 STM32MP_EMMC_BOOT \ 108 STM32MP_RAW_NAND \ 109 STM32MP_RECONFIGURE_CONSOLE \ 110 STM32MP_SDMMC \ 111 STM32MP_SPI_NAND \ 112 STM32MP_SPI_NOR \ 113 STM32MP_UART_PROGRAMMER \ 114 STM32MP_USB_PROGRAMMER \ 115))) 116 117$(eval $(call assert_numerics,\ 118 $(sort \ 119 STM32_TF_VERSION \ 120 STM32MP_UART_BAUDRATE \ 121))) 122 123$(eval $(call add_defines,\ 124 $(sort \ 125 PLAT_XLAT_TABLES_DYNAMIC \ 126 STM32_TF_VERSION \ 127 STM32MP_EMMC \ 128 STM32MP_EMMC_BOOT \ 129 STM32MP_RAW_NAND \ 130 STM32MP_RECONFIGURE_CONSOLE \ 131 STM32MP_SDMMC \ 132 STM32MP_SPI_NAND \ 133 STM32MP_SPI_NOR \ 134 STM32MP_UART_BAUDRATE \ 135 STM32MP_UART_PROGRAMMER \ 136 STM32MP_USB_PROGRAMMER \ 137))) 138 139# Include paths and source files 140PLAT_INCLUDES += -Iplat/st/common/include/ 141 142include lib/fconf/fconf.mk 143include lib/libfdt/libfdt.mk 144include lib/zlib/zlib.mk 145ifeq (${PSA_FWU_SUPPORT},1) 146include drivers/fwu/fwu.mk 147endif 148 149PLAT_BL_COMMON_SOURCES += common/uuid.c \ 150 plat/st/common/stm32mp_common.c 151 152 153include lib/xlat_tables_v2/xlat_tables.mk 154PLAT_BL_COMMON_SOURCES += ${XLAT_TABLES_LIB_SRCS} 155 156PLAT_BL_COMMON_SOURCES += drivers/clk/clk.c \ 157 drivers/delay_timer/delay_timer.c \ 158 drivers/delay_timer/generic_delay_timer.c \ 159 drivers/st/clk/stm32mp_clkfunc.c \ 160 drivers/st/ddr/stm32mp_ddr.c \ 161 drivers/st/gpio/stm32_gpio.c \ 162 drivers/st/regulator/regulator_core.c \ 163 drivers/st/regulator/regulator_fixed.c \ 164 plat/st/common/stm32mp_dt.c 165 166BL2_SOURCES += ${FCONF_SOURCES} ${FCONF_DYN_SOURCES} 167BL2_SOURCES += $(ZLIB_SOURCES) 168 169BL2_SOURCES += drivers/io/io_fip.c \ 170 plat/st/common/bl2_io_storage.c \ 171 plat/st/common/plat_image_load.c \ 172 plat/st/common/stm32mp_fconf_io.c 173 174BL2_SOURCES += drivers/io/io_block.c \ 175 drivers/io/io_mtd.c \ 176 drivers/io/io_storage.c 177 178ifneq (${DECRYPTION_SUPPORT},none) 179BL2_SOURCES += drivers/io/io_encrypted.c 180endif 181 182ifeq (${TRUSTED_BOARD_BOOT},1) 183AUTH_MK := drivers/auth/auth.mk 184$(info Including ${AUTH_MK}) 185include ${AUTH_MK} 186 187ifeq (${GENERATE_COT},1) 188TFW_NVCTR_VAL := 0 189NTFW_NVCTR_VAL := 0 190KEY_ALG := ecdsa 191HASH_ALG := sha256 192 193ifeq (${SAVE_KEYS},1) 194TRUSTED_WORLD_KEY ?= ${BUILD_PLAT}/trusted.pem 195NON_TRUSTED_WORLD_KEY ?= ${BUILD_PLAT}/non-trusted.pem 196BL32_KEY ?= ${BUILD_PLAT}/trusted_os.pem 197BL33_KEY ?= ${BUILD_PLAT}/non-trusted_os.pem 198endif 199 200endif 201TF_MBEDTLS_KEY_ALG := ecdsa 202KEY_SIZE := 256 203 204PLAT_INCLUDES += -Iinclude/drivers/auth/mbedtls 205 206MBEDTLS_CONFIG_FILE ?= "<stm32mp_mbedtls_config.h>" 207 208include drivers/auth/mbedtls/mbedtls_x509.mk 209 210COT_DESC_IN_DTB := 1 211AUTH_SOURCES += lib/fconf/fconf_cot_getter.c \ 212 lib/fconf/fconf_tbbr_getter.c \ 213 plat/st/common/stm32mp_crypto_lib.c 214 215BL2_SOURCES += $(AUTH_SOURCES) \ 216 plat/st/common/stm32mp_trusted_boot.c 217endif 218 219ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),) 220BL2_SOURCES += drivers/mmc/mmc.c \ 221 drivers/partition/gpt.c \ 222 drivers/partition/partition.c 223endif 224 225ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),) 226BL2_SOURCES += drivers/mtd/spi-mem/spi_mem.c 227endif 228 229ifeq (${STM32MP_RAW_NAND},1) 230$(eval $(call add_define_val,NAND_ONFI_DETECT,1)) 231BL2_SOURCES += drivers/mtd/nand/raw_nand.c 232endif 233 234ifeq (${STM32MP_SPI_NAND},1) 235BL2_SOURCES += drivers/mtd/nand/spi_nand.c 236endif 237 238ifeq (${STM32MP_SPI_NOR},1) 239ifneq (${STM32MP_FORCE_MTD_START_OFFSET},) 240$(eval $(call add_define_val,STM32MP_NOR_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET})) 241endif 242BL2_SOURCES += drivers/mtd/nor/spi_nor.c 243endif 244 245ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),) 246ifneq (${STM32MP_FORCE_MTD_START_OFFSET},) 247$(eval $(call add_define_val,STM32MP_NAND_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET})) 248endif 249BL2_SOURCES += drivers/mtd/nand/core.c 250endif 251 252ifneq ($(filter 1,${STM32MP_UART_PROGRAMMER} ${STM32MP_USB_PROGRAMMER}),) 253BL2_SOURCES += drivers/io/io_memmap.c 254endif 255 256ifeq (${STM32MP_UART_PROGRAMMER},1) 257BL2_SOURCES += plat/st/common/stm32cubeprogrammer_uart.c 258endif 259 260ifeq (${STM32MP_USB_PROGRAMMER},1) 261BL2_SOURCES += drivers/usb/usb_device.c \ 262 plat/st/common/stm32cubeprogrammer_usb.c \ 263 plat/st/common/usb_dfu.c 264endif 265 266BL2_SOURCES += drivers/st/ddr/stm32mp_ddr_test.c \ 267 drivers/st/ddr/stm32mp_ram.c 268 269BL2_SOURCES += common/desc_image_load.c 270 271BL2_SOURCES += lib/optee/optee_utils.c 272