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