1# 2# Copyright (c) 2013-2023, 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 10include plat/qemu/common/common.mk 11 12# Use the GICv2 driver on QEMU by default 13QEMU_USE_GIC_DRIVER := QEMU_GICV2 14 15ifeq (${ARM_ARCH_MAJOR},7) 16# ARMv7 Qemu support in trusted firmware expects the Cortex-A15 model. 17# Qemu Cortex-A15 model does not implement the virtualization extension. 18# For this reason, we cannot set ARM_CORTEX_A15=yes and must define all 19# the ARMv7 build directives. 20MARCH_DIRECTIVE := -mcpu=cortex-a15 21$(eval $(call add_define,ARMV7_SUPPORTS_LARGE_PAGE_ADDRESSING)) 22$(eval $(call add_define,ARMV7_SUPPORTS_GENERIC_TIMER)) 23$(eval $(call add_define,ARMV7_SUPPORTS_VFP)) 24# Qemu expects a BL32 boot stage. 25NEED_BL32 := yes 26endif # ARMv7 27 28ifeq (${SPD},opteed) 29add-lib-optee := yes 30endif 31ifeq ($(AARCH32_SP),optee) 32add-lib-optee := yes 33endif 34ifeq ($(SPMC_OPTEE),1) 35$(eval $(call add_define,SPMC_OPTEE)) 36add-lib-optee := yes 37endif 38 39ifeq ($(NEED_BL32),yes) 40$(eval $(call add_define,QEMU_LOAD_BL32)) 41endif 42 43ifneq (${TRUSTED_BOARD_BOOT},0) 44 45 AUTH_SOURCES := drivers/auth/auth_mod.c \ 46 drivers/auth/img_parser_mod.c \ 47 drivers/auth/tbbr/tbbr_cot_common.c 48 49 BL1_SOURCES += ${AUTH_SOURCES} \ 50 bl1/tbbr/tbbr_img_desc.c \ 51 plat/common/tbbr/plat_tbbr.c \ 52 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 53 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 54 drivers/auth/tbbr/tbbr_cot_bl1.c 55 56 BL2_SOURCES += ${AUTH_SOURCES} \ 57 plat/common/tbbr/plat_tbbr.c \ 58 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 59 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 60 drivers/auth/tbbr/tbbr_cot_bl2.c 61 62 include drivers/auth/mbedtls/mbedtls_x509.mk 63 64 ROT_KEY = $(BUILD_PLAT)/rot_key.pem 65 ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin 66 67 $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) 68 69 $(BUILD_PLAT)/bl1/qemu_rotpk.o: $(ROTPK_HASH) 70 $(BUILD_PLAT)/bl2/qemu_rotpk.o: $(ROTPK_HASH) 71 72 certificates: $(ROT_KEY) 73 74 $(ROT_KEY): | $(BUILD_PLAT) 75 @echo " OPENSSL $@" 76 $(Q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null 77 78 $(ROTPK_HASH): $(ROT_KEY) 79 @echo " OPENSSL $@" 80 $(Q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ 81 ${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null 82endif 83 84# Include Measured Boot makefile before any Crypto library makefile. 85# Crypto library makefile may need default definitions of Measured Boot build 86# flags present in Measured Boot makefile. 87ifeq (${MEASURED_BOOT},1) 88 MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk 89 $(info Including ${MEASURED_BOOT_MK}) 90 include ${MEASURED_BOOT_MK} 91 92 ifneq (${MBOOT_EL_HASH_ALG}, sha256) 93 $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA512)) 94 endif 95 96 BL2_SOURCES += plat/qemu/qemu/qemu_measured_boot.c \ 97 plat/qemu/qemu/qemu_helpers.c \ 98 ${EVENT_LOG_SOURCES} 99 100 BL1_SOURCES += plat/qemu/qemu/qemu_bl1_measured_boot.c 101 102endif 103 104ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 105 CRYPTO_SOURCES := drivers/auth/crypto_mod.c 106 107 BL1_SOURCES += ${CRYPTO_SOURCES} 108 BL2_SOURCES += ${CRYPTO_SOURCES} 109 110 # We expect to locate the *.mk files under the directories specified below 111 # 112 include drivers/auth/mbedtls/mbedtls_crypto.mk 113endif 114 115BL2_SOURCES += ${FDT_WRAPPERS_SOURCES} \ 116 common/uuid.c 117 118ifeq ($(add-lib-optee),yes) 119BL2_SOURCES += lib/optee/optee_utils.c 120endif 121 122ifneq (${DECRYPTION_SUPPORT},none) 123BL1_SOURCES += drivers/io/io_encrypted.c 124BL2_SOURCES += drivers/io/io_encrypted.c 125endif 126 127# Include GICv2 driver files 128include drivers/arm/gic/v2/gicv2.mk 129QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 130 plat/common/plat_gicv2.c \ 131 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 132 133# Include GICv3 driver files 134include drivers/arm/gic/v3/gicv3.mk 135 136QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 137 plat/common/plat_gicv3.c \ 138 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 139 140ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 141QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 142else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 143QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 144else 145$(error "Incorrect GIC driver chosen for QEMU platform") 146endif 147 148ifeq (${ARCH},aarch64) 149BL31_SOURCES += drivers/arm/pl061/pl061_gpio.c \ 150 drivers/gpio/gpio.c \ 151 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 152 ${PLAT_QEMU_COMMON_PATH}/topology.c 153 154ifeq (${SDEI_SUPPORT}, 1) 155BL31_SOURCES += plat/qemu/common/qemu_sdei.c 156endif 157 158# Pointer Authentication sources 159ifeq (${ENABLE_PAUTH}, 1) 160PLAT_BL_COMMON_SOURCES += plat/arm/common/aarch64/arm_pauth.c \ 161 lib/extensions/pauth/pauth_helpers.S 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 203SEPARATE_CODE_AND_RODATA := 1 204ENABLE_STACK_PROTECTOR := 0 205 206BL32_RAM_LOCATION := tdram 207ifeq (${BL32_RAM_LOCATION}, tsram) 208 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 209else ifeq (${BL32_RAM_LOCATION}, tdram) 210 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 211else 212 $(error "Unsupported BL32_RAM_LOCATION value") 213endif 214 215# Process flags 216$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 217 218# Don't have the Linux kernel as a BL33 image by default 219ARM_LINUX_KERNEL_AS_BL33 := 0 220$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 221$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 222 223ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 224$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 225 226qemu_fw.bios: bl1 fip 227 $(ECHO) " DD $@" 228 $(Q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 229 $(Q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 230 231qemu_fw.rom: qemu_fw.bios 232 $(ECHO) " DD $@" 233 $(Q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 234 $(Q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 235 236ifneq (${BL33},) 237all: qemu_fw.bios qemu_fw.rom 238endif 239 240ifeq (${EL3_EXCEPTION_HANDLING},1) 241BL31_SOURCES += plat/common/aarch64/plat_ehf.c 242endif 243