1# 2# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7PLAT_QEMU_PATH := plat/qemu/qemu 8PLAT_QEMU_COMMON_PATH := plat/qemu/common 9 10SEPARATE_CODE_AND_RODATA := 1 11ENABLE_STACK_PROTECTOR := 0 12 13include plat/qemu/common/common.mk 14 15# Use the GICv2 driver on QEMU by default 16QEMU_USE_GIC_DRIVER := QEMU_GICV2 17 18ifeq (${ARM_ARCH_MAJOR},7) 19# ARMv7 Qemu support in trusted firmware expects the Cortex-A15 model. 20# Qemu Cortex-A15 model does not implement the virtualization extension. 21# For this reason, we cannot set ARM_CORTEX_A15=yes and must define all 22# the ARMv7 build directives. 23MARCH_DIRECTIVE := -mcpu=cortex-a15 24$(eval $(call add_define,ARMV7_SUPPORTS_LARGE_PAGE_ADDRESSING)) 25$(eval $(call add_define,ARMV7_SUPPORTS_GENERIC_TIMER)) 26$(eval $(call add_define,ARMV7_SUPPORTS_VFP)) 27# Qemu expects a BL32 boot stage. 28NEED_BL32 := yes 29endif # ARMv7 30 31ifeq (${SPD},opteed) 32add-lib-optee := yes 33endif 34ifeq ($(AARCH32_SP),optee) 35add-lib-optee := yes 36endif 37ifeq ($(SPMC_OPTEE),1) 38$(eval $(call add_define,SPMC_OPTEE)) 39add-lib-optee := yes 40endif 41 42ifeq ($(NEED_BL32),yes) 43$(eval $(call add_define,QEMU_LOAD_BL32)) 44endif 45 46ifneq (${TRUSTED_BOARD_BOOT},0) 47 48 AUTH_MK := drivers/auth/auth.mk 49 $(info Including ${AUTH_MK}) 50 include ${AUTH_MK} 51 52 AUTH_SOURCES += drivers/auth/tbbr/tbbr_cot_common.c 53 54 BL1_SOURCES += ${AUTH_SOURCES} \ 55 bl1/tbbr/tbbr_img_desc.c \ 56 plat/common/tbbr/plat_tbbr.c \ 57 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 58 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 59 drivers/auth/tbbr/tbbr_cot_bl1.c 60 61 BL2_SOURCES += ${AUTH_SOURCES} \ 62 plat/common/tbbr/plat_tbbr.c \ 63 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 64 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 65 drivers/auth/tbbr/tbbr_cot_bl2.c 66 67 include drivers/auth/mbedtls/mbedtls_x509.mk 68 69 ROT_KEY = $(BUILD_PLAT)/rot_key.pem 70 ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin 71 72 $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) 73 74 $(BUILD_PLAT)/bl1/qemu_rotpk.o: $(ROTPK_HASH) 75 $(BUILD_PLAT)/bl2/qemu_rotpk.o: $(ROTPK_HASH) 76 77 certificates: $(ROT_KEY) 78 79 $(ROT_KEY): | $$(@D)/ 80 $(s)echo " OPENSSL $@" 81 $(q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null 82 83 $(ROTPK_HASH): $(ROT_KEY) | $$(@D)/ 84 $(s)echo " OPENSSL $@" 85 $(q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ 86 ${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null 87endif 88 89# Include Measured Boot makefile before any Crypto library makefile. 90# Crypto library makefile may need default definitions of Measured Boot build 91# flags present in Measured Boot makefile. 92ifeq (${MEASURED_BOOT},1) 93 MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk 94 $(info Including ${MEASURED_BOOT_MK}) 95 include ${MEASURED_BOOT_MK} 96 97 BL2_SOURCES += plat/qemu/qemu/qemu_measured_boot.c \ 98 plat/qemu/qemu/qemu_helpers.c 99 100 BL2_LIBS += $(LIBEVLOG_LIBS) 101 BL2_INCLUDE_DIRS += $(LIBEVLOG_INCLUDE_DIRS) 102 103 BL1_SOURCES += plat/qemu/qemu/qemu_bl1_measured_boot.c 104 105endif 106 107ifeq (${MEASURED_BOOT},1) 108ifeq (${TRUSTED_BOARD_BOOT},0) 109 CRYPTO_SOURCES := drivers/auth/crypto_mod.c 110 111 BL1_SOURCES += ${CRYPTO_SOURCES} 112 BL2_SOURCES += ${CRYPTO_SOURCES} 113endif 114endif 115 116ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 117 # We expect to locate the *.mk files under the directories specified below 118 # 119 include drivers/auth/mbedtls/mbedtls_crypto.mk 120endif 121 122BL2_SOURCES += common/uuid.c 123 124ifeq ($(add-lib-optee),yes) 125BL2_SOURCES += lib/optee/optee_utils.c 126endif 127 128ifneq (${DECRYPTION_SUPPORT},none) 129BL1_SOURCES += drivers/io/io_encrypted.c 130BL2_SOURCES += drivers/io/io_encrypted.c 131endif 132 133# Include GICv2 driver files 134include drivers/arm/gic/v2/gicv2.mk 135QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 136 plat/common/plat_gicv2.c \ 137 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 138 139# Include GICv3 driver files 140include drivers/arm/gic/v3/gicv3.mk 141 142QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 143 plat/common/plat_gicv3.c \ 144 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 145 146ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 147QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 148else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 149QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 150else 151$(error "Incorrect GIC driver chosen for QEMU platform") 152endif 153 154ifeq (${ARCH},aarch64) 155BL31_SOURCES += drivers/arm/pl061/pl061_gpio.c \ 156 drivers/gpio/gpio.c \ 157 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 158 ${PLAT_QEMU_COMMON_PATH}/topology.c 159 160ifeq (${SDEI_SUPPORT}, 1) 161BL31_SOURCES += plat/qemu/common/qemu_sdei.c 162endif 163 164ifeq (${SPD},spmd) 165BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 166 common/uuid.c \ 167 ${LIBFDT_SRCS} \ 168 ${FDT_WRAPPERS_SOURCES} 169endif 170endif 171 172# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 173# in the FIP if the platform requires. 174ifneq ($(BL32_EXTRA1),) 175ifneq (${DECRYPTION_SUPPORT},none) 176$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 177else 178$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 179endif 180endif 181ifneq ($(BL32_EXTRA2),) 182ifneq (${DECRYPTION_SUPPORT},none) 183$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 184else 185$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 186endif 187endif 188 189ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 190FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 191QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 192# Add the TB_FW_CONFIG to FIP 193$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 194endif 195 196ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 197FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 198QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 199# Add the TOS_FW_CONFIG to FIP 200$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 201endif 202 203BL32_RAM_LOCATION := tdram 204ifeq (${BL32_RAM_LOCATION}, tsram) 205 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 206 ifeq (${ENABLE_RME},1) 207 # Avoid overlap between BL2 and BL32 to ease GPT partition 208 $(error "With RME, BL32 must use secure DRAM") 209 endif 210else ifeq (${BL32_RAM_LOCATION}, tdram) 211 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 212else 213 $(error "Unsupported BL32_RAM_LOCATION value") 214endif 215 216# Process flags 217$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 218 219# Don't have the Linux kernel as a BL33 image by default 220ARM_LINUX_KERNEL_AS_BL33 := 0 221$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 222$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 223 224ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 225$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 226 227qemu_fw.bios: bl1 fip 228 $(s)echo " DD $@" 229 $(q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 230 $(q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 231 232qemu_fw.rom: qemu_fw.bios 233 $(s)echo " DD $@" 234 $(q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 235 $(q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 236 237ifneq (${BL33},) 238all: qemu_fw.bios qemu_fw.rom 239endif 240 241ifeq (${EL3_EXCEPTION_HANDLING},1) 242BL31_SOURCES += plat/common/aarch64/plat_ehf.c 243endif 244