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