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