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