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