common.mk 7.3 KB

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