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