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. 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 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 233# Pointer Authentication sources 234ifeq (${ENABLE_PAUTH}, 1) 235PLAT_BL_COMMON_SOURCES += plat/arm/common/aarch64/arm_pauth.c \ 236 lib/extensions/pauth/pauth_helpers.S 237endif 238 239ifeq (${SPD},spmd) 240BL31_SOURCES += plat/common/plat_spmd_manifest.c \ 241 common/uuid.c \ 242 ${LIBFDT_SRCS} \ 243 ${FDT_WRAPPERS_SOURCES} 244endif 245endif 246 247# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images 248# in the FIP if the platform requires. 249ifneq ($(BL32_EXTRA1),) 250ifneq (${DECRYPTION_SUPPORT},none) 251$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32))) 252else 253$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1)) 254endif 255endif 256ifneq ($(BL32_EXTRA2),) 257ifneq (${DECRYPTION_SUPPORT},none) 258$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32))) 259else 260$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2)) 261endif 262endif 263 264ifneq ($(QEMU_TB_FW_CONFIG_DTS),) 265FDT_SOURCES += ${QEMU_TB_FW_CONFIG_DTS} 266QEMU_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb 267# Add the TB_FW_CONFIG to FIP 268$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG})) 269endif 270 271ifneq ($(QEMU_TOS_FW_CONFIG_DTS),) 272FDT_SOURCES += ${QEMU_TOS_FW_CONFIG_DTS} 273QEMU_TOS_FW_CONFIG := ${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb 274# Add the TOS_FW_CONFIG to FIP 275$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG})) 276endif 277 278SEPARATE_CODE_AND_RODATA := 1 279ENABLE_STACK_PROTECTOR := 0 280ifneq ($(ENABLE_STACK_PROTECTOR), 0) 281 PLAT_BL_COMMON_SOURCES += ${PLAT_QEMU_COMMON_PATH}/qemu_stack_protector.c 282endif 283 284BL32_RAM_LOCATION := tdram 285ifeq (${BL32_RAM_LOCATION}, tsram) 286 BL32_RAM_LOCATION_ID = SEC_SRAM_ID 287else ifeq (${BL32_RAM_LOCATION}, tdram) 288 BL32_RAM_LOCATION_ID = SEC_DRAM_ID 289else 290 $(error "Unsupported BL32_RAM_LOCATION value") 291endif 292 293# Process flags 294$(eval $(call add_define,BL32_RAM_LOCATION_ID)) 295 296# Don't have the Linux kernel as a BL33 image by default 297ARM_LINUX_KERNEL_AS_BL33 := 0 298$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33)) 299$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33)) 300 301ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE 302$(eval $(call add_define,ARM_PRELOADED_DTB_BASE)) 303 304# QEMU will use the RNDR instruction for the stack protector canary. 305ENABLE_FEAT_RNG := 2 306 307# Later QEMU versions support SME and SVE. 308ifneq (${ARCH},aarch32) 309 ENABLE_SVE_FOR_NS := 2 310 ENABLE_SME_FOR_NS := 2 311endif 312 313qemu_fw.bios: bl1 fip 314 $(ECHO) " DD $@" 315 $(Q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@ 316 $(Q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none 317 318qemu_fw.rom: qemu_fw.bios 319 $(ECHO) " DD $@" 320 $(Q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@ 321 $(Q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none 322 323ifneq (${BL33},) 324all: qemu_fw.bios qemu_fw.rom 325endif 326