1# 2# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7include lib/libfdt/libfdt.mk 8include lib/xlat_tables_v2/xlat_tables.mk 9 10PLAT_INCLUDES := -Iplat/rpi/common/include \ 11 -Iplat/rpi/rpi3/include \ 12 -Iinclude/lib/libfdt 13 14PLAT_BL_COMMON_SOURCES := drivers/ti/uart/aarch64/16550_console.S \ 15 drivers/arm/pl011/aarch64/pl011_console.S \ 16 drivers/gpio/gpio.c \ 17 drivers/delay_timer/delay_timer.c \ 18 drivers/rpi3/gpio/rpi3_gpio.c \ 19 plat/rpi/common/aarch64/plat_helpers.S \ 20 plat/rpi/common/rpi3_common.c \ 21 plat/rpi/common/rpi3_console_dual.c \ 22 ${XLAT_TABLES_LIB_SRCS} 23 24ifeq (${MEASURED_BOOT},1) 25MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk 26$(info Including ${MEASURED_BOOT_MK}) 27include ${MEASURED_BOOT_MK} 28 29PLAT_BL_COMMON_SOURCES += ${EVENT_LOG_SOURCES} 30 31BL1_SOURCES += plat/rpi/rpi3/rpi3_bl1_mboot.c 32BL2_SOURCES += plat/rpi/rpi3/rpi3_bl2_mboot.c \ 33 plat/rpi/rpi3/rpi3_dyn_cfg_helpers.c \ 34 common/fdt_wrappers.c \ 35 common/fdt_fixup.c 36 37CRYPTO_SOURCES := drivers/auth/crypto_mod.c 38 39BL1_SOURCES += ${CRYPTO_SOURCES} 40BL2_SOURCES += ${CRYPTO_SOURCES} 41 42include drivers/auth/mbedtls/mbedtls_crypto.mk 43 44endif 45 46BL1_SOURCES += drivers/io/io_fip.c \ 47 drivers/io/io_memmap.c \ 48 drivers/io/io_storage.c \ 49 drivers/delay_timer/generic_delay_timer.c \ 50 lib/cpus/aarch64/cortex_a53.S \ 51 plat/common/aarch64/platform_mp_stack.S \ 52 plat/rpi/rpi3/rpi3_bl1_setup.c \ 53 plat/rpi/common/rpi3_io_storage.c \ 54 drivers/rpi3/mailbox/rpi3_mbox.c \ 55 plat/rpi/rpi3/rpi_mbox_board.c 56 57BL2_SOURCES += common/desc_image_load.c \ 58 drivers/io/io_fip.c \ 59 drivers/io/io_memmap.c \ 60 drivers/io/io_storage.c \ 61 drivers/delay_timer/generic_delay_timer.c \ 62 drivers/io/io_block.c \ 63 drivers/mmc/mmc.c \ 64 drivers/rpi3/sdhost/rpi3_sdhost.c \ 65 plat/common/aarch64/platform_mp_stack.S \ 66 plat/rpi/rpi3/aarch64/rpi3_bl2_mem_params_desc.c \ 67 plat/rpi/rpi3/rpi3_bl2_setup.c \ 68 plat/rpi/common/rpi3_image_load.c \ 69 plat/rpi/common/rpi3_io_storage.c 70 71BL31_SOURCES += lib/cpus/aarch64/cortex_a53.S \ 72 plat/common/plat_gicv2.c \ 73 plat/common/plat_psci_common.c \ 74 plat/rpi/rpi3/rpi3_bl31_setup.c \ 75 plat/rpi/common/rpi3_pm.c \ 76 plat/rpi/common/rpi3_topology.c \ 77 ${LIBFDT_SRCS} 78 79# Tune compiler for Cortex-A53 80ifeq ($($(ARCH)-cc-id),arm-clang) 81 TF_CFLAGS_aarch64 += -mcpu=cortex-a53 82else ifneq ($(filter %-clang,$($(ARCH)-cc-id)),) 83 TF_CFLAGS_aarch64 += -mcpu=cortex-a53 84else 85 TF_CFLAGS_aarch64 += -mtune=cortex-a53 86endif 87 88# Platform Makefile target 89# ------------------------ 90 91RPI3_BL1_PAD_BIN := ${BUILD_PLAT}/bl1_pad.bin 92RPI3_ARMSTUB8_BIN := ${BUILD_PLAT}/armstub8.bin 93 94# Add new default target when compiling this platform 95all: armstub 96 97# This target concatenates BL1 and the FIP so that the base addresses match the 98# ones defined in the memory map 99armstub: bl1 fip 100 $(s)echo " CAT $@" 101 $(q)cp ${BUILD_PLAT}/bl1.bin ${RPI3_BL1_PAD_BIN} 102 $(q)truncate --size=131072 ${RPI3_BL1_PAD_BIN} 103 $(q)cat ${RPI3_BL1_PAD_BIN} ${BUILD_PLAT}/fip.bin > ${RPI3_ARMSTUB8_BIN} 104 $(s)echo 105 $(s)echo "Built $@ successfully" 106 $(s)echo 107 108# Build config flags 109# ------------------ 110 111# Enable all errata workarounds for Cortex-A53 112ERRATA_A53_826319 := 1 113ERRATA_A53_835769 := 1 114ERRATA_A53_836870 := 1 115ERRATA_A53_843419 := 1 116ERRATA_A53_855873 := 1 117 118WORKAROUND_CVE_2017_5715 := 0 119 120# Disable stack protector by default 121ENABLE_STACK_PROTECTOR := 0 122 123# Reset to BL31 isn't supported 124RESET_TO_BL31 := 0 125 126# Have different sections for code and rodata 127SEPARATE_CODE_AND_RODATA := 1 128 129# Use Coherent memory 130USE_COHERENT_MEM := 1 131 132# Platform build flags 133# -------------------- 134 135# BL33 images are in AArch64 by default 136RPI3_BL33_IN_AARCH32 := 0 137 138# Assume that BL33 isn't the Linux kernel by default 139RPI3_DIRECT_LINUX_BOOT := 0 140 141# UART to use at runtime. -1 means the runtime UART is disabled. 142# Any other value means the default UART will be used. 143RPI3_RUNTIME_UART := -1 144 145# Use normal memory mapping for ROM, FIP, SRAM and DRAM 146RPI3_USE_UEFI_MAP := 0 147 148# BL32 location 149RPI3_BL32_RAM_LOCATION := tdram 150ifeq (${RPI3_BL32_RAM_LOCATION}, tsram) 151 RPI3_BL32_RAM_LOCATION_ID = SEC_SRAM_ID 152else ifeq (${RPI3_BL32_RAM_LOCATION}, tdram) 153 RPI3_BL32_RAM_LOCATION_ID = SEC_DRAM_ID 154else 155 $(error "Unsupported RPI3_BL32_RAM_LOCATION value") 156endif 157 158# Process platform flags 159# ---------------------- 160 161$(eval $(call add_define,RPI3_BL32_RAM_LOCATION_ID)) 162$(eval $(call add_define,RPI3_BL33_IN_AARCH32)) 163$(eval $(call add_define,RPI3_DIRECT_LINUX_BOOT)) 164ifdef RPI3_PRELOADED_DTB_BASE 165$(eval $(call add_define,RPI3_PRELOADED_DTB_BASE)) 166endif 167$(eval $(call add_define,RPI3_RUNTIME_UART)) 168$(eval $(call add_define,RPI3_USE_UEFI_MAP)) 169 170# Verify build config 171# ------------------- 172# 173ifneq (${RPI3_DIRECT_LINUX_BOOT}, 0) 174 ifndef RPI3_PRELOADED_DTB_BASE 175 $(error Error: RPI3_PRELOADED_DTB_BASE needed if RPI3_DIRECT_LINUX_BOOT=1) 176 endif 177endif 178 179ifneq (${RESET_TO_BL31}, 0) 180 $(error Error: rpi3 needs RESET_TO_BL31=0) 181endif 182 183ifeq (${ARCH},aarch32) 184 $(error Error: AArch32 not supported on rpi3) 185endif 186 187ifneq ($(ENABLE_STACK_PROTECTOR), 0) 188PLAT_BL_COMMON_SOURCES += drivers/rpi3/rng/rpi3_rng.c \ 189 plat/rpi/common/rpi3_stack_protector.c 190endif 191 192ifeq (${SPD},opteed) 193BL2_SOURCES += \ 194 lib/optee/optee_utils.c 195endif 196 197# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 198# in the FIP if the platform requires. 199ifneq ($(BL32_EXTRA1),) 200$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1)) 201endif 202ifneq ($(BL32_EXTRA2),) 203$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2)) 204endif 205 206ifneq (${TRUSTED_BOARD_BOOT},0) 207 208 include drivers/auth/mbedtls/mbedtls_crypto.mk 209 include drivers/auth/mbedtls/mbedtls_x509.mk 210 211 AUTH_SOURCES := drivers/auth/auth_mod.c \ 212 drivers/auth/crypto_mod.c \ 213 drivers/auth/img_parser_mod.c \ 214 drivers/auth/tbbr/tbbr_cot_common.c 215 216 BL1_SOURCES += ${AUTH_SOURCES} \ 217 bl1/tbbr/tbbr_img_desc.c \ 218 plat/common/tbbr/plat_tbbr.c \ 219 plat/rpi/common/rpi3_trusted_boot.c \ 220 plat/rpi/common/rpi3_rotpk.S \ 221 drivers/auth/tbbr/tbbr_cot_bl1.c 222 223 BL2_SOURCES += ${AUTH_SOURCES} \ 224 plat/common/tbbr/plat_tbbr.c \ 225 plat/rpi/common/rpi3_trusted_boot.c \ 226 plat/rpi/common/rpi3_rotpk.S \ 227 drivers/auth/tbbr/tbbr_cot_bl2.c 228 229 ROT_KEY = $(BUILD_PLAT)/rot_key.pem 230 ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin 231 232 $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) 233 234 $(BUILD_PLAT)/bl1/rpi3_rotpk.o: $(ROTPK_HASH) 235 $(BUILD_PLAT)/bl2/rpi3_rotpk.o: $(ROTPK_HASH) 236 237 certificates: $(ROT_KEY) 238 239 $(ROT_KEY): | $$(@D)/ 240 $(s)echo " OPENSSL $@" 241 $(q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null 242 243 $(ROTPK_HASH): $(ROT_KEY) | $$(@D)/ 244 $(s)echo " OPENSSL $@" 245 $(q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ 246 ${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null 247endif 248