1# 2# Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7RESET_TO_BL2 := 1 8 9STM32MP_RECONFIGURE_CONSOLE ?= 0 10STM32MP_UART_BAUDRATE ?= 115200 11 12TRUSTED_BOARD_BOOT ?= 0 13STM32MP_USE_EXTERNAL_HEAP ?= 0 14 15# Use secure library from the ROM code for authentication 16STM32MP_CRYPTO_ROM_LIB ?= 0 17 18# Please don't increment this value without good understanding of 19# the monotonic counter 20STM32_TF_VERSION ?= 0 21 22# Enable dynamic memory mapping 23PLAT_XLAT_TABLES_DYNAMIC := 1 24 25# STM32 image header binary type for BL2 26STM32_HEADER_BL2_BINARY_TYPE := 0x10 27 28TF_CFLAGS += -Wsign-compare 29TF_CFLAGS += -Wformat-signedness 30 31# Number of TF-A copies in the device 32STM32_TF_A_COPIES := 2 33 34# PLAT_PARTITION_MAX_ENTRIES must take care of STM32_TF-A_COPIES and other partitions 35PLAT_PARTITION_MAX_ENTRIES := $(shell echo $$(($(STM32_TF_A_COPIES) + $(STM32_EXTRA_PARTS)))) 36 37ifeq (${PSA_FWU_SUPPORT},1) 38# Number of banks of updatable firmware 39NR_OF_FW_BANKS := 2 40NR_OF_IMAGES_IN_FW_BANK := 1 41 42FWU_MAX_PART = $(shell echo $$(($(STM32_TF_A_COPIES) + 2 + $(NR_OF_FW_BANKS)))) 43ifeq ($(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)") 46endif 47endif 48 49# Boot devices 50STM32MP_EMMC ?= 0 51STM32MP_SDMMC ?= 0 52STM32MP_RAW_NAND ?= 0 53STM32MP_SPI_NAND ?= 0 54STM32MP_SPI_NOR ?= 0 55 56# Put both BL2 and FIP in eMMC boot partition 57STM32MP_EMMC_BOOT ?= 0 58 59# Serial boot devices 60STM32MP_UART_PROGRAMMER ?= 0 61STM32MP_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]*"))) 65DTC_CPPFLAGS += ${INCLUDES} 66DTC_FLAGS += -Wno-unit_address_vs_reg 67ifeq ($(shell test $(DTC_VERSION) -ge 10601; echo $$?),0) 68DTC_FLAGS += -Wno-interrupt_provider 69endif 70 71# Macros and rules to build TF binary 72STM32_TF_ELF_LDFLAGS := --hash-style=gnu --as-needed 73STM32_TF_LINKERFILE := ${BUILD_PLAT}/${PLAT}.ld 74 75ASFLAGS += -DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\" 76 77# Variables for use with stm32image 78STM32IMAGEPATH ?= tools/stm32image 79STM32IMAGE ?= ${STM32IMAGEPATH}/stm32image${BIN_EXT} 80STM32IMAGE_SRC := ${STM32IMAGEPATH}/stm32image.c 81STM32_DEPS += ${STM32IMAGE} 82 83FIP_DEPS += dtbs 84STM32MP_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. 91ifneq ($(BL32_EXTRA1),) 92$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 93endif 94ifneq ($(BL32_EXTRA2),) 95$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 96endif 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 136PLAT_INCLUDES += -Iplat/st/common/include/ 137 138include lib/fconf/fconf.mk 139include lib/libfdt/libfdt.mk 140include lib/zlib/zlib.mk 141ifeq (${PSA_FWU_SUPPORT},1) 142include drivers/fwu/fwu.mk 143endif 144 145PLAT_BL_COMMON_SOURCES += common/uuid.c \ 146 plat/st/common/stm32mp_common.c 147 148 149include lib/xlat_tables_v2/xlat_tables.mk 150PLAT_BL_COMMON_SOURCES += ${XLAT_TABLES_LIB_SRCS} 151 152PLAT_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 162BL2_SOURCES += ${FCONF_SOURCES} ${FCONF_DYN_SOURCES} 163BL2_SOURCES += $(ZLIB_SOURCES) 164 165BL2_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 170BL2_SOURCES += drivers/io/io_block.c \ 171 drivers/io/io_mtd.c \ 172 drivers/io/io_storage.c 173 174ifneq (${DECRYPTION_SUPPORT},none) 175BL2_SOURCES += drivers/io/io_encrypted.c 176endif 177 178ifeq (${TRUSTED_BOARD_BOOT},1) 179AUTH_SOURCES := drivers/auth/auth_mod.c \ 180 drivers/auth/crypto_mod.c \ 181 drivers/auth/img_parser_mod.c 182 183ifeq (${GENERATE_COT},1) 184TFW_NVCTR_VAL := 0 185NTFW_NVCTR_VAL := 0 186KEY_ALG := ecdsa 187HASH_ALG := sha256 188 189ifeq (${SAVE_KEYS},1) 190TRUSTED_WORLD_KEY ?= ${BUILD_PLAT}/trusted.pem 191NON_TRUSTED_WORLD_KEY ?= ${BUILD_PLAT}/non-trusted.pem 192BL32_KEY ?= ${BUILD_PLAT}/trusted_os.pem 193BL33_KEY ?= ${BUILD_PLAT}/non-trusted_os.pem 194endif 195 196endif 197TF_MBEDTLS_KEY_ALG := ecdsa 198KEY_SIZE := 256 199 200ifneq (${MBEDTLS_DIR},) 201MBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" \ 202${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)') 203 204ifeq (${MBEDTLS_MAJOR}, 3) 205MBEDTLS_CONFIG_FILE ?= "<stm32mp_mbedtls_config-3.h>" 206else 207$(error Error: TF-A only supports MbedTLS versions > 3.x) 208endif 209endif 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