summaryrefslogtreecommitdiffstats
path: root/plat/st/common/common.mk
blob: 7f93961d8641f6ad06872103fbfd9b123d1b81dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#
# Copyright (c) 2023, STMicroelectronics - All Rights Reserved
#
# SPDX-License-Identifier: BSD-3-Clause
#

RESET_TO_BL2			:=	1

STM32MP_EARLY_CONSOLE		?=	0
STM32MP_RECONFIGURE_CONSOLE	?=	0
STM32MP_UART_BAUDRATE		?=	115200

TRUSTED_BOARD_BOOT		?=	0
STM32MP_USE_EXTERNAL_HEAP	?=	0

# Use secure library from the ROM code for authentication
STM32MP_CRYPTO_ROM_LIB		?=	0

# Please don't increment this value without good understanding of
# the monotonic counter
STM32_TF_VERSION		?=	0

# Enable dynamic memory mapping
PLAT_XLAT_TABLES_DYNAMIC	:=	1

# STM32 image header binary type for BL2
STM32_HEADER_BL2_BINARY_TYPE	:=	0x10

TF_CFLAGS			+=	-Wsign-compare
TF_CFLAGS			+=	-Wformat-signedness

# Boot devices
STM32MP_EMMC			?=	0
STM32MP_SDMMC			?=	0
STM32MP_RAW_NAND		?=	0
STM32MP_SPI_NAND		?=	0
STM32MP_SPI_NOR			?=	0

# Put both BL2 and FIP in eMMC boot partition
STM32MP_EMMC_BOOT		?=	0

# Serial boot devices
STM32MP_UART_PROGRAMMER		?=	0
STM32MP_USB_PROGRAMMER		?=	0

$(eval DTC_V = $(shell $(DTC) -v | awk '{print $$NF}'))
$(eval DTC_VERSION = $(shell printf "%d" $(shell echo ${DTC_V} | cut -d- -f1 | sed "s/\./0/g" | grep -o "[0-9]*")))
DTC_CPPFLAGS			+=	${INCLUDES}
DTC_FLAGS			+=	-Wno-unit_address_vs_reg
ifeq ($(shell test $(DTC_VERSION) -ge 10601; echo $$?),0)
DTC_FLAGS			+=	-Wno-interrupt_provider
endif

# Macros and rules to build TF binary
STM32_TF_ELF_LDFLAGS		:=	--hash-style=gnu --as-needed
STM32_TF_LINKERFILE		:=	${BUILD_PLAT}/${PLAT}.ld

ASFLAGS				+=	-DBL2_BIN_PATH=\"${BUILD_PLAT}/bl2.bin\"

# Variables for use with stm32image
STM32IMAGEPATH			?=	tools/stm32image
STM32IMAGE			?=	${STM32IMAGEPATH}/stm32image${BIN_EXT}
STM32IMAGE_SRC			:=	${STM32IMAGEPATH}/stm32image.c
STM32_DEPS			+=	${STM32IMAGE}

FIP_DEPS			+=	dtbs
STM32MP_HW_CONFIG		:=	${BL33_CFG}

# Add the HW_CONFIG to FIP and specify the same to certtool
$(eval $(call TOOL_ADD_PAYLOAD,${STM32MP_HW_CONFIG},--hw-config))

# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images
# in the FIP if the platform requires.
ifneq ($(BL32_EXTRA1),)
$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1,,$(ENCRYPT_BL32)))
endif
ifneq ($(BL32_EXTRA2),)
$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2,,$(ENCRYPT_BL32)))
endif

# Enable flags for C files
$(eval $(call assert_booleans,\
	$(sort \
		PLAT_XLAT_TABLES_DYNAMIC \
		STM32MP_EARLY_CONSOLE \
		STM32MP_EMMC \
		STM32MP_EMMC_BOOT \
		STM32MP_RAW_NAND \
		STM32MP_RECONFIGURE_CONSOLE \
		STM32MP_SDMMC \
		STM32MP_SPI_NAND \
		STM32MP_SPI_NOR \
		STM32MP_UART_PROGRAMMER \
		STM32MP_USB_PROGRAMMER \
)))

$(eval $(call assert_numerics,\
	$(sort \
		STM32_TF_VERSION \
		STM32MP_UART_BAUDRATE \
)))

$(eval $(call add_defines,\
	$(sort \
		PLAT_XLAT_TABLES_DYNAMIC \
		STM32_TF_VERSION \
		STM32MP_EARLY_CONSOLE \
		STM32MP_EMMC \
		STM32MP_EMMC_BOOT \
		STM32MP_RAW_NAND \
		STM32MP_RECONFIGURE_CONSOLE \
		STM32MP_SDMMC \
		STM32MP_SPI_NAND \
		STM32MP_SPI_NOR \
		STM32MP_UART_BAUDRATE \
		STM32MP_UART_PROGRAMMER \
		STM32MP_USB_PROGRAMMER \
)))

# Include paths and source files
PLAT_INCLUDES			+=	-Iplat/st/common/include/

include lib/fconf/fconf.mk
include lib/libfdt/libfdt.mk
include lib/zlib/zlib.mk

PLAT_BL_COMMON_SOURCES		+=	common/uuid.c					\
					plat/st/common/stm32mp_common.c


include lib/xlat_tables_v2/xlat_tables.mk
PLAT_BL_COMMON_SOURCES		+=	${XLAT_TABLES_LIB_SRCS}

PLAT_BL_COMMON_SOURCES		+=	drivers/clk/clk.c				\
					drivers/delay_timer/delay_timer.c		\
					drivers/delay_timer/generic_delay_timer.c	\
					drivers/st/clk/stm32mp_clkfunc.c		\
					drivers/st/ddr/stm32mp_ddr.c			\
					drivers/st/gpio/stm32_gpio.c			\
					drivers/st/regulator/regulator_core.c		\
					drivers/st/regulator/regulator_fixed.c		\
					plat/st/common/stm32mp_dt.c

BL2_SOURCES			+=	${FCONF_SOURCES} ${FCONF_DYN_SOURCES}
BL2_SOURCES			+=	$(ZLIB_SOURCES)

BL2_SOURCES			+=	drivers/io/io_fip.c				\
					plat/st/common/bl2_io_storage.c			\
					plat/st/common/plat_image_load.c		\
					plat/st/common/stm32mp_fconf_io.c

BL2_SOURCES			+=	drivers/io/io_block.c				\
					drivers/io/io_mtd.c				\
					drivers/io/io_storage.c

ifneq (${DECRYPTION_SUPPORT},none)
BL2_SOURCES			+=	drivers/io/io_encrypted.c
endif

ifeq (${TRUSTED_BOARD_BOOT},1)
AUTH_SOURCES			:=	drivers/auth/auth_mod.c				\
					drivers/auth/crypto_mod.c			\
					drivers/auth/img_parser_mod.c

ifeq (${GENERATE_COT},1)
TFW_NVCTR_VAL			:=	0
NTFW_NVCTR_VAL			:=	0
KEY_ALG				:=	ecdsa
HASH_ALG			:=	sha256

ifeq (${SAVE_KEYS},1)
TRUSTED_WORLD_KEY		?=	${BUILD_PLAT}/trusted.pem
NON_TRUSTED_WORLD_KEY		?=	${BUILD_PLAT}/non-trusted.pem
BL32_KEY			?=	${BUILD_PLAT}/trusted_os.pem
BL33_KEY			?=	${BUILD_PLAT}/non-trusted_os.pem
endif

endif
TF_MBEDTLS_KEY_ALG		:=	ecdsa
KEY_SIZE			:=	256

ifneq (${MBEDTLS_DIR},)
MBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" \
${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')

ifeq (${MBEDTLS_MAJOR}, 2)
MBEDTLS_CONFIG_FILE		?=	"<stm32mp_mbedtls_config-2.h>"
endif

ifeq (${MBEDTLS_MAJOR}, 3)
MBEDTLS_CONFIG_FILE		?=	"<stm32mp_mbedtls_config-3.h>"
endif
endif

include drivers/auth/mbedtls/mbedtls_x509.mk

COT_DESC_IN_DTB			:=	1
AUTH_SOURCES			+=	lib/fconf/fconf_cot_getter.c			\
					lib/fconf/fconf_tbbr_getter.c			\
					plat/st/common/stm32mp_crypto_lib.c

BL2_SOURCES			+=	$(AUTH_SOURCES)					\
					plat/st/common/stm32mp_trusted_boot.c
endif

ifneq ($(filter 1,${STM32MP_EMMC} ${STM32MP_SDMMC}),)
BL2_SOURCES			+=	drivers/mmc/mmc.c				\
					drivers/partition/gpt.c				\
					drivers/partition/partition.c
endif

ifneq ($(filter 1,${STM32MP_SPI_NAND} ${STM32MP_SPI_NOR}),)
BL2_SOURCES			+=	drivers/mtd/spi-mem/spi_mem.c
endif

ifeq (${STM32MP_RAW_NAND},1)
$(eval $(call add_define_val,NAND_ONFI_DETECT,1))
BL2_SOURCES			+=	drivers/mtd/nand/raw_nand.c
endif

ifeq (${STM32MP_SPI_NAND},1)
BL2_SOURCES			+=	drivers/mtd/nand/spi_nand.c
endif

ifeq (${STM32MP_SPI_NOR},1)
ifneq (${STM32MP_FORCE_MTD_START_OFFSET},)
$(eval $(call add_define_val,STM32MP_NOR_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET}))
endif
BL2_SOURCES			+=	drivers/mtd/nor/spi_nor.c
endif

ifneq ($(filter 1,${STM32MP_RAW_NAND} ${STM32MP_SPI_NAND}),)
ifneq (${STM32MP_FORCE_MTD_START_OFFSET},)
$(eval $(call add_define_val,STM32MP_NAND_FIP_OFFSET,${STM32MP_FORCE_MTD_START_OFFSET}))
endif
BL2_SOURCES			+=	drivers/mtd/nand/core.c
endif

ifneq ($(filter 1,${STM32MP_UART_PROGRAMMER} ${STM32MP_USB_PROGRAMMER}),)
BL2_SOURCES			+=	drivers/io/io_memmap.c
endif

ifeq (${STM32MP_UART_PROGRAMMER},1)
BL2_SOURCES			+=	plat/st/common/stm32cubeprogrammer_uart.c
endif

ifeq (${STM32MP_USB_PROGRAMMER},1)
BL2_SOURCES			+=	drivers/usb/usb_device.c			\
					plat/st/common/stm32cubeprogrammer_usb.c	\
					plat/st/common/usb_dfu.c
endif

BL2_SOURCES			+=	drivers/st/ddr/stm32mp_ddr_test.c		\
					drivers/st/ddr/stm32mp_ram.c

BL2_SOURCES			+=	common/desc_image_load.c

BL2_SOURCES			+=	lib/optee/optee_utils.c