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