xref: /rk3399_ARM-atf/Makefile (revision c0cbf5ad6e5d6ef6ee43f6e926e1d9f7a488b451)
1#
2# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7#
8# Trusted Firmware Version
9#
10VERSION_MAJOR			:= 2
11VERSION_MINOR			:= 13
12# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH			:= 0
14VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15
16# Default goal is build all images
17.DEFAULT_GOAL			:= all
18
19# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
24MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
27include ${MAKE_HELPERS_DIRECTORY}common.mk
28
29################################################################################
30# Default values for build configurations, and their dependencies
31################################################################################
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34# Include the CPU specific operations makefile, which provides default
35# values for all CPU errata workarounds and CPU specific optimisations.
36# This can be overridden by the platform.
37include lib/cpus/cpu-ops.mk
38
39PLAT				:= ${DEFAULT_PLAT}
40include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
41
42# To be able to set platform specific defaults
43ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
44include ${PLAT_DEFAULTS_MAKEFILE_FULL}
45endif
46
47################################################################################
48# Configure the toolchains used to build TF-A and its tools
49################################################################################
50
51include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
52
53# Assertions enabled for DEBUG builds by default
54ENABLE_ASSERTIONS		:= ${DEBUG}
55ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
56
57################################################################################
58# Checkpatch script options
59################################################################################
60
61CHECKCODE_ARGS		:=	--no-patch
62# Do not check the coding style on imported library files or documentation files
63INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
64					include/drivers/arm,		\
65					$(wildcard include/drivers/*)))
66INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
67					include/lib/libfdt		\
68					include/lib/libc,		\
69					$(wildcard include/lib/*)))
70INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
71					include/lib			\
72					include/drivers,		\
73					$(wildcard include/*)))
74LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
75					lib/compiler-rt			\
76					lib/libfdt%			\
77					lib/libc,			\
78					lib/zlib			\
79					$(wildcard lib/*)))
80ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
81					lib				\
82					include				\
83					docs				\
84					%.rst,				\
85					$(wildcard *)))
86CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
87				${INC_DIRS_TO_CHECK}			\
88				${INC_LIB_DIRS_TO_CHECK}		\
89				${LIB_DIRS_TO_CHECK}			\
90				${INC_DRV_DIRS_TO_CHECK}		\
91				${INC_ARM_DIRS_TO_CHECK}
92
93################################################################################
94# Process build options
95################################################################################
96
97ifeq ($(verbose),)
98	CHECKCODE_ARGS	+=	--no-summary --terse
99endif
100
101################################################################################
102# Auxiliary tools (fiptool, cert_create, etc)
103################################################################################
104
105# Variables for use with Certificate Generation Tool
106CRTTOOLPATH		?=	tools/cert_create
107CRTTOOL			?=	${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
108
109# Variables for use with Firmware Encryption Tool
110ENCTOOLPATH		?=	tools/encrypt_fw
111ENCTOOL			?=	${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
112
113# Variables for use with Firmware Image Package
114FIPTOOLPATH		?=	tools/fiptool
115FIPTOOL			?=	${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
116
117# Variables for use with sptool
118SPTOOLPATH		?=	tools/sptool
119SPTOOL			?=	${SPTOOLPATH}/sptool.py
120SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
121SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
122
123# Variables for use with sptool
124TLCTOOL 		?=	poetry run tlc
125
126# Variables for use with ROMLIB
127ROMLIBPATH		?=	lib/romlib
128
129# Variable for use with Python
130PYTHON			?=	python3
131
132# Variables for use with documentation build using Sphinx tool
133DOCS_PATH		?=	docs
134
135# Process Debug flag
136ifneq (${DEBUG}, 0)
137	BUILD_TYPE	:=	debug
138	# Use LOG_LEVEL_INFO by default for debug builds
139	LOG_LEVEL	:=	40
140else
141	BUILD_TYPE	:=	release
142	# Use LOG_LEVEL_NOTICE by default for release builds
143	LOG_LEVEL	:=	20
144endif #(Debug)
145
146# Default build string (git branch and commit)
147ifeq (${BUILD_STRING},)
148	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
149endif
150VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
151
152# Setting W is quite verbose and most warnings will be pre-existing issues
153# outside of the contributor's control. Don't fail the build on them so warnings
154# can be seen and hopefully addressed
155ifdef W
156	ifneq (${W},0)
157		E	 ?= 0
158	endif
159endif
160
161################################################################################
162# Setup ARCH_MAJOR/MINOR before parsing arch_features.
163################################################################################
164ifeq (${ENABLE_RME},1)
165	ARM_ARCH_MAJOR := 9
166	ARM_ARCH_MINOR := 2
167endif
168
169################################################################################
170# Common sources and include directories
171################################################################################
172include lib/compiler-rt/compiler-rt.mk
173
174# Allow overriding the timestamp, for example for reproducible builds, or to
175# synchronize timestamps across multiple projects.
176# This must be set to a C string (including quotes where applicable).
177BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
178
179DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
180DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
181DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
182
183BL_COMMON_SOURCES	+=	common/bl_common.c			\
184				common/tf_log.c				\
185				common/${ARCH}/debug.S			\
186				drivers/console/multi_console.c		\
187				lib/${ARCH}/cache_helpers.S		\
188				lib/${ARCH}/misc_helpers.S		\
189				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
190				plat/common/plat_bl_common.c		\
191				plat/common/plat_log_common.c		\
192				plat/common/${ARCH}/plat_common.c	\
193				plat/common/${ARCH}/platform_helpers.S	\
194				${COMPILER_RT_SRCS}
195
196ifeq ($($(ARCH)-cc-id),arm-clang)
197	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
198endif
199
200ifeq (${SANITIZE_UB},on)
201	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
202endif
203
204INCLUDES		+=	-Iinclude				\
205				-Iinclude/arch/${ARCH}			\
206				-Iinclude/lib/cpus/${ARCH}		\
207				-Iinclude/lib/el3_runtime/${ARCH}	\
208				${PLAT_INCLUDES}			\
209				${SPD_INCLUDES}
210
211include common/backtrace/backtrace.mk
212
213################################################################################
214# Generic definitions
215################################################################################
216
217ifeq (${BUILD_BASE},)
218     BUILD_BASE		:=	./build
219endif
220BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
221
222SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
223
224# Platforms providing their own TBB makefile may override this value
225INCLUDE_TBBR_MK		:=	1
226
227################################################################################
228# Include SPD Makefile if one has been specified
229################################################################################
230
231ifneq (${SPD},none)
232	ifeq (${SPD},spmd)
233	# SPMD is located in std_svc directory
234		SPD_DIR := std_svc
235
236		ifeq ($(SPMD_SPM_AT_SEL2),1)
237			CTX_INCLUDE_EL2_REGS := 1
238		endif
239
240		ifneq ($(SP_LAYOUT_FILE),)
241		BL2_ENABLE_SP_LOAD := 1
242		endif
243	else
244		# All other SPDs in spd directory
245		SPD_DIR := spd
246	endif #(SPD)
247
248	# We expect to locate an spd.mk under the specified SPD directory
249	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
250
251	ifeq (${SPD_MAKE},)
252                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
253	endif
254        $(info Including ${SPD_MAKE})
255        include ${SPD_MAKE}
256
257	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
258	# Makefile would set NEED_BL32 to "yes". In this case, the build system
259	# supports two mutually exclusive options:
260	# * BL32 is built from source: then BL32_SOURCES must contain the list
261	#   of source files to build BL32
262	# * BL32 is a prebuilt binary: then BL32 must point to the image file
263	#   that will be included in the FIP
264	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
265	# over the sources.
266endif #(SPD=none)
267
268################################################################################
269# Include the platform specific Makefile after the SPD Makefile (the platform
270# makefile may use all previous definitions in this file)
271################################################################################
272include ${PLAT_MAKEFILE_FULL}
273
274################################################################################
275# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
276# platform.
277################################################################################
278
279include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
280################################################################################
281# Process BRANCH_PROTECTION value and set
282# Pointer Authentication and Branch Target Identification flags
283################################################################################
284ifeq (${BRANCH_PROTECTION},0)
285	# Default value turns off all types of branch protection
286	BP_OPTION := none
287else ifneq (${ARCH},aarch64)
288        $(error BRANCH_PROTECTION requires AArch64)
289else ifeq (${BRANCH_PROTECTION},1)
290	# Enables all types of branch protection features
291	BP_OPTION := standard
292	ENABLE_BTI := 1
293	ENABLE_PAUTH := 1
294else ifeq (${BRANCH_PROTECTION},2)
295	# Return address signing to its standard level
296	BP_OPTION := pac-ret
297	ENABLE_PAUTH := 1
298else ifeq (${BRANCH_PROTECTION},3)
299	# Extend the signing to include leaf functions
300	BP_OPTION := pac-ret+leaf
301	ENABLE_PAUTH := 1
302else ifeq (${BRANCH_PROTECTION},4)
303	# Turn on branch target identification mechanism
304	BP_OPTION := bti
305	ENABLE_BTI := 1
306else ifeq (${BRANCH_PROTECTION},5)
307	# Turn on branch target identification mechanism
308	BP_OPTION := standard
309	ENABLE_BTI := 2
310	ENABLE_PAUTH := 2
311else
312        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
313endif #(BRANCH_PROTECTION)
314
315ifneq ($(ENABLE_PAUTH),0)
316	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
317endif
318
319# Pointer Authentication sources
320ifneq (${ENABLE_PAUTH},0)
321# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
322# Pauth support. As it's not secure, it must be reimplemented for real platforms
323	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
324endif
325
326################################################################################
327# RME dependent flags configuration, Enable optional features for RME.
328################################################################################
329# FEAT_RME
330ifeq (${ENABLE_RME},1)
331	# RME requires el2 context to be saved for now.
332	CTX_INCLUDE_EL2_REGS := 1
333	CTX_INCLUDE_AARCH32_REGS := 0
334	CTX_INCLUDE_PAUTH_REGS := 1
335
336	ifneq ($(ENABLE_FEAT_MPAM), 0)
337		CTX_INCLUDE_MPAM_REGS := 1
338	endif
339
340	# RME enables CSV2_2 extension by default.
341	ENABLE_FEAT_CSV2_2 = 1
342endif #(FEAT_RME)
343
344################################################################################
345# Include rmmd Makefile if RME is enabled
346################################################################################
347ifneq (${ENABLE_RME},0)
348include services/std_svc/rmmd/rmmd.mk
349$(warning "RME is an experimental feature")
350endif
351
352################################################################################
353# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
354################################################################################
355ifneq (${ENABLE_FEAT_D128}, 0)
356        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
357endif
358
359# This internal flag is common option which is set to 1 for scenarios
360# when the BL2 is running in EL3 level. This occurs in two scenarios -
361# 4 world system running BL2 at EL3 and two world system without BL1 running
362# BL2 in EL3
363
364ifeq (${RESET_TO_BL2},1)
365	BL2_RUNS_AT_EL3	:=	1
366	ifeq (${ENABLE_RME},1)
367                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
368                supported at the moment.)
369	endif
370else ifeq (${ENABLE_RME},1)
371	BL2_RUNS_AT_EL3	:=	1
372else
373	BL2_RUNS_AT_EL3	:=	0
374endif
375
376# This internal flag is set to 1 when Firmware First handling of External aborts
377# is required by lowe ELs. Currently only NS requires this support.
378ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
379	FFH_SUPPORT := 1
380else
381	FFH_SUPPORT := 0
382endif
383
384ifneq ($(filter 1,${ERRATA_A53_1530924} ${ERRATA_A55_1530923}	\
385        ${ERRATA_A57_1319537} ${ERRATA_A72_1319367} ${ERRATA_A76_1165522}),)
386ERRATA_SPECULATIVE_AT	:= 1
387else
388ERRATA_SPECULATIVE_AT	:= 0
389endif
390
391################################################################################
392# Build `AARCH32_SP` as BL32 image for AArch32
393################################################################################
394ifeq (${ARCH},aarch32)
395        NEED_BL32 := yes
396
397        ifneq (${AARCH32_SP},none)
398        # We expect to locate an sp.mk under the specified AARCH32_SP directory
399		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
400
401                ifeq (${AARCH32_SP_MAKE},)
402                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
403                endif
404                $(info Including ${AARCH32_SP_MAKE})
405                include ${AARCH32_SP_MAKE}
406        endif
407endif #(ARCH=aarch32)
408
409################################################################################
410# Include libc if not overridden
411################################################################################
412ifeq (${OVERRIDE_LIBC},0)
413include lib/libc/libc.mk
414endif
415
416ifneq (${USE_GIC_DRIVER},0)
417include drivers/arm/gic/gic.mk
418endif
419
420################################################################################
421# Check incompatible options and dependencies
422################################################################################
423include ${MAKE_HELPERS_DIRECTORY}constraints.mk
424
425# The cert_create tool cannot generate certificates individually, so we use the
426# target 'certificates' to create them all
427ifneq (${GENERATE_COT},0)
428    FIP_DEPS += certificates
429    FWU_FIP_DEPS += fwu_certificates
430    BL2_FIP_DEPS += bl2_certificates
431endif
432
433ifneq (${DECRYPTION_SUPPORT},none)
434	ENC_ARGS += -f ${FW_ENC_STATUS}
435	ENC_ARGS += -k ${ENC_KEY}
436	ENC_ARGS += -n ${ENC_NONCE}
437	FIP_DEPS += enctool
438	FWU_FIP_DEPS += enctool
439	BL2_FIP_DEPS += enctool
440endif #(DECRYPTION_SUPPORT)
441
442################################################################################
443# Process platform overrideable behaviour
444################################################################################
445
446ifdef BL1_SOURCES
447	NEED_BL1 := yes
448endif #(BL1_SOURCES)
449
450ifdef BL2_SOURCES
451	NEED_BL2 := yes
452
453	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
454	# Certificate generation tools. This flag can be overridden by the platform.
455	ifdef EL3_PAYLOAD_BASE
456		# If booting an EL3 payload there is no need for a BL33 image
457		# in the FIP file.
458		NEED_BL33		:=	no
459	else
460		ifdef PRELOADED_BL33_BASE
461			# If booting a BL33 preloaded image there is no need of
462			# another one in the FIP file.
463			NEED_BL33		:=	no
464		else
465			NEED_BL33		?=	yes
466		endif
467	endif
468endif #(BL2_SOURCES)
469
470ifdef BL2U_SOURCES
471	NEED_BL2U := yes
472endif #(BL2U_SOURCES)
473
474# If SCP_BL2 is given, we always want FIP to include it.
475ifdef SCP_BL2
476	NEED_SCP_BL2		:=	yes
477endif #(SCP_BL2)
478
479# For AArch32, BL31 is not currently supported.
480ifneq (${ARCH},aarch32)
481	ifdef BL31_SOURCES
482	# When booting an EL3 payload, there is no need to compile the BL31
483	# image nor put it in the FIP.
484		ifndef EL3_PAYLOAD_BASE
485			NEED_BL31 := yes
486		endif
487	endif
488endif #(ARCH=aarch64)
489
490# Process TBB related flags
491ifneq (${GENERATE_COT},0)
492    # Common cert_create options
493    ifneq (${CREATE_KEYS},0)
494        $(eval CRT_ARGS += -n)
495        $(eval FWU_CRT_ARGS += -n)
496        $(eval BL2_CRT_ARGS += -n)
497        ifneq (${SAVE_KEYS},0)
498            $(eval CRT_ARGS += -k)
499            $(eval FWU_CRT_ARGS += -k)
500            $(eval BL2_CRT_ARGS += -k)
501        endif
502    endif
503    # Include TBBR makefile (unless the platform indicates otherwise)
504    ifeq (${INCLUDE_TBBR_MK},1)
505        include make_helpers/tbbr/tbbr_tools.mk
506    endif
507endif #(GENERATE_COT)
508
509ifneq (${FIP_ALIGN},0)
510	FIP_ARGS += --align ${FIP_ALIGN}
511endif #(FIP_ALIGN)
512
513ifdef FDT_SOURCES
514	NEED_FDT := yes
515endif #(FDT_SOURCES)
516
517################################################################################
518# Include libraries' Makefile that are used in all BL
519################################################################################
520
521include lib/stack_protector/stack_protector.mk
522
523################################################################################
524# Include BL specific makefiles
525################################################################################
526
527ifeq (${NEED_BL1},yes)
528include bl1/bl1.mk
529endif
530
531ifeq (${NEED_BL2},yes)
532include bl2/bl2.mk
533endif
534
535ifeq (${NEED_BL2U},yes)
536include bl2u/bl2u.mk
537endif
538
539ifeq (${NEED_BL31},yes)
540include bl31/bl31.mk
541endif
542
543################################################################################
544# Build options checks
545################################################################################
546
547# Boolean_Flags
548$(eval $(call assert_booleans,\
549    $(sort \
550	ALLOW_RO_XLAT_TABLES \
551	BL2_ENABLE_SP_LOAD \
552	COLD_BOOT_SINGLE_CPU \
553	$(CPU_FLAG_LIST) \
554	CREATE_KEYS \
555	CTX_INCLUDE_AARCH32_REGS \
556	CTX_INCLUDE_FPREGS \
557	CTX_INCLUDE_SVE_REGS \
558	CTX_INCLUDE_EL2_REGS \
559	CTX_INCLUDE_MPAM_REGS \
560	DEBUG \
561	DYN_DISABLE_AUTH \
562	EL3_EXCEPTION_HANDLING \
563	ENABLE_AMU_AUXILIARY_COUNTERS \
564	AMU_RESTRICT_COUNTERS \
565	ENABLE_ASSERTIONS \
566	ENABLE_PIE \
567	ENABLE_PMF \
568	ENABLE_PSCI_STAT \
569	ENABLE_RUNTIME_INSTRUMENTATION \
570	ENABLE_SME_FOR_SWD \
571	ENABLE_SVE_FOR_SWD \
572	ENABLE_FEAT_GCIE \
573	ENABLE_FEAT_RAS	\
574	FFH_SUPPORT	\
575	ERROR_DEPRECATED \
576	FAULT_INJECTION_SUPPORT \
577	GENERATE_COT \
578	GICV2_G0_FOR_EL3 \
579	HANDLE_EA_EL3_FIRST_NS \
580	HARDEN_SLS \
581	HW_ASSISTED_COHERENCY \
582	MEASURED_BOOT \
583	DISCRETE_TPM \
584	DICE_PROTECTION_ENVIRONMENT \
585	RMMD_ENABLE_EL3_TOKEN_SIGN \
586	RMMD_ENABLE_IDE_KEY_PROG \
587	DRTM_SUPPORT \
588	NS_TIMER_SWITCH \
589	OVERRIDE_LIBC \
590	PL011_GENERIC_UART \
591	PLAT_EXTRA_LD_SCRIPT \
592	PROGRAMMABLE_RESET_ADDRESS \
593	PSCI_EXTENDED_STATE_ID \
594	PSCI_OS_INIT_MODE \
595	ARCH_FEATURE_AVAILABILITY \
596	RESET_TO_BL31 \
597	SAVE_KEYS \
598	SEPARATE_CODE_AND_RODATA \
599	SEPARATE_BL2_NOLOAD_REGION \
600	SEPARATE_NOBITS_REGION \
601	SEPARATE_RWDATA_REGION \
602	SEPARATE_SIMD_SECTION \
603	SPIN_ON_BL1_EXIT \
604	SPM_MM \
605	SPMC_AT_EL3 \
606	SPMC_AT_EL3_SEL0_SP \
607	SPMD_SPM_AT_SEL2 \
608	ENABLE_SPMD_LP \
609	TRANSFER_LIST \
610	TRUSTED_BOARD_BOOT \
611	USE_COHERENT_MEM \
612	USE_DEBUGFS \
613	USE_KERNEL_DT_CONVENTION \
614	ARM_IO_IN_DTB \
615	SDEI_IN_FCONF \
616	SEC_INT_DESC_IN_FCONF \
617	USE_ROMLIB \
618	USE_TBBR_DEFS \
619	WARMBOOT_ENABLE_DCACHE_EARLY \
620	RESET_TO_BL2 \
621	BL2_IN_XIP_MEM \
622	BL2_INV_DCACHE \
623	USE_SPINLOCK_CAS \
624	ENCRYPT_BL31 \
625	ENCRYPT_BL32 \
626	ERRATA_SPECULATIVE_AT \
627	ERRATA_SME_POWER_DOWN \
628	RAS_TRAP_NS_ERR_REC_ACCESS \
629	COT_DESC_IN_DTB \
630	USE_SP804_TIMER \
631	PSA_FWU_SUPPORT \
632	PSA_FWU_METADATA_FW_STORE_DESC \
633	ENABLE_MPMM \
634	FEATURE_DETECTION \
635	TRNG_SUPPORT \
636	ENABLE_ERRATA_ALL \
637	ERRATA_ABI_SUPPORT \
638	ERRATA_NON_ARM_INTERCONNECT \
639	CONDITIONAL_CMO \
640	PSA_CRYPTO	\
641	ENABLE_CONSOLE_GETC \
642	INIT_UNUSED_NS_EL2	\
643	PLATFORM_REPORT_CTX_MEM_USE \
644	EARLY_CONSOLE \
645	PRESERVE_DSU_PMU_REGS \
646	HOB_LIST \
647	LFA_SUPPORT \
648)))
649
650# Numeric_Flags
651$(eval $(call assert_numerics,\
652    $(sort \
653	ARM_ARCH_MAJOR \
654	ARM_ARCH_MINOR \
655	BRANCH_PROTECTION \
656	CTX_INCLUDE_PAUTH_REGS \
657	CTX_INCLUDE_NEVE_REGS \
658	DISABLE_MTPMU \
659	ENABLE_BRBE_FOR_NS \
660	ENABLE_TRBE_FOR_NS \
661	ENABLE_BTI \
662	ENABLE_PAUTH \
663	ENABLE_FEAT_PAUTH_LR \
664	ENABLE_FEAT_AIE \
665	ENABLE_FEAT_AMU \
666	ENABLE_FEAT_AMUv1p1 \
667	ENABLE_FEAT_CPA2 \
668	ENABLE_FEAT_CSV2_2 \
669	ENABLE_FEAT_CSV2_3 \
670	ENABLE_FEAT_DEBUGV8P9 \
671	ENABLE_FEAT_DIT \
672	ENABLE_FEAT_ECV \
673	ENABLE_FEAT_FGT \
674	ENABLE_FEAT_FGT2 \
675	ENABLE_FEAT_FGWTE3 \
676	ENABLE_FEAT_FPMR \
677	ENABLE_FEAT_HCX \
678	ENABLE_FEAT_LS64_ACCDATA \
679	ENABLE_FEAT_MEC \
680	ENABLE_FEAT_MOPS \
681	ENABLE_FEAT_MTE2 \
682	ENABLE_FEAT_PAN \
683	ENABLE_FEAT_PFAR \
684	ENABLE_FEAT_RNG \
685	ENABLE_FEAT_RNG_TRAP \
686	ENABLE_FEAT_SEL2 \
687	ENABLE_FEAT_TCR2 \
688	ENABLE_FEAT_THE \
689	ENABLE_FEAT_SB \
690	ENABLE_FEAT_S2PIE \
691	ENABLE_FEAT_S1PIE \
692	ENABLE_FEAT_S2POE \
693	ENABLE_FEAT_S1POE \
694	ENABLE_FEAT_SCTLR2 \
695	ENABLE_FEAT_D128 \
696	ENABLE_FEAT_GCS \
697	ENABLE_FEAT_VHE \
698	ENABLE_FEAT_MPAM \
699	ENABLE_FEAT_MPAM_PE_BW_CTRL \
700	ENABLE_RME \
701	ENABLE_SPE_FOR_NS \
702	ENABLE_SYS_REG_TRACE_FOR_NS \
703	ENABLE_SME_FOR_NS \
704	ENABLE_SME2_FOR_NS \
705	ENABLE_SVE_FOR_NS \
706	ENABLE_TRF_FOR_NS \
707	FW_ENC_STATUS \
708	NR_OF_FW_BANKS \
709	NR_OF_IMAGES_IN_FW_BANK \
710	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
711	TWED_DELAY \
712	ENABLE_FEAT_TWED \
713	SVE_VECTOR_LEN \
714	IMPDEF_SYSREG_TRAP \
715	W \
716)))
717
718ifdef KEY_SIZE
719        $(eval $(call assert_numeric,KEY_SIZE))
720endif
721
722ifeq ($(filter $(SANITIZE_UB), on off trap),)
723        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
724endif
725
726################################################################################
727# Add definitions to the cpp preprocessor based on the current build options.
728# This is done after including the platform specific makefile to allow the
729# platform to overwrite the default options
730################################################################################
731
732$(eval $(call add_defines,\
733    $(sort \
734	ALLOW_RO_XLAT_TABLES \
735	ARM_ARCH_MAJOR \
736	ARM_ARCH_MINOR \
737	BL2_ENABLE_SP_LOAD \
738	COLD_BOOT_SINGLE_CPU \
739	$(CPU_FLAG_LIST) \
740	CTX_INCLUDE_AARCH32_REGS \
741	CTX_INCLUDE_FPREGS \
742	CTX_INCLUDE_SVE_REGS \
743	CTX_INCLUDE_PAUTH_REGS \
744	CTX_INCLUDE_MPAM_REGS \
745	EL3_EXCEPTION_HANDLING \
746	CTX_INCLUDE_EL2_REGS \
747	CTX_INCLUDE_NEVE_REGS \
748	DEBUG \
749	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
750	DISABLE_MTPMU \
751	ENABLE_FEAT_AMU \
752	ENABLE_AMU_AUXILIARY_COUNTERS \
753	AMU_RESTRICT_COUNTERS \
754	ENABLE_ASSERTIONS \
755	ENABLE_BTI \
756	ENABLE_FEAT_DEBUGV8P9 \
757	ENABLE_FEAT_MPAM \
758	ENABLE_FEAT_MPAM_PE_BW_CTRL \
759	ENABLE_PAUTH \
760	ENABLE_FEAT_PAUTH_LR \
761	ENABLE_PIE \
762	ENABLE_PMF \
763	ENABLE_PSCI_STAT \
764	ENABLE_RME \
765	RMMD_ENABLE_EL3_TOKEN_SIGN \
766	RMMD_ENABLE_IDE_KEY_PROG \
767	ENABLE_RUNTIME_INSTRUMENTATION \
768	ENABLE_SME_FOR_NS \
769	ENABLE_SME2_FOR_NS \
770	ENABLE_SME_FOR_SWD \
771	ENABLE_SPE_FOR_NS \
772	ENABLE_SVE_FOR_NS \
773	ENABLE_SVE_FOR_SWD \
774	ENABLE_FEAT_RAS \
775	FFH_SUPPORT \
776	ENCRYPT_BL31 \
777	ENCRYPT_BL32 \
778	ERROR_DEPRECATED \
779	FAULT_INJECTION_SUPPORT \
780	GICV2_G0_FOR_EL3 \
781	HANDLE_EA_EL3_FIRST_NS \
782	HW_ASSISTED_COHERENCY \
783	LOG_LEVEL \
784	MEASURED_BOOT \
785	DISCRETE_TPM \
786	DICE_PROTECTION_ENVIRONMENT \
787	DRTM_SUPPORT \
788	NS_TIMER_SWITCH \
789	PL011_GENERIC_UART \
790	PLAT_EXTRA_LD_SCRIPT \
791	PLAT_${PLAT} \
792	PROGRAMMABLE_RESET_ADDRESS \
793	PSCI_EXTENDED_STATE_ID \
794	PSCI_OS_INIT_MODE \
795	ARCH_FEATURE_AVAILABILITY \
796	RESET_TO_BL31 \
797	RME_GPT_BITLOCK_BLOCK \
798	RME_GPT_MAX_BLOCK \
799	SEPARATE_CODE_AND_RODATA \
800	SEPARATE_BL2_FIP \
801	SEPARATE_BL2_NOLOAD_REGION \
802	SEPARATE_NOBITS_REGION \
803	SEPARATE_RWDATA_REGION \
804	SEPARATE_SIMD_SECTION \
805	RECLAIM_INIT_CODE \
806	SPD_${SPD} \
807	SPIN_ON_BL1_EXIT \
808	SPM_MM \
809	SPMC_AT_EL3 \
810	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
811	SPMC_AT_EL3_SEL0_SP \
812	SPMD_SPM_AT_SEL2 \
813	TRANSFER_LIST \
814	TRUSTED_BOARD_BOOT \
815	TRNG_SUPPORT \
816	ERRATA_ABI_SUPPORT \
817	ERRATA_NON_ARM_INTERCONNECT \
818	USE_COHERENT_MEM \
819	USE_DEBUGFS \
820	ARM_IO_IN_DTB \
821	SDEI_IN_FCONF \
822	SEC_INT_DESC_IN_FCONF \
823	USE_ROMLIB \
824	USE_TBBR_DEFS \
825	USE_KERNEL_DT_CONVENTION \
826	WARMBOOT_ENABLE_DCACHE_EARLY \
827	RESET_TO_BL2 \
828	BL2_RUNS_AT_EL3	\
829	BL2_IN_XIP_MEM \
830	BL2_INV_DCACHE \
831	USE_SPINLOCK_CAS \
832	ERRATA_SPECULATIVE_AT \
833	ERRATA_SME_POWER_DOWN \
834	RAS_TRAP_NS_ERR_REC_ACCESS \
835	COT_DESC_IN_DTB \
836	USE_SP804_TIMER \
837	ENABLE_FEAT_RNG \
838	ENABLE_FEAT_RNG_TRAP \
839	ENABLE_FEAT_SB \
840	ENABLE_FEAT_DIT \
841	NR_OF_FW_BANKS \
842	NR_OF_IMAGES_IN_FW_BANK \
843	PSA_FWU_SUPPORT \
844	PSA_FWU_METADATA_FW_STORE_DESC \
845	ENABLE_BRBE_FOR_NS \
846	ENABLE_TRBE_FOR_NS \
847	ENABLE_SYS_REG_TRACE_FOR_NS \
848	ENABLE_TRF_FOR_NS \
849	ENABLE_FEAT_AIE \
850	ENABLE_FEAT_HCX \
851	ENABLE_MPMM \
852	ENABLE_FEAT_FGT \
853	ENABLE_FEAT_FGT2 \
854	ENABLE_FEAT_FGWTE3 \
855	ENABLE_FEAT_FPMR \
856	ENABLE_FEAT_ECV \
857	ENABLE_FEAT_AMUv1p1 \
858	ENABLE_FEAT_SEL2 \
859	ENABLE_FEAT_VHE \
860	ENABLE_FEAT_CPA2 \
861	ENABLE_FEAT_CSV2_2 \
862	ENABLE_FEAT_CSV2_3 \
863	ENABLE_FEAT_LS64_ACCDATA \
864	ENABLE_FEAT_MEC \
865	ENABLE_FEAT_PAN \
866	ENABLE_FEAT_TCR2 \
867	ENABLE_FEAT_THE \
868	ENABLE_FEAT_S2PIE \
869	ENABLE_FEAT_S1PIE \
870	ENABLE_FEAT_S2POE \
871	ENABLE_FEAT_S1POE \
872	ENABLE_FEAT_SCTLR2 \
873	ENABLE_FEAT_D128 \
874	ENABLE_FEAT_GCS \
875	ENABLE_FEAT_MOPS \
876	ENABLE_FEAT_GCIE \
877	ENABLE_FEAT_MTE2 \
878	ENABLE_FEAT_PFAR \
879	FEATURE_DETECTION \
880	TWED_DELAY \
881	ENABLE_FEAT_TWED \
882	CONDITIONAL_CMO \
883	IMPDEF_SYSREG_TRAP \
884	SVE_VECTOR_LEN \
885	ENABLE_SPMD_LP \
886	PSA_CRYPTO	\
887	ENABLE_CONSOLE_GETC \
888	INIT_UNUSED_NS_EL2	\
889	PLATFORM_REPORT_CTX_MEM_USE \
890	EARLY_CONSOLE \
891	PRESERVE_DSU_PMU_REGS \
892	HOB_LIST \
893	HW_CONFIG_BASE \
894	LFA_SUPPORT \
895)))
896
897ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
898ifeq (${DEBUG}, 0)
899        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
900        override PLATFORM_REPORT_CTX_MEM_USE := 0
901endif
902endif
903
904ifeq (${SANITIZE_UB},trap)
905        $(eval $(call add_define,MONITOR_TRAPS))
906endif #(SANITIZE_UB)
907
908# Define the EL3_PAYLOAD_BASE flag only if it is provided.
909ifdef EL3_PAYLOAD_BASE
910        $(eval $(call add_define,EL3_PAYLOAD_BASE))
911else
912# Define the PRELOADED_BL33_BASE flag only if it is provided and
913# EL3_PAYLOAD_BASE is not defined, as it has priority.
914	ifdef PRELOADED_BL33_BASE
915                $(eval $(call add_define,PRELOADED_BL33_BASE))
916	endif
917endif #(EL3_PAYLOAD_BASE)
918
919# Define the DYN_DISABLE_AUTH flag only if set.
920ifeq (${DYN_DISABLE_AUTH},1)
921        $(eval $(call add_define,DYN_DISABLE_AUTH))
922endif
923
924ifeq ($($(ARCH)-ld-id),arm-link)
925        $(eval $(call add_define,USE_ARM_LINK))
926endif
927
928# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
929ifeq (${SPD},spmd)
930ifdef SP_LAYOUT_FILE
931	-include $(BUILD_PLAT)/sp_gen.mk
932	FIP_DEPS += sp
933	CRT_DEPS += sp
934	NEED_SP_PKG := yes
935else
936	ifeq (${SPMD_SPM_AT_SEL2},1)
937                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
938	endif
939endif #(SP_LAYOUT_FILE)
940endif #(SPD)
941
942################################################################################
943# Configure the flags for the specified compiler and linker
944################################################################################
945include ${MAKE_HELPERS_DIRECTORY}cflags.mk
946
947################################################################################
948# Build targets
949################################################################################
950
951.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
952
953all: msg_start
954
955msg_start:
956	$(s)echo "Building ${PLAT}"
957
958$(eval $(call MAKE_LIB,c))
959
960# Expand build macros for the different images
961ifeq (${NEED_BL1},yes)
962BL1_SOURCES := $(sort ${BL1_SOURCES})
963$(eval $(call MAKE_BL,bl1))
964endif #(NEED_BL1)
965
966ifeq (${NEED_BL2},yes)
967
968ifeq (${RESET_TO_BL2}, 0)
969FIP_BL2_ARGS := tb-fw
970endif
971
972BL2_SOURCES := $(sort ${BL2_SOURCES})
973
974ifeq (${SEPARATE_BL2_FIP},1)
975$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS},BL2_)), \
976	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS},BL2_)))
977else
978$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})), \
979	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
980endif #(SEPARATE_BL2_FIP)
981
982endif #(NEED_BL2)
983
984ifeq (${NEED_SCP_BL2},yes)
985$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
986endif #(NEED_SCP_BL2)
987
988ifeq (${NEED_BL31},yes)
989BL31_SOURCES += ${SPD_SOURCES}
990# Sort BL31 source files to remove duplicates
991BL31_SOURCES := $(sort ${BL31_SOURCES})
992ifneq (${DECRYPTION_SUPPORT},none)
993$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
994	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
995else
996$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
997	$(eval $(call MAKE_BL,bl31,soc-fw)))
998endif #(DECRYPTION_SUPPORT)
999endif #(NEED_BL31)
1000
1001# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1002# build system will call TOOL_ADD_IMG to print a warning message and abort the
1003# process. Note that the dependency on BL32 applies to the FIP only.
1004ifeq (${NEED_BL32},yes)
1005# Sort BL32 source files to remove duplicates
1006BL32_SOURCES := $(sort ${BL32_SOURCES})
1007BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1008
1009ifneq (${DECRYPTION_SUPPORT},none)
1010$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1011	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1012else
1013$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1014	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1015endif #(DECRYPTION_SUPPORT)
1016endif #(NEED_BL32)
1017
1018# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1019# needs to be built from RMM_SOURCES.
1020ifeq (${NEED_RMM},yes)
1021# Sort RMM source files to remove duplicates
1022RMM_SOURCES := $(sort ${RMM_SOURCES})
1023BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1024
1025$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1026	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1027endif #(NEED_RMM)
1028
1029# Add the BL33 image if required by the platform
1030ifeq (${NEED_BL33},yes)
1031$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1032endif #(NEED_BL33)
1033
1034ifeq (${NEED_BL2U},yes)
1035$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1036	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1037endif #(NEED_BL2U)
1038
1039# Expand build macros for the different images
1040ifeq (${NEED_FDT},yes)
1041    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1042
1043    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1044        ifndef INITRD_BASE
1045            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1046        endif
1047
1048        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1049        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1050
1051        define $(HW_CONFIG)-after +=
1052            $(s)echo "  INITRD  $(HW_CONFIG)"
1053            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1054            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1055        endef
1056    endif
1057endif #(NEED_FDT)
1058
1059# Add Secure Partition packages
1060ifeq (${NEED_SP_PKG},yes)
1061$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1062	$(if $(host-poetry),$(q)poetry -q install --no-root)
1063	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1064sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1065	$(s)echo
1066	$(s)echo "Built SP Images successfully"
1067	$(s)echo
1068endif #(NEED_SP_PKG)
1069
1070locate-checkpatch:
1071ifndef CHECKPATCH
1072	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1073else
1074ifeq (,$(wildcard ${CHECKPATCH}))
1075	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1076endif
1077endif #(CHECKPATCH)
1078
1079clean:
1080	$(s)echo "  CLEAN"
1081	$(q)rm -rf $(BUILD_PLAT)
1082	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1083	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1084	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1085	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1086	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1087	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1088
1089realclean distclean:
1090	$(s)echo "  REALCLEAN"
1091	$(q)rm -rf $(BUILD_BASE)
1092	$(q)rm -rf $(CURDIR)/cscope.*
1093	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1094	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1095	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1096	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1097	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1098	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1099
1100checkcodebase:		locate-checkpatch
1101	$(s)echo "  CHECKING STYLE"
1102	$(q)if test -d .git ; then						\
1103		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1104		while read GIT_FILE ;					\
1105		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1106		done ;							\
1107	else								\
1108		 find . -type f -not -iwholename "*.git*"		\
1109		 -not -iwholename "*build*"				\
1110		 -not -iwholename "*libfdt*"				\
1111		 -not -iwholename "*libc*"				\
1112		 -not -iwholename "*docs*"				\
1113		 -not -iwholename "*.rst"				\
1114		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1115	fi
1116
1117checkpatch:		locate-checkpatch
1118	$(s)echo "  CHECKING STYLE"
1119	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1120		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1121	fi
1122	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1123	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1124	do								\
1125		printf "\n[*] Checking style of '$$commit'\n\n";	\
1126		( git log --format=email "$$commit~..$$commit"		\
1127			-- ${CHECK_PATHS} ;				\
1128		  git diff --format=email "$$commit~..$$commit"		\
1129			-- ${CHECK_PATHS}; ) |				\
1130			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1131	done
1132
1133certtool: ${CRTTOOL}
1134
1135${CRTTOOL}: FORCE | $$(@D)/
1136	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1137	$(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
1138	$(s)echo
1139	$(s)echo "Built $@ successfully"
1140	$(s)echo
1141
1142ifneq (${GENERATE_COT},0)
1143certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1144	$(q)${CRTTOOL} ${CRT_ARGS}
1145	$(s)echo
1146	$(s)echo "Built $@ successfully"
1147	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1148	$(s)echo
1149endif #(GENERATE_COT)
1150
1151ifeq (${SEPARATE_BL2_FIP},1)
1152${BUILD_PLAT}/${BL2_FIP_NAME}: ${BL2_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1153	$(eval ${CHECK_BL2_FIP_CMD})
1154	$(q)${FIPTOOL} create ${BL2_FIP_ARGS} $@
1155	$(q)${FIPTOOL} info $@
1156	$(s)echo
1157	$(s)echo "Built $@ successfully"
1158	$(s)echo
1159endif #(SEPARATE_BL2_FIP)
1160
1161${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} | $$(@D)/
1162	$(eval ${CHECK_FIP_CMD})
1163	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1164	$(q)${FIPTOOL} info $@
1165	$(s)echo
1166	$(s)echo "Built $@ successfully"
1167	$(s)echo
1168
1169ifneq (${GENERATE_COT},0)
1170fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1171	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1172	$(s)echo
1173	$(s)echo "Built $@ successfully"
1174	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1175	$(s)echo
1176endif #(GENERATE_COT)
1177
1178ifneq (${GENERATE_COT},0)
1179bl2_certificates: ${BUILD_PLAT}/${FIP_NAME} ${BL2_CRT_DEPS} ${CRTTOOL} | ${BUILD_PLAT}/
1180	$(q)${CRTTOOL} ${BL2_CRT_ARGS}
1181	$(s)echo
1182	$(s)echo "Built $@ successfully"
1183	$(s)echo "BL2 certificates can be found in ${BUILD_PLAT}"
1184	$(s)echo
1185endif #(GENERATE_COT)
1186
1187${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1188	$(eval ${CHECK_FWU_FIP_CMD})
1189	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1190	$(q)${FIPTOOL} info $@
1191	$(s)echo
1192	$(s)echo "Built $@ successfully"
1193	$(s)echo
1194
1195fiptool: ${FIPTOOL}
1196ifeq (${SEPARATE_BL2_FIP},1)
1197bl2_fip: ${BUILD_PLAT}/${BL2_FIP_NAME}
1198fip: bl2_fip
1199else
1200fip: ${BUILD_PLAT}/${FIP_NAME}
1201endif #(SEPARATE_BL2_FIP)
1202fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1203
1204# symlink for compatibility before tools were in the build directory
1205${FIPTOOL}: FORCE | $$(@D)/
1206	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1207	$(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
1208
1209$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB) | $$(@D)/
1210	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_LIB=$(CRYPTO_LIB) ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1211
1212memmap: all
1213	$(if $(host-poetry),$(q)poetry -q install --no-root)
1214	$(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
1215
1216tl: ${BUILD_PLAT}/tl.bin
1217${BUILD_PLAT}/tl.bin: ${HW_CONFIG} | $$(@D)/
1218	$(if $(host-poetry),$(q)poetry -q install --no-root)
1219	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1220
1221doc:
1222	$(s)echo "  BUILD DOCUMENTATION"
1223	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1224	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} BUILDDIR=$(abspath ${BUILD_BASE}/docs) html
1225
1226enctool: ${ENCTOOL}
1227
1228${ENCTOOL}: FORCE | $$(@D)/
1229	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1230	$(s)echo
1231	$(s)echo "Built $@ successfully"
1232	$(s)echo
1233
1234cscope:
1235	$(s)echo "  CSCOPE"
1236	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1237	$(q)cscope -b -q -k
1238
1239help:
1240	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1241	$(s)echo ""
1242	$(s)echo "PLAT is used to specify which platform you wish to build."
1243	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1244	$(s)echo ""
1245	$(s)echo "platform = ${PLATFORM_LIST}"
1246	$(s)echo ""
1247	$(s)echo "Please refer to the User Guide for a list of all supported options."
1248	$(s)echo "Note that the build system doesn't track dependencies for build "
1249	$(s)echo "options. Therefore, if any of the build options are changed "
1250	$(s)echo "from a previous build, a clean build must be performed."
1251	$(s)echo ""
1252	$(s)echo "Supported Targets:"
1253	$(s)echo "  all            Build all individual bootloader binaries"
1254	$(s)echo "  bl1            Build the BL1 binary"
1255	$(s)echo "  bl2            Build the BL2 binary"
1256	$(s)echo "  bl2u           Build the BL2U binary"
1257	$(s)echo "  bl31           Build the BL31 binary"
1258	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1259	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1260	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1261	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1262	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1263	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1264	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1265	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1266	$(s)echo "  clean          Clean the build for the selected platform"
1267	$(s)echo "  cscope         Generate cscope index"
1268	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1269	$(s)echo "  certtool       Build the Certificate generation tool"
1270	$(s)echo "  enctool        Build the Firmware encryption tool"
1271	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1272	$(s)echo "  sp             Build the Secure Partition Packages"
1273	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1274	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1275	$(s)echo "  memmap         Print the memory map of the built binaries"
1276	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1277	$(s)echo ""
1278	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1279	$(s)echo ""
1280	$(s)echo "example: build all targets for the FVP platform:"
1281	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1282
1283.PHONY: FORCE
1284FORCE:;
1285