blob: 50fb1b77b44e0e44a9f5a51cfd232e01fa7fec9f [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001#
Yann Gautierdca61542021-02-10 18:19:23 +01002# Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Yann Gautier4b0c72a2018-07-16 10:54:09 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7ARM_CORTEX_A7 := yes
8ARM_WITH_NEON := yes
Yann Gautier4b0c72a2018-07-16 10:54:09 +02009BL2_AT_EL3 := 1
Yann Gautier4b0c72a2018-07-16 10:54:09 +020010USE_COHERENT_MEM := 0
11
Yann Gautierdca61542021-02-10 18:19:23 +010012ENABLE_PIE := 1
13
Yann Gautier4b0c72a2018-07-16 10:54:09 +020014STM32_TF_VERSION ?= 0
15
Yann Gautiera55169b2020-01-10 18:18:59 +010016# Enable dynamic memory mapping
17PLAT_XLAT_TABLES_DYNAMIC := 1
Yann Gautiera55169b2020-01-10 18:18:59 +010018
Etienne Carriereca651fb2020-04-10 18:51:54 +020019ifeq ($(AARCH32_SP),sp_min)
20# Disable Neon support: sp_min runtime may conflict with non-secure world
Yann Gautier46f8e672020-09-18 10:32:37 +020021TF_CFLAGS += -mfloat-abi=soft
Etienne Carriereca651fb2020-04-10 18:51:54 +020022endif
23
Yann Gautier4b0c72a2018-07-16 10:54:09 +020024# Not needed for Cortex-A7
25WORKAROUND_CVE_2017_5715:= 0
26
Yann Gautier8244e1d2018-10-15 09:36:58 +020027# Number of TF-A copies in the device
28STM32_TF_A_COPIES := 2
Yann Gautier6916a442020-09-17 12:28:12 +020029STM32_BL33_PARTS_NUM := 1
Yann Gautierb3386f72019-04-19 09:41:01 +020030ifeq ($(AARCH32_SP),optee)
Yann Gautier6916a442020-09-17 12:28:12 +020031STM32_RUNTIME_PARTS_NUM := 3
Yann Gautierb3386f72019-04-19 09:41:01 +020032else
Yann Gautier6916a442020-09-17 12:28:12 +020033STM32_RUNTIME_PARTS_NUM := 0
Yann Gautierb3386f72019-04-19 09:41:01 +020034endif
Yann Gautier6916a442020-09-17 12:28:12 +020035PLAT_PARTITION_MAX_ENTRIES := $(shell echo $$(($(STM32_TF_A_COPIES) + \
36 $(STM32_BL33_PARTS_NUM) + \
37 $(STM32_RUNTIME_PARTS_NUM))))
Yann Gautier8244e1d2018-10-15 09:36:58 +020038
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020039# Boot devices
40STM32MP_EMMC ?= 0
41STM32MP_SDMMC ?= 0
Lionel Debieve402a46b2019-11-04 12:28:15 +010042STM32MP_RAW_NAND ?= 0
Lionel Debieve186b0462019-09-24 18:30:12 +020043STM32MP_SPI_NAND ?= 0
Lionel Debievecb0dbc42019-09-25 09:11:31 +020044STM32MP_SPI_NOR ?= 0
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020045
Lionel Debieve186b0462019-09-24 18:30:12 +020046ifeq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC} ${STM32MP_RAW_NAND} \
Lionel Debievecb0dbc42019-09-25 09:11:31 +020047 ${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020048$(error "No boot device driver is enabled")
49endif
50
Yann Gautier5f400632020-02-12 09:30:49 +010051# Device tree
52DTB_FILE_NAME ?= stm32mp157c-ev1.dtb
53FDT_SOURCES := $(addprefix fdts/, $(patsubst %.dtb,%.dts,$(DTB_FILE_NAME)))
54DTC_FLAGS += -Wno-unit_address_vs_reg
55
56# Macros and rules to build TF binary
57STM32_TF_ELF_LDFLAGS := --hash-style=gnu --as-needed
58STM32_TF_STM32 := $(addprefix ${BUILD_PLAT}/tf-a-, $(patsubst %.dtb,%.stm32,$(DTB_FILE_NAME)))
59STM32_TF_LINKERFILE := ${BUILD_PLAT}/stm32mp1.ld
60
61ASFLAGS += -DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\"
62ifeq ($(AARCH32_SP),sp_min)
63# BL32 is built only if using SP_MIN
64BL32_DEP := bl32
65ASFLAGS += -DBL32_BIN_PATH=\"${BUILD_PLAT}/bl32.bin\"
66endif
67
68# Variables for use with stm32image
69STM32IMAGEPATH ?= tools/stm32image
70STM32IMAGE ?= ${STM32IMAGEPATH}/stm32image${BIN_EXT}
71
72# Enable flags for C files
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050073$(eval $(call assert_booleans,\
Yann Gautier5f400632020-02-12 09:30:49 +010074 $(sort \
75 STM32MP_EMMC \
76 STM32MP_SDMMC \
77 STM32MP_RAW_NAND \
78 STM32MP_SPI_NAND \
79 STM32MP_SPI_NOR \
80 PLAT_XLAT_TABLES_DYNAMIC \
81)))
82
83$(eval $(call assert_numerics,\
84 $(sort \
85 STM32_TF_A_COPIES \
86 PLAT_PARTITION_MAX_ENTRIES \
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050087)))
88
89$(eval $(call add_defines,\
Yann Gautier5f400632020-02-12 09:30:49 +010090 $(sort \
91 STM32MP_EMMC \
92 STM32MP_SDMMC \
93 STM32MP_RAW_NAND \
94 STM32MP_SPI_NAND \
95 STM32MP_SPI_NOR \
96 PLAT_XLAT_TABLES_DYNAMIC \
97 STM32_TF_A_COPIES \
98 PLAT_PARTITION_MAX_ENTRIES \
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050099)))
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200100
Yann Gautier5f400632020-02-12 09:30:49 +0100101# Include paths and source files
Yann Gautieree8f5422019-02-14 11:13:25 +0100102PLAT_INCLUDES := -Iplat/st/common/include/
103PLAT_INCLUDES += -Iplat/st/stm32mp1/include/
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200104
105include lib/libfdt/libfdt.mk
106
Andre Przywaracc99f3f2020-03-26 12:51:21 +0000107PLAT_BL_COMMON_SOURCES := common/fdt_wrappers.c \
108 plat/st/common/stm32mp_common.c \
Yann Gautieree8f5422019-02-14 11:13:25 +0100109 plat/st/stm32mp1/stm32mp1_private.c
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200110
Julius Werner6b88b652018-11-27 17:50:28 -0800111PLAT_BL_COMMON_SOURCES += drivers/st/uart/aarch32/stm32_console.S
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200112
113ifneq (${ENABLE_STACK_PROTECTOR},0)
114PLAT_BL_COMMON_SOURCES += plat/st/stm32mp1/stm32mp1_stack_protector.c
115endif
116
117include lib/xlat_tables_v2/xlat_tables.mk
118PLAT_BL_COMMON_SOURCES += ${XLAT_TABLES_LIB_SRCS}
119
120PLAT_BL_COMMON_SOURCES += lib/cpus/aarch32/cortex_a7.S
121
Yann Gautier2c1fa282019-05-09 11:56:30 +0200122PLAT_BL_COMMON_SOURCES += drivers/arm/tzc/tzc400.c \
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200123 drivers/delay_timer/delay_timer.c \
124 drivers/delay_timer/generic_delay_timer.c \
Yann Gautier36a1e4b2019-01-17 14:52:47 +0100125 drivers/st/bsec/bsec.c \
Yann Gautier4d429472019-02-14 11:15:20 +0100126 drivers/st/clk/stm32mp_clkfunc.c \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200127 drivers/st/clk/stm32mp1_clk.c \
Yann Gautiercaf575b2018-07-24 17:18:19 +0200128 drivers/st/ddr/stm32mp1_ddr_helpers.c \
Yann Gautierd0ca7f42018-07-13 21:33:09 +0200129 drivers/st/gpio/stm32_gpio.c \
Yann Gautier113f31e2019-01-17 09:34:18 +0100130 drivers/st/i2c/stm32_i2c.c \
Yann Gautier091eab52019-06-04 18:06:34 +0200131 drivers/st/iwdg/stm32_iwdg.c \
Yann Gautiera45433b2019-01-16 18:31:00 +0100132 drivers/st/pmic/stm32mp_pmic.c \
133 drivers/st/pmic/stpmic1.c \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200134 drivers/st/reset/stm32mp1_reset.c \
Yann Gautieree8f5422019-02-14 11:13:25 +0100135 plat/st/common/stm32mp_dt.c \
Yann Gautier41934662018-07-20 11:36:05 +0200136 plat/st/stm32mp1/stm32mp1_context.c \
Yann Gautier091eab52019-06-04 18:06:34 +0200137 plat/st/stm32mp1/stm32mp1_dbgmcu.c \
Yann Gautiercaf575b2018-07-24 17:18:19 +0200138 plat/st/stm32mp1/stm32mp1_helper.S \
Yann Gautier3edc7c32019-05-20 19:17:08 +0200139 plat/st/stm32mp1/stm32mp1_security.c \
140 plat/st/stm32mp1/stm32mp1_syscfg.c
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200141
Yann Gautier8244e1d2018-10-15 09:36:58 +0200142BL2_SOURCES += drivers/io/io_block.c \
143 drivers/io/io_dummy.c \
Lionel Debieve402a46b2019-11-04 12:28:15 +0100144 drivers/io/io_mtd.c \
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200145 drivers/io/io_storage.c \
Lionel Debieve7bd96f42019-09-03 12:22:23 +0200146 drivers/st/crypto/stm32_hash.c \
Yann Gautier8244e1d2018-10-15 09:36:58 +0200147 drivers/st/io/io_stm32image.c \
Lionel Debieve7bd96f42019-09-03 12:22:23 +0200148 plat/st/common/stm32mp_auth.c \
Yann Gautieree8f5422019-02-14 11:13:25 +0100149 plat/st/common/bl2_io_storage.c \
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200150 plat/st/stm32mp1/bl2_plat_setup.c
151
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200152ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),)
Yann Gautier8244e1d2018-10-15 09:36:58 +0200153BL2_SOURCES += drivers/mmc/mmc.c \
154 drivers/partition/gpt.c \
155 drivers/partition/partition.c \
156 drivers/st/io/io_mmc.c \
157 drivers/st/mmc/stm32_sdmmc2.c
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200158endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200159
Lionel Debieve402a46b2019-11-04 12:28:15 +0100160ifeq (${STM32MP_RAW_NAND},1)
161$(eval $(call add_define_val,NAND_ONFI_DETECT,1))
162BL2_SOURCES += drivers/mtd/nand/raw_nand.c \
163 drivers/st/fmc/stm32_fmc2_nand.c
164endif
165
Lionel Debieve186b0462019-09-24 18:30:12 +0200166ifeq (${STM32MP_SPI_NAND},1)
167BL2_SOURCES += drivers/mtd/nand/spi_nand.c
168endif
169
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200170ifeq (${STM32MP_SPI_NOR},1)
171BL2_SOURCES += drivers/mtd/nor/spi_nor.c
172endif
173
174ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
Lionel Debieve186b0462019-09-24 18:30:12 +0200175BL2_SOURCES += drivers/mtd/spi-mem/spi_mem.c \
176 drivers/st/spi/stm32_qspi.c
177endif
178
179ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),)
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200180BL2_SOURCES += drivers/mtd/nand/core.c
181endif
182
183ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
184BL2_SOURCES += plat/st/stm32mp1/stm32mp1_boot_device.c
Lionel Debieve402a46b2019-11-04 12:28:15 +0100185endif
186
Yann Gautiercaf575b2018-07-24 17:18:19 +0200187BL2_SOURCES += drivers/st/ddr/stm32mp1_ddr.c \
188 drivers/st/ddr/stm32mp1_ram.c
189
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200190BL2_SOURCES += common/desc_image_load.c \
191 plat/st/stm32mp1/plat_bl2_mem_params_desc.c \
192 plat/st/stm32mp1/plat_image_load.c
193
Yann Gautierb3386f72019-04-19 09:41:01 +0200194ifeq ($(AARCH32_SP),optee)
195BL2_SOURCES += lib/optee/optee_utils.c
196endif
197
Yann Gautier5f400632020-02-12 09:30:49 +0100198# Compilation rules
199.PHONY: check_dtc_version stm32image clean_stm32image
Yann Gautier761797d2018-07-16 14:34:50 +0200200.SUFFIXES:
201
Yann Gautier3f10a2f2020-09-18 10:21:29 +0200202all: check_dtc_version stm32image ${STM32_TF_STM32}
Yann Gautier761797d2018-07-16 14:34:50 +0200203
Yann Gautier761797d2018-07-16 14:34:50 +0200204distclean realclean clean: clean_stm32image
205
Yann Gautier3f10a2f2020-09-18 10:21:29 +0200206stm32image: ${STM32IMAGE}
207
208${STM32IMAGE}: ${STM32IMAGE_SRC}
Yann Gautier761797d2018-07-16 14:34:50 +0200209 ${Q}${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}
210
211clean_stm32image:
212 ${Q}${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean
213
214check_dtc_version:
215 $(eval DTC_V = $(shell $(DTC) -v | awk '{print $$NF}'))
216 $(eval DTC_VERSION = $(shell printf "%d" $(shell echo ${DTC_V} | cut -d- -f1 | sed "s/\./0/g")))
217 @if [ ${DTC_VERSION} -lt 10404 ]; then \
218 echo "dtc version too old (${DTC_V}), you need at least version 1.4.4"; \
219 false; \
220 fi
221
222
Yann Gautier46f8e672020-09-18 10:32:37 +0200223${BUILD_PLAT}/stm32mp1-%.o: ${BUILD_PLAT}/fdts/%.dtb plat/st/stm32mp1/stm32mp1.S bl2 ${BL32_DEP}
224 @echo " AS stm32mp1.S"
225 ${Q}${AS} ${ASFLAGS} ${TF_CFLAGS} \
226 -DDTB_BIN_PATH=\"$<\" \
227 -c plat/st/stm32mp1/stm32mp1.S -o $@
Yann Gautier761797d2018-07-16 14:34:50 +0200228
Yann Gautier7faa3bb2020-05-14 16:54:12 +0200229$(eval $(call MAKE_LD,${STM32_TF_LINKERFILE},plat/st/stm32mp1/stm32mp1.ld.S,2))
Yann Gautier761797d2018-07-16 14:34:50 +0200230
Yann Gautier46f8e672020-09-18 10:32:37 +0200231tf-a-%.elf: stm32mp1-%.o ${STM32_TF_LINKERFILE}
232 @echo " LDS $<"
233 ${Q}${LD} -o $@ ${STM32_TF_ELF_LDFLAGS} -Map=$(@:.elf=.map) --script ${STM32_TF_LINKERFILE} $<
Yann Gautier761797d2018-07-16 14:34:50 +0200234
Yann Gautier46f8e672020-09-18 10:32:37 +0200235tf-a-%.bin: tf-a-%.elf
236 ${Q}${OC} -O binary $< $@
237 @echo
238 @echo "Built $@ successfully"
239 @echo
Yann Gautier761797d2018-07-16 14:34:50 +0200240
Yann Gautier46f8e672020-09-18 10:32:37 +0200241tf-a-%.stm32: ${STM32IMAGE} tf-a-%.bin
242 @echo
243 @echo "Generate $@"
244 $(eval LOADADDR = $(shell cat $(@:.stm32=.map) | grep RAM | awk '{print $$2}'))
245 $(eval ENTRY = $(shell cat $(@:.stm32=.map) | grep "__BL2_IMAGE_START" | awk '{print $$1}'))
246 ${Q}${STM32IMAGE} -s $(word 2,$^) -d $@ \
247 -l $(LOADADDR) -e ${ENTRY} \
248 -v ${STM32_TF_VERSION}
249 @echo