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