xref: /rk3399_ARM-atf/plat/qemu/qemu/platform.mk (revision 5fdf198c117a4b6dbcf5242f5136f7224ceff6ff)
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
10SEPARATE_CODE_AND_RODATA := 1
11ENABLE_STACK_PROTECTOR	 := 0
12
13include plat/qemu/common/common.mk
14
15# Use the GICv2 driver on QEMU by default
16QEMU_USE_GIC_DRIVER	:= QEMU_GICV2
17
18ifeq (${ARM_ARCH_MAJOR},7)
19# ARMv7 Qemu support in trusted firmware expects the Cortex-A15 model.
20# Qemu Cortex-A15 model does not implement the virtualization extension.
21# For this reason, we cannot set ARM_CORTEX_A15=yes and must define all
22# the ARMv7 build directives.
23MARCH_DIRECTIVE 	:= 	-mcpu=cortex-a15
24$(eval $(call add_define,ARMV7_SUPPORTS_LARGE_PAGE_ADDRESSING))
25$(eval $(call add_define,ARMV7_SUPPORTS_GENERIC_TIMER))
26$(eval $(call add_define,ARMV7_SUPPORTS_VFP))
27# Qemu expects a BL32 boot stage.
28NEED_BL32		:=	yes
29endif # ARMv7
30
31ifeq (${SPD},opteed)
32add-lib-optee 		:= 	yes
33endif
34ifeq ($(AARCH32_SP),optee)
35add-lib-optee 		:= 	yes
36endif
37ifeq ($(SPMC_OPTEE),1)
38$(eval $(call add_define,SPMC_OPTEE))
39add-lib-optee 		:= 	yes
40endif
41
42ifeq ($(NEED_BL32),yes)
43$(eval $(call add_define,QEMU_LOAD_BL32))
44endif
45
46ifneq (${TRUSTED_BOARD_BOOT},0)
47
48    AUTH_SOURCES	:=	drivers/auth/auth_mod.c			\
49				drivers/auth/img_parser_mod.c		\
50				drivers/auth/tbbr/tbbr_cot_common.c
51
52    BL1_SOURCES		+=	${AUTH_SOURCES}				\
53				bl1/tbbr/tbbr_img_desc.c		\
54				plat/common/tbbr/plat_tbbr.c		\
55				${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c	     	\
56				$(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S	\
57				drivers/auth/tbbr/tbbr_cot_bl1.c
58
59    BL2_SOURCES		+=	${AUTH_SOURCES}				\
60				plat/common/tbbr/plat_tbbr.c		\
61				${PLAT_QEMU_COMMON_PATH}/qemu_trusted_boot.c	     	\
62				$(PLAT_QEMU_COMMON_PATH)/qemu_rotpk.S	\
63				drivers/auth/tbbr/tbbr_cot_bl2.c
64
65    include drivers/auth/mbedtls/mbedtls_x509.mk
66
67    ROT_KEY             = $(BUILD_PLAT)/rot_key.pem
68    ROTPK_HASH          = $(BUILD_PLAT)/rotpk_sha256.bin
69
70    $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"'))
71
72    $(BUILD_PLAT)/bl1/qemu_rotpk.o: $(ROTPK_HASH)
73    $(BUILD_PLAT)/bl2/qemu_rotpk.o: $(ROTPK_HASH)
74
75    certificates: $(ROT_KEY)
76
77    $(ROT_KEY): | $(BUILD_PLAT)
78	@echo "  OPENSSL $@"
79	$(Q)${OPENSSL_BIN_PATH}/openssl genrsa 2048 > $@ 2>/dev/null
80
81    $(ROTPK_HASH): $(ROT_KEY)
82	@echo "  OPENSSL $@"
83	$(Q)${OPENSSL_BIN_PATH}/openssl rsa -in $< -pubout -outform DER 2>/dev/null |\
84	${OPENSSL_BIN_PATH}/openssl dgst -sha256 -binary > $@ 2>/dev/null
85endif
86
87# Include Measured Boot makefile before any Crypto library makefile.
88# Crypto library makefile may need default definitions of Measured Boot build
89# flags present in Measured Boot makefile.
90ifeq (${MEASURED_BOOT},1)
91    MEASURED_BOOT_MK := drivers/measured_boot/event_log/event_log.mk
92    $(info Including ${MEASURED_BOOT_MK})
93    include ${MEASURED_BOOT_MK}
94
95    ifneq (${MBOOT_EL_HASH_ALG}, sha256)
96        $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA512))
97    endif
98
99    BL2_SOURCES		+=	plat/qemu/qemu/qemu_measured_boot.c	\
100				plat/qemu/qemu/qemu_helpers.c		\
101				${EVENT_LOG_SOURCES}
102
103     BL1_SOURCES	+=      plat/qemu/qemu/qemu_bl1_measured_boot.c
104
105endif
106
107ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
108    CRYPTO_SOURCES	:=	drivers/auth/crypto_mod.c
109
110    BL1_SOURCES		+=	${CRYPTO_SOURCES}
111    BL2_SOURCES		+=	${CRYPTO_SOURCES}
112
113    # We expect to locate the *.mk files under the directories specified below
114    #
115    include drivers/auth/mbedtls/mbedtls_crypto.mk
116endif
117
118BL2_SOURCES		+=	${FDT_WRAPPERS_SOURCES}					\
119				common/uuid.c
120
121ifeq ($(add-lib-optee),yes)
122BL2_SOURCES		+=	lib/optee/optee_utils.c
123endif
124
125ifneq (${DECRYPTION_SUPPORT},none)
126BL1_SOURCES		+=	drivers/io/io_encrypted.c
127BL2_SOURCES		+=	drivers/io/io_encrypted.c
128endif
129
130# Include GICv2 driver files
131include drivers/arm/gic/v2/gicv2.mk
132QEMU_GICV2_SOURCES	:=	${GICV2_SOURCES}			\
133				plat/common/plat_gicv2.c		\
134				${PLAT_QEMU_COMMON_PATH}/qemu_gicv2.c
135
136# Include GICv3 driver files
137include drivers/arm/gic/v3/gicv3.mk
138
139QEMU_GICV3_SOURCES	:=	${GICV3_SOURCES}			\
140				plat/common/plat_gicv3.c		\
141				${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c
142
143ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV2)
144QEMU_GIC_SOURCES	:=	${QEMU_GICV2_SOURCES}
145else ifeq (${QEMU_USE_GIC_DRIVER}, QEMU_GICV3)
146QEMU_GIC_SOURCES	:=	${QEMU_GICV3_SOURCES}
147else
148$(error "Incorrect GIC driver chosen for QEMU platform")
149endif
150
151ifeq (${ARCH},aarch64)
152BL31_SOURCES		+=	drivers/arm/pl061/pl061_gpio.c		\
153				drivers/gpio/gpio.c			\
154				${PLAT_QEMU_COMMON_PATH}/qemu_pm.c	\
155				${PLAT_QEMU_COMMON_PATH}/topology.c
156
157ifeq (${SDEI_SUPPORT}, 1)
158BL31_SOURCES		+=	plat/qemu/common/qemu_sdei.c
159endif
160
161# Pointer Authentication sources
162ifeq (${ENABLE_PAUTH}, 1)
163PLAT_BL_COMMON_SOURCES	+=	plat/arm/common/aarch64/arm_pauth.c	\
164				lib/extensions/pauth/pauth_helpers.S
165endif
166
167ifeq (${SPD},spmd)
168BL31_SOURCES		+=	plat/common/plat_spmd_manifest.c	\
169				common/uuid.c				\
170				${LIBFDT_SRCS} 				\
171				${FDT_WRAPPERS_SOURCES}
172endif
173endif
174
175# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images
176# in the FIP if the platform requires.
177ifneq ($(BL32_EXTRA1),)
178ifneq (${DECRYPTION_SUPPORT},none)
179$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1,,$(ENCRYPT_BL32)))
180else
181$(eval $(call TOOL_ADD_IMG,bl32_extra1,--tos-fw-extra1))
182endif
183endif
184ifneq ($(BL32_EXTRA2),)
185ifneq (${DECRYPTION_SUPPORT},none)
186$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2,,$(ENCRYPT_BL32)))
187else
188$(eval $(call TOOL_ADD_IMG,bl32_extra2,--tos-fw-extra2))
189endif
190endif
191
192ifneq ($(QEMU_TB_FW_CONFIG_DTS),)
193FDT_SOURCES		+=	${QEMU_TB_FW_CONFIG_DTS}
194QEMU_TB_FW_CONFIG	:=	${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TB_FW_CONFIG_DTS})).dtb
195# Add the TB_FW_CONFIG to FIP
196$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TB_FW_CONFIG},--tb-fw-config,${QEMU_TB_FW_CONFIG}))
197endif
198
199ifneq ($(QEMU_TOS_FW_CONFIG_DTS),)
200FDT_SOURCES		+=	${QEMU_TOS_FW_CONFIG_DTS}
201QEMU_TOS_FW_CONFIG	:=	${BUILD_PLAT}/fdts/$(notdir $(basename ${QEMU_TOS_FW_CONFIG_DTS})).dtb
202# Add the TOS_FW_CONFIG to FIP
203$(eval $(call TOOL_ADD_PAYLOAD,${QEMU_TOS_FW_CONFIG},--tos-fw-config,${QEMU_TOS_FW_CONFIG}))
204endif
205
206BL32_RAM_LOCATION	:=	tdram
207ifeq (${BL32_RAM_LOCATION}, tsram)
208  BL32_RAM_LOCATION_ID = SEC_SRAM_ID
209else ifeq (${BL32_RAM_LOCATION}, tdram)
210  BL32_RAM_LOCATION_ID = SEC_DRAM_ID
211else
212  $(error "Unsupported BL32_RAM_LOCATION value")
213endif
214
215# Process flags
216$(eval $(call add_define,BL32_RAM_LOCATION_ID))
217
218# Don't have the Linux kernel as a BL33 image by default
219ARM_LINUX_KERNEL_AS_BL33	:=	0
220$(eval $(call assert_boolean,ARM_LINUX_KERNEL_AS_BL33))
221$(eval $(call add_define,ARM_LINUX_KERNEL_AS_BL33))
222
223ARM_PRELOADED_DTB_BASE := PLAT_QEMU_DT_BASE
224$(eval $(call add_define,ARM_PRELOADED_DTB_BASE))
225
226qemu_fw.bios: bl1 fip
227	$(ECHO) "  DD      $@"
228	$(Q)cp ${BUILD_PLAT}/bl1.bin ${BUILD_PLAT}/$@
229	$(Q)dd if=${BUILD_PLAT}/fip.bin of=${BUILD_PLAT}/$@ bs=64k seek=4 status=none
230
231qemu_fw.rom: qemu_fw.bios
232	$(ECHO) "  DD      $@"
233	$(Q)cp ${BUILD_PLAT}/$^ ${BUILD_PLAT}/$@
234	$(Q)dd if=/dev/zero of=${BUILD_PLAT}/$@ bs=1M seek=64 count=0 status=none
235
236ifneq (${BL33},)
237all: qemu_fw.bios qemu_fw.rom
238endif
239
240ifeq (${EL3_EXCEPTION_HANDLING},1)
241BL31_SOURCES		+=	plat/common/aarch64/plat_ehf.c
242endif
243