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