1# 2# Copyright (c) 2013-2024, 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_SOURCES := drivers/auth/auth_mod.c \ 49 drivers/auth/img_parser_mod.c \ 50 drivers/auth/tbbr/tbbr_cot_common.c 51 52 BL1_SOURCES += ${AUTH_SOURCES} \ 53 bl1/tbbr/tbbr_img_desc.c \ 54 plat/common/tbbr/plat_tbbr.c \ 55 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 56 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 57 drivers/auth/tbbr/tbbr_cot_bl1.c 58 59 BL2_SOURCES += ${AUTH_SOURCES} \ 60 plat/common/tbbr/plat_tbbr.c \ 61 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 62 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 63 drivers/auth/tbbr/tbbr_cot_bl2.c 64 65 include drivers/auth/mbedtls/mbedtls_x509.mk 66 67 ROT_KEY = $(BUILD_PLAT)/rot_key.pem 68 ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin 69 70 $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) 71 72 $(BUILD_PLAT)/bl1/qemu_rotpk.o: $(ROTPK_HASH) 73 $(BUILD_PLAT)/bl2/qemu_rotpk.o: $(ROTPK_HASH) 74 75 certificates: $(ROT_KEY) 76 77 $(ROT_KEY): | $$(@D)/ 78 $(s)echo " OPENSSL $@" 79 $(q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null 80 81 $(ROTPK_HASH): $(ROT_KEY) | $$(@D)/ 82 $(s)echo " OPENSSL $@" 83 $(q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ 84 ${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null 85endif 86 87# Include Measured Boot makefile before any Crypto library makefile. 88# Crypto library makefile may need default definitions of Measured Boot build 89# flags present in Measured Boot makefile. 90ifeq (${MEASURED_BOOT},1) 91 MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk 92 $(info Including ${MEASURED_BOOT_MK}) 93 include ${MEASURED_BOOT_MK} 94 95 BL2_SOURCES += plat/qemu/qemu/qemu_measured_boot.c \ 96 plat/qemu/qemu/qemu_helpers.c \ 97 ${EVENT_LOG_SOURCES} 98 99 BL1_SOURCES += plat/qemu/qemu/qemu_bl1_measured_boot.c 100 101endif 102 103ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 104 CRYPTO_SOURCES := drivers/auth/crypto_mod.c 105 106 BL1_SOURCES += ${CRYPTO_SOURCES} 107 BL2_SOURCES += ${CRYPTO_SOURCES} 108 109 # We expect to locate the *.mk files under the directories specified below 110 # 111 include drivers/auth/mbedtls/mbedtls_crypto.mk 112endif 113 114BL2_SOURCES += common/uuid.c 115 116ifeq ($(add-lib-optee),yes) 117BL2_SOURCES += lib/optee/optee_utils.c 118endif 119 120ifneq (${DECRYPTION_SUPPORT},none) 121BL1_SOURCES += drivers/io/io_encrypted.c 122BL2_SOURCES += drivers/io/io_encrypted.c 123endif 124 125# Include GICv2 driver files 126include drivers/arm/gic/v2/gicv2.mk 127QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 128 plat/common/plat_gicv2.c \ 129 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 130 131# Include GICv3 driver files 132include drivers/arm/gic/v3/gicv3.mk 133 134QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 135 plat/common/plat_gicv3.c \ 136 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 137 138ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 139QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 140else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 141QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 142else 143$(error "Incorrect GIC driver chosen for QEMU platform") 144endif 145 146ifeq (${ARCH},aarch64) 147BL31_SOURCES += drivers/arm/pl061/pl061_gpio.c \ 148 drivers/gpio/gpio.c \ 149 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 150 ${PLAT_QEMU_COMMON_PATH}/topology.c 151 152ifeq (${SDEI_SUPPORT}, 1) 153BL31_SOURCES += plat/qemu/common/qemu_sdei.c 154endif 155 156ifeq (${SPD},spmd) 157BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 158 common/uuid.c \ 159 ${LIBFDT_SRCS} \ 160 ${FDT_WRAPPERS_SOURCES} 161endif 162endif 163 164# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 165# in the FIP if the platform requires. 166ifneq ($(BL32_EXTRA1),) 167ifneq (${DECRYPTION_SUPPORT},none) 168$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 169else 170$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 171endif 172endif 173ifneq ($(BL32_EXTRA2),) 174ifneq (${DECRYPTION_SUPPORT},none) 175$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 176else 177$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 178endif 179endif 180 181ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 182FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 183QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 184# Add the TB_FW_CONFIG to FIP 185$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 186endif 187 188ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 189FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 190QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 191# Add the TOS_FW_CONFIG to FIP 192$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 193endif 194 195BL32_RAM_LOCATION := tdram 196ifeq (${BL32_RAM_LOCATION}, tsram) 197 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 198 ifeq (${ENABLE_RME},1) 199 # Avoid overlap between BL2 and BL32 to ease GPT partition 200 $(error "With RME, BL32 must use secure DRAM") 201 endif 202else ifeq (${BL32_RAM_LOCATION}, tdram) 203 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 204else 205 $(error "Unsupported BL32_RAM_LOCATION value") 206endif 207 208# Process flags 209$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 210 211# Don't have the Linux kernel as a BL33 image by default 212ARM_LINUX_KERNEL_AS_BL33 := 0 213$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 214$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 215 216ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 217$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 218 219qemu_fw.bios: bl1 fip 220 $(s)echo " DD $@" 221 $(q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 222 $(q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 223 224qemu_fw.rom: qemu_fw.bios 225 $(s)echo " DD $@" 226 $(q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 227 $(q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 228 229ifneq (${BL33},) 230all: qemu_fw.bios qemu_fw.rom 231endif 232 233ifeq (${EL3_EXCEPTION_HANDLING},1) 234BL31_SOURCES += plat/common/aarch64/plat_ehf.c 235endif 236