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