xref: /rk3399_ARM-atf/Makefile (revision 39b08bc366ff1bb08a2ab1dfd9c1eab3157fe16d)
1#
2# Copyright (c) 2013-2024, 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			:= 12
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_env.mk
27include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
28include ${MAKE_HELPERS_DIRECTORY}common.mk
29
30################################################################################
31# Default values for build configurations, and their dependencies
32################################################################################
33
34include ${MAKE_HELPERS_DIRECTORY}defaults.mk
35include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36
37# To be able to set platform specific defaults
38ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39include ${PLAT_DEFAULTS_MAKEFILE_FULL}
40endif
41
42################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
48# Assertions enabled for DEBUG builds by default
49ENABLE_ASSERTIONS		:= ${DEBUG}
50ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
51
52################################################################################
53# Checkpatch script options
54################################################################################
55
56CHECKCODE_ARGS		:=	--no-patch
57# Do not check the coding style on imported library files or documentation files
58INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					include/drivers/arm,		\
60					$(wildcard include/drivers/*)))
61INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
62					include/lib/libfdt		\
63					include/lib/libc,		\
64					$(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
66					include/lib			\
67					include/drivers,		\
68					$(wildcard include/*)))
69LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
70					lib/compiler-rt			\
71					lib/libfdt%			\
72					lib/libc,			\
73					lib/zlib			\
74					$(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
76					lib				\
77					include				\
78					docs				\
79					%.rst,				\
80					$(wildcard *)))
81CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
82				${INC_DIRS_TO_CHECK}			\
83				${INC_LIB_DIRS_TO_CHECK}		\
84				${LIB_DIRS_TO_CHECK}			\
85				${INC_DRV_DIRS_TO_CHECK}		\
86				${INC_ARM_DIRS_TO_CHECK}
87
88################################################################################
89# Process build options
90################################################################################
91
92ifeq ($(verbose),)
93	CHECKCODE_ARGS	+=	--no-summary --terse
94endif
95
96################################################################################
97# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH		?=	tools/cert_create
102CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH		?=	tools/encrypt_fw
106ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH		?=	tools/fiptool
110FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
111
112# Variables for use with sptool
113SPTOOLPATH		?=	tools/sptool
114SPTOOL			?=	${SPTOOLPATH}/sptool.py
115SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
116SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
117
118# Variables for use with ROMLIB
119ROMLIBPATH		?=	lib/romlib
120
121# Variable for use with Python
122PYTHON			?=	python3
123
124# Variables for use with documentation build using Sphinx tool
125DOCS_PATH		?=	docs
126
127################################################################################
128# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
129################################################################################
130ifeq (${ARM_ARCH_MAJOR},7)
131	target32-directive	= 	-target arm-none-eabi
132# Will set march-directive from platform configuration
133else
134	target32-directive	= 	-target armv8a-none-eabi
135endif #(ARM_ARCH_MAJOR)
136
137################################################################################
138# Get Architecture Feature Modifiers
139################################################################################
140arch-features		=	${ARM_ARCH_FEATURE}
141
142ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
143	ifeq ($($(ARCH)-cc-id),arm-clang)
144		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
145		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
146	else
147		TF_CFLAGS_aarch32	=	$(target32-directive)
148		TF_CFLAGS_aarch64	:=	-target aarch64-elf
149	endif
150
151else ifeq ($($(ARCH)-cc-id),gnu-gcc)
152	# Enable LTO only for aarch64
153	ifeq (${ARCH},aarch64)
154		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
155	endif
156endif #(clang)
157
158# Process Debug flag
159$(eval $(call add_define,DEBUG))
160ifneq (${DEBUG}, 0)
161	BUILD_TYPE	:=	debug
162	TF_CFLAGS	+=	-g -gdwarf-4
163	ASFLAGS		+=	-g -Wa,-gdwarf-4
164
165	# Use LOG_LEVEL_INFO by default for debug builds
166	LOG_LEVEL	:=	40
167else
168	BUILD_TYPE	:=	release
169	# Use LOG_LEVEL_NOTICE by default for release builds
170	LOG_LEVEL	:=	20
171endif #(Debug)
172
173# Default build string (git branch and commit)
174ifeq (${BUILD_STRING},)
175	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
176endif
177VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
178
179ifeq (${AARCH32_INSTRUCTION_SET},A32)
180	TF_CFLAGS_aarch32	+=	-marm
181else ifeq (${AARCH32_INSTRUCTION_SET},T32)
182	TF_CFLAGS_aarch32	+=	-mthumb
183else
184        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
185endif #(AARCH32_INSTRUCTION_SET)
186
187TF_CFLAGS_aarch32	+=	-mno-unaligned-access
188TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
189
190##############################################################################
191# WARNINGS Configuration
192###############################################################################
193# General warnings
194WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
195				-Wdisabled-optimization -Wvla -Wshadow	\
196				-Wredundant-decls
197# stricter warnings
198WARNINGS		+=	-Wextra -Wno-trigraphs
199# too verbose for generic build
200WARNINGS		+=	-Wno-missing-field-initializers \
201				-Wno-type-limits -Wno-sign-compare \
202# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
203WARNINGS		+=	-Wno-unused-parameter
204
205# Additional warnings
206# Level 1 - infrequent warnings we should have none of
207# full -Wextra
208WARNING1 += -Wsign-compare
209WARNING1 += -Wtype-limits
210WARNING1 += -Wmissing-field-initializers
211
212# Level 2 - problematic warnings that we want
213# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
214# TODO: disable just for them and move into default build
215WARNING2 += -Wold-style-definition
216WARNING2 += -Wmissing-prototypes
217WARNING2 += -Wmissing-format-attribute
218# TF-A aims to comply with this eventually. Effort too large at present
219WARNING2 += -Wundef
220# currently very involved and many platforms set this off
221WARNING2 += -Wunused-const-variable=2
222
223# Level 3 - very pedantic, frequently ignored
224WARNING3 := -Wbad-function-cast
225WARNING3 += -Waggregate-return
226WARNING3 += -Wnested-externs
227WARNING3 += -Wcast-align
228WARNING3 += -Wcast-qual
229WARNING3 += -Wconversion
230WARNING3 += -Wpacked
231WARNING3 += -Wpointer-arith
232WARNING3 += -Wswitch-default
233
234# Setting W is quite verbose and most warnings will be pre-existing issues
235# outside of the contributor's control. Don't fail the build on them so warnings
236# can be seen and hopefully addressed
237ifdef W
238	ifneq (${W},0)
239		E	 ?= 0
240	endif
241endif
242
243ifeq (${W},1)
244	WARNINGS += $(WARNING1)
245else ifeq (${W},2)
246	WARNINGS += $(WARNING1) $(WARNING2)
247else ifeq (${W},3)
248	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
249endif #(W)
250
251# Compiler specific warnings
252ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
253# not using clang
254WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
255				-Wpacked-bitfield-compat -Wshift-overflow=2 \
256				-Wlogical-op
257
258# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
259TF_CFLAGS_MIN_PAGE_SIZE	:=	$(call cc_option, --param=min-pagesize=0)
260TF_CFLAGS		+=	$(TF_CFLAGS_MIN_PAGE_SIZE)
261
262ifeq ($(HARDEN_SLS), 1)
263        TF_CFLAGS_MHARDEN_SLS	:=      $(call cc_option, -mharden-sls=all)
264        TF_CFLAGS_aarch64	+=      $(TF_CFLAGS_MHARDEN_SLS)
265endif
266
267else
268# using clang
269WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
270				-Wlogical-op-parentheses
271endif #(Clang Warning)
272
273ifneq (${E},0)
274	ERRORS := -Werror
275endif #(E)
276
277################################################################################
278# Compiler and Linker Directives
279################################################################################
280CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
281				$(ERRORS) $(WARNINGS)
282ASFLAGS			+=	$(CPPFLAGS)                 			\
283				-ffreestanding -Wa,--fatal-warnings
284TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
285				-ffunction-sections -fdata-sections		\
286				-ffreestanding -fno-builtin -fno-common		\
287				-Os -std=gnu99
288
289ifeq (${SANITIZE_UB},on)
290	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
291endif #(${SANITIZE_UB},on)
292
293ifeq (${SANITIZE_UB},trap)
294	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
295				-fsanitize-undefined-trap-on-error
296endif #(${SANITIZE_UB},trap)
297
298GCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
299
300TF_LDFLAGS		+=	-z noexecstack
301
302# LD = armlink
303ifeq ($($(ARCH)-ld-id),arm-link)
304	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
305	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
306	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
307
308# LD = gcc (used when GCC LTO is enabled)
309else ifeq ($($(ARCH)-ld-id),gnu-gcc)
310	# Pass ld options with Wl or Xlinker switches
311	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
312	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
313	TF_LDFLAGS		+=	-Wl,--gc-sections
314
315	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
316	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
317	TF_LDFLAGS		+=	-Wl,--build-id=none
318
319	ifeq ($(ENABLE_LTO),1)
320		ifeq (${ARCH},aarch64)
321			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
322			TF_LDFLAGS      +=	-flto-partition=one
323		endif
324	endif #(ENABLE_LTO)
325
326# GCC automatically adds fix-cortex-a53-843419 flag when used to link
327# which breaks some builds, so disable if errata fix is not explicitly enabled
328	ifeq (${ARCH},aarch64)
329		ifneq (${ERRATA_A53_843419},1)
330			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
331		endif
332	endif
333	TF_LDFLAGS		+= 	-nostdlib
334	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
335
336# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
337else
338# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
339# are not loaded by a elf loader.
340	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
341	TF_LDFLAGS		+=	-O1
342	TF_LDFLAGS		+=	--gc-sections
343
344	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
345	TF_LDFLAGS		+=	-z max-page-size=4096
346	TF_LDFLAGS		+=	--build-id=none
347
348# ld.lld doesn't recognize the errata flags,
349# therefore don't add those in that case.
350# ld.lld reports section type mismatch warnings,
351# therefore don't add --fatal-warnings to it.
352	ifneq ($($(ARCH)-ld-id),llvm-lld)
353		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
354	endif
355
356endif #(LD = armlink)
357
358################################################################################
359# Setup ARCH_MAJOR/MINOR before parsing arch_features.
360################################################################################
361ifeq (${ENABLE_RME},1)
362	ARM_ARCH_MAJOR := 9
363	ARM_ARCH_MINOR := 2
364endif
365
366################################################################################
367# Common sources and include directories
368################################################################################
369include lib/compiler-rt/compiler-rt.mk
370
371# Allow overriding the timestamp, for example for reproducible builds, or to
372# synchronize timestamps across multiple projects.
373# This must be set to a C string (including quotes where applicable).
374BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
375
376DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
377DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
378DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
379
380BL_COMMON_SOURCES	+=	common/bl_common.c			\
381				common/tf_log.c				\
382				common/${ARCH}/debug.S			\
383				drivers/console/multi_console.c		\
384				lib/${ARCH}/cache_helpers.S		\
385				lib/${ARCH}/misc_helpers.S		\
386				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
387				plat/common/plat_bl_common.c		\
388				plat/common/plat_log_common.c		\
389				plat/common/${ARCH}/plat_common.c	\
390				plat/common/${ARCH}/platform_helpers.S	\
391				${COMPILER_RT_SRCS}
392
393ifeq ($($(ARCH)-cc-id),arm-clang)
394	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
395endif
396
397ifeq (${SANITIZE_UB},on)
398	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
399endif
400
401INCLUDES		+=	-Iinclude				\
402				-Iinclude/arch/${ARCH}			\
403				-Iinclude/lib/cpus/${ARCH}		\
404				-Iinclude/lib/el3_runtime/${ARCH}	\
405				${PLAT_INCLUDES}			\
406				${SPD_INCLUDES}
407
408DTC_FLAGS		+=	-I dts -O dtb
409DTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
410				-x assembler-with-cpp $(DEFINES)
411
412include common/backtrace/backtrace.mk
413
414################################################################################
415# Generic definitions
416################################################################################
417
418ifeq (${BUILD_BASE},)
419     BUILD_BASE		:=	./build
420endif
421BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
422
423SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
424
425# Platforms providing their own TBB makefile may override this value
426INCLUDE_TBBR_MK		:=	1
427
428################################################################################
429# Include SPD Makefile if one has been specified
430################################################################################
431
432ifneq (${SPD},none)
433	ifeq (${ARCH},aarch32)
434                $(error "Error: SPD is incompatible with AArch32.")
435	endif
436
437	ifdef EL3_PAYLOAD_BASE
438                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
439                $(warning "The SPD and its BL32 companion will be present but \
440                ignored.")
441	endif
442
443	ifeq (${SPD},spmd)
444	# SPMD is located in std_svc directory
445		SPD_DIR := std_svc
446
447		ifeq ($(SPMD_SPM_AT_SEL2),1)
448			CTX_INCLUDE_EL2_REGS := 1
449			ifeq ($(SPMC_AT_EL3),1)
450                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
451			endif
452			ifeq ($(CTX_INCLUDE_SVE_REGS),1)
453                                $(error SVE context management not needed with Hafnium SPMC.)
454			endif
455		endif
456
457		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
458			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
459		endif
460
461		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
462			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
463		endif
464
465		ifeq ($(TS_SP_FW_CONFIG),1)
466			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
467		endif
468
469		ifneq ($(ARM_BL2_SP_LIST_DTS),)
470		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
471		endif
472
473		ifneq ($(SP_LAYOUT_FILE),)
474		BL2_ENABLE_SP_LOAD := 1
475		endif
476
477		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
478			ifneq ($(SPMC_AT_EL3),1)
479			$(error SEL0 SP cannot be enabled without SPMC at EL3)
480			endif
481		endif
482	else
483		# All other SPDs in spd directory
484		SPD_DIR := spd
485	endif #(SPD)
486
487	# We expect to locate an spd.mk under the specified SPD directory
488	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
489
490	ifeq (${SPD_MAKE},)
491                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
492	endif
493        $(info Including ${SPD_MAKE})
494        include ${SPD_MAKE}
495
496	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
497	# Makefile would set NEED_BL32 to "yes". In this case, the build system
498	# supports two mutually exclusive options:
499	# * BL32 is built from source: then BL32_SOURCES must contain the list
500	#   of source files to build BL32
501	# * BL32 is a prebuilt binary: then BL32 must point to the image file
502	#   that will be included in the FIP
503	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
504	# over the sources.
505endif #(SPD=none)
506
507ifeq (${ENABLE_SPMD_LP}, 1)
508ifneq (${SPD},spmd)
509        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
510endif
511ifeq ($(SPMC_AT_EL3),1)
512        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
513endif
514endif
515
516################################################################################
517# Process BRANCH_PROTECTION value and set
518# Pointer Authentication and Branch Target Identification flags
519################################################################################
520ifeq (${BRANCH_PROTECTION},0)
521	# Default value turns off all types of branch protection
522	BP_OPTION := none
523else ifneq (${ARCH},aarch64)
524        $(error BRANCH_PROTECTION requires AArch64)
525else ifeq (${BRANCH_PROTECTION},1)
526	# Enables all types of branch protection features
527	BP_OPTION := standard
528	ENABLE_BTI := 1
529	ENABLE_PAUTH := 1
530else ifeq (${BRANCH_PROTECTION},2)
531	# Return address signing to its standard level
532	BP_OPTION := pac-ret
533	ENABLE_PAUTH := 1
534else ifeq (${BRANCH_PROTECTION},3)
535	# Extend the signing to include leaf functions
536	BP_OPTION := pac-ret+leaf
537	ENABLE_PAUTH := 1
538else ifeq (${BRANCH_PROTECTION},4)
539	# Turn on branch target identification mechanism
540	BP_OPTION := bti
541	ENABLE_BTI := 1
542else
543        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
544endif #(BRANCH_PROTECTION)
545
546ifeq ($(ENABLE_PAUTH),1)
547	CTX_INCLUDE_PAUTH_REGS := 1
548endif
549ifneq (${BP_OPTION},none)
550	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
551endif #(BP_OPTION)
552
553# Pointer Authentication sources
554ifeq (${ENABLE_PAUTH}, 1)
555# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
556# Pauth support. As it's not secure, it must be reimplemented for real platforms
557	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
558endif
559
560################################################################################
561# Include the platform specific Makefile after the SPD Makefile (the platform
562# makefile may use all previous definitions in this file)
563################################################################################
564include ${PLAT_MAKEFILE_FULL}
565
566################################################################################
567# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
568# platform.
569################################################################################
570include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
571
572####################################################
573# Enable required options for Memory Stack Tagging.
574####################################################
575
576# Currently, these options are enabled only for clang and armclang compiler.
577ifeq (${SUPPORT_STACK_MEMTAG},yes)
578    ifdef mem_tag_arch_support
579        # Check for armclang and clang compilers
580        ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
581        # Add "memtag" architecture feature modifier if not specified
582            ifeq ( ,$(findstring memtag,$(arch-features)))
583                arch-features	:=	$(arch-features)+memtag
584            endif	# memtag
585            ifeq ($($(ARCH)-cc-id),arm-clang)
586                TF_CFLAGS	+=	-mmemtag-stack
587            else ifeq ($($(ARCH)-cc-id),llvm-clang)
588                TF_CFLAGS	+=	-fsanitize=memtag
589            endif	# armclang
590        endif
591    else
592        $(error "Error: stack memory tagging is not supported for  \
593        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
594	endif #(mem_tag_arch_support)
595endif #(SUPPORT_STACK_MEMTAG)
596
597################################################################################
598# RME dependent flags configuration, Enable optional features for RME.
599################################################################################
600# FEAT_RME
601ifeq (${ENABLE_RME},1)
602	# RME doesn't support PIE
603	ifneq (${ENABLE_PIE},0)
604                $(error ENABLE_RME does not support PIE)
605	endif
606
607	# RME requires AARCH64
608	ifneq (${ARCH},aarch64)
609                $(error ENABLE_RME requires AArch64)
610	endif
611
612	# RME requires el2 context to be saved for now.
613	CTX_INCLUDE_EL2_REGS := 1
614	CTX_INCLUDE_AARCH32_REGS := 0
615	CTX_INCLUDE_PAUTH_REGS := 1
616
617	# RME enables CSV2_2 extension by default.
618	ENABLE_FEAT_CSV2_2 = 1
619endif #(FEAT_RME)
620
621################################################################################
622# Include rmmd Makefile if RME is enabled
623################################################################################
624ifneq (${ENABLE_RME},0)
625	ifneq (${ARCH},aarch64)
626                $(error ENABLE_RME requires AArch64)
627	endif
628	ifeq ($(SPMC_AT_EL3),1)
629                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
630	endif
631
632	ifneq (${SPD}, none)
633		ifneq (${SPD}, spmd)
634                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
635		endif
636	endif
637include services/std_svc/rmmd/rmmd.mk
638$(warning "RME is an experimental feature")
639endif
640
641ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
642	ifeq (${SPD},none)
643		ifeq (${ENABLE_RME},0)
644                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
645                        or RME is enabled)
646		endif
647	endif
648endif
649
650################################################################################
651# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
652################################################################################
653ifneq (${ENABLE_FEAT_D128}, 0)
654        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
655endif
656
657################################################################################
658# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
659# up with appropriate march values for compiler.
660################################################################################
661include ${MAKE_HELPERS_DIRECTORY}march.mk
662
663TF_CFLAGS   +=	$(march-directive)
664ASFLAGS		+=	$(march-directive)
665
666# This internal flag is common option which is set to 1 for scenarios
667# when the BL2 is running in EL3 level. This occurs in two scenarios -
668# 4 world system running BL2 at EL3 and two world system without BL1 running
669# BL2 in EL3
670
671ifeq (${RESET_TO_BL2},1)
672	BL2_RUNS_AT_EL3	:=	1
673	ifeq (${ENABLE_RME},1)
674                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
675                supported at the moment.)
676	endif
677else ifeq (${ENABLE_RME},1)
678	BL2_RUNS_AT_EL3	:=	1
679else
680	BL2_RUNS_AT_EL3	:=	0
681endif
682
683# This internal flag is set to 1 when Firmware First handling of External aborts
684# is required by lowe ELs. Currently only NS requires this support.
685ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
686	FFH_SUPPORT := 1
687else
688	FFH_SUPPORT := 0
689endif
690
691ifeq (${ARM_ARCH_MAJOR},7)
692include make_helpers/armv7-a-cpus.mk
693endif
694
695PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
696ifneq ($(PIE_FOUND),)
697	TF_CFLAGS	+=	-fno-PIE
698ifeq ($($(ARCH)-ld-id),gnu-gcc)
699	TF_LDFLAGS	+=	-no-pie
700endif
701endif #(PIE_FOUND)
702
703ifeq ($($(ARCH)-ld-id),gnu-gcc)
704	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
705else
706	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
707endif
708
709ifeq ($(ENABLE_PIE),1)
710	ifeq ($(RESET_TO_BL2),1)
711		ifneq ($(BL2_IN_XIP_MEM),1)
712			BL2_CPPFLAGS	+=	-fpie
713			BL2_CFLAGS	+=	-fpie
714			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
715		endif #(BL2_IN_XIP_MEM)
716	endif #(RESET_TO_BL2)
717	BL31_CPPFLAGS	+=	-fpie
718	BL31_CFLAGS 	+=	-fpie
719	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
720
721	BL32_CPPFLAGS	+=	-fpie
722	BL32_CFLAGS	+=	-fpie
723	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
724endif #(ENABLE_PIE)
725
726BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
727BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
728BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
729
730BL1_CPPFLAGS += -DIMAGE_AT_EL3
731ifeq ($(RESET_TO_BL2),1)
732	BL2_CPPFLAGS += -DIMAGE_AT_EL3
733else
734	BL2_CPPFLAGS += -DIMAGE_AT_EL1
735endif #(RESET_TO_BL2)
736
737ifeq (${ARCH},aarch64)
738	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
739	BL31_CPPFLAGS += -DIMAGE_AT_EL3
740	BL32_CPPFLAGS += -DIMAGE_AT_EL1
741else
742	BL32_CPPFLAGS += -DIMAGE_AT_EL3
743endif
744
745# Include the CPU specific operations makefile, which provides default
746# values for all CPU errata workarounds and CPU specific optimisations.
747# This can be overridden by the platform.
748include lib/cpus/cpu-ops.mk
749
750################################################################################
751# Build `AARCH32_SP` as BL32 image for AArch32
752################################################################################
753ifeq (${ARCH},aarch32)
754        NEED_BL32 := yes
755
756        ifneq (${AARCH32_SP},none)
757        # We expect to locate an sp.mk under the specified AARCH32_SP directory
758		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
759
760                ifeq (${AARCH32_SP_MAKE},)
761                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
762                endif
763                $(info Including ${AARCH32_SP_MAKE})
764                include ${AARCH32_SP_MAKE}
765        endif
766endif #(ARCH=aarch32)
767
768################################################################################
769# Include libc if not overridden
770################################################################################
771ifeq (${OVERRIDE_LIBC},0)
772include lib/libc/libc.mk
773endif
774
775################################################################################
776# Check incompatible options and dependencies
777################################################################################
778
779# USE_DEBUGFS experimental feature recommended only in debug builds
780ifeq (${USE_DEBUGFS},1)
781        ifeq (${DEBUG},1)
782                $(warning DEBUGFS experimental feature is enabled.)
783        else
784                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
785        endif
786endif #(USE_DEBUGFS)
787
788# USE_SPINLOCK_CAS requires AArch64 build
789ifeq (${USE_SPINLOCK_CAS},1)
790        ifneq (${ARCH},aarch64)
791               $(error USE_SPINLOCK_CAS requires AArch64)
792        endif
793endif #(USE_SPINLOCK_CAS)
794
795# The cert_create tool cannot generate certificates individually, so we use the
796# target 'certificates' to create them all
797ifneq (${GENERATE_COT},0)
798        FIP_DEPS += certificates
799        FWU_FIP_DEPS += fwu_certificates
800endif
801
802ifneq (${DECRYPTION_SUPPORT},none)
803	ENC_ARGS += -f ${FW_ENC_STATUS}
804	ENC_ARGS += -k ${ENC_KEY}
805	ENC_ARGS += -n ${ENC_NONCE}
806	FIP_DEPS += enctool
807	FWU_FIP_DEPS += enctool
808endif #(DECRYPTION_SUPPORT)
809
810ifdef EL3_PAYLOAD_BASE
811	ifdef PRELOADED_BL33_BASE
812                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
813		incompatible build options. EL3_PAYLOAD_BASE has priority.")
814	endif
815	ifneq (${GENERATE_COT},0)
816                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
817                build options.")
818	endif
819	ifneq (${TRUSTED_BOARD_BOOT},0)
820                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
821                incompatible \ build options.")
822	endif
823endif #(EL3_PAYLOAD_BASE)
824
825ifeq (${NEED_BL33},yes)
826	ifdef EL3_PAYLOAD_BASE
827                $(warning "BL33 image is not needed when option \
828                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
829	endif
830	ifdef PRELOADED_BL33_BASE
831                $(warning "BL33 image is not needed when option \
832                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
833	endif
834endif #(NEED_BL33)
835
836# When building for systems with hardware-assisted coherency, there's no need to
837# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
838ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
839        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
840endif
841
842#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
843ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
844        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
845endif
846
847# RAS_EXTENSION is deprecated, provide alternate build options
848ifeq ($(RAS_EXTENSION),1)
849        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
850        and HANDLE_EA_EL3_FIRST_NS instead")
851endif
852
853
854# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
855ifeq ($(FAULT_INJECTION_SUPPORT),1)
856	ifeq ($(ENABLE_FEAT_RAS),0)
857                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
858	endif
859endif #(FAULT_INJECTION_SUPPORT)
860
861# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
862ifeq ($(DYN_DISABLE_AUTH), 1)
863	ifeq (${TRUSTED_BOARD_BOOT}, 0)
864                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
865                to be set.")
866	endif
867endif #(DYN_DISABLE_AUTH)
868
869ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
870# Support authentication verification and hash calculation
871	CRYPTO_SUPPORT := 3
872else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
873# Support authentication verification and hash calculation
874	CRYPTO_SUPPORT := 3
875else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
876# Support hash calculation only
877	CRYPTO_SUPPORT := 2
878else ifeq (${TRUSTED_BOARD_BOOT},1)
879# Support authentication verification only
880	CRYPTO_SUPPORT := 1
881else
882	CRYPTO_SUPPORT := 0
883endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
884
885# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
886ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
887        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
888endif
889
890# If pointer authentication is used in the firmware, make sure that all the
891# registers associated to it are also saved and restored.
892# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
893ifeq ($(ENABLE_PAUTH),1)
894	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
895                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
896	endif
897endif #(ENABLE_PAUTH)
898
899ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
900	ifneq (${ARCH},aarch64)
901                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
902	endif
903endif #(CTX_INCLUDE_PAUTH_REGS)
904
905ifeq ($(FEATURE_DETECTION),1)
906        $(info FEATURE_DETECTION is an experimental feature)
907endif #(FEATURE_DETECTION)
908
909ifneq ($(ENABLE_SME2_FOR_NS), 0)
910	ifeq (${ENABLE_SME_FOR_NS}, 0)
911                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
912                to be set")
913                $(warning "Forced ENABLE_SME_FOR_NS=1")
914		override ENABLE_SME_FOR_NS	:= 1
915	endif
916endif #(ENABLE_SME2_FOR_NS)
917
918ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
919	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
920                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
921                library v2")
922	endif
923endif #(ARM_XLAT_TABLES_LIB_V1)
924
925ifneq (${DECRYPTION_SUPPORT},none)
926	ifeq (${TRUSTED_BOARD_BOOT}, 0)
927                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
928                to be set)
929	endif
930endif #(DECRYPTION_SUPPORT)
931
932# Ensure that no Aarch64-only features are enabled in Aarch32 build
933ifeq (${ARCH},aarch32)
934
935	# SME/SVE only supported on AArch64
936	ifneq (${ENABLE_SME_FOR_NS},0)
937                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
938	endif
939
940	ifeq (${ENABLE_SVE_FOR_NS},1)
941		# Warning instead of error due to CI dependency on this
942                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
943	endif
944
945	# BRBE is not supported in AArch32
946	ifeq (${ENABLE_BRBE_FOR_NS},1)
947                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
948	endif
949
950	# FEAT_RNG_TRAP is not supported in AArch32
951	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
952                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
953	endif
954endif #(ARCH=aarch32)
955
956ifneq (${ENABLE_SME_FOR_NS},0)
957	ifeq (${ENABLE_SVE_FOR_NS},0)
958                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
959	endif
960endif #(ENABLE_SME_FOR_NS)
961
962# Secure SME/SVE requires the non-secure component as well
963ifeq (${ENABLE_SME_FOR_SWD},1)
964	ifeq (${ENABLE_SME_FOR_NS},0)
965                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
966	endif
967	ifeq (${ENABLE_SVE_FOR_SWD},0)
968                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
969	endif
970endif #(ENABLE_SME_FOR_SWD)
971
972# Enabling SVE for SWD requires enabling SVE for NWD due to ENABLE_FEAT
973# mechanism.
974ifeq (${ENABLE_SVE_FOR_SWD},1)
975    ifeq (${ENABLE_SVE_FOR_NS},0)
976        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
977    endif
978endif
979
980# Enabling SVE for both the worlds typically requires the context
981# management of SVE registers. The only exception being SPMC at S-EL2.
982ifeq (${ENABLE_SVE_FOR_SWD}, 1)
983    ifneq (${ENABLE_SVE_FOR_NS}, 0)
984        ifeq (${CTX_INCLUDE_SVE_REGS}-$(SPMD_SPM_AT_SEL2),0-0)
985            $(warning "ENABLE_SVE_FOR_SWD and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
986        endif
987    endif
988endif
989
990# Enabling SVE in either world while enabling CTX_INCLUDE_FPREGS requires
991# CTX_INCLUDE_SVE_REGS to be enabled due to architectural dependency between FP
992# and SVE registers.
993ifeq (${CTX_INCLUDE_FPREGS}, 1)
994    ifneq (${ENABLE_SVE_FOR_NS},0)
995        ifeq (${CTX_INCLUDE_SVE_REGS},0)
996	    # Warning instead of error due to CI dependency on this
997            $(warning "CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
998            $(warning "Forced ENABLE_SVE_FOR_NS=0")
999	    override ENABLE_SVE_FOR_NS	:= 0
1000        endif
1001    endif
1002endif #(CTX_INCLUDE_FPREGS)
1003
1004# SVE context management is only required if secure world has access to SVE/FP
1005# functionality.
1006ifeq (${CTX_INCLUDE_SVE_REGS},1)
1007    ifeq (${ENABLE_SVE_FOR_SWD},0)
1008        $(error "CTX_INCLUDE_SVE_REGS requires ENABLE_SVE_FOR_SWD to also be enabled")
1009    endif
1010endif
1011
1012# SME cannot be used with CTX_INCLUDE_FPREGS since SPM does its own context
1013# management including FPU registers.
1014ifeq (${CTX_INCLUDE_FPREGS},1)
1015    ifneq (${ENABLE_SME_FOR_NS},0)
1016        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1017    endif
1018endif #(CTX_INCLUDE_FPREGS)
1019
1020ifeq ($(DRTM_SUPPORT),1)
1021        $(info DRTM_SUPPORT is an experimental feature)
1022endif
1023
1024ifeq (${HOB_LIST},1)
1025        $(warning HOB_LIST is an experimental feature)
1026endif
1027
1028ifeq (${TRANSFER_LIST},1)
1029        $(info TRANSFER_LIST is an experimental feature)
1030endif
1031
1032ifeq (${ENABLE_RME},1)
1033	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1034                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1035	endif
1036endif
1037
1038ifeq ($(PSA_CRYPTO),1)
1039        $(info PSA_CRYPTO is an experimental feature)
1040endif
1041
1042ifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
1043        $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
1044endif
1045
1046################################################################################
1047# Process platform overrideable behaviour
1048################################################################################
1049
1050ifdef BL1_SOURCES
1051	NEED_BL1 := yes
1052endif #(BL1_SOURCES)
1053
1054ifdef BL2_SOURCES
1055	NEED_BL2 := yes
1056
1057	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1058	# Certificate generation tools. This flag can be overridden by the platform.
1059	ifdef EL3_PAYLOAD_BASE
1060		# If booting an EL3 payload there is no need for a BL33 image
1061		# in the FIP file.
1062		NEED_BL33		:=	no
1063	else
1064		ifdef PRELOADED_BL33_BASE
1065			# If booting a BL33 preloaded image there is no need of
1066			# another one in the FIP file.
1067			NEED_BL33		:=	no
1068		else
1069			NEED_BL33		?=	yes
1070		endif
1071	endif
1072endif #(BL2_SOURCES)
1073
1074ifdef BL2U_SOURCES
1075	NEED_BL2U := yes
1076endif #(BL2U_SOURCES)
1077
1078# If SCP_BL2 is given, we always want FIP to include it.
1079ifdef SCP_BL2
1080	NEED_SCP_BL2		:=	yes
1081endif #(SCP_BL2)
1082
1083# For AArch32, BL31 is not currently supported.
1084ifneq (${ARCH},aarch32)
1085	ifdef BL31_SOURCES
1086	# When booting an EL3 payload, there is no need to compile the BL31
1087	# image nor put it in the FIP.
1088		ifndef EL3_PAYLOAD_BASE
1089			NEED_BL31 := yes
1090		endif
1091	endif
1092endif #(ARCH=aarch64)
1093
1094# Process TBB related flags
1095ifneq (${GENERATE_COT},0)
1096	# Common cert_create options
1097	ifneq (${CREATE_KEYS},0)
1098                $(eval CRT_ARGS += -n)
1099                $(eval FWU_CRT_ARGS += -n)
1100		ifneq (${SAVE_KEYS},0)
1101                        $(eval CRT_ARGS += -k)
1102                        $(eval FWU_CRT_ARGS += -k)
1103		endif
1104	endif
1105	# Include TBBR makefile (unless the platform indicates otherwise)
1106	ifeq (${INCLUDE_TBBR_MK},1)
1107                include make_helpers/tbbr/tbbr_tools.mk
1108	endif
1109endif #(GENERATE_COT)
1110
1111ifneq (${FIP_ALIGN},0)
1112	FIP_ARGS += --align ${FIP_ALIGN}
1113endif #(FIP_ALIGN)
1114
1115ifdef FDT_SOURCES
1116	NEED_FDT := yes
1117endif #(FDT_SOURCES)
1118
1119################################################################################
1120# Include libraries' Makefile that are used in all BL
1121################################################################################
1122
1123include lib/stack_protector/stack_protector.mk
1124
1125################################################################################
1126# Include BL specific makefiles
1127################################################################################
1128
1129ifeq (${NEED_BL1},yes)
1130include bl1/bl1.mk
1131endif
1132
1133ifeq (${NEED_BL2},yes)
1134include bl2/bl2.mk
1135endif
1136
1137ifeq (${NEED_BL2U},yes)
1138include bl2u/bl2u.mk
1139endif
1140
1141ifeq (${NEED_BL31},yes)
1142include bl31/bl31.mk
1143endif
1144
1145################################################################################
1146# Build options checks
1147################################################################################
1148
1149# Boolean_Flags
1150$(eval $(call assert_booleans,\
1151    $(sort \
1152	ALLOW_RO_XLAT_TABLES \
1153	BL2_ENABLE_SP_LOAD \
1154	COLD_BOOT_SINGLE_CPU \
1155	CREATE_KEYS \
1156	CTX_INCLUDE_AARCH32_REGS \
1157	CTX_INCLUDE_FPREGS \
1158	CTX_INCLUDE_SVE_REGS \
1159	CTX_INCLUDE_EL2_REGS \
1160	CTX_INCLUDE_MPAM_REGS \
1161	DEBUG \
1162	DYN_DISABLE_AUTH \
1163	EL3_EXCEPTION_HANDLING \
1164	ENABLE_AMU_AUXILIARY_COUNTERS \
1165	ENABLE_AMU_FCONF \
1166	AMU_RESTRICT_COUNTERS \
1167	ENABLE_ASSERTIONS \
1168	ENABLE_PIE \
1169	ENABLE_PMF \
1170	ENABLE_PSCI_STAT \
1171	ENABLE_RUNTIME_INSTRUMENTATION \
1172	ENABLE_SME_FOR_SWD \
1173	ENABLE_SVE_FOR_SWD \
1174	ENABLE_FEAT_RAS	\
1175	FFH_SUPPORT	\
1176	ERROR_DEPRECATED \
1177	FAULT_INJECTION_SUPPORT \
1178	GENERATE_COT \
1179	GICV2_G0_FOR_EL3 \
1180	HANDLE_EA_EL3_FIRST_NS \
1181	HARDEN_SLS \
1182	HW_ASSISTED_COHERENCY \
1183	MEASURED_BOOT \
1184	DICE_PROTECTION_ENVIRONMENT \
1185	RMMD_ENABLE_EL3_TOKEN_SIGN \
1186	DRTM_SUPPORT \
1187	NS_TIMER_SWITCH \
1188	OVERRIDE_LIBC \
1189	PL011_GENERIC_UART \
1190	PROGRAMMABLE_RESET_ADDRESS \
1191	PSCI_EXTENDED_STATE_ID \
1192	PSCI_OS_INIT_MODE \
1193	RESET_TO_BL31 \
1194	SAVE_KEYS \
1195	SEPARATE_CODE_AND_RODATA \
1196	SEPARATE_BL2_NOLOAD_REGION \
1197	SEPARATE_NOBITS_REGION \
1198	SEPARATE_RWDATA_REGION \
1199	SEPARATE_SIMD_SECTION \
1200	SPIN_ON_BL1_EXIT \
1201	SPM_MM \
1202	SPMC_AT_EL3 \
1203	SPMC_AT_EL3_SEL0_SP \
1204	SPMD_SPM_AT_SEL2 \
1205	ENABLE_SPMD_LP \
1206	TRANSFER_LIST \
1207	TRUSTED_BOARD_BOOT \
1208	USE_COHERENT_MEM \
1209	USE_DEBUGFS \
1210	ARM_IO_IN_DTB \
1211	SDEI_IN_FCONF \
1212	SEC_INT_DESC_IN_FCONF \
1213	USE_ROMLIB \
1214	USE_TBBR_DEFS \
1215	WARMBOOT_ENABLE_DCACHE_EARLY \
1216	RESET_TO_BL2 \
1217	BL2_IN_XIP_MEM \
1218	BL2_INV_DCACHE \
1219	USE_SPINLOCK_CAS \
1220	ENCRYPT_BL31 \
1221	ENCRYPT_BL32 \
1222	ERRATA_SPECULATIVE_AT \
1223	RAS_TRAP_NS_ERR_REC_ACCESS \
1224	COT_DESC_IN_DTB \
1225	USE_SP804_TIMER \
1226	PSA_FWU_SUPPORT \
1227	PSA_FWU_METADATA_FW_STORE_DESC \
1228	ENABLE_MPMM \
1229	ENABLE_MPMM_FCONF \
1230	FEATURE_DETECTION \
1231	TRNG_SUPPORT \
1232	ERRATA_ABI_SUPPORT \
1233	ERRATA_NON_ARM_INTERCONNECT \
1234	CONDITIONAL_CMO \
1235	PSA_CRYPTO	\
1236	ENABLE_CONSOLE_GETC \
1237	INIT_UNUSED_NS_EL2	\
1238	PLATFORM_REPORT_CTX_MEM_USE \
1239	EARLY_CONSOLE \
1240	PRESERVE_DSU_PMU_REGS \
1241	HOB_LIST \
1242)))
1243
1244# Numeric_Flags
1245$(eval $(call assert_numerics,\
1246    $(sort \
1247	ARM_ARCH_MAJOR \
1248	ARM_ARCH_MINOR \
1249	BRANCH_PROTECTION \
1250	CTX_INCLUDE_PAUTH_REGS \
1251	CTX_INCLUDE_NEVE_REGS \
1252	CRYPTO_SUPPORT \
1253	DISABLE_MTPMU \
1254	ENABLE_BRBE_FOR_NS \
1255	ENABLE_TRBE_FOR_NS \
1256	ENABLE_BTI \
1257	ENABLE_PAUTH \
1258	ENABLE_FEAT_AMU \
1259	ENABLE_FEAT_AMUv1p1 \
1260	ENABLE_FEAT_CSV2_2 \
1261	ENABLE_FEAT_CSV2_3 \
1262	ENABLE_FEAT_DEBUGV8P9 \
1263	ENABLE_FEAT_DIT \
1264	ENABLE_FEAT_ECV \
1265	ENABLE_FEAT_FGT \
1266	ENABLE_FEAT_FGT2 \
1267	ENABLE_FEAT_HCX \
1268	ENABLE_FEAT_LS64_ACCDATA \
1269	ENABLE_FEAT_MTE2 \
1270	ENABLE_FEAT_PAN \
1271	ENABLE_FEAT_RNG \
1272	ENABLE_FEAT_RNG_TRAP \
1273	ENABLE_FEAT_SEL2 \
1274	ENABLE_FEAT_TCR2 \
1275	ENABLE_FEAT_THE \
1276	ENABLE_FEAT_SB \
1277	ENABLE_FEAT_S2PIE \
1278	ENABLE_FEAT_S1PIE \
1279	ENABLE_FEAT_S2POE \
1280	ENABLE_FEAT_S1POE \
1281	ENABLE_FEAT_SCTLR2 \
1282	ENABLE_FEAT_D128 \
1283	ENABLE_FEAT_GCS \
1284	ENABLE_FEAT_VHE \
1285	ENABLE_FEAT_MPAM \
1286	ENABLE_RME \
1287	ENABLE_SPE_FOR_NS \
1288	ENABLE_SYS_REG_TRACE_FOR_NS \
1289	ENABLE_SME_FOR_NS \
1290	ENABLE_SME2_FOR_NS \
1291	ENABLE_SVE_FOR_NS \
1292	ENABLE_TRF_FOR_NS \
1293	FW_ENC_STATUS \
1294	NR_OF_FW_BANKS \
1295	NR_OF_IMAGES_IN_FW_BANK \
1296	TWED_DELAY \
1297	ENABLE_FEAT_TWED \
1298	SVE_VECTOR_LEN \
1299	IMPDEF_SYSREG_TRAP \
1300)))
1301
1302ifdef KEY_SIZE
1303        $(eval $(call assert_numeric,KEY_SIZE))
1304endif
1305
1306ifeq ($(filter $(SANITIZE_UB), on off trap),)
1307        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1308endif
1309
1310################################################################################
1311# Add definitions to the cpp preprocessor based on the current build options.
1312# This is done after including the platform specific makefile to allow the
1313# platform to overwrite the default options
1314################################################################################
1315
1316$(eval $(call add_defines,\
1317    $(sort \
1318	ALLOW_RO_XLAT_TABLES \
1319	ARM_ARCH_MAJOR \
1320	ARM_ARCH_MINOR \
1321	BL2_ENABLE_SP_LOAD \
1322	COLD_BOOT_SINGLE_CPU \
1323	CTX_INCLUDE_AARCH32_REGS \
1324	CTX_INCLUDE_FPREGS \
1325	CTX_INCLUDE_SVE_REGS \
1326	CTX_INCLUDE_PAUTH_REGS \
1327	CTX_INCLUDE_MPAM_REGS \
1328	EL3_EXCEPTION_HANDLING \
1329	CTX_INCLUDE_EL2_REGS \
1330	CTX_INCLUDE_NEVE_REGS \
1331	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1332	DISABLE_MTPMU \
1333	ENABLE_FEAT_AMU \
1334	ENABLE_AMU_AUXILIARY_COUNTERS \
1335	ENABLE_AMU_FCONF \
1336	AMU_RESTRICT_COUNTERS \
1337	ENABLE_ASSERTIONS \
1338	ENABLE_BTI \
1339	ENABLE_FEAT_DEBUGV8P9 \
1340	ENABLE_FEAT_MPAM \
1341	ENABLE_PAUTH \
1342	ENABLE_PIE \
1343	ENABLE_PMF \
1344	ENABLE_PSCI_STAT \
1345	ENABLE_RME \
1346	RMMD_ENABLE_EL3_TOKEN_SIGN \
1347	ENABLE_RUNTIME_INSTRUMENTATION \
1348	ENABLE_SME_FOR_NS \
1349	ENABLE_SME2_FOR_NS \
1350	ENABLE_SME_FOR_SWD \
1351	ENABLE_SPE_FOR_NS \
1352	ENABLE_SVE_FOR_NS \
1353	ENABLE_SVE_FOR_SWD \
1354	ENABLE_FEAT_RAS \
1355	FFH_SUPPORT \
1356	ENCRYPT_BL31 \
1357	ENCRYPT_BL32 \
1358	ERROR_DEPRECATED \
1359	FAULT_INJECTION_SUPPORT \
1360	GICV2_G0_FOR_EL3 \
1361	HANDLE_EA_EL3_FIRST_NS \
1362	HW_ASSISTED_COHERENCY \
1363	LOG_LEVEL \
1364	MEASURED_BOOT \
1365	DICE_PROTECTION_ENVIRONMENT \
1366	DRTM_SUPPORT \
1367	NS_TIMER_SWITCH \
1368	PL011_GENERIC_UART \
1369	PLAT_${PLAT} \
1370	PROGRAMMABLE_RESET_ADDRESS \
1371	PSCI_EXTENDED_STATE_ID \
1372	PSCI_OS_INIT_MODE \
1373	RESET_TO_BL31 \
1374	RME_GPT_BITLOCK_BLOCK \
1375	RME_GPT_MAX_BLOCK \
1376	SEPARATE_CODE_AND_RODATA \
1377	SEPARATE_BL2_NOLOAD_REGION \
1378	SEPARATE_NOBITS_REGION \
1379	SEPARATE_RWDATA_REGION \
1380	SEPARATE_SIMD_SECTION \
1381	RECLAIM_INIT_CODE \
1382	SPD_${SPD} \
1383	SPIN_ON_BL1_EXIT \
1384	SPM_MM \
1385	SPMC_AT_EL3 \
1386	SPMC_AT_EL3_SEL0_SP \
1387	SPMD_SPM_AT_SEL2 \
1388	TRANSFER_LIST \
1389	TRUSTED_BOARD_BOOT \
1390	CRYPTO_SUPPORT \
1391	TRNG_SUPPORT \
1392	ERRATA_ABI_SUPPORT \
1393	ERRATA_NON_ARM_INTERCONNECT \
1394	USE_COHERENT_MEM \
1395	USE_DEBUGFS \
1396	ARM_IO_IN_DTB \
1397	SDEI_IN_FCONF \
1398	SEC_INT_DESC_IN_FCONF \
1399	USE_ROMLIB \
1400	USE_TBBR_DEFS \
1401	WARMBOOT_ENABLE_DCACHE_EARLY \
1402	RESET_TO_BL2 \
1403	BL2_RUNS_AT_EL3	\
1404	BL2_IN_XIP_MEM \
1405	BL2_INV_DCACHE \
1406	USE_SPINLOCK_CAS \
1407	ERRATA_SPECULATIVE_AT \
1408	RAS_TRAP_NS_ERR_REC_ACCESS \
1409	COT_DESC_IN_DTB \
1410	USE_SP804_TIMER \
1411	ENABLE_FEAT_RNG \
1412	ENABLE_FEAT_RNG_TRAP \
1413	ENABLE_FEAT_SB \
1414	ENABLE_FEAT_DIT \
1415	NR_OF_FW_BANKS \
1416	NR_OF_IMAGES_IN_FW_BANK \
1417	PSA_FWU_SUPPORT \
1418	PSA_FWU_METADATA_FW_STORE_DESC \
1419	ENABLE_BRBE_FOR_NS \
1420	ENABLE_TRBE_FOR_NS \
1421	ENABLE_SYS_REG_TRACE_FOR_NS \
1422	ENABLE_TRF_FOR_NS \
1423	ENABLE_FEAT_HCX \
1424	ENABLE_MPMM \
1425	ENABLE_MPMM_FCONF \
1426	ENABLE_FEAT_FGT \
1427	ENABLE_FEAT_FGT2 \
1428	ENABLE_FEAT_ECV \
1429	ENABLE_FEAT_AMUv1p1 \
1430	ENABLE_FEAT_SEL2 \
1431	ENABLE_FEAT_VHE \
1432	ENABLE_FEAT_CSV2_2 \
1433	ENABLE_FEAT_CSV2_3 \
1434	ENABLE_FEAT_LS64_ACCDATA \
1435	ENABLE_FEAT_PAN \
1436	ENABLE_FEAT_TCR2 \
1437	ENABLE_FEAT_THE \
1438	ENABLE_FEAT_S2PIE \
1439	ENABLE_FEAT_S1PIE \
1440	ENABLE_FEAT_S2POE \
1441	ENABLE_FEAT_S1POE \
1442	ENABLE_FEAT_SCTLR2 \
1443	ENABLE_FEAT_D128 \
1444	ENABLE_FEAT_GCS \
1445	ENABLE_FEAT_MTE2 \
1446	FEATURE_DETECTION \
1447	TWED_DELAY \
1448	ENABLE_FEAT_TWED \
1449	CONDITIONAL_CMO \
1450	IMPDEF_SYSREG_TRAP \
1451	SVE_VECTOR_LEN \
1452	ENABLE_SPMD_LP \
1453	PSA_CRYPTO	\
1454	ENABLE_CONSOLE_GETC \
1455	INIT_UNUSED_NS_EL2	\
1456	PLATFORM_REPORT_CTX_MEM_USE \
1457	EARLY_CONSOLE \
1458	PRESERVE_DSU_PMU_REGS \
1459	HOB_LIST \
1460)))
1461
1462ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1463ifeq (${DEBUG}, 0)
1464        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1465        override PLATFORM_REPORT_CTX_MEM_USE := 0
1466endif
1467endif
1468
1469ifeq (${SANITIZE_UB},trap)
1470        $(eval $(call add_define,MONITOR_TRAPS))
1471endif #(SANITIZE_UB)
1472
1473# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1474ifdef EL3_PAYLOAD_BASE
1475        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1476else
1477# Define the PRELOADED_BL33_BASE flag only if it is provided and
1478# EL3_PAYLOAD_BASE is not defined, as it has priority.
1479	ifdef PRELOADED_BL33_BASE
1480                $(eval $(call add_define,PRELOADED_BL33_BASE))
1481	endif
1482endif #(EL3_PAYLOAD_BASE)
1483
1484# Define the DYN_DISABLE_AUTH flag only if set.
1485ifeq (${DYN_DISABLE_AUTH},1)
1486        $(eval $(call add_define,DYN_DISABLE_AUTH))
1487endif
1488
1489ifeq ($($(ARCH)-ld-id),arm-link)
1490        $(eval $(call add_define,USE_ARM_LINK))
1491endif
1492
1493# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1494ifeq (${SPD},spmd)
1495ifdef SP_LAYOUT_FILE
1496	-include $(BUILD_PLAT)/sp_gen.mk
1497	FIP_DEPS += sp
1498	CRT_DEPS += sp
1499	NEED_SP_PKG := yes
1500else
1501	ifeq (${SPMD_SPM_AT_SEL2},1)
1502                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1503	endif
1504endif #(SP_LAYOUT_FILE)
1505endif #(SPD)
1506
1507################################################################################
1508# Build targets
1509################################################################################
1510
1511.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
1512
1513all: msg_start
1514
1515msg_start:
1516	$(s)echo "Building ${PLAT}"
1517
1518ifeq (${ERROR_DEPRECATED},0)
1519# Check if deprecated declarations and cpp warnings should be treated as error or not.
1520ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1521    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1522else
1523    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1524endif
1525endif #(!ERROR_DEPRECATED)
1526
1527$(eval $(call MAKE_LIB,c))
1528
1529# Expand build macros for the different images
1530ifeq (${NEED_BL1},yes)
1531BL1_SOURCES := $(sort ${BL1_SOURCES})
1532$(eval $(call MAKE_BL,bl1))
1533endif #(NEED_BL1)
1534
1535ifeq (${NEED_BL2},yes)
1536
1537ifeq (${RESET_TO_BL2}, 0)
1538FIP_BL2_ARGS := tb-fw
1539endif
1540
1541BL2_SOURCES := $(sort ${BL2_SOURCES})
1542
1543$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1544	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1545
1546endif #(NEED_BL2)
1547
1548ifeq (${NEED_SCP_BL2},yes)
1549$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1550endif #(NEED_SCP_BL2)
1551
1552ifeq (${NEED_BL31},yes)
1553BL31_SOURCES += ${SPD_SOURCES}
1554# Sort BL31 source files to remove duplicates
1555BL31_SOURCES := $(sort ${BL31_SOURCES})
1556ifneq (${DECRYPTION_SUPPORT},none)
1557$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1558	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1559else
1560$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1561	$(eval $(call MAKE_BL,bl31,soc-fw)))
1562endif #(DECRYPTION_SUPPORT)
1563endif #(NEED_BL31)
1564
1565# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1566# build system will call TOOL_ADD_IMG to print a warning message and abort the
1567# process. Note that the dependency on BL32 applies to the FIP only.
1568ifeq (${NEED_BL32},yes)
1569# Sort BL32 source files to remove duplicates
1570BL32_SOURCES := $(sort ${BL32_SOURCES})
1571BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1572
1573ifneq (${DECRYPTION_SUPPORT},none)
1574$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1575	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1576else
1577$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1578	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1579endif #(DECRYPTION_SUPPORT)
1580endif #(NEED_BL32)
1581
1582# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1583# needs to be built from RMM_SOURCES.
1584ifeq (${NEED_RMM},yes)
1585# Sort RMM source files to remove duplicates
1586RMM_SOURCES := $(sort ${RMM_SOURCES})
1587BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1588
1589$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1590	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1591endif #(NEED_RMM)
1592
1593# Add the BL33 image if required by the platform
1594ifeq (${NEED_BL33},yes)
1595$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1596endif #(NEED_BL33)
1597
1598ifeq (${NEED_BL2U},yes)
1599$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1600	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1601endif #(NEED_BL2U)
1602
1603# Expand build macros for the different images
1604ifeq (${NEED_FDT},yes)
1605    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1606endif #(NEED_FDT)
1607
1608# Add Secure Partition packages
1609ifeq (${NEED_SP_PKG},yes)
1610$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1611	$(q)${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1612sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1613	$(s)echo
1614	$(s)echo "Built SP Images successfully"
1615	$(s)echo
1616endif #(NEED_SP_PKG)
1617
1618locate-checkpatch:
1619ifndef CHECKPATCH
1620	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1621else
1622ifeq (,$(wildcard ${CHECKPATCH}))
1623	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1624endif
1625endif #(CHECKPATCH)
1626
1627clean:
1628	$(s)echo "  CLEAN"
1629	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1630ifdef UNIX_MK
1631	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1632else
1633# Clear the MAKEFLAGS as we do not want
1634# to pass the gnumake flags to nmake.
1635	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1636endif #(UNIX_MK)
1637	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1638	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1639	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1640
1641realclean distclean:
1642	$(s)echo "  REALCLEAN"
1643	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1644	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1645ifdef UNIX_MK
1646	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1647else
1648# Clear the MAKEFLAGS as we do not want
1649# to pass the gnumake flags to nmake.
1650	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1651endif #(UNIX_MK)
1652	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1653	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1654	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1655
1656checkcodebase:		locate-checkpatch
1657	$(s)echo "  CHECKING STYLE"
1658	$(q)if test -d .git ; then						\
1659		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1660		while read GIT_FILE ;					\
1661		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1662		done ;							\
1663	else								\
1664		 find . -type f -not -iwholename "*.git*"		\
1665		 -not -iwholename "*build*"				\
1666		 -not -iwholename "*libfdt*"				\
1667		 -not -iwholename "*libc*"				\
1668		 -not -iwholename "*docs*"				\
1669		 -not -iwholename "*.rst"				\
1670		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1671	fi
1672
1673checkpatch:		locate-checkpatch
1674	$(s)echo "  CHECKING STYLE"
1675	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1676		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1677	fi
1678	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1679	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1680	do								\
1681		printf "\n[*] Checking style of '$$commit'\n\n";	\
1682		( git log --format=email "$$commit~..$$commit"		\
1683			-- ${CHECK_PATHS} ;				\
1684		  git diff --format=email "$$commit~..$$commit"		\
1685			-- ${CHECK_PATHS}; ) |				\
1686			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1687	done
1688
1689certtool: ${CRTTOOL}
1690
1691${CRTTOOL}: FORCE
1692	$(q)${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1693	$(s)echo
1694	$(s)echo "Built $@ successfully"
1695	$(s)echo
1696
1697ifneq (${GENERATE_COT},0)
1698certificates: ${CRT_DEPS} ${CRTTOOL}
1699	$(q)${CRTTOOL} ${CRT_ARGS}
1700	$(s)echo
1701	$(s)echo "Built $@ successfully"
1702	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1703	$(s)echo
1704endif #(GENERATE_COT)
1705
1706${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1707	$(eval ${CHECK_FIP_CMD})
1708	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1709	$(q)${FIPTOOL} info $@
1710	$(s)echo
1711	$(s)echo "Built $@ successfully"
1712	$(s)echo
1713
1714ifneq (${GENERATE_COT},0)
1715fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1716	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1717	$(s)echo
1718	$(s)echo "Built $@ successfully"
1719	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1720	$(s)echo
1721endif #(GENERATE_COT)
1722
1723${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1724	$(eval ${CHECK_FWU_FIP_CMD})
1725	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1726	$(q)${FIPTOOL} info $@
1727	$(s)echo
1728	$(s)echo "Built $@ successfully"
1729	$(s)echo
1730
1731fiptool: ${FIPTOOL}
1732fip: ${BUILD_PLAT}/${FIP_NAME}
1733fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1734
1735${FIPTOOL}: FORCE
1736ifdef UNIX_MK
1737	$(q)${MAKE} PLAT=${PLAT} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1738else
1739# Clear the MAKEFLAGS as we do not want
1740# to pass the gnumake flags to nmake.
1741	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1742endif #(UNIX_MK)
1743
1744$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libmbedtls.a $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a
1745	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1746
1747memmap: all
1748ifdef UNIX_MK
1749	$(q)PYTHONPATH=${CURDIR}/tools/memory \
1750		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1751else
1752	$(q)set PYTHONPATH=${CURDIR}/tools/memory && \
1753		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1754endif
1755
1756tl: ${BUILD_PLAT}/tl.bin
1757${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
1758	$(if $(host-poetry),$(q)poetry -q install)
1759	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1760
1761doc:
1762	$(s)echo "  BUILD DOCUMENTATION"
1763	$(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
1764
1765enctool: ${ENCTOOL}
1766
1767${ENCTOOL}: FORCE
1768	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1769	$(s)echo
1770	$(s)echo "Built $@ successfully"
1771	$(s)echo
1772
1773cscope:
1774	$(s)echo "  CSCOPE"
1775	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1776	$(q)cscope -b -q -k
1777
1778help:
1779	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1780	$(s)echo ""
1781	$(s)echo "PLAT is used to specify which platform you wish to build."
1782	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1783	$(s)echo ""
1784	$(s)echo "platform = ${PLATFORM_LIST}"
1785	$(s)echo ""
1786	$(s)echo "Please refer to the User Guide for a list of all supported options."
1787	$(s)echo "Note that the build system doesn't track dependencies for build "
1788	$(s)echo "options. Therefore, if any of the build options are changed "
1789	$(s)echo "from a previous build, a clean build must be performed."
1790	$(s)echo ""
1791	$(s)echo "Supported Targets:"
1792	$(s)echo "  all            Build all individual bootloader binaries"
1793	$(s)echo "  bl1            Build the BL1 binary"
1794	$(s)echo "  bl2            Build the BL2 binary"
1795	$(s)echo "  bl2u           Build the BL2U binary"
1796	$(s)echo "  bl31           Build the BL31 binary"
1797	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1798	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1799	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1800	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1801	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1802	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1803	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1804	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1805	$(s)echo "  clean          Clean the build for the selected platform"
1806	$(s)echo "  cscope         Generate cscope index"
1807	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1808	$(s)echo "  certtool       Build the Certificate generation tool"
1809	$(s)echo "  enctool        Build the Firmware encryption tool"
1810	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1811	$(s)echo "  sp             Build the Secure Partition Packages"
1812	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1813	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1814	$(s)echo "  memmap         Print the memory map of the built binaries"
1815	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1816	$(s)echo ""
1817	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1818	$(s)echo ""
1819	$(s)echo "example: build all targets for the FVP platform:"
1820	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1821
1822.PHONY: FORCE
1823FORCE:;
1824