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