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