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 ${EVENT_LOG_SOURCES} 100 101 BL1_SOURCES += plat/qemu/qemu/qemu_bl1_measured_boot.c 102 103endif 104 105ifeq (${MEASURED_BOOT},1) 106ifeq (${TRUSTED_BOARD_BOOT},0) 107 CRYPTO_SOURCES := drivers/auth/crypto_mod.c 108 109 BL1_SOURCES += ${CRYPTO_SOURCES} 110 BL2_SOURCES += ${CRYPTO_SOURCES} 111endif 112endif 113 114ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 115 # We expect to locate the *.mk files under the directories specified below 116 # 117 include drivers/auth/mbedtls/mbedtls_crypto.mk 118endif 119 120BL2_SOURCES += common/uuid.c 121 122ifeq ($(add-lib-optee),yes) 123BL2_SOURCES += lib/optee/optee_utils.c 124endif 125 126ifneq (${DECRYPTION_SUPPORT},none) 127BL1_SOURCES += drivers/io/io_encrypted.c 128BL2_SOURCES += drivers/io/io_encrypted.c 129endif 130 131# Include GICv2 driver files 132include drivers/arm/gic/v2/gicv2.mk 133QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 134 plat/common/plat_gicv2.c \ 135 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 136 137# Include GICv3 driver files 138include drivers/arm/gic/v3/gicv3.mk 139 140QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 141 plat/common/plat_gicv3.c \ 142 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 143 144ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 145QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 146else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 147QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 148else 149$(error "Incorrect GIC driver chosen for QEMU platform") 150endif 151 152ifeq (${ARCH},aarch64) 153BL31_SOURCES += drivers/arm/pl061/pl061_gpio.c \ 154 drivers/gpio/gpio.c \ 155 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 156 ${PLAT_QEMU_COMMON_PATH}/topology.c 157 158ifeq (${SDEI_SUPPORT}, 1) 159BL31_SOURCES += plat/qemu/common/qemu_sdei.c 160endif 161 162ifeq (${SPD},spmd) 163BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 164 common/uuid.c \ 165 ${LIBFDT_SRCS} \ 166 ${FDT_WRAPPERS_SOURCES} 167endif 168endif 169 170# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 171# in the FIP if the platform requires. 172ifneq ($(BL32_EXTRA1),) 173ifneq (${DECRYPTION_SUPPORT},none) 174$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 175else 176$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 177endif 178endif 179ifneq ($(BL32_EXTRA2),) 180ifneq (${DECRYPTION_SUPPORT},none) 181$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 182else 183$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 184endif 185endif 186 187ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 188FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 189QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 190# Add the TB_FW_CONFIG to FIP 191$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 192endif 193 194ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 195FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 196QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 197# Add the TOS_FW_CONFIG to FIP 198$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 199endif 200 201BL32_RAM_LOCATION := tdram 202ifeq (${BL32_RAM_LOCATION}, tsram) 203 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 204 ifeq (${ENABLE_RME},1) 205 # Avoid overlap between BL2 and BL32 to ease GPT partition 206 $(error "With RME, BL32 must use secure DRAM") 207 endif 208else ifeq (${BL32_RAM_LOCATION}, tdram) 209 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 210else 211 $(error "Unsupported BL32_RAM_LOCATION value") 212endif 213 214# Process flags 215$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 216 217# Don't have the Linux kernel as a BL33 image by default 218ARM_LINUX_KERNEL_AS_BL33 := 0 219$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 220$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 221 222ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 223$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 224 225qemu_fw.bios: bl1 fip 226 $(s)echo " DD $@" 227 $(q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 228 $(q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 229 230qemu_fw.rom: qemu_fw.bios 231 $(s)echo " DD $@" 232 $(q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 233 $(q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 234 235ifneq (${BL33},) 236all: qemu_fw.bios qemu_fw.rom 237endif 238 239ifeq (${EL3_EXCEPTION_HANDLING},1) 240BL31_SOURCES += plat/common/aarch64/plat_ehf.c 241endif 242