1# 2# Copyright (c) 2013-2023, 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. 15MARCH_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 163ifeq (${ARM_ARCH_MAJOR},8) 164BL1_SOURCES += lib/cpus/${ARCH}/aem_generic.S \ 165 lib/cpus/${ARCH}/cortex_a53.S \ 166 lib/cpus/${ARCH}/cortex_a57.S \ 167 lib/cpus/${ARCH}/cortex_a72.S \ 168 lib/cpus/${ARCH}/qemu_max.S \ 169 170else 171BL1_SOURCES += lib/cpus/${ARCH}/cortex_a15.S 172endif 173 174BL2_SOURCES += drivers/io/io_semihosting.c \ 175 drivers/io/io_storage.c \ 176 drivers/io/io_fip.c \ 177 drivers/io/io_memmap.c \ 178 lib/semihosting/semihosting.c \ 179 lib/semihosting/${ARCH}/semihosting_call.S \ 180 ${PLAT_QEMU_COMMON_PATH}/qemu_io_storage.c \ 181 ${PLAT_QEMU_COMMON_PATH}/${ARCH}/plat_helpers.S \ 182 ${PLAT_QEMU_COMMON_PATH}/qemu_bl2_setup.c \ 183 ${PLAT_QEMU_COMMON_PATH}/qemu_bl2_mem_params_desc.c \ 184 ${PLAT_QEMU_COMMON_PATH}/qemu_image_load.c \ 185 common/fdt_fixup.c \ 186 common/fdt_wrappers.c \ 187 common/desc_image_load.c \ 188 common/uuid.c 189 190ifeq ($(add-lib-optee),yes) 191BL2_SOURCES += lib/optee/optee_utils.c 192endif 193 194ifneq (${DECRYPTION_SUPPORT},none) 195BL1_SOURCES += drivers/io/io_encrypted.c 196BL2_SOURCES += drivers/io/io_encrypted.c 197endif 198 199# Include GICv2 driver files 200include drivers/arm/gic/v2/gicv2.mk 201QEMU_GICV2_SOURCES := ${GICV2_SOURCES} \ 202 plat/common/plat_gicv2.c \ 203 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c 204 205# Include GICv3 driver files 206include drivers/arm/gic/v3/gicv3.mk 207 208QEMU_GICV3_SOURCES := ${GICV3_SOURCES} \ 209 plat/common/plat_gicv3.c \ 210 ${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c 211 212ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2) 213QEMU_GIC_SOURCES := ${QEMU_GICV2_SOURCES} 214else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3) 215QEMU_GIC_SOURCES := ${QEMU_GICV3_SOURCES} 216else 217$(error "Incorrect GIC driver chosen for QEMU platform") 218endif 219 220ifeq (${ARM_ARCH_MAJOR},8) 221BL31_SOURCES += ${QEMU_CPU_LIBS} \ 222 lib/semihosting/semihosting.c \ 223 lib/semihosting/${ARCH}/semihosting_call.S \ 224 plat/common/plat_psci_common.c \ 225 drivers/arm/pl061/pl061_gpio.c \ 226 drivers/gpio/gpio.c \ 227 ${PLAT_QEMU_COMMON_PATH}/qemu_pm.c \ 228 ${PLAT_QEMU_COMMON_PATH}/topology.c \ 229 ${PLAT_QEMU_COMMON_PATH}/aarch64/plat_helpers.S \ 230 ${PLAT_QEMU_COMMON_PATH}/qemu_bl31_setup.c \ 231 ${QEMU_GIC_SOURCES} 232 233ifeq (${SDEI_SUPPORT}, 1) 234BL31_SOURCES += plat/qemu/common/qemu_sdei.c 235endif 236 237# Pointer Authentication sources 238ifeq (${ENABLE_PAUTH}, 1) 239PLAT_BL_COMMON_SOURCES += plat/arm/common/aarch64/arm_pauth.c \ 240 lib/extensions/pauth/pauth_helpers.S 241endif 242 243ifeq (${SPD},spmd) 244BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 245 common/uuid.c \ 246 ${LIBFDT_SRCS} \ 247 ${FDT_WRAPPERS_SOURCES} 248endif 249endif 250 251# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 252# in the FIP if the platform requires. 253ifneq ($(BL32_EXTRA1),) 254ifneq (${DECRYPTION_SUPPORT},none) 255$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 256else 257$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 258endif 259endif 260ifneq ($(BL32_EXTRA2),) 261ifneq (${DECRYPTION_SUPPORT},none) 262$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 263else 264$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 265endif 266endif 267 268ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 269FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 270QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 271# Add the TB_FW_CONFIG to FIP 272$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 273endif 274 275ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 276FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 277QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 278# Add the TOS_FW_CONFIG to FIP 279$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 280endif 281 282SEPARATE_CODE_AND_RODATA := 1 283ENABLE_STACK_PROTECTOR := 0 284ifneq ($(ENABLE_STACK_PROTECTOR), 0) 285 PLAT_BL_COMMON_SOURCES += ${PLAT_QEMU_COMMON_PATH}/qemu_stack_protector.c 286endif 287 288BL32_RAM_LOCATION := tdram 289ifeq (${BL32_RAM_LOCATION}, tsram) 290 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 291else ifeq (${BL32_RAM_LOCATION}, tdram) 292 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 293else 294 $(error "Unsupported BL32_RAM_LOCATION value") 295endif 296 297# Process flags 298$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 299 300# Don't have the Linux kernel as a BL33 image by default 301ARM_LINUX_KERNEL_AS_BL33 := 0 302$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 303$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 304 305ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 306$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 307 308# QEMU will use the RNDR instruction for the stack protector canary. 309ENABLE_FEAT_RNG := 2 310 311# Later QEMU versions support SME and SVE. 312ifneq (${ARCH},aarch32) 313 ENABLE_SVE_FOR_NS := 2 314 ENABLE_SME_FOR_NS := 2 315endif 316 317qemu_fw.bios: bl1 fip 318 $(ECHO) " DD $@" 319 $(Q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 320 $(Q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 321 322qemu_fw.rom: qemu_fw.bios 323 $(ECHO) " DD $@" 324 $(Q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 325 $(Q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 326 327ifneq (${BL33},) 328all: qemu_fw.bios qemu_fw.rom 329endif 330 331ifeq (${EL3_EXCEPTION_HANDLING},1) 332BL31_SOURCES += plat/common/aarch64/plat_ehf.c 333endif 334