1#
2# Copyright (c) 2015 - 2021, Broadcom
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7PLAT_BL_COMMON_SOURCES	+=	plat/brcm/board/common/board_common.c
8
9# If no board config makefile, do not include it
10ifneq (${BOARD_CFG},)
11BOARD_CFG_MAKE := $(shell find plat/brcm/board/${PLAT} -name '${BOARD_CFG}.mk')
12$(eval $(call add_define,BOARD_CFG))
13ifneq (${BOARD_CFG_MAKE},)
14$(info Including ${BOARD_CFG_MAKE})
15include ${BOARD_CFG_MAKE}
16else
17$(error Error: File ${BOARD_CFG}.mk not found in plat/brcm/board/${PLAT})
18endif
19endif
20
21# To compile with highest log level (VERBOSE) set value to 50
22LOG_LEVEL := 40
23
24# Use custom generic timer clock
25ifneq (${GENTIMER_ACTUAL_CLOCK},)
26$(info Using GENTIMER_ACTUAL_CLOCK=$(GENTIMER_ACTUAL_CLOCK))
27SYSCNT_FREQ := $(GENTIMER_ACTUAL_CLOCK)
28$(eval $(call add_define,SYSCNT_FREQ))
29endif
30
31ifeq (${DRIVER_EMMC_ENABLE},)
32DRIVER_EMMC_ENABLE :=1
33endif
34
35ifeq (${DRIVER_SPI_ENABLE},)
36DRIVER_SPI_ENABLE := 0
37endif
38
39ifeq (${DRIVER_I2C_ENABLE},)
40DRIVER_I2C_ENABLE := 0
41endif
42
43# By default, Trusted Watchdog is always enabled unless SPIN_ON_BL1_EXIT is set
44ifeq (${BRCM_DISABLE_TRUSTED_WDOG},)
45BRCM_DISABLE_TRUSTED_WDOG	:=	0
46endif
47ifeq (${SPIN_ON_BL1_EXIT}, 1)
48BRCM_DISABLE_TRUSTED_WDOG	:=	1
49endif
50
51$(eval $(call assert_boolean,BRCM_DISABLE_TRUSTED_WDOG))
52$(eval $(call add_define,BRCM_DISABLE_TRUSTED_WDOG))
53
54# Process ARM_BL31_IN_DRAM flag
55ifeq (${ARM_BL31_IN_DRAM},)
56ARM_BL31_IN_DRAM		:=	0
57endif
58$(eval $(call assert_boolean,ARM_BL31_IN_DRAM))
59$(eval $(call add_define,ARM_BL31_IN_DRAM))
60
61ifeq (${STANDALONE_BL2},yes)
62BL2_LOG_LEVEL := 40
63$(eval $(call add_define,MMU_DISABLED))
64endif
65
66# BL2 XIP from QSPI
67RUN_BL2_FROM_QSPI := 0
68ifeq (${RUN_BL2_FROM_QSPI},1)
69$(eval $(call add_define,RUN_BL2_FROM_QSPI))
70endif
71
72# BL2 XIP from NAND
73RUN_BL2_FROM_NAND := 0
74ifeq (${RUN_BL2_FROM_NAND},1)
75$(eval $(call add_define,RUN_BL2_FROM_NAND))
76endif
77
78ifneq (${ELOG_AP_UART_LOG_BASE},)
79$(eval $(call add_define,ELOG_AP_UART_LOG_BASE))
80endif
81
82ifeq (${ELOG_SUPPORT},1)
83ifeq (${ELOG_STORE_MEDIA},DDR)
84$(eval $(call add_define,ELOG_STORE_MEDIA_DDR))
85ifneq (${ELOG_STORE_OFFSET},)
86$(eval $(call add_define,ELOG_STORE_OFFSET))
87endif
88endif
89endif
90
91ifneq (${BL2_LOG_LEVEL},)
92$(eval $(call add_define,BL2_LOG_LEVEL))
93endif
94
95ifneq (${BL31_LOG_LEVEL},)
96$(eval $(call add_define,BL31_LOG_LEVEL))
97endif
98
99# Use CRMU SRAM from iHOST
100ifneq (${USE_CRMU_SRAM},)
101$(eval $(call add_define,USE_CRMU_SRAM))
102endif
103
104# Use PIO mode if DDR is not used
105ifeq (${USE_DDR},yes)
106EMMC_USE_DMA	:=	1
107else
108EMMC_USE_DMA	:=	0
109endif
110$(eval $(call add_define,EMMC_USE_DMA))
111
112# On BRCM platforms, separate the code and read-only data sections to allow
113# mapping the former as executable and the latter as execute-never.
114SEPARATE_CODE_AND_RODATA	:=	1
115
116# Use generic OID definition (tbbr_oid.h)
117USE_TBBR_DEFS			:=	1
118
119PLAT_INCLUDES		+=	-Iplat/brcm/board/common \
120				-Iinclude/drivers/brcm \
121				-Iinclude/drivers/brcm/emmc \
122				-Iinclude/drivers/brcm/mdio
123
124PLAT_BL_COMMON_SOURCES	+=	plat/brcm/common/brcm_common.c \
125				plat/brcm/board/common/cmn_sec.c \
126				plat/brcm/board/common/bcm_console.c \
127				plat/brcm/board/common/brcm_mbedtls.c \
128				plat/brcm/board/common/plat_setup.c \
129				plat/brcm/board/common/platform_common.c \
130				drivers/arm/sp804/sp804_delay_timer.c \
131				drivers/brcm/sotp.c \
132				drivers/delay_timer/delay_timer.c \
133				drivers/io/io_fip.c \
134				drivers/io/io_memmap.c \
135				drivers/io/io_storage.c \
136				plat/brcm/common/brcm_io_storage.c \
137				plat/brcm/board/common/err.c \
138				plat/brcm/board/common/sbl_util.c \
139				drivers/arm/sp805/sp805.c
140
141# Add RNG driver
142DRIVER_RNG_ENABLE := 1
143ifeq (${DRIVER_RNG_ENABLE},1)
144PLAT_BL_COMMON_SOURCES	+=	drivers/brcm/rng.c
145endif
146
147# Add eMMC driver
148ifeq (${DRIVER_EMMC_ENABLE},1)
149$(eval $(call add_define,DRIVER_EMMC_ENABLE))
150
151EMMC_SOURCES		+=	drivers/brcm/emmc/emmc_chal_sd.c \
152				drivers/brcm/emmc/emmc_csl_sdcard.c \
153				drivers/brcm/emmc/emmc_csl_sdcmd.c \
154				drivers/brcm/emmc/emmc_pboot_hal_memory_drv.c
155
156PLAT_BL_COMMON_SOURCES += ${EMMC_SOURCES}
157
158ifeq (${DRIVER_EMMC_ENABLE_DATA_WIDTH_8BIT},)
159$(eval $(call add_define,DRIVER_EMMC_ENABLE_DATA_WIDTH_8BIT))
160endif
161endif
162
163BL2_SOURCES		+=	plat/brcm/common/brcm_bl2_mem_params_desc.c \
164				plat/brcm/common/brcm_image_load.c \
165				common/desc_image_load.c
166
167BL2_SOURCES		+= 	plat/brcm/common/brcm_bl2_setup.c
168
169BL31_SOURCES		+=	plat/brcm/common/brcm_bl31_setup.c
170
171ifeq (${BCM_ELOG},yes)
172ELOG_SOURCES		+= 	plat/brcm/board/common/bcm_elog.c
173BL2_SOURCES		+= 	${ELOG_SOURCES}
174BL31_SOURCES		+= 	${ELOG_SOURCES}
175endif
176
177# Add spi driver
178ifeq (${DRIVER_SPI_ENABLE},1)
179PLAT_BL_COMMON_SOURCES	+=	drivers/brcm/spi/iproc_spi.c \
180				drivers/brcm/spi/iproc_qspi.c
181endif
182
183# Add spi nor/flash driver
184ifeq (${DRIVER_SPI_NOR_ENABLE},1)
185PLAT_BL_COMMON_SOURCES	+=	drivers/brcm/spi_sf.c \
186				drivers/brcm/spi_flash.c
187endif
188
189ifeq (${DRIVER_I2C_ENABLE},1)
190$(eval $(call add_define,DRIVER_I2C_ENABLE))
191BL2_SOURCES		+= 	drivers/brcm/i2c/i2c.c
192PLAT_INCLUDES		+=	-Iinclude/drivers/brcm/i2c
193endif
194
195ifeq (${DRIVER_OCOTP_ENABLE},1)
196$(eval $(call add_define,DRIVER_OCOTP_ENABLE))
197BL2_SOURCES		+= drivers/brcm/ocotp.c
198endif
199
200# Enable FRU table support
201ifeq (${USE_FRU},yes)
202$(eval $(call add_define,USE_FRU))
203BL2_SOURCES		+= drivers/brcm/fru.c
204endif
205
206# Enable GPIO support
207ifeq (${USE_GPIO},yes)
208$(eval $(call add_define,USE_GPIO))
209BL2_SOURCES             += drivers/gpio/gpio.c
210BL2_SOURCES             += drivers/brcm/iproc_gpio.c
211ifeq (${GPIO_SUPPORT_FLOAT_DETECTION},yes)
212$(eval $(call add_define,GPIO_SUPPORT_FLOAT_DETECTION))
213endif
214endif
215
216# Include mbedtls if it can be located
217MBEDTLS_DIR := mbedtls
218MBEDTLS_CHECK := $(shell find ${MBEDTLS_DIR}/include -name '${MBEDTLS_DIR}')
219
220ifneq (${MBEDTLS_CHECK},)
221$(info Found mbedTLS at ${MBEDTLS_DIR})
222PLAT_INCLUDES += -I${MBEDTLS_DIR}/include/mbedtls
223# Specify mbedTLS configuration file
224MBEDTLS_CONFIG_FILE	:=	"<brcm_mbedtls_config.h>"
225
226# By default, use RSA keys
227KEY_ALG := rsa_1_5
228
229# Include common TBB sources
230AUTH_SOURCES	+= 	drivers/auth/auth_mod.c \
231			drivers/auth/crypto_mod.c \
232			drivers/auth/img_parser_mod.c \
233			drivers/auth/tbbr/tbbr_cot_common.c \
234			drivers/auth/tbbr/tbbr_cot_bl2.c
235
236BL2_SOURCES	+=	${AUTH_SOURCES}
237
238# Use ATF framework for MBEDTLS
239TRUSTED_BOARD_BOOT := 1
240CRYPTO_LIB_MK := drivers/auth/mbedtls/mbedtls_crypto.mk
241IMG_PARSER_LIB_MK := drivers/auth/mbedtls/mbedtls_x509.mk
242$(info Including ${CRYPTO_LIB_MK})
243include ${CRYPTO_LIB_MK}
244$(info Including ${IMG_PARSER_LIB_MK})
245include ${IMG_PARSER_LIB_MK}
246
247# Use ATF secure boot functions
248# Use Hardcoded hash for devel
249
250ARM_ROTPK_LOCATION=arm_rsa
251ifeq (${ARM_ROTPK_LOCATION}, arm_rsa)
252ARM_ROTPK_LOCATION_ID=ARM_ROTPK_DEVEL_RSA_ID
253ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem
254else ifeq (${ARM_ROTPK_LOCATION}, brcm_rsa)
255ARM_ROTPK_LOCATION_ID=BRCM_ROTPK_SOTP_RSA_ID
256ifeq (${ROT_KEY},)
257ROT_KEY=plat/brcm/board/common/rotpk/rsa_dauth2048_key.pem
258endif
259KEY_FIND := $(shell m="${ROT_KEY}"; [ -f "$$m" ] && echo "$$m")
260ifeq (${KEY_FIND},)
261$(error Error: No ${ROT_KEY} located)
262else
263$(info Using ROT_KEY: ${ROT_KEY})
264endif
265else
266$(error "Unsupported ARM_ROTPK_LOCATION value")
267endif
268
269$(eval $(call add_define,ARM_ROTPK_LOCATION_ID))
270PLAT_BL_COMMON_SOURCES+=plat/brcm/board/common/board_arm_trusted_boot.c
271endif
272
273#M0 runtime firmware
274ifdef SCP_BL2
275$(eval $(call add_define,NEED_SCP_BL2))
276SCP_CFG_DIR=$(dir ${SCP_BL2})
277PLAT_INCLUDES += -I${SCP_CFG_DIR}
278endif
279
280ifneq (${NEED_BL33},yes)
281# If there is no BL33, BL31 will jump to this address.
282ifeq (${USE_DDR},yes)
283PRELOADED_BL33_BASE := 0x80000000
284else
285PRELOADED_BL33_BASE := 0x74000000
286endif
287endif
288
289# Use translation tables library v1 by default
290ARM_XLAT_TABLES_LIB_V1		:=	1
291ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
292$(eval $(call assert_boolean,ARM_XLAT_TABLES_LIB_V1))
293$(eval $(call add_define,ARM_XLAT_TABLES_LIB_V1))
294PLAT_BL_COMMON_SOURCES	+=	lib/xlat_tables/aarch64/xlat_tables.c \
295				lib/xlat_tables/xlat_tables_common.c
296endif
297