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