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 26else 27CTX_INCLUDE_AARCH32_REGS := 0 28ifeq (${CTX_INCLUDE_AARCH32_REGS}, 1) 29$(error "This is an AArch64-only port; CTX_INCLUDE_AARCH32_REGS must be disabled") 30endif 31 32# Treating this as a memory-constrained port for now 33USE_COHERENT_MEM := 0 34 35# This can be overridden depending on CPU(s) used in the QEMU image 36HW_ASSISTED_COHERENCY := 1 37endif # ARMv7 38 39ifeq (${SPD},opteed) 40add-lib-optee := yes 41endif 42ifeq ($(AARCH32_SP),optee) 43add-lib-optee := yes 44endif 45ifeq ($(SPMC_OPTEE),1) 46$(eval $(call add_define,SPMC_OPTEE)) 47add-lib-optee := yes 48endif 49 50ifeq ($(NEED_BL32),yes) 51$(eval $(call add_define,QEMU_LOAD_BL32)) 52endif 53 54PLAT_BL_COMMON_SOURCES := ${PLAT_QEMU_COMMON_PATH}/qemu_common.c \ 55 ${PLAT_QEMU_COMMON_PATH}/qemu_console.c \ 56 drivers/arm/pl011/${ARCH}/pl011_console.S 57 58include lib/xlat_tables_v2/xlat_tables.mk 59PLAT_BL_COMMON_SOURCES += ${XLAT_TABLES_LIB_SRCS} 60 61ifneq (${TRUSTED_BOARD_BOOT},0) 62 63 AUTH_SOURCES := drivers/auth/auth_mod.c \ 64 drivers/auth/img_parser_mod.c \ 65 drivers/auth/tbbr/tbbr_cot_common.c 66 67 BL1_SOURCES += ${AUTH_SOURCES} \ 68 bl1/tbbr/tbbr_img_desc.c \ 69 plat/common/tbbr/plat_tbbr.c \ 70 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 71 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 72 drivers/auth/tbbr/tbbr_cot_bl1.c 73 74 BL2_SOURCES += ${AUTH_SOURCES} \ 75 plat/common/tbbr/plat_tbbr.c \ 76 ${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c \ 77 $(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S \ 78 drivers/auth/tbbr/tbbr_cot_bl2.c 79 80 include drivers/auth/mbedtls/mbedtls_x509.mk 81 82 ROT_KEY = $(BUILD_PLAT)/rot_key.pem 83 ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin 84 85 $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) 86 87 $(BUILD_PLAT)/bl1/qemu_rotpk.o: $(ROTPK_HASH) 88 $(BUILD_PLAT)/bl2/qemu_rotpk.o: $(ROTPK_HASH) 89 90 certificates: $(ROT_KEY) 91 92 $(ROT_KEY): | $(BUILD_PLAT) 93 @echo " OPENSSL $@" 94 $(Q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null 95 96 $(ROTPK_HASH): $(ROT_KEY) 97 @echo " OPENSSL $@" 98 $(Q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ 99 ${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null 100endif 101 102# Include Measured Boot makefile before any Crypto library makefile. 103# Crypto library makefile may need default definitions of Measured Boot build 104# flags present in Measured Boot makefile. 105ifeq (${MEASURED_BOOT},1) 106 MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk 107 $(info Including ${MEASURED_BOOT_MK}) 108 include ${MEASURED_BOOT_MK} 109 110 ifneq (${MBOOT_EL_HASH_ALG}, sha256) 111 $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA512)) 112 endif 113 114 BL2_SOURCES += plat/qemu/qemu/qemu_measured_boot.c \ 115 plat/qemu/qemu/qemu_helpers.c \ 116 ${EVENT_LOG_SOURCES} 117 118 BL1_SOURCES += plat/qemu/qemu/qemu_bl1_measured_boot.c 119 120endif 121 122ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 123 CRYPTO_SOURCES := drivers/auth/crypto_mod.c 124 125 BL1_SOURCES += ${CRYPTO_SOURCES} 126 BL2_SOURCES += ${CRYPTO_SOURCES} 127 128 # We expect to locate the *.mk files under the directories specified below 129 # 130 include drivers/auth/mbedtls/mbedtls_crypto.mk 131endif 132 133BL1_SOURCES += drivers/io/io_semihosting.c \ 134 drivers/io/io_storage.c \ 135 drivers/io/io_fip.c \ 136 drivers/io/io_memmap.c \ 137 lib/semihosting/semihosting.c \ 138 lib/semihosting/${ARCH}/semihosting_call.S \ 139 ${PLAT_QEMU_COMMON_PATH}/qemu_io_storage.c \ 140 ${PLAT_QEMU_COMMON_PATH}/${ARCH}/plat_helpers.S \ 141 ${PLAT_QEMU_COMMON_PATH}/qemu_bl1_setup.c \ 142 ${QEMU_CPU_LIBS} 143 144BL2_SOURCES += drivers/io/io_semihosting.c \ 145 drivers/io/io_storage.c \ 146 drivers/io/io_fip.c \ 147 drivers/io/io_memmap.c \ 148 lib/semihosting/semihosting.c \ 149 lib/semihosting/${ARCH}/semihosting_call.S \ 150 ${PLAT_QEMU_COMMON_PATH}/qemu_io_storage.c \ 151 ${PLAT_QEMU_COMMON_PATH}/${ARCH}/plat_helpers.S \ 152 ${PLAT_QEMU_COMMON_PATH}/qemu_bl2_setup.c \ 153 ${PLAT_QEMU_COMMON_PATH}/qemu_bl2_mem_params_desc.c \ 154 ${PLAT_QEMU_COMMON_PATH}/qemu_image_load.c \ 155 common/fdt_fixup.c \ 156 ${FDT_WRAPPERS_SOURCES} \ 157 common/desc_image_load.c \ 158 common/uuid.c 159 160ifeq ($(add-lib-optee),yes) 161BL2_SOURCES += lib/optee/optee_utils.c 162endif 163 164ifneq (${DECRYPTION_SUPPORT},none) 165BL1_SOURCES += drivers/io/io_encrypted.c 166BL2_SOURCES += drivers/io/io_encrypted.c 167endif 168 169# Include GICv2 driver files 170include drivers/arm/gic/v2/gicv2.mk 171QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 172 plat/common/plat_gicv2.c \ 173 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 174 175# Include GICv3 driver files 176include drivers/arm/gic/v3/gicv3.mk 177 178QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 179 plat/common/plat_gicv3.c \ 180 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 181 182ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 183QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 184else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 185QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 186else 187$(error "Incorrect GIC driver chosen for QEMU platform") 188endif 189 190ifeq (${ARM_ARCH_MAJOR},8) 191BL31_SOURCES += ${QEMU_CPU_LIBS} \ 192 lib/semihosting/semihosting.c \ 193 lib/semihosting/${ARCH}/semihosting_call.S \ 194 plat/common/plat_psci_common.c \ 195 drivers/arm/pl061/pl061_gpio.c \ 196 drivers/gpio/gpio.c \ 197 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 198 ${PLAT_QEMU_COMMON_PATH}/topology.c \ 199 ${PLAT_QEMU_COMMON_PATH}/aarch64/plat_helpers.S \ 200 ${PLAT_QEMU_COMMON_PATH}/qemu_bl31_setup.c \ 201 ${QEMU_GIC_SOURCES} 202 203ifeq (${SDEI_SUPPORT}, 1) 204BL31_SOURCES += plat/qemu/common/qemu_sdei.c 205endif 206 207# Pointer Authentication sources 208ifeq (${ENABLE_PAUTH}, 1) 209PLAT_BL_COMMON_SOURCES += plat/arm/common/aarch64/arm_pauth.c \ 210 lib/extensions/pauth/pauth_helpers.S 211endif 212 213ifeq (${SPD},spmd) 214BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 215 common/uuid.c \ 216 ${LIBFDT_SRCS} \ 217 ${FDT_WRAPPERS_SOURCES} 218endif 219endif 220 221# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 222# in the FIP if the platform requires. 223ifneq ($(BL32_EXTRA1),) 224ifneq (${DECRYPTION_SUPPORT},none) 225$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 226else 227$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 228endif 229endif 230ifneq ($(BL32_EXTRA2),) 231ifneq (${DECRYPTION_SUPPORT},none) 232$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 233else 234$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 235endif 236endif 237 238ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 239FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 240QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 241# Add the TB_FW_CONFIG to FIP 242$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 243endif 244 245ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 246FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 247QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 248# Add the TOS_FW_CONFIG to FIP 249$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 250endif 251 252SEPARATE_CODE_AND_RODATA := 1 253ENABLE_STACK_PROTECTOR := 0 254ifneq ($(ENABLE_STACK_PROTECTOR), 0) 255 PLAT_BL_COMMON_SOURCES += ${PLAT_QEMU_COMMON_PATH}/qemu_stack_protector.c 256endif 257 258BL32_RAM_LOCATION := tdram 259ifeq (${BL32_RAM_LOCATION}, tsram) 260 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 261else ifeq (${BL32_RAM_LOCATION}, tdram) 262 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 263else 264 $(error "Unsupported BL32_RAM_LOCATION value") 265endif 266 267# Process flags 268$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 269 270# Don't have the Linux kernel as a BL33 image by default 271ARM_LINUX_KERNEL_AS_BL33 := 0 272$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 273$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 274 275ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 276$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 277 278# QEMU will use the RNDR instruction for the stack protector canary. 279ENABLE_FEAT_RNG := 2 280 281# Later QEMU versions support SME and SVE. 282ifneq (${ARCH},aarch32) 283 ENABLE_SVE_FOR_NS := 2 284 ENABLE_SME_FOR_NS := 2 285endif 286 287qemu_fw.bios: bl1 fip 288 $(ECHO) " DD $@" 289 $(Q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 290 $(Q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 291 292qemu_fw.rom: qemu_fw.bios 293 $(ECHO) " DD $@" 294 $(Q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 295 $(Q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 296 297ifneq (${BL33},) 298all: qemu_fw.bios qemu_fw.rom 299endif 300 301ifeq (${EL3_EXCEPTION_HANDLING},1) 302BL31_SOURCES += plat/common/aarch64/plat_ehf.c 303endif 304