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