xref: /rk3399_ARM-atf/Makefile (revision e77cd73f944acb67f66c3d30a508a4adf35cbb79)
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
384################################################################################
385# Build `AARCH32_SP` as BL32 image for AArch32
386################################################################################
387ifeq (${ARCH},aarch32)
388        NEED_BL32 := yes
389
390        ifneq (${AARCH32_SP},none)
391        # We expect to locate an sp.mk under the specified AARCH32_SP directory
392		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
393
394                ifeq (${AARCH32_SP_MAKE},)
395                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
396                endif
397                $(info Including ${AARCH32_SP_MAKE})
398                include ${AARCH32_SP_MAKE}
399        endif
400endif #(ARCH=aarch32)
401
402################################################################################
403# Include libc if not overridden
404################################################################################
405ifeq (${OVERRIDE_LIBC},0)
406include lib/libc/libc.mk
407endif
408
409ifneq (${USE_GIC_DRIVER},0)
410include drivers/arm/gic/gic.mk
411endif
412
413################################################################################
414# Check incompatible options and dependencies
415################################################################################
416include ${MAKE_HELPERS_DIRECTORY}constraints.mk
417
418# The cert_create tool cannot generate certificates individually, so we use the
419# target 'certificates' to create them all
420ifneq (${GENERATE_COT},0)
421    FIP_DEPS += certificates
422    FWU_FIP_DEPS += fwu_certificates
423    BL2_FIP_DEPS += bl2_certificates
424endif
425
426ifneq (${DECRYPTION_SUPPORT},none)
427	ENC_ARGS += -f ${FW_ENC_STATUS}
428	ENC_ARGS += -k ${ENC_KEY}
429	ENC_ARGS += -n ${ENC_NONCE}
430	FIP_DEPS += enctool
431	FWU_FIP_DEPS += enctool
432	BL2_FIP_DEPS += enctool
433endif #(DECRYPTION_SUPPORT)
434
435ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
436# Support authentication verification and hash calculation
437	CRYPTO_SUPPORT := 3
438else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
439# Support authentication verification and hash calculation
440	CRYPTO_SUPPORT := 3
441else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
442# Support hash calculation only
443	CRYPTO_SUPPORT := 2
444else ifeq (${TRUSTED_BOARD_BOOT},1)
445# Support authentication verification only
446	CRYPTO_SUPPORT := 1
447else
448	CRYPTO_SUPPORT := 0
449endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
450
451ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
452CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
453endif
454
455################################################################################
456# Process platform overrideable behaviour
457################################################################################
458
459ifdef BL1_SOURCES
460	NEED_BL1 := yes
461endif #(BL1_SOURCES)
462
463ifdef BL2_SOURCES
464	NEED_BL2 := yes
465
466	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
467	# Certificate generation tools. This flag can be overridden by the platform.
468	ifdef EL3_PAYLOAD_BASE
469		# If booting an EL3 payload there is no need for a BL33 image
470		# in the FIP file.
471		NEED_BL33		:=	no
472	else
473		ifdef PRELOADED_BL33_BASE
474			# If booting a BL33 preloaded image there is no need of
475			# another one in the FIP file.
476			NEED_BL33		:=	no
477		else
478			NEED_BL33		?=	yes
479		endif
480	endif
481endif #(BL2_SOURCES)
482
483ifdef BL2U_SOURCES
484	NEED_BL2U := yes
485endif #(BL2U_SOURCES)
486
487# If SCP_BL2 is given, we always want FIP to include it.
488ifdef SCP_BL2
489	NEED_SCP_BL2		:=	yes
490endif #(SCP_BL2)
491
492# For AArch32, BL31 is not currently supported.
493ifneq (${ARCH},aarch32)
494	ifdef BL31_SOURCES
495	# When booting an EL3 payload, there is no need to compile the BL31
496	# image nor put it in the FIP.
497		ifndef EL3_PAYLOAD_BASE
498			NEED_BL31 := yes
499		endif
500	endif
501endif #(ARCH=aarch64)
502
503# Process TBB related flags
504ifneq (${GENERATE_COT},0)
505    # Common cert_create options
506    ifneq (${CREATE_KEYS},0)
507        $(eval CRT_ARGS += -n)
508        $(eval FWU_CRT_ARGS += -n)
509        $(eval BL2_CRT_ARGS += -n)
510        ifneq (${SAVE_KEYS},0)
511            $(eval CRT_ARGS += -k)
512            $(eval FWU_CRT_ARGS += -k)
513            $(eval BL2_CRT_ARGS += -k)
514        endif
515    endif
516    # Include TBBR makefile (unless the platform indicates otherwise)
517    ifeq (${INCLUDE_TBBR_MK},1)
518        include make_helpers/tbbr/tbbr_tools.mk
519    endif
520endif #(GENERATE_COT)
521
522ifneq (${FIP_ALIGN},0)
523	FIP_ARGS += --align ${FIP_ALIGN}
524endif #(FIP_ALIGN)
525
526ifdef FDT_SOURCES
527	NEED_FDT := yes
528endif #(FDT_SOURCES)
529
530################################################################################
531# Include libraries' Makefile that are used in all BL
532################################################################################
533
534include lib/stack_protector/stack_protector.mk
535
536################################################################################
537# Include BL specific makefiles
538################################################################################
539
540ifeq (${NEED_BL1},yes)
541include bl1/bl1.mk
542endif
543
544ifeq (${NEED_BL2},yes)
545include bl2/bl2.mk
546endif
547
548ifeq (${NEED_BL2U},yes)
549include bl2u/bl2u.mk
550endif
551
552ifeq (${NEED_BL31},yes)
553include bl31/bl31.mk
554endif
555
556################################################################################
557# Build options checks
558################################################################################
559
560# Boolean_Flags
561$(eval $(call assert_booleans,\
562    $(sort \
563	ALLOW_RO_XLAT_TABLES \
564	BL2_ENABLE_SP_LOAD \
565	COLD_BOOT_SINGLE_CPU \
566	$(CPU_FLAG_LIST) \
567	CREATE_KEYS \
568	CTX_INCLUDE_AARCH32_REGS \
569	CTX_INCLUDE_FPREGS \
570	CTX_INCLUDE_SVE_REGS \
571	CTX_INCLUDE_EL2_REGS \
572	CTX_INCLUDE_MPAM_REGS \
573	DEBUG \
574	DYN_DISABLE_AUTH \
575	EL3_EXCEPTION_HANDLING \
576	ENABLE_AMU_AUXILIARY_COUNTERS \
577	AMU_RESTRICT_COUNTERS \
578	ENABLE_ASSERTIONS \
579	ENABLE_PIE \
580	ENABLE_PMF \
581	ENABLE_PSCI_STAT \
582	ENABLE_RUNTIME_INSTRUMENTATION \
583	ENABLE_SME_FOR_SWD \
584	ENABLE_SVE_FOR_SWD \
585	ENABLE_FEAT_GCIE \
586	ENABLE_FEAT_RAS	\
587	FFH_SUPPORT	\
588	ERROR_DEPRECATED \
589	FAULT_INJECTION_SUPPORT \
590	GENERATE_COT \
591	GICV2_G0_FOR_EL3 \
592	HANDLE_EA_EL3_FIRST_NS \
593	HARDEN_SLS \
594	HW_ASSISTED_COHERENCY \
595	MEASURED_BOOT \
596	DISCRETE_TPM \
597	DICE_PROTECTION_ENVIRONMENT \
598	RMMD_ENABLE_EL3_TOKEN_SIGN \
599	RMMD_ENABLE_IDE_KEY_PROG \
600	DRTM_SUPPORT \
601	NS_TIMER_SWITCH \
602	OVERRIDE_LIBC \
603	PL011_GENERIC_UART \
604	PLAT_EXTRA_LD_SCRIPT \
605	PROGRAMMABLE_RESET_ADDRESS \
606	PSCI_EXTENDED_STATE_ID \
607	PSCI_OS_INIT_MODE \
608	ARCH_FEATURE_AVAILABILITY \
609	RESET_TO_BL31 \
610	SAVE_KEYS \
611	SEPARATE_CODE_AND_RODATA \
612	SEPARATE_BL2_NOLOAD_REGION \
613	SEPARATE_NOBITS_REGION \
614	SEPARATE_RWDATA_REGION \
615	SEPARATE_SIMD_SECTION \
616	SPIN_ON_BL1_EXIT \
617	SPM_MM \
618	SPMC_AT_EL3 \
619	SPMC_AT_EL3_SEL0_SP \
620	SPMD_SPM_AT_SEL2 \
621	ENABLE_SPMD_LP \
622	TRANSFER_LIST \
623	TRUSTED_BOARD_BOOT \
624	USE_COHERENT_MEM \
625	USE_DEBUGFS \
626	USE_KERNEL_DT_CONVENTION \
627	ARM_IO_IN_DTB \
628	SDEI_IN_FCONF \
629	SEC_INT_DESC_IN_FCONF \
630	USE_ROMLIB \
631	USE_TBBR_DEFS \
632	WARMBOOT_ENABLE_DCACHE_EARLY \
633	RESET_TO_BL2 \
634	BL2_IN_XIP_MEM \
635	BL2_INV_DCACHE \
636	USE_SPINLOCK_CAS \
637	ENCRYPT_BL31 \
638	ENCRYPT_BL32 \
639	ERRATA_SPECULATIVE_AT \
640	ERRATA_SME_POWER_DOWN \
641	RAS_TRAP_NS_ERR_REC_ACCESS \
642	COT_DESC_IN_DTB \
643	USE_SP804_TIMER \
644	PSA_FWU_SUPPORT \
645	PSA_FWU_METADATA_FW_STORE_DESC \
646	ENABLE_MPMM \
647	FEATURE_DETECTION \
648	TRNG_SUPPORT \
649	ENABLE_ERRATA_ALL \
650	ERRATA_ABI_SUPPORT \
651	ERRATA_NON_ARM_INTERCONNECT \
652	CONDITIONAL_CMO \
653	PSA_CRYPTO	\
654	ENABLE_CONSOLE_GETC \
655	INIT_UNUSED_NS_EL2	\
656	PLATFORM_REPORT_CTX_MEM_USE \
657	EARLY_CONSOLE \
658	PRESERVE_DSU_PMU_REGS \
659	HOB_LIST \
660	LFA_SUPPORT \
661)))
662
663# Numeric_Flags
664$(eval $(call assert_numerics,\
665    $(sort \
666	ARM_ARCH_MAJOR \
667	ARM_ARCH_MINOR \
668	BRANCH_PROTECTION \
669	CTX_INCLUDE_PAUTH_REGS \
670	CTX_INCLUDE_NEVE_REGS \
671	CRYPTO_SUPPORT \
672	DISABLE_MTPMU \
673	ENABLE_BRBE_FOR_NS \
674	ENABLE_TRBE_FOR_NS \
675	ENABLE_BTI \
676	ENABLE_PAUTH \
677	ENABLE_FEAT_PAUTH_LR \
678	ENABLE_FEAT_AIE \
679	ENABLE_FEAT_AMU \
680	ENABLE_FEAT_AMUv1p1 \
681	ENABLE_FEAT_CPA2 \
682	ENABLE_FEAT_CSV2_2 \
683	ENABLE_FEAT_CSV2_3 \
684	ENABLE_FEAT_DEBUGV8P9 \
685	ENABLE_FEAT_DIT \
686	ENABLE_FEAT_ECV \
687	ENABLE_FEAT_FGT \
688	ENABLE_FEAT_FGT2 \
689	ENABLE_FEAT_FGWTE3 \
690	ENABLE_FEAT_FPMR \
691	ENABLE_FEAT_HCX \
692	ENABLE_FEAT_LS64_ACCDATA \
693	ENABLE_FEAT_MEC \
694	ENABLE_FEAT_MOPS \
695	ENABLE_FEAT_MTE2 \
696	ENABLE_FEAT_PAN \
697	ENABLE_FEAT_PFAR \
698	ENABLE_FEAT_RNG \
699	ENABLE_FEAT_RNG_TRAP \
700	ENABLE_FEAT_SEL2 \
701	ENABLE_FEAT_TCR2 \
702	ENABLE_FEAT_THE \
703	ENABLE_FEAT_SB \
704	ENABLE_FEAT_S2PIE \
705	ENABLE_FEAT_S1PIE \
706	ENABLE_FEAT_S2POE \
707	ENABLE_FEAT_S1POE \
708	ENABLE_FEAT_SCTLR2 \
709	ENABLE_FEAT_D128 \
710	ENABLE_FEAT_GCS \
711	ENABLE_FEAT_VHE \
712	ENABLE_FEAT_MPAM \
713	ENABLE_FEAT_MPAM_PE_BW_CTRL \
714	ENABLE_RME \
715	ENABLE_SPE_FOR_NS \
716	ENABLE_SYS_REG_TRACE_FOR_NS \
717	ENABLE_SME_FOR_NS \
718	ENABLE_SME2_FOR_NS \
719	ENABLE_SVE_FOR_NS \
720	ENABLE_TRF_FOR_NS \
721	FW_ENC_STATUS \
722	NR_OF_FW_BANKS \
723	NR_OF_IMAGES_IN_FW_BANK \
724	TWED_DELAY \
725	ENABLE_FEAT_TWED \
726	SVE_VECTOR_LEN \
727	IMPDEF_SYSREG_TRAP \
728	W \
729)))
730
731ifdef KEY_SIZE
732        $(eval $(call assert_numeric,KEY_SIZE))
733endif
734
735ifeq ($(filter $(SANITIZE_UB), on off trap),)
736        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
737endif
738
739################################################################################
740# Add definitions to the cpp preprocessor based on the current build options.
741# This is done after including the platform specific makefile to allow the
742# platform to overwrite the default options
743################################################################################
744
745$(eval $(call add_defines,\
746    $(sort \
747	ALLOW_RO_XLAT_TABLES \
748	ARM_ARCH_MAJOR \
749	ARM_ARCH_MINOR \
750	BL2_ENABLE_SP_LOAD \
751	COLD_BOOT_SINGLE_CPU \
752	$(CPU_FLAG_LIST) \
753	CTX_INCLUDE_AARCH32_REGS \
754	CTX_INCLUDE_FPREGS \
755	CTX_INCLUDE_SVE_REGS \
756	CTX_INCLUDE_PAUTH_REGS \
757	CTX_INCLUDE_MPAM_REGS \
758	EL3_EXCEPTION_HANDLING \
759	CTX_INCLUDE_EL2_REGS \
760	CTX_INCLUDE_NEVE_REGS \
761	DEBUG \
762	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
763	DISABLE_MTPMU \
764	ENABLE_FEAT_AMU \
765	ENABLE_AMU_AUXILIARY_COUNTERS \
766	AMU_RESTRICT_COUNTERS \
767	ENABLE_ASSERTIONS \
768	ENABLE_BTI \
769	ENABLE_FEAT_DEBUGV8P9 \
770	ENABLE_FEAT_MPAM \
771	ENABLE_FEAT_MPAM_PE_BW_CTRL \
772	ENABLE_PAUTH \
773	ENABLE_FEAT_PAUTH_LR \
774	ENABLE_PIE \
775	ENABLE_PMF \
776	ENABLE_PSCI_STAT \
777	ENABLE_RME \
778	RMMD_ENABLE_EL3_TOKEN_SIGN \
779	RMMD_ENABLE_IDE_KEY_PROG \
780	ENABLE_RUNTIME_INSTRUMENTATION \
781	ENABLE_SME_FOR_NS \
782	ENABLE_SME2_FOR_NS \
783	ENABLE_SME_FOR_SWD \
784	ENABLE_SPE_FOR_NS \
785	ENABLE_SVE_FOR_NS \
786	ENABLE_SVE_FOR_SWD \
787	ENABLE_FEAT_RAS \
788	FFH_SUPPORT \
789	ENCRYPT_BL31 \
790	ENCRYPT_BL32 \
791	ERROR_DEPRECATED \
792	FAULT_INJECTION_SUPPORT \
793	GICV2_G0_FOR_EL3 \
794	HANDLE_EA_EL3_FIRST_NS \
795	HW_ASSISTED_COHERENCY \
796	LOG_LEVEL \
797	MEASURED_BOOT \
798	DISCRETE_TPM \
799	DICE_PROTECTION_ENVIRONMENT \
800	DRTM_SUPPORT \
801	NS_TIMER_SWITCH \
802	PL011_GENERIC_UART \
803	PLAT_EXTRA_LD_SCRIPT \
804	PLAT_${PLAT} \
805	PROGRAMMABLE_RESET_ADDRESS \
806	PSCI_EXTENDED_STATE_ID \
807	PSCI_OS_INIT_MODE \
808	ARCH_FEATURE_AVAILABILITY \
809	RESET_TO_BL31 \
810	RME_GPT_BITLOCK_BLOCK \
811	RME_GPT_MAX_BLOCK \
812	SEPARATE_CODE_AND_RODATA \
813	SEPARATE_BL2_FIP \
814	SEPARATE_BL2_NOLOAD_REGION \
815	SEPARATE_NOBITS_REGION \
816	SEPARATE_RWDATA_REGION \
817	SEPARATE_SIMD_SECTION \
818	RECLAIM_INIT_CODE \
819	SPD_${SPD} \
820	SPIN_ON_BL1_EXIT \
821	SPM_MM \
822	SPMC_AT_EL3 \
823	SPMC_AT_EL3_SEL0_SP \
824	SPMD_SPM_AT_SEL2 \
825	TRANSFER_LIST \
826	TRUSTED_BOARD_BOOT \
827	CRYPTO_SUPPORT \
828	TRNG_SUPPORT \
829	ERRATA_ABI_SUPPORT \
830	ERRATA_NON_ARM_INTERCONNECT \
831	USE_COHERENT_MEM \
832	USE_DEBUGFS \
833	ARM_IO_IN_DTB \
834	SDEI_IN_FCONF \
835	SEC_INT_DESC_IN_FCONF \
836	USE_ROMLIB \
837	USE_TBBR_DEFS \
838	USE_KERNEL_DT_CONVENTION \
839	WARMBOOT_ENABLE_DCACHE_EARLY \
840	RESET_TO_BL2 \
841	BL2_RUNS_AT_EL3	\
842	BL2_IN_XIP_MEM \
843	BL2_INV_DCACHE \
844	USE_SPINLOCK_CAS \
845	ERRATA_SPECULATIVE_AT \
846	ERRATA_SME_POWER_DOWN \
847	RAS_TRAP_NS_ERR_REC_ACCESS \
848	COT_DESC_IN_DTB \
849	USE_SP804_TIMER \
850	ENABLE_FEAT_RNG \
851	ENABLE_FEAT_RNG_TRAP \
852	ENABLE_FEAT_SB \
853	ENABLE_FEAT_DIT \
854	NR_OF_FW_BANKS \
855	NR_OF_IMAGES_IN_FW_BANK \
856	PSA_FWU_SUPPORT \
857	PSA_FWU_METADATA_FW_STORE_DESC \
858	ENABLE_BRBE_FOR_NS \
859	ENABLE_TRBE_FOR_NS \
860	ENABLE_SYS_REG_TRACE_FOR_NS \
861	ENABLE_TRF_FOR_NS \
862	ENABLE_FEAT_AIE \
863	ENABLE_FEAT_HCX \
864	ENABLE_MPMM \
865	ENABLE_FEAT_FGT \
866	ENABLE_FEAT_FGT2 \
867	ENABLE_FEAT_FGWTE3 \
868	ENABLE_FEAT_FPMR \
869	ENABLE_FEAT_ECV \
870	ENABLE_FEAT_AMUv1p1 \
871	ENABLE_FEAT_SEL2 \
872	ENABLE_FEAT_VHE \
873	ENABLE_FEAT_CPA2 \
874	ENABLE_FEAT_CSV2_2 \
875	ENABLE_FEAT_CSV2_3 \
876	ENABLE_FEAT_LS64_ACCDATA \
877	ENABLE_FEAT_MEC \
878	ENABLE_FEAT_PAN \
879	ENABLE_FEAT_TCR2 \
880	ENABLE_FEAT_THE \
881	ENABLE_FEAT_S2PIE \
882	ENABLE_FEAT_S1PIE \
883	ENABLE_FEAT_S2POE \
884	ENABLE_FEAT_S1POE \
885	ENABLE_FEAT_SCTLR2 \
886	ENABLE_FEAT_D128 \
887	ENABLE_FEAT_GCS \
888	ENABLE_FEAT_MOPS \
889	ENABLE_FEAT_GCIE \
890	ENABLE_FEAT_MTE2 \
891	ENABLE_FEAT_PFAR \
892	FEATURE_DETECTION \
893	TWED_DELAY \
894	ENABLE_FEAT_TWED \
895	CONDITIONAL_CMO \
896	IMPDEF_SYSREG_TRAP \
897	SVE_VECTOR_LEN \
898	ENABLE_SPMD_LP \
899	PSA_CRYPTO	\
900	ENABLE_CONSOLE_GETC \
901	INIT_UNUSED_NS_EL2	\
902	PLATFORM_REPORT_CTX_MEM_USE \
903	EARLY_CONSOLE \
904	PRESERVE_DSU_PMU_REGS \
905	HOB_LIST \
906	HW_CONFIG_BASE \
907	LFA_SUPPORT \
908)))
909
910ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
911ifeq (${DEBUG}, 0)
912        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
913        override PLATFORM_REPORT_CTX_MEM_USE := 0
914endif
915endif
916
917ifeq (${SANITIZE_UB},trap)
918        $(eval $(call add_define,MONITOR_TRAPS))
919endif #(SANITIZE_UB)
920
921# Define the EL3_PAYLOAD_BASE flag only if it is provided.
922ifdef EL3_PAYLOAD_BASE
923        $(eval $(call add_define,EL3_PAYLOAD_BASE))
924else
925# Define the PRELOADED_BL33_BASE flag only if it is provided and
926# EL3_PAYLOAD_BASE is not defined, as it has priority.
927	ifdef PRELOADED_BL33_BASE
928                $(eval $(call add_define,PRELOADED_BL33_BASE))
929	endif
930endif #(EL3_PAYLOAD_BASE)
931
932# Define the DYN_DISABLE_AUTH flag only if set.
933ifeq (${DYN_DISABLE_AUTH},1)
934        $(eval $(call add_define,DYN_DISABLE_AUTH))
935endif
936
937ifeq ($($(ARCH)-ld-id),arm-link)
938        $(eval $(call add_define,USE_ARM_LINK))
939endif
940
941# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
942ifeq (${SPD},spmd)
943ifdef SP_LAYOUT_FILE
944	-include $(BUILD_PLAT)/sp_gen.mk
945	FIP_DEPS += sp
946	CRT_DEPS += sp
947	NEED_SP_PKG := yes
948else
949	ifeq (${SPMD_SPM_AT_SEL2},1)
950                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
951	endif
952endif #(SP_LAYOUT_FILE)
953endif #(SPD)
954
955################################################################################
956# Configure the flags for the specified compiler and linker
957################################################################################
958include ${MAKE_HELPERS_DIRECTORY}cflags.mk
959
960################################################################################
961# Build targets
962################################################################################
963
964.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
965
966all: msg_start
967
968msg_start:
969	$(s)echo "Building ${PLAT}"
970
971$(eval $(call MAKE_LIB,c))
972
973# Expand build macros for the different images
974ifeq (${NEED_BL1},yes)
975BL1_SOURCES := $(sort ${BL1_SOURCES})
976$(eval $(call MAKE_BL,bl1))
977endif #(NEED_BL1)
978
979ifeq (${NEED_BL2},yes)
980
981ifeq (${RESET_TO_BL2}, 0)
982FIP_BL2_ARGS := tb-fw
983endif
984
985BL2_SOURCES := $(sort ${BL2_SOURCES})
986
987ifeq (${SEPARATE_BL2_FIP},1)
988$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS},BL2_)), \
989	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS},BL2_)))
990else
991$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})), \
992	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
993endif #(SEPARATE_BL2_FIP)
994
995endif #(NEED_BL2)
996
997ifeq (${NEED_SCP_BL2},yes)
998$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
999endif #(NEED_SCP_BL2)
1000
1001ifeq (${NEED_BL31},yes)
1002BL31_SOURCES += ${SPD_SOURCES}
1003# Sort BL31 source files to remove duplicates
1004BL31_SOURCES := $(sort ${BL31_SOURCES})
1005ifneq (${DECRYPTION_SUPPORT},none)
1006$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1007	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1008else
1009$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1010	$(eval $(call MAKE_BL,bl31,soc-fw)))
1011endif #(DECRYPTION_SUPPORT)
1012endif #(NEED_BL31)
1013
1014# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1015# build system will call TOOL_ADD_IMG to print a warning message and abort the
1016# process. Note that the dependency on BL32 applies to the FIP only.
1017ifeq (${NEED_BL32},yes)
1018# Sort BL32 source files to remove duplicates
1019BL32_SOURCES := $(sort ${BL32_SOURCES})
1020BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1021
1022ifneq (${DECRYPTION_SUPPORT},none)
1023$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1024	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1025else
1026$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1027	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1028endif #(DECRYPTION_SUPPORT)
1029endif #(NEED_BL32)
1030
1031# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1032# needs to be built from RMM_SOURCES.
1033ifeq (${NEED_RMM},yes)
1034# Sort RMM source files to remove duplicates
1035RMM_SOURCES := $(sort ${RMM_SOURCES})
1036BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1037
1038$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1039	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1040endif #(NEED_RMM)
1041
1042# Add the BL33 image if required by the platform
1043ifeq (${NEED_BL33},yes)
1044$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1045endif #(NEED_BL33)
1046
1047ifeq (${NEED_BL2U},yes)
1048$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1049	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1050endif #(NEED_BL2U)
1051
1052# Expand build macros for the different images
1053ifeq (${NEED_FDT},yes)
1054    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1055
1056    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1057        ifndef INITRD_BASE
1058            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1059        endif
1060
1061        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1062        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1063
1064        define $(HW_CONFIG)-after +=
1065            $(s)echo "  INITRD  $(HW_CONFIG)"
1066            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1067            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1068        endef
1069    endif
1070endif #(NEED_FDT)
1071
1072# Add Secure Partition packages
1073ifeq (${NEED_SP_PKG},yes)
1074$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1075	$(if $(host-poetry),$(q)poetry -q install --no-root)
1076	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1077sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1078	$(s)echo
1079	$(s)echo "Built SP Images successfully"
1080	$(s)echo
1081endif #(NEED_SP_PKG)
1082
1083locate-checkpatch:
1084ifndef CHECKPATCH
1085	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1086else
1087ifeq (,$(wildcard ${CHECKPATCH}))
1088	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1089endif
1090endif #(CHECKPATCH)
1091
1092clean:
1093	$(s)echo "  CLEAN"
1094	$(q)rm -rf $(BUILD_PLAT)
1095	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1096	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1097	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1098	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1099	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1100	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1101
1102realclean distclean:
1103	$(s)echo "  REALCLEAN"
1104	$(q)rm -rf $(BUILD_BASE)
1105	$(q)rm -rf $(CURDIR)/cscope.*
1106	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1107	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1108	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1109	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1110	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1111	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1112
1113checkcodebase:		locate-checkpatch
1114	$(s)echo "  CHECKING STYLE"
1115	$(q)if test -d .git ; then						\
1116		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1117		while read GIT_FILE ;					\
1118		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1119		done ;							\
1120	else								\
1121		 find . -type f -not -iwholename "*.git*"		\
1122		 -not -iwholename "*build*"				\
1123		 -not -iwholename "*libfdt*"				\
1124		 -not -iwholename "*libc*"				\
1125		 -not -iwholename "*docs*"				\
1126		 -not -iwholename "*.rst"				\
1127		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1128	fi
1129
1130checkpatch:		locate-checkpatch
1131	$(s)echo "  CHECKING STYLE"
1132	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1133		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1134	fi
1135	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1136	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1137	do								\
1138		printf "\n[*] Checking style of '$$commit'\n\n";	\
1139		( git log --format=email "$$commit~..$$commit"		\
1140			-- ${CHECK_PATHS} ;				\
1141		  git diff --format=email "$$commit~..$$commit"		\
1142			-- ${CHECK_PATHS}; ) |				\
1143			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1144	done
1145
1146certtool: ${CRTTOOL}
1147
1148${CRTTOOL}: FORCE | $$(@D)/
1149	$(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
1150	$(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
1151	$(s)echo
1152	$(s)echo "Built $@ successfully"
1153	$(s)echo
1154
1155ifneq (${GENERATE_COT},0)
1156certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1157	$(q)${CRTTOOL} ${CRT_ARGS}
1158	$(s)echo
1159	$(s)echo "Built $@ successfully"
1160	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1161	$(s)echo
1162endif #(GENERATE_COT)
1163
1164ifeq (${SEPARATE_BL2_FIP},1)
1165${BUILD_PLAT}/${BL2_FIP_NAME}: ${BL2_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1166	$(eval ${CHECK_BL2_FIP_CMD})
1167	$(q)${FIPTOOL} create ${BL2_FIP_ARGS} $@
1168	$(q)${FIPTOOL} info $@
1169	$(s)echo
1170	$(s)echo "Built $@ successfully"
1171	$(s)echo
1172endif #(SEPARATE_BL2_FIP)
1173
1174${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} | $$(@D)/
1175	$(eval ${CHECK_FIP_CMD})
1176	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1177	$(q)${FIPTOOL} info $@
1178	$(s)echo
1179	$(s)echo "Built $@ successfully"
1180	$(s)echo
1181
1182ifneq (${GENERATE_COT},0)
1183fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1184	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1185	$(s)echo
1186	$(s)echo "Built $@ successfully"
1187	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1188	$(s)echo
1189endif #(GENERATE_COT)
1190
1191ifneq (${GENERATE_COT},0)
1192bl2_certificates: ${BUILD_PLAT}/${FIP_NAME} ${BL2_CRT_DEPS} ${CRTTOOL} | ${BUILD_PLAT}/
1193	$(q)${CRTTOOL} ${BL2_CRT_ARGS}
1194	$(s)echo
1195	$(s)echo "Built $@ successfully"
1196	$(s)echo "BL2 certificates can be found in ${BUILD_PLAT}"
1197	$(s)echo
1198endif #(GENERATE_COT)
1199
1200${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1201	$(eval ${CHECK_FWU_FIP_CMD})
1202	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1203	$(q)${FIPTOOL} info $@
1204	$(s)echo
1205	$(s)echo "Built $@ successfully"
1206	$(s)echo
1207
1208fiptool: ${FIPTOOL}
1209ifeq (${SEPARATE_BL2_FIP},1)
1210bl2_fip: ${BUILD_PLAT}/${BL2_FIP_NAME}
1211fip: bl2_fip
1212else
1213fip: ${BUILD_PLAT}/${FIP_NAME}
1214endif #(SEPARATE_BL2_FIP)
1215fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1216
1217# symlink for compatibility before tools were in the build directory
1218${FIPTOOL}: FORCE | $$(@D)/
1219	$(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
1220	$(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
1221
1222$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB) | $$(@D)/
1223	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1224
1225memmap: all
1226	$(if $(host-poetry),$(q)poetry -q install --no-root)
1227	$(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
1228
1229tl: ${BUILD_PLAT}/tl.bin
1230${BUILD_PLAT}/tl.bin: ${HW_CONFIG} | $$(@D)/
1231	$(if $(host-poetry),$(q)poetry -q install --no-root)
1232	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1233
1234doc:
1235	$(s)echo "  BUILD DOCUMENTATION"
1236	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1237	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} BUILDDIR=$(abspath ${BUILD_BASE}/docs) html
1238
1239enctool: ${ENCTOOL}
1240
1241${ENCTOOL}: FORCE | $$(@D)/
1242	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1243	$(s)echo
1244	$(s)echo "Built $@ successfully"
1245	$(s)echo
1246
1247cscope:
1248	$(s)echo "  CSCOPE"
1249	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1250	$(q)cscope -b -q -k
1251
1252help:
1253	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1254	$(s)echo ""
1255	$(s)echo "PLAT is used to specify which platform you wish to build."
1256	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1257	$(s)echo ""
1258	$(s)echo "platform = ${PLATFORM_LIST}"
1259	$(s)echo ""
1260	$(s)echo "Please refer to the User Guide for a list of all supported options."
1261	$(s)echo "Note that the build system doesn't track dependencies for build "
1262	$(s)echo "options. Therefore, if any of the build options are changed "
1263	$(s)echo "from a previous build, a clean build must be performed."
1264	$(s)echo ""
1265	$(s)echo "Supported Targets:"
1266	$(s)echo "  all            Build all individual bootloader binaries"
1267	$(s)echo "  bl1            Build the BL1 binary"
1268	$(s)echo "  bl2            Build the BL2 binary"
1269	$(s)echo "  bl2u           Build the BL2U binary"
1270	$(s)echo "  bl31           Build the BL31 binary"
1271	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1272	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1273	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1274	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1275	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1276	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1277	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1278	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1279	$(s)echo "  clean          Clean the build for the selected platform"
1280	$(s)echo "  cscope         Generate cscope index"
1281	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1282	$(s)echo "  certtool       Build the Certificate generation tool"
1283	$(s)echo "  enctool        Build the Firmware encryption tool"
1284	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1285	$(s)echo "  sp             Build the Secure Partition Packages"
1286	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1287	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1288	$(s)echo "  memmap         Print the memory map of the built binaries"
1289	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1290	$(s)echo ""
1291	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1292	$(s)echo ""
1293	$(s)echo "example: build all targets for the FVP platform:"
1294	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1295
1296.PHONY: FORCE
1297FORCE:;
1298