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