xref: /rk3399_ARM-atf/Makefile (revision 6b8df7b9e5cc70ef0433a99bf73db6db6002482c)
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-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# Include the platform specific Makefile after the SPD Makefile (the platform
518# makefile may use all previous definitions in this file)
519################################################################################
520include ${PLAT_MAKEFILE_FULL}
521
522################################################################################
523# Process BRANCH_PROTECTION value and set
524# Pointer Authentication and Branch Target Identification flags
525################################################################################
526ifeq (${BRANCH_PROTECTION},0)
527	# Default value turns off all types of branch protection
528	BP_OPTION := none
529else ifneq (${ARCH},aarch64)
530        $(error BRANCH_PROTECTION requires AArch64)
531else ifeq (${BRANCH_PROTECTION},1)
532	# Enables all types of branch protection features
533	BP_OPTION := standard
534	ENABLE_BTI := 1
535	ENABLE_PAUTH := 1
536else ifeq (${BRANCH_PROTECTION},2)
537	# Return address signing to its standard level
538	BP_OPTION := pac-ret
539	ENABLE_PAUTH := 1
540else ifeq (${BRANCH_PROTECTION},3)
541	# Extend the signing to include leaf functions
542	BP_OPTION := pac-ret+leaf
543	ENABLE_PAUTH := 1
544else ifeq (${BRANCH_PROTECTION},4)
545	# Turn on branch target identification mechanism
546	BP_OPTION := bti
547	ENABLE_BTI := 1
548else
549        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
550endif #(BRANCH_PROTECTION)
551
552ifeq ($(ENABLE_PAUTH),1)
553	CTX_INCLUDE_PAUTH_REGS := 1
554endif
555ifneq (${BP_OPTION},none)
556	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
557endif #(BP_OPTION)
558
559# Pointer Authentication sources
560ifeq (${ENABLE_PAUTH}, 1)
561# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
562# Pauth support. As it's not secure, it must be reimplemented for real platforms
563	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
564endif
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 requires AARCH64
603	ifneq (${ARCH},aarch64)
604                $(error ENABLE_RME requires AArch64)
605	endif
606
607	# RME requires el2 context to be saved for now.
608	CTX_INCLUDE_EL2_REGS := 1
609	CTX_INCLUDE_AARCH32_REGS := 0
610	CTX_INCLUDE_PAUTH_REGS := 1
611
612	# RME enables CSV2_2 extension by default.
613	ENABLE_FEAT_CSV2_2 = 1
614endif #(FEAT_RME)
615
616################################################################################
617# Include rmmd Makefile if RME is enabled
618################################################################################
619ifneq (${ENABLE_RME},0)
620	ifneq (${ARCH},aarch64)
621                $(error ENABLE_RME requires AArch64)
622	endif
623	ifeq ($(SPMC_AT_EL3),1)
624                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
625	endif
626
627	ifneq (${SPD}, none)
628		ifneq (${SPD}, spmd)
629                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
630		endif
631	endif
632include services/std_svc/rmmd/rmmd.mk
633$(warning "RME is an experimental feature")
634endif
635
636ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
637	ifeq (${SPD},none)
638		ifeq (${ENABLE_RME},0)
639                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
640                        or RME is enabled)
641		endif
642	endif
643endif
644
645################################################################################
646# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
647################################################################################
648ifneq (${ENABLE_FEAT_D128}, 0)
649        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
650endif
651
652################################################################################
653# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
654# up with appropriate march values for compiler.
655################################################################################
656include ${MAKE_HELPERS_DIRECTORY}march.mk
657
658TF_CFLAGS   +=	$(march-directive)
659ASFLAGS		+=	$(march-directive)
660
661# This internal flag is common option which is set to 1 for scenarios
662# when the BL2 is running in EL3 level. This occurs in two scenarios -
663# 4 world system running BL2 at EL3 and two world system without BL1 running
664# BL2 in EL3
665
666ifeq (${RESET_TO_BL2},1)
667	BL2_RUNS_AT_EL3	:=	1
668	ifeq (${ENABLE_RME},1)
669                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
670                supported at the moment.)
671	endif
672else ifeq (${ENABLE_RME},1)
673	BL2_RUNS_AT_EL3	:=	1
674else
675	BL2_RUNS_AT_EL3	:=	0
676endif
677
678# This internal flag is set to 1 when Firmware First handling of External aborts
679# is required by lowe ELs. Currently only NS requires this support.
680ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
681	FFH_SUPPORT := 1
682else
683	FFH_SUPPORT := 0
684endif
685
686ifeq (${ARM_ARCH_MAJOR},7)
687include make_helpers/armv7-a-cpus.mk
688endif
689
690PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
691ifneq ($(PIE_FOUND),)
692	TF_CFLAGS	+=	-fno-PIE
693ifeq ($($(ARCH)-ld-id),gnu-gcc)
694	TF_LDFLAGS	+=	-no-pie
695endif
696endif #(PIE_FOUND)
697
698ifeq ($($(ARCH)-ld-id),gnu-gcc)
699	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
700else
701	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
702endif
703
704ifeq ($(ENABLE_PIE),1)
705	ifeq ($(RESET_TO_BL2),1)
706		ifneq ($(BL2_IN_XIP_MEM),1)
707			BL2_CPPFLAGS	+=	-fpie
708			BL2_CFLAGS	+=	-fpie
709			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
710		endif #(BL2_IN_XIP_MEM)
711	endif #(RESET_TO_BL2)
712	BL31_CPPFLAGS	+=	-fpie
713	BL31_CFLAGS 	+=	-fpie
714	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
715
716	BL32_CPPFLAGS	+=	-fpie
717	BL32_CFLAGS	+=	-fpie
718	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
719endif #(ENABLE_PIE)
720
721BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
722BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
723BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
724
725BL1_CPPFLAGS += -DIMAGE_AT_EL3
726ifeq ($(RESET_TO_BL2),1)
727	BL2_CPPFLAGS += -DIMAGE_AT_EL3
728else
729	BL2_CPPFLAGS += -DIMAGE_AT_EL1
730endif #(RESET_TO_BL2)
731
732ifeq (${ARCH},aarch64)
733	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
734	BL31_CPPFLAGS += -DIMAGE_AT_EL3
735	BL32_CPPFLAGS += -DIMAGE_AT_EL1
736else
737	BL32_CPPFLAGS += -DIMAGE_AT_EL3
738endif
739
740# Include the CPU specific operations makefile, which provides default
741# values for all CPU errata workarounds and CPU specific optimisations.
742# This can be overridden by the platform.
743include lib/cpus/cpu-ops.mk
744
745################################################################################
746# Build `AARCH32_SP` as BL32 image for AArch32
747################################################################################
748ifeq (${ARCH},aarch32)
749        NEED_BL32 := yes
750
751        ifneq (${AARCH32_SP},none)
752        # We expect to locate an sp.mk under the specified AARCH32_SP directory
753		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
754
755                ifeq (${AARCH32_SP_MAKE},)
756                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
757                endif
758                $(info Including ${AARCH32_SP_MAKE})
759                include ${AARCH32_SP_MAKE}
760        endif
761endif #(ARCH=aarch32)
762
763################################################################################
764# Include libc if not overridden
765################################################################################
766ifeq (${OVERRIDE_LIBC},0)
767include lib/libc/libc.mk
768endif
769
770################################################################################
771# Check incompatible options and dependencies
772################################################################################
773
774# USE_DEBUGFS experimental feature recommended only in debug builds
775ifeq (${USE_DEBUGFS},1)
776        ifeq (${DEBUG},1)
777                $(warning DEBUGFS experimental feature is enabled.)
778        else
779                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
780        endif
781endif #(USE_DEBUGFS)
782
783# USE_SPINLOCK_CAS requires AArch64 build
784ifeq (${USE_SPINLOCK_CAS},1)
785        ifneq (${ARCH},aarch64)
786               $(error USE_SPINLOCK_CAS requires AArch64)
787        endif
788endif #(USE_SPINLOCK_CAS)
789
790# The cert_create tool cannot generate certificates individually, so we use the
791# target 'certificates' to create them all
792ifneq (${GENERATE_COT},0)
793        FIP_DEPS += certificates
794        FWU_FIP_DEPS += fwu_certificates
795endif
796
797ifneq (${DECRYPTION_SUPPORT},none)
798	ENC_ARGS += -f ${FW_ENC_STATUS}
799	ENC_ARGS += -k ${ENC_KEY}
800	ENC_ARGS += -n ${ENC_NONCE}
801	FIP_DEPS += enctool
802	FWU_FIP_DEPS += enctool
803endif #(DECRYPTION_SUPPORT)
804
805ifdef EL3_PAYLOAD_BASE
806	ifdef PRELOADED_BL33_BASE
807                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
808		incompatible build options. EL3_PAYLOAD_BASE has priority.")
809	endif
810	ifneq (${GENERATE_COT},0)
811                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
812                build options.")
813	endif
814	ifneq (${TRUSTED_BOARD_BOOT},0)
815                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
816                incompatible \ build options.")
817	endif
818endif #(EL3_PAYLOAD_BASE)
819
820ifeq (${NEED_BL33},yes)
821	ifdef EL3_PAYLOAD_BASE
822                $(warning "BL33 image is not needed when option \
823                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
824	endif
825	ifdef PRELOADED_BL33_BASE
826                $(warning "BL33 image is not needed when option \
827                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
828	endif
829endif #(NEED_BL33)
830
831# When building for systems with hardware-assisted coherency, there's no need to
832# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
833ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
834        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
835endif
836
837#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
838ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
839        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
840endif
841
842# RAS_EXTENSION is deprecated, provide alternate build options
843ifeq ($(RAS_EXTENSION),1)
844        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
845        and HANDLE_EA_EL3_FIRST_NS instead")
846endif
847
848
849# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
850ifeq ($(FAULT_INJECTION_SUPPORT),1)
851	ifeq ($(ENABLE_FEAT_RAS),0)
852                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
853	endif
854endif #(FAULT_INJECTION_SUPPORT)
855
856# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
857ifeq ($(DYN_DISABLE_AUTH), 1)
858	ifeq (${TRUSTED_BOARD_BOOT}, 0)
859                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
860                to be set.")
861	endif
862endif #(DYN_DISABLE_AUTH)
863
864ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
865# Support authentication verification and hash calculation
866	CRYPTO_SUPPORT := 3
867else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
868# Support authentication verification and hash calculation
869	CRYPTO_SUPPORT := 3
870else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
871# Support hash calculation only
872	CRYPTO_SUPPORT := 2
873else ifeq (${TRUSTED_BOARD_BOOT},1)
874# Support authentication verification only
875	CRYPTO_SUPPORT := 1
876else
877	CRYPTO_SUPPORT := 0
878endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
879
880ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
881CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
882endif
883
884# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
885ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
886        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
887endif
888
889# If pointer authentication is used in the firmware, make sure that all the
890# registers associated to it are also saved and restored.
891# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
892ifeq ($(ENABLE_PAUTH),1)
893	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
894                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
895	endif
896endif #(ENABLE_PAUTH)
897
898ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
899	ifneq (${ARCH},aarch64)
900                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
901	endif
902endif #(CTX_INCLUDE_PAUTH_REGS)
903
904ifeq ($(FEATURE_DETECTION),1)
905        $(info FEATURE_DETECTION is an experimental feature)
906endif #(FEATURE_DETECTION)
907
908ifneq ($(ENABLE_SME2_FOR_NS), 0)
909	ifeq (${ENABLE_SME_FOR_NS}, 0)
910                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
911                to be set")
912                $(warning "Forced ENABLE_SME_FOR_NS=1")
913		override ENABLE_SME_FOR_NS	:= 1
914	endif
915endif #(ENABLE_SME2_FOR_NS)
916
917ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
918	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
919                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
920                library v2")
921	endif
922endif #(ARM_XLAT_TABLES_LIB_V1)
923
924ifneq (${DECRYPTION_SUPPORT},none)
925	ifeq (${TRUSTED_BOARD_BOOT}, 0)
926                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
927                to be set)
928	endif
929endif #(DECRYPTION_SUPPORT)
930
931# Ensure that no Aarch64-only features are enabled in Aarch32 build
932ifeq (${ARCH},aarch32)
933
934	# SME/SVE only supported on AArch64
935	ifneq (${ENABLE_SME_FOR_NS},0)
936                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
937	endif
938
939	ifeq (${ENABLE_SVE_FOR_NS},1)
940		# Warning instead of error due to CI dependency on this
941                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
942	endif
943
944	# BRBE is not supported in AArch32
945	ifeq (${ENABLE_BRBE_FOR_NS},1)
946                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
947	endif
948
949	# FEAT_RNG_TRAP is not supported in AArch32
950	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
951                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
952	endif
953
954	ifneq (${ENABLE_FEAT_FPMR},0)
955                $(error "ENABLE_FEAT_FPMR cannot be used with ARCH=aarch32")
956	endif
957
958	ifeq (${ARCH_FEATURE_AVAILABILITY},1)
959                $(error "ARCH_FEATURE_AVAILABILITY cannot be used with ARCH=aarch32")
960	endif
961	# FEAT_MOPS is only supported on AArch64
962	ifneq (${ENABLE_FEAT_MOPS},0)
963		$(error "ENABLE_FEAT_MOPS cannot be used with ARCH=aarch32")
964	endif
965endif #(ARCH=aarch32)
966
967ifneq (${ENABLE_FEAT_FPMR},0)
968	ifeq (${ENABLE_FEAT_FGT},0)
969                $(error "ENABLE_FEAT_FPMR requires ENABLE_FEAT_FGT")
970	endif
971	ifeq (${ENABLE_FEAT_HCX},0)
972                $(error "ENABLE_FEAT_FPMR requires ENABLE_FEAT_HCX")
973	endif
974endif #(ENABLE_FEAT_FPMR)
975
976ifneq (${ENABLE_SME_FOR_NS},0)
977	ifeq (${ENABLE_SVE_FOR_NS},0)
978                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
979	endif
980endif #(ENABLE_SME_FOR_NS)
981
982# Secure SME/SVE requires the non-secure component as well
983ifeq (${ENABLE_SME_FOR_SWD},1)
984	ifeq (${ENABLE_SME_FOR_NS},0)
985                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
986	endif
987	ifeq (${ENABLE_SVE_FOR_SWD},0)
988                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
989	endif
990endif #(ENABLE_SME_FOR_SWD)
991
992# Enabling SVE for SWD requires enabling SVE for NWD due to ENABLE_FEAT
993# mechanism.
994ifeq (${ENABLE_SVE_FOR_SWD},1)
995    ifeq (${ENABLE_SVE_FOR_NS},0)
996        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
997    endif
998endif
999
1000# Enabling SVE for both the worlds typically requires the context
1001# management of SVE registers. The only exception being SPMC at S-EL2.
1002ifeq (${ENABLE_SVE_FOR_SWD}, 1)
1003    ifneq (${ENABLE_SVE_FOR_NS}, 0)
1004        ifeq (${CTX_INCLUDE_SVE_REGS}-$(SPMD_SPM_AT_SEL2),0-0)
1005            $(warning "ENABLE_SVE_FOR_SWD and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
1006        endif
1007    endif
1008endif
1009
1010# Enabling SVE in either world while enabling CTX_INCLUDE_FPREGS requires
1011# CTX_INCLUDE_SVE_REGS to be enabled due to architectural dependency between FP
1012# and SVE registers.
1013ifeq (${CTX_INCLUDE_FPREGS}, 1)
1014    ifneq (${ENABLE_SVE_FOR_NS},0)
1015        ifeq (${CTX_INCLUDE_SVE_REGS},0)
1016	    # Warning instead of error due to CI dependency on this
1017            $(warning "CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
1018            $(warning "Forced ENABLE_SVE_FOR_NS=0")
1019	    override ENABLE_SVE_FOR_NS	:= 0
1020        endif
1021    endif
1022endif #(CTX_INCLUDE_FPREGS)
1023
1024# SVE context management is only required if secure world has access to SVE/FP
1025# functionality.
1026ifeq (${CTX_INCLUDE_SVE_REGS},1)
1027    ifeq (${ENABLE_SVE_FOR_SWD},0)
1028        $(error "CTX_INCLUDE_SVE_REGS requires ENABLE_SVE_FOR_SWD to also be enabled")
1029    endif
1030endif
1031
1032# SME cannot be used with CTX_INCLUDE_FPREGS since SPM does its own context
1033# management including FPU registers.
1034ifeq (${CTX_INCLUDE_FPREGS},1)
1035    ifneq (${ENABLE_SME_FOR_NS},0)
1036        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1037    endif
1038endif #(CTX_INCLUDE_FPREGS)
1039
1040ifeq ($(DRTM_SUPPORT),1)
1041        $(info DRTM_SUPPORT is an experimental feature)
1042endif
1043
1044ifeq (${HOB_LIST},1)
1045        $(warning HOB_LIST is an experimental feature)
1046endif
1047
1048ifeq (${TRANSFER_LIST},1)
1049        $(info TRANSFER_LIST is an experimental feature)
1050endif
1051
1052ifeq (${ENABLE_RME},1)
1053	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1054                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1055	endif
1056endif
1057
1058ifeq ($(PSA_CRYPTO),1)
1059        $(info PSA_CRYPTO is an experimental feature)
1060endif
1061
1062ifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
1063        $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
1064endif
1065
1066################################################################################
1067# Process platform overrideable behaviour
1068################################################################################
1069
1070ifdef BL1_SOURCES
1071	NEED_BL1 := yes
1072endif #(BL1_SOURCES)
1073
1074ifdef BL2_SOURCES
1075	NEED_BL2 := yes
1076
1077	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1078	# Certificate generation tools. This flag can be overridden by the platform.
1079	ifdef EL3_PAYLOAD_BASE
1080		# If booting an EL3 payload there is no need for a BL33 image
1081		# in the FIP file.
1082		NEED_BL33		:=	no
1083	else
1084		ifdef PRELOADED_BL33_BASE
1085			# If booting a BL33 preloaded image there is no need of
1086			# another one in the FIP file.
1087			NEED_BL33		:=	no
1088		else
1089			NEED_BL33		?=	yes
1090		endif
1091	endif
1092endif #(BL2_SOURCES)
1093
1094ifdef BL2U_SOURCES
1095	NEED_BL2U := yes
1096endif #(BL2U_SOURCES)
1097
1098# If SCP_BL2 is given, we always want FIP to include it.
1099ifdef SCP_BL2
1100	NEED_SCP_BL2		:=	yes
1101endif #(SCP_BL2)
1102
1103# For AArch32, BL31 is not currently supported.
1104ifneq (${ARCH},aarch32)
1105	ifdef BL31_SOURCES
1106	# When booting an EL3 payload, there is no need to compile the BL31
1107	# image nor put it in the FIP.
1108		ifndef EL3_PAYLOAD_BASE
1109			NEED_BL31 := yes
1110		endif
1111	endif
1112endif #(ARCH=aarch64)
1113
1114# Process TBB related flags
1115ifneq (${GENERATE_COT},0)
1116	# Common cert_create options
1117	ifneq (${CREATE_KEYS},0)
1118                $(eval CRT_ARGS += -n)
1119                $(eval FWU_CRT_ARGS += -n)
1120		ifneq (${SAVE_KEYS},0)
1121                        $(eval CRT_ARGS += -k)
1122                        $(eval FWU_CRT_ARGS += -k)
1123		endif
1124	endif
1125	# Include TBBR makefile (unless the platform indicates otherwise)
1126	ifeq (${INCLUDE_TBBR_MK},1)
1127                include make_helpers/tbbr/tbbr_tools.mk
1128	endif
1129endif #(GENERATE_COT)
1130
1131ifneq (${FIP_ALIGN},0)
1132	FIP_ARGS += --align ${FIP_ALIGN}
1133endif #(FIP_ALIGN)
1134
1135ifdef FDT_SOURCES
1136	NEED_FDT := yes
1137endif #(FDT_SOURCES)
1138
1139################################################################################
1140# Include libraries' Makefile that are used in all BL
1141################################################################################
1142
1143include lib/stack_protector/stack_protector.mk
1144
1145################################################################################
1146# Include BL specific makefiles
1147################################################################################
1148
1149ifeq (${NEED_BL1},yes)
1150include bl1/bl1.mk
1151endif
1152
1153ifeq (${NEED_BL2},yes)
1154include bl2/bl2.mk
1155endif
1156
1157ifeq (${NEED_BL2U},yes)
1158include bl2u/bl2u.mk
1159endif
1160
1161ifeq (${NEED_BL31},yes)
1162include bl31/bl31.mk
1163endif
1164
1165################################################################################
1166# Build options checks
1167################################################################################
1168
1169# Boolean_Flags
1170$(eval $(call assert_booleans,\
1171    $(sort \
1172	ALLOW_RO_XLAT_TABLES \
1173	BL2_ENABLE_SP_LOAD \
1174	COLD_BOOT_SINGLE_CPU \
1175	CREATE_KEYS \
1176	CTX_INCLUDE_AARCH32_REGS \
1177	CTX_INCLUDE_FPREGS \
1178	CTX_INCLUDE_SVE_REGS \
1179	CTX_INCLUDE_EL2_REGS \
1180	CTX_INCLUDE_MPAM_REGS \
1181	DEBUG \
1182	DYN_DISABLE_AUTH \
1183	EL3_EXCEPTION_HANDLING \
1184	ENABLE_AMU_AUXILIARY_COUNTERS \
1185	ENABLE_AMU_FCONF \
1186	AMU_RESTRICT_COUNTERS \
1187	ENABLE_ASSERTIONS \
1188	ENABLE_PIE \
1189	ENABLE_PMF \
1190	ENABLE_PSCI_STAT \
1191	ENABLE_RUNTIME_INSTRUMENTATION \
1192	ENABLE_SME_FOR_SWD \
1193	ENABLE_SVE_FOR_SWD \
1194	ENABLE_FEAT_RAS	\
1195	FFH_SUPPORT	\
1196	ERROR_DEPRECATED \
1197	FAULT_INJECTION_SUPPORT \
1198	GENERATE_COT \
1199	GICV2_G0_FOR_EL3 \
1200	HANDLE_EA_EL3_FIRST_NS \
1201	HARDEN_SLS \
1202	HW_ASSISTED_COHERENCY \
1203	MEASURED_BOOT \
1204	DICE_PROTECTION_ENVIRONMENT \
1205	RMMD_ENABLE_EL3_TOKEN_SIGN \
1206	DRTM_SUPPORT \
1207	NS_TIMER_SWITCH \
1208	OVERRIDE_LIBC \
1209	PL011_GENERIC_UART \
1210	PROGRAMMABLE_RESET_ADDRESS \
1211	PSCI_EXTENDED_STATE_ID \
1212	PSCI_OS_INIT_MODE \
1213	ARCH_FEATURE_AVAILABILITY \
1214	RESET_TO_BL31 \
1215	SAVE_KEYS \
1216	SEPARATE_CODE_AND_RODATA \
1217	SEPARATE_BL2_NOLOAD_REGION \
1218	SEPARATE_NOBITS_REGION \
1219	SEPARATE_RWDATA_REGION \
1220	SEPARATE_SIMD_SECTION \
1221	SPIN_ON_BL1_EXIT \
1222	SPM_MM \
1223	SPMC_AT_EL3 \
1224	SPMC_AT_EL3_SEL0_SP \
1225	SPMD_SPM_AT_SEL2 \
1226	ENABLE_SPMD_LP \
1227	TRANSFER_LIST \
1228	TRUSTED_BOARD_BOOT \
1229	USE_COHERENT_MEM \
1230	USE_DEBUGFS \
1231	ARM_IO_IN_DTB \
1232	SDEI_IN_FCONF \
1233	SEC_INT_DESC_IN_FCONF \
1234	USE_ROMLIB \
1235	USE_TBBR_DEFS \
1236	WARMBOOT_ENABLE_DCACHE_EARLY \
1237	RESET_TO_BL2 \
1238	BL2_IN_XIP_MEM \
1239	BL2_INV_DCACHE \
1240	USE_SPINLOCK_CAS \
1241	ENCRYPT_BL31 \
1242	ENCRYPT_BL32 \
1243	ERRATA_SPECULATIVE_AT \
1244	RAS_TRAP_NS_ERR_REC_ACCESS \
1245	COT_DESC_IN_DTB \
1246	USE_SP804_TIMER \
1247	PSA_FWU_SUPPORT \
1248	PSA_FWU_METADATA_FW_STORE_DESC \
1249	ENABLE_MPMM \
1250	ENABLE_MPMM_FCONF \
1251	FEATURE_DETECTION \
1252	TRNG_SUPPORT \
1253	ERRATA_ABI_SUPPORT \
1254	ERRATA_NON_ARM_INTERCONNECT \
1255	CONDITIONAL_CMO \
1256	PSA_CRYPTO	\
1257	ENABLE_CONSOLE_GETC \
1258	INIT_UNUSED_NS_EL2	\
1259	PLATFORM_REPORT_CTX_MEM_USE \
1260	EARLY_CONSOLE \
1261	PRESERVE_DSU_PMU_REGS \
1262	HOB_LIST \
1263)))
1264
1265# Numeric_Flags
1266$(eval $(call assert_numerics,\
1267    $(sort \
1268	ARM_ARCH_MAJOR \
1269	ARM_ARCH_MINOR \
1270	BRANCH_PROTECTION \
1271	CTX_INCLUDE_PAUTH_REGS \
1272	CTX_INCLUDE_NEVE_REGS \
1273	CRYPTO_SUPPORT \
1274	DISABLE_MTPMU \
1275	ENABLE_BRBE_FOR_NS \
1276	ENABLE_TRBE_FOR_NS \
1277	ENABLE_BTI \
1278	ENABLE_PAUTH \
1279	ENABLE_FEAT_AMU \
1280	ENABLE_FEAT_AMUv1p1 \
1281	ENABLE_FEAT_CSV2_2 \
1282	ENABLE_FEAT_CSV2_3 \
1283	ENABLE_FEAT_DEBUGV8P9 \
1284	ENABLE_FEAT_DIT \
1285	ENABLE_FEAT_ECV \
1286	ENABLE_FEAT_FGT \
1287	ENABLE_FEAT_FGT2 \
1288	ENABLE_FEAT_FPMR \
1289	ENABLE_FEAT_HCX \
1290	ENABLE_FEAT_LS64_ACCDATA \
1291	ENABLE_FEAT_MOPS \
1292	ENABLE_FEAT_MTE2 \
1293	ENABLE_FEAT_PAN \
1294	ENABLE_FEAT_RNG \
1295	ENABLE_FEAT_RNG_TRAP \
1296	ENABLE_FEAT_SEL2 \
1297	ENABLE_FEAT_TCR2 \
1298	ENABLE_FEAT_THE \
1299	ENABLE_FEAT_SB \
1300	ENABLE_FEAT_S2PIE \
1301	ENABLE_FEAT_S1PIE \
1302	ENABLE_FEAT_S2POE \
1303	ENABLE_FEAT_S1POE \
1304	ENABLE_FEAT_SCTLR2 \
1305	ENABLE_FEAT_D128 \
1306	ENABLE_FEAT_GCS \
1307	ENABLE_FEAT_VHE \
1308	ENABLE_FEAT_MPAM \
1309	ENABLE_RME \
1310	ENABLE_SPE_FOR_NS \
1311	ENABLE_SYS_REG_TRACE_FOR_NS \
1312	ENABLE_SME_FOR_NS \
1313	ENABLE_SME2_FOR_NS \
1314	ENABLE_SVE_FOR_NS \
1315	ENABLE_TRF_FOR_NS \
1316	FW_ENC_STATUS \
1317	NR_OF_FW_BANKS \
1318	NR_OF_IMAGES_IN_FW_BANK \
1319	TWED_DELAY \
1320	ENABLE_FEAT_TWED \
1321	SVE_VECTOR_LEN \
1322	IMPDEF_SYSREG_TRAP \
1323)))
1324
1325ifdef KEY_SIZE
1326        $(eval $(call assert_numeric,KEY_SIZE))
1327endif
1328
1329ifeq ($(filter $(SANITIZE_UB), on off trap),)
1330        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1331endif
1332
1333################################################################################
1334# Add definitions to the cpp preprocessor based on the current build options.
1335# This is done after including the platform specific makefile to allow the
1336# platform to overwrite the default options
1337################################################################################
1338
1339$(eval $(call add_defines,\
1340    $(sort \
1341	ALLOW_RO_XLAT_TABLES \
1342	ARM_ARCH_MAJOR \
1343	ARM_ARCH_MINOR \
1344	BL2_ENABLE_SP_LOAD \
1345	COLD_BOOT_SINGLE_CPU \
1346	CTX_INCLUDE_AARCH32_REGS \
1347	CTX_INCLUDE_FPREGS \
1348	CTX_INCLUDE_SVE_REGS \
1349	CTX_INCLUDE_PAUTH_REGS \
1350	CTX_INCLUDE_MPAM_REGS \
1351	EL3_EXCEPTION_HANDLING \
1352	CTX_INCLUDE_EL2_REGS \
1353	CTX_INCLUDE_NEVE_REGS \
1354	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1355	DISABLE_MTPMU \
1356	ENABLE_FEAT_AMU \
1357	ENABLE_AMU_AUXILIARY_COUNTERS \
1358	ENABLE_AMU_FCONF \
1359	AMU_RESTRICT_COUNTERS \
1360	ENABLE_ASSERTIONS \
1361	ENABLE_BTI \
1362	ENABLE_FEAT_DEBUGV8P9 \
1363	ENABLE_FEAT_MPAM \
1364	ENABLE_PAUTH \
1365	ENABLE_PIE \
1366	ENABLE_PMF \
1367	ENABLE_PSCI_STAT \
1368	ENABLE_RME \
1369	RMMD_ENABLE_EL3_TOKEN_SIGN \
1370	ENABLE_RUNTIME_INSTRUMENTATION \
1371	ENABLE_SME_FOR_NS \
1372	ENABLE_SME2_FOR_NS \
1373	ENABLE_SME_FOR_SWD \
1374	ENABLE_SPE_FOR_NS \
1375	ENABLE_SVE_FOR_NS \
1376	ENABLE_SVE_FOR_SWD \
1377	ENABLE_FEAT_RAS \
1378	FFH_SUPPORT \
1379	ENCRYPT_BL31 \
1380	ENCRYPT_BL32 \
1381	ERROR_DEPRECATED \
1382	FAULT_INJECTION_SUPPORT \
1383	GICV2_G0_FOR_EL3 \
1384	HANDLE_EA_EL3_FIRST_NS \
1385	HW_ASSISTED_COHERENCY \
1386	LOG_LEVEL \
1387	MEASURED_BOOT \
1388	DICE_PROTECTION_ENVIRONMENT \
1389	DRTM_SUPPORT \
1390	NS_TIMER_SWITCH \
1391	PL011_GENERIC_UART \
1392	PLAT_${PLAT} \
1393	PROGRAMMABLE_RESET_ADDRESS \
1394	PSCI_EXTENDED_STATE_ID \
1395	PSCI_OS_INIT_MODE \
1396	ARCH_FEATURE_AVAILABILITY \
1397	RESET_TO_BL31 \
1398	RME_GPT_BITLOCK_BLOCK \
1399	RME_GPT_MAX_BLOCK \
1400	SEPARATE_CODE_AND_RODATA \
1401	SEPARATE_BL2_NOLOAD_REGION \
1402	SEPARATE_NOBITS_REGION \
1403	SEPARATE_RWDATA_REGION \
1404	SEPARATE_SIMD_SECTION \
1405	RECLAIM_INIT_CODE \
1406	SPD_${SPD} \
1407	SPIN_ON_BL1_EXIT \
1408	SPM_MM \
1409	SPMC_AT_EL3 \
1410	SPMC_AT_EL3_SEL0_SP \
1411	SPMD_SPM_AT_SEL2 \
1412	TRANSFER_LIST \
1413	TRUSTED_BOARD_BOOT \
1414	CRYPTO_SUPPORT \
1415	TRNG_SUPPORT \
1416	ERRATA_ABI_SUPPORT \
1417	ERRATA_NON_ARM_INTERCONNECT \
1418	USE_COHERENT_MEM \
1419	USE_DEBUGFS \
1420	ARM_IO_IN_DTB \
1421	SDEI_IN_FCONF \
1422	SEC_INT_DESC_IN_FCONF \
1423	USE_ROMLIB \
1424	USE_TBBR_DEFS \
1425	WARMBOOT_ENABLE_DCACHE_EARLY \
1426	RESET_TO_BL2 \
1427	BL2_RUNS_AT_EL3	\
1428	BL2_IN_XIP_MEM \
1429	BL2_INV_DCACHE \
1430	USE_SPINLOCK_CAS \
1431	ERRATA_SPECULATIVE_AT \
1432	RAS_TRAP_NS_ERR_REC_ACCESS \
1433	COT_DESC_IN_DTB \
1434	USE_SP804_TIMER \
1435	ENABLE_FEAT_RNG \
1436	ENABLE_FEAT_RNG_TRAP \
1437	ENABLE_FEAT_SB \
1438	ENABLE_FEAT_DIT \
1439	NR_OF_FW_BANKS \
1440	NR_OF_IMAGES_IN_FW_BANK \
1441	PSA_FWU_SUPPORT \
1442	PSA_FWU_METADATA_FW_STORE_DESC \
1443	ENABLE_BRBE_FOR_NS \
1444	ENABLE_TRBE_FOR_NS \
1445	ENABLE_SYS_REG_TRACE_FOR_NS \
1446	ENABLE_TRF_FOR_NS \
1447	ENABLE_FEAT_HCX \
1448	ENABLE_MPMM \
1449	ENABLE_MPMM_FCONF \
1450	ENABLE_FEAT_FGT \
1451	ENABLE_FEAT_FGT2 \
1452	ENABLE_FEAT_FPMR \
1453	ENABLE_FEAT_ECV \
1454	ENABLE_FEAT_AMUv1p1 \
1455	ENABLE_FEAT_SEL2 \
1456	ENABLE_FEAT_VHE \
1457	ENABLE_FEAT_CSV2_2 \
1458	ENABLE_FEAT_CSV2_3 \
1459	ENABLE_FEAT_LS64_ACCDATA \
1460	ENABLE_FEAT_PAN \
1461	ENABLE_FEAT_TCR2 \
1462	ENABLE_FEAT_THE \
1463	ENABLE_FEAT_S2PIE \
1464	ENABLE_FEAT_S1PIE \
1465	ENABLE_FEAT_S2POE \
1466	ENABLE_FEAT_S1POE \
1467	ENABLE_FEAT_SCTLR2 \
1468	ENABLE_FEAT_D128 \
1469	ENABLE_FEAT_GCS \
1470	ENABLE_FEAT_MOPS \
1471	ENABLE_FEAT_MTE2 \
1472	FEATURE_DETECTION \
1473	TWED_DELAY \
1474	ENABLE_FEAT_TWED \
1475	CONDITIONAL_CMO \
1476	IMPDEF_SYSREG_TRAP \
1477	SVE_VECTOR_LEN \
1478	ENABLE_SPMD_LP \
1479	PSA_CRYPTO	\
1480	ENABLE_CONSOLE_GETC \
1481	INIT_UNUSED_NS_EL2	\
1482	PLATFORM_REPORT_CTX_MEM_USE \
1483	EARLY_CONSOLE \
1484	PRESERVE_DSU_PMU_REGS \
1485	HOB_LIST \
1486)))
1487
1488ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1489ifeq (${DEBUG}, 0)
1490        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1491        override PLATFORM_REPORT_CTX_MEM_USE := 0
1492endif
1493endif
1494
1495ifeq (${SANITIZE_UB},trap)
1496        $(eval $(call add_define,MONITOR_TRAPS))
1497endif #(SANITIZE_UB)
1498
1499# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1500ifdef EL3_PAYLOAD_BASE
1501        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1502else
1503# Define the PRELOADED_BL33_BASE flag only if it is provided and
1504# EL3_PAYLOAD_BASE is not defined, as it has priority.
1505	ifdef PRELOADED_BL33_BASE
1506                $(eval $(call add_define,PRELOADED_BL33_BASE))
1507	endif
1508endif #(EL3_PAYLOAD_BASE)
1509
1510# Define the DYN_DISABLE_AUTH flag only if set.
1511ifeq (${DYN_DISABLE_AUTH},1)
1512        $(eval $(call add_define,DYN_DISABLE_AUTH))
1513endif
1514
1515ifeq ($($(ARCH)-ld-id),arm-link)
1516        $(eval $(call add_define,USE_ARM_LINK))
1517endif
1518
1519# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1520ifeq (${SPD},spmd)
1521ifdef SP_LAYOUT_FILE
1522	-include $(BUILD_PLAT)/sp_gen.mk
1523	FIP_DEPS += sp
1524	CRT_DEPS += sp
1525	NEED_SP_PKG := yes
1526else
1527	ifeq (${SPMD_SPM_AT_SEL2},1)
1528                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1529	endif
1530endif #(SP_LAYOUT_FILE)
1531endif #(SPD)
1532
1533################################################################################
1534# Build targets
1535################################################################################
1536
1537.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
1538
1539all: msg_start
1540
1541msg_start:
1542	$(s)echo "Building ${PLAT}"
1543
1544ifeq (${ERROR_DEPRECATED},0)
1545# Check if deprecated declarations and cpp warnings should be treated as error or not.
1546ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1547    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1548else
1549    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1550endif
1551endif #(!ERROR_DEPRECATED)
1552
1553$(eval $(call MAKE_LIB,c))
1554
1555# Expand build macros for the different images
1556ifeq (${NEED_BL1},yes)
1557BL1_SOURCES := $(sort ${BL1_SOURCES})
1558$(eval $(call MAKE_BL,bl1))
1559endif #(NEED_BL1)
1560
1561ifeq (${NEED_BL2},yes)
1562
1563ifeq (${RESET_TO_BL2}, 0)
1564FIP_BL2_ARGS := tb-fw
1565endif
1566
1567BL2_SOURCES := $(sort ${BL2_SOURCES})
1568
1569$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1570	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1571
1572endif #(NEED_BL2)
1573
1574ifeq (${NEED_SCP_BL2},yes)
1575$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1576endif #(NEED_SCP_BL2)
1577
1578ifeq (${NEED_BL31},yes)
1579BL31_SOURCES += ${SPD_SOURCES}
1580# Sort BL31 source files to remove duplicates
1581BL31_SOURCES := $(sort ${BL31_SOURCES})
1582ifneq (${DECRYPTION_SUPPORT},none)
1583$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1584	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1585else
1586$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1587	$(eval $(call MAKE_BL,bl31,soc-fw)))
1588endif #(DECRYPTION_SUPPORT)
1589endif #(NEED_BL31)
1590
1591# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1592# build system will call TOOL_ADD_IMG to print a warning message and abort the
1593# process. Note that the dependency on BL32 applies to the FIP only.
1594ifeq (${NEED_BL32},yes)
1595# Sort BL32 source files to remove duplicates
1596BL32_SOURCES := $(sort ${BL32_SOURCES})
1597BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1598
1599ifneq (${DECRYPTION_SUPPORT},none)
1600$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1601	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1602else
1603$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1604	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1605endif #(DECRYPTION_SUPPORT)
1606endif #(NEED_BL32)
1607
1608# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1609# needs to be built from RMM_SOURCES.
1610ifeq (${NEED_RMM},yes)
1611# Sort RMM source files to remove duplicates
1612RMM_SOURCES := $(sort ${RMM_SOURCES})
1613BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1614
1615$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1616	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1617endif #(NEED_RMM)
1618
1619# Add the BL33 image if required by the platform
1620ifeq (${NEED_BL33},yes)
1621$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1622endif #(NEED_BL33)
1623
1624ifeq (${NEED_BL2U},yes)
1625$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1626	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1627endif #(NEED_BL2U)
1628
1629# Expand build macros for the different images
1630ifeq (${NEED_FDT},yes)
1631    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1632endif #(NEED_FDT)
1633
1634# Add Secure Partition packages
1635ifeq (${NEED_SP_PKG},yes)
1636$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1637	$(q)${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1638sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1639	$(s)echo
1640	$(s)echo "Built SP Images successfully"
1641	$(s)echo
1642endif #(NEED_SP_PKG)
1643
1644locate-checkpatch:
1645ifndef CHECKPATCH
1646	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1647else
1648ifeq (,$(wildcard ${CHECKPATCH}))
1649	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1650endif
1651endif #(CHECKPATCH)
1652
1653clean:
1654	$(s)echo "  CLEAN"
1655	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1656ifdef UNIX_MK
1657	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1658else
1659# Clear the MAKEFLAGS as we do not want
1660# to pass the gnumake flags to nmake.
1661	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1662endif #(UNIX_MK)
1663	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1664	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1665	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1666
1667realclean distclean:
1668	$(s)echo "  REALCLEAN"
1669	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1670	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1671ifdef UNIX_MK
1672	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1673else
1674# Clear the MAKEFLAGS as we do not want
1675# to pass the gnumake flags to nmake.
1676	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1677endif #(UNIX_MK)
1678	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1679	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1680	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1681
1682checkcodebase:		locate-checkpatch
1683	$(s)echo "  CHECKING STYLE"
1684	$(q)if test -d .git ; then						\
1685		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1686		while read GIT_FILE ;					\
1687		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1688		done ;							\
1689	else								\
1690		 find . -type f -not -iwholename "*.git*"		\
1691		 -not -iwholename "*build*"				\
1692		 -not -iwholename "*libfdt*"				\
1693		 -not -iwholename "*libc*"				\
1694		 -not -iwholename "*docs*"				\
1695		 -not -iwholename "*.rst"				\
1696		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1697	fi
1698
1699checkpatch:		locate-checkpatch
1700	$(s)echo "  CHECKING STYLE"
1701	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1702		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1703	fi
1704	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1705	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1706	do								\
1707		printf "\n[*] Checking style of '$$commit'\n\n";	\
1708		( git log --format=email "$$commit~..$$commit"		\
1709			-- ${CHECK_PATHS} ;				\
1710		  git diff --format=email "$$commit~..$$commit"		\
1711			-- ${CHECK_PATHS}; ) |				\
1712			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1713	done
1714
1715certtool: ${CRTTOOL}
1716
1717${CRTTOOL}: FORCE
1718	$(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
1719	$(s)echo
1720	$(s)echo "Built $@ successfully"
1721	$(s)echo
1722
1723ifneq (${GENERATE_COT},0)
1724certificates: ${CRT_DEPS} ${CRTTOOL}
1725	$(q)${CRTTOOL} ${CRT_ARGS}
1726	$(s)echo
1727	$(s)echo "Built $@ successfully"
1728	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1729	$(s)echo
1730endif #(GENERATE_COT)
1731
1732${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1733	$(eval ${CHECK_FIP_CMD})
1734	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1735	$(q)${FIPTOOL} info $@
1736	$(s)echo
1737	$(s)echo "Built $@ successfully"
1738	$(s)echo
1739
1740ifneq (${GENERATE_COT},0)
1741fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1742	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1743	$(s)echo
1744	$(s)echo "Built $@ successfully"
1745	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1746	$(s)echo
1747endif #(GENERATE_COT)
1748
1749${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1750	$(eval ${CHECK_FWU_FIP_CMD})
1751	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1752	$(q)${FIPTOOL} info $@
1753	$(s)echo
1754	$(s)echo "Built $@ successfully"
1755	$(s)echo
1756
1757fiptool: ${FIPTOOL}
1758fip: ${BUILD_PLAT}/${FIP_NAME}
1759fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1760
1761${FIPTOOL}: FORCE
1762ifdef UNIX_MK
1763	$(q)${MAKE} PLAT=${PLAT} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1764else
1765# Clear the MAKEFLAGS as we do not want
1766# to pass the gnumake flags to nmake.
1767	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1768endif #(UNIX_MK)
1769
1770$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1771	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1772
1773memmap: all
1774ifdef UNIX_MK
1775	$(q)PYTHONPATH=${CURDIR}/tools/memory \
1776		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1777else
1778	$(q)set PYTHONPATH=${CURDIR}/tools/memory && \
1779		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1780endif
1781
1782tl: ${BUILD_PLAT}/tl.bin
1783${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
1784	$(if $(host-poetry),$(q)poetry -q install)
1785	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1786
1787doc:
1788	$(s)echo "  BUILD DOCUMENTATION"
1789	$(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
1790
1791enctool: ${ENCTOOL}
1792
1793${ENCTOOL}: FORCE
1794	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1795	$(s)echo
1796	$(s)echo "Built $@ successfully"
1797	$(s)echo
1798
1799cscope:
1800	$(s)echo "  CSCOPE"
1801	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1802	$(q)cscope -b -q -k
1803
1804help:
1805	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1806	$(s)echo ""
1807	$(s)echo "PLAT is used to specify which platform you wish to build."
1808	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1809	$(s)echo ""
1810	$(s)echo "platform = ${PLATFORM_LIST}"
1811	$(s)echo ""
1812	$(s)echo "Please refer to the User Guide for a list of all supported options."
1813	$(s)echo "Note that the build system doesn't track dependencies for build "
1814	$(s)echo "options. Therefore, if any of the build options are changed "
1815	$(s)echo "from a previous build, a clean build must be performed."
1816	$(s)echo ""
1817	$(s)echo "Supported Targets:"
1818	$(s)echo "  all            Build all individual bootloader binaries"
1819	$(s)echo "  bl1            Build the BL1 binary"
1820	$(s)echo "  bl2            Build the BL2 binary"
1821	$(s)echo "  bl2u           Build the BL2U binary"
1822	$(s)echo "  bl31           Build the BL31 binary"
1823	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1824	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1825	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1826	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1827	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1828	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1829	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1830	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1831	$(s)echo "  clean          Clean the build for the selected platform"
1832	$(s)echo "  cscope         Generate cscope index"
1833	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1834	$(s)echo "  certtool       Build the Certificate generation tool"
1835	$(s)echo "  enctool        Build the Firmware encryption tool"
1836	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1837	$(s)echo "  sp             Build the Secure Partition Packages"
1838	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1839	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1840	$(s)echo "  memmap         Print the memory map of the built binaries"
1841	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1842	$(s)echo ""
1843	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1844	$(s)echo ""
1845	$(s)echo "example: build all targets for the FVP platform:"
1846	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1847
1848.PHONY: FORCE
1849FORCE:;
1850