xref: /rk3399_ARM-atf/Makefile (revision 538516f5d3db6e2c30dfa9f0b82859389f529e78)
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
315ifeq ($(HARDEN_SLS), 1)
316        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
317endif
318
319else
320# using clang
321WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
322				-Wlogical-op-parentheses
323endif #(Clang Warning)
324
325ifneq (${E},0)
326	ERRORS := -Werror
327endif #(E)
328
329################################################################################
330# Compiler and Linker Directives
331################################################################################
332CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
333				$(ERRORS) $(WARNINGS)
334ASFLAGS			+=	$(CPPFLAGS)                 			\
335				-ffreestanding -Wa,--fatal-warnings
336TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
337				-ffunction-sections -fdata-sections		\
338				-ffreestanding -fno-builtin -fno-common		\
339				-Os -std=gnu99
340
341ifeq (${SANITIZE_UB},on)
342	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
343endif #(${SANITIZE_UB},on)
344
345ifeq (${SANITIZE_UB},trap)
346	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
347				-fsanitize-undefined-trap-on-error
348endif #(${SANITIZE_UB},trap)
349
350GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
351
352TF_LDFLAGS		+=	-z noexecstack
353
354# LD = armlink
355ifneq ($(findstring armlink,$(notdir $(LD))),)
356	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
357	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
358	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
359
360# LD = gcc (used when GCC LTO is enabled)
361else ifneq ($(findstring gcc,$(notdir $(LD))),)
362	# Pass ld options with Wl or Xlinker switches
363	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
364	TF_LDFLAGS		+=	-Wl,--gc-sections
365
366	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
367	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
368
369	ifeq ($(ENABLE_LTO),1)
370		ifeq (${ARCH},aarch64)
371			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
372		endif
373	endif #(ENABLE_LTO)
374
375# GCC automatically adds fix-cortex-a53-843419 flag when used to link
376# which breaks some builds, so disable if errata fix is not explicitly enabled
377	ifneq (${ERRATA_A53_843419},1)
378		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
379	endif
380	TF_LDFLAGS		+= 	-nostdlib
381	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
382
383# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
384else
385# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
386# are not loaded by a elf loader.
387	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
388	TF_LDFLAGS		+=	-O1
389	TF_LDFLAGS		+=	--gc-sections
390
391	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
392	TF_LDFLAGS		+=	-z max-page-size=4096
393
394# ld.lld doesn't recognize the errata flags,
395# therefore don't add those in that case.
396# ld.lld reports section type mismatch warnings,
397# therefore don't add --fatal-warnings to it.
398	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
399		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
400	endif
401
402endif #(LD = armlink)
403
404DTC_FLAGS		+=	-I dts -O dtb
405DTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
406				-x assembler-with-cpp $(DEFINES)
407
408################################################################################
409# Setup ARCH_MAJOR/MINOR before parsing arch_features.
410################################################################################
411ifeq (${ENABLE_RME},1)
412	ARM_ARCH_MAJOR := 8
413	ARM_ARCH_MINOR := 6
414endif
415
416################################################################################
417# Common sources and include directories
418################################################################################
419include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
420include lib/compiler-rt/compiler-rt.mk
421
422BL_COMMON_SOURCES	+=	common/bl_common.c			\
423				common/tf_log.c				\
424				common/${ARCH}/debug.S			\
425				drivers/console/multi_console.c		\
426				lib/${ARCH}/cache_helpers.S		\
427				lib/${ARCH}/misc_helpers.S		\
428				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
429				plat/common/plat_bl_common.c		\
430				plat/common/plat_log_common.c		\
431				plat/common/${ARCH}/plat_common.c	\
432				plat/common/${ARCH}/platform_helpers.S	\
433				${COMPILER_RT_SRCS}
434
435ifeq ($(notdir $(CC)),armclang)
436	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
437endif
438
439ifeq (${SANITIZE_UB},on)
440	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
441endif
442
443INCLUDES		+=	-Iinclude				\
444				-Iinclude/arch/${ARCH}			\
445				-Iinclude/lib/cpus/${ARCH}		\
446				-Iinclude/lib/el3_runtime/${ARCH}	\
447				${PLAT_INCLUDES}			\
448				${SPD_INCLUDES}
449
450include common/backtrace/backtrace.mk
451
452################################################################################
453# Process BRANCH_PROTECTION value and set
454# Pointer Authentication and Branch Target Identification flags
455################################################################################
456ifeq (${BRANCH_PROTECTION},0)
457	# Default value turns off all types of branch protection
458	BP_OPTION := none
459else ifneq (${ARCH},aarch64)
460        $(error BRANCH_PROTECTION requires AArch64)
461else ifeq (${BRANCH_PROTECTION},1)
462	# Enables all types of branch protection features
463	BP_OPTION := standard
464	ENABLE_BTI := 1
465	ENABLE_PAUTH := 1
466else ifeq (${BRANCH_PROTECTION},2)
467	# Return address signing to its standard level
468	BP_OPTION := pac-ret
469	ENABLE_PAUTH := 1
470else ifeq (${BRANCH_PROTECTION},3)
471	# Extend the signing to include leaf functions
472	BP_OPTION := pac-ret+leaf
473	ENABLE_PAUTH := 1
474else ifeq (${BRANCH_PROTECTION},4)
475	# Turn on branch target identification mechanism
476	BP_OPTION := bti
477	ENABLE_BTI := 1
478else
479        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
480endif #(BRANCH_PROTECTION)
481
482ifeq ($(ENABLE_PAUTH),1)
483	CTX_INCLUDE_PAUTH_REGS := 1
484endif
485ifneq (${BP_OPTION},none)
486	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
487endif #(BP_OPTION)
488
489# Pointer Authentication sources
490ifeq (${ENABLE_PAUTH}, 1)
491# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
492# Pauth support. As it's not secure, it must be reimplemented for real platforms
493	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
494endif
495
496####################################################
497# Enable required options for Memory Stack Tagging.
498####################################################
499
500# Currently, these options are enabled only for clang and armclang compiler.
501ifeq (${SUPPORT_STACK_MEMTAG},yes)
502    ifdef mem_tag_arch_support
503        # Check for armclang and clang compilers
504        ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
505        # Add "memtag" architecture feature modifier if not specified
506            ifeq ( ,$(findstring memtag,$(arch-features)))
507                arch-features	:=	$(arch-features)+memtag
508            endif	# memtag
509            ifeq ($(notdir $(CC)),armclang)
510                TF_CFLAGS	+=	-mmemtag-stack
511            else ifeq ($(notdir $(CC)),clang)
512                TF_CFLAGS	+=	-fsanitize=memtag
513            endif	# armclang
514        endif
515    else
516        $(error "Error: stack memory tagging is not supported for  \
517        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
518	endif #(mem_tag_arch_support)
519endif #(SUPPORT_STACK_MEMTAG)
520
521################################################################################
522# RME dependent flags configuration, Enable optional features for RME.
523################################################################################
524# FEAT_RME
525ifeq (${ENABLE_RME},1)
526	# RME doesn't support PIE
527	ifneq (${ENABLE_PIE},0)
528                $(error ENABLE_RME does not support PIE)
529	endif
530
531	# RME doesn't support BRBE
532	ifneq (${ENABLE_BRBE_FOR_NS},0)
533                $(error ENABLE_RME does not support BRBE.)
534	endif
535
536	# RME requires AARCH64
537	ifneq (${ARCH},aarch64)
538                $(error ENABLE_RME requires AArch64)
539	endif
540
541	# RME requires el2 context to be saved for now.
542	CTX_INCLUDE_EL2_REGS := 1
543	CTX_INCLUDE_AARCH32_REGS := 0
544	CTX_INCLUDE_PAUTH_REGS := 1
545
546	# RME enables CSV2_2 extension by default.
547	ENABLE_FEAT_CSV2_2 = 1
548endif #(FEAT_RME)
549
550################################################################################
551# Generic definitions
552################################################################################
553include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
554
555ifeq (${BUILD_BASE},)
556     BUILD_BASE		:=	./build
557endif
558BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
559
560SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
561
562# Platforms providing their own TBB makefile may override this value
563INCLUDE_TBBR_MK		:=	1
564
565################################################################################
566# Include SPD Makefile if one has been specified
567################################################################################
568
569ifneq (${SPD},none)
570	ifeq (${ARCH},aarch32)
571                $(error "Error: SPD is incompatible with AArch32.")
572	endif
573
574	ifdef EL3_PAYLOAD_BASE
575                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
576                $(warning "The SPD and its BL32 companion will be present but \
577                ignored.")
578	endif
579
580	ifeq (${SPD},spmd)
581	# SPMD is located in std_svc directory
582		SPD_DIR := std_svc
583
584		ifeq ($(SPMD_SPM_AT_SEL2),1)
585			CTX_INCLUDE_EL2_REGS := 1
586			ifeq ($(SPMC_AT_EL3),1)
587                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
588			endif
589		endif
590
591		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
592			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
593		endif
594
595		ifeq ($(TS_SP_FW_CONFIG),1)
596		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
597		endif
598
599		ifneq ($(ARM_BL2_SP_LIST_DTS),)
600		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
601		endif
602
603		ifneq ($(SP_LAYOUT_FILE),)
604		BL2_ENABLE_SP_LOAD := 1
605		endif
606
607		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
608			ifneq ($(SPMC_AT_EL3),1)
609			$(error SEL0 SP cannot be enabled without SPMC at EL3)
610			endif
611		endif
612	else
613		# All other SPDs in spd directory
614		SPD_DIR := spd
615	endif #(SPD)
616
617	# We expect to locate an spd.mk under the specified SPD directory
618	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
619
620	ifeq (${SPD_MAKE},)
621                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
622	endif
623        $(info Including ${SPD_MAKE})
624        include ${SPD_MAKE}
625
626	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
627	# Makefile would set NEED_BL32 to "yes". In this case, the build system
628	# supports two mutually exclusive options:
629	# * BL32 is built from source: then BL32_SOURCES must contain the list
630	#   of source files to build BL32
631	# * BL32 is a prebuilt binary: then BL32 must point to the image file
632	#   that will be included in the FIP
633	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
634	# over the sources.
635endif #(SPD=none)
636
637ifeq (${ENABLE_SPMD_LP}, 1)
638ifneq (${SPD},spmd)
639        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
640endif
641ifeq ($(SPMC_AT_EL3),1)
642        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
643endif
644endif
645
646ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
647	ifeq (${SPD},none)
648		ifeq (${ENABLE_RME},0)
649                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
650                        or RME is enabled)
651		endif
652	endif
653endif
654
655################################################################################
656# Include rmmd Makefile if RME is enabled
657################################################################################
658ifneq (${ENABLE_RME},0)
659	ifneq (${ARCH},aarch64)
660                $(error ENABLE_RME requires AArch64)
661	endif
662	ifeq ($(SPMC_AT_EL3),1)
663                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
664	endif
665
666	ifneq (${SPD}, none)
667		ifneq (${SPD}, spmd)
668                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
669		endif
670	endif
671include services/std_svc/rmmd/rmmd.mk
672$(warning "RME is an experimental feature")
673endif
674
675################################################################################
676# Include the platform specific Makefile after the SPD Makefile (the platform
677# makefile may use all previous definitions in this file)
678################################################################################
679
680include ${PLAT_MAKEFILE_FULL}
681
682################################################################################
683# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
684# up with appropriate march values for compiler.
685################################################################################
686include ${MAKE_HELPERS_DIRECTORY}march.mk
687
688TF_CFLAGS   +=	$(march-directive)
689
690# This internal flag is common option which is set to 1 for scenarios
691# when the BL2 is running in EL3 level. This occurs in two scenarios -
692# 4 world system running BL2 at EL3 and two world system without BL1 running
693# BL2 in EL3
694
695ifeq (${RESET_TO_BL2},1)
696	BL2_RUNS_AT_EL3	:=	1
697	ifeq (${ENABLE_RME},1)
698                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
699                supported at the moment.)
700	endif
701else ifeq (${ENABLE_RME},1)
702	BL2_RUNS_AT_EL3	:=	1
703else
704	BL2_RUNS_AT_EL3	:=	0
705endif
706
707$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
708
709ifeq (${ARM_ARCH_MAJOR},7)
710include make_helpers/armv7-a-cpus.mk
711endif
712
713PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
714ifneq ($(PIE_FOUND),)
715	TF_CFLAGS	+=	-fno-PIE
716ifneq ($(findstring gcc,$(notdir $(LD))),)
717	TF_LDFLAGS	+=	-no-pie
718endif
719endif #(PIE_FOUND)
720
721ifneq ($(findstring gcc,$(notdir $(LD))),)
722	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
723else
724	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
725endif
726
727ifeq ($(ENABLE_PIE),1)
728	ifeq ($(RESET_TO_BL2),1)
729		ifneq ($(BL2_IN_XIP_MEM),1)
730			BL2_CPPFLAGS	+=	-fpie
731			BL2_CFLAGS	+=	-fpie
732			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
733		endif #(BL2_IN_XIP_MEM)
734	endif #(RESET_TO_BL2)
735	BL31_CPPFLAGS	+=	-fpie
736	BL31_CFLAGS 	+=	-fpie
737	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
738
739	BL32_CPPFLAGS	+=	-fpie
740	BL32_CFLAGS	+=	-fpie
741	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
742endif #(ENABLE_PIE)
743
744BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
745BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
746BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
747
748BL1_CPPFLAGS += -DIMAGE_AT_EL3
749ifeq ($(RESET_TO_BL2),1)
750	BL2_CPPFLAGS += -DIMAGE_AT_EL3
751else
752	BL2_CPPFLAGS += -DIMAGE_AT_EL1
753endif #(RESET_TO_BL2)
754
755ifeq (${ARCH},aarch64)
756	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
757	BL31_CPPFLAGS += -DIMAGE_AT_EL3
758	BL32_CPPFLAGS += -DIMAGE_AT_EL1
759else
760	BL32_CPPFLAGS += -DIMAGE_AT_EL3
761endif
762
763# Include the CPU specific operations makefile, which provides default
764# values for all CPU errata workarounds and CPU specific optimisations.
765# This can be overridden by the platform.
766include lib/cpus/cpu-ops.mk
767
768################################################################################
769# Build `AARCH32_SP` as BL32 image for AArch32
770################################################################################
771ifeq (${ARCH},aarch32)
772        NEED_BL32 := yes
773
774        ifneq (${AARCH32_SP},none)
775        # We expect to locate an sp.mk under the specified AARCH32_SP directory
776		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
777
778                ifeq (${AARCH32_SP_MAKE},)
779                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
780                endif
781                $(info Including ${AARCH32_SP_MAKE})
782                include ${AARCH32_SP_MAKE}
783        endif
784endif #(ARCH=aarch32)
785
786################################################################################
787# Include libc if not overridden
788################################################################################
789ifeq (${OVERRIDE_LIBC},0)
790include lib/libc/libc.mk
791endif
792
793################################################################################
794# Check incompatible options and dependencies
795################################################################################
796
797# USE_DEBUGFS experimental feature recommended only in debug builds
798ifeq (${USE_DEBUGFS},1)
799        ifeq (${DEBUG},1)
800                $(warning DEBUGFS experimental feature is enabled.)
801        else
802                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
803        endif
804endif #(USE_DEBUGFS)
805
806# USE_SPINLOCK_CAS requires AArch64 build
807ifeq (${USE_SPINLOCK_CAS},1)
808        ifneq (${ARCH},aarch64)
809               $(error USE_SPINLOCK_CAS requires AArch64)
810        endif
811endif #(USE_SPINLOCK_CAS)
812
813# The cert_create tool cannot generate certificates individually, so we use the
814# target 'certificates' to create them all
815ifneq (${GENERATE_COT},0)
816        FIP_DEPS += certificates
817        FWU_FIP_DEPS += fwu_certificates
818endif
819
820ifneq (${DECRYPTION_SUPPORT},none)
821	ENC_ARGS += -f ${FW_ENC_STATUS}
822	ENC_ARGS += -k ${ENC_KEY}
823	ENC_ARGS += -n ${ENC_NONCE}
824	FIP_DEPS += enctool
825	FWU_FIP_DEPS += enctool
826endif #(DECRYPTION_SUPPORT)
827
828ifdef EL3_PAYLOAD_BASE
829	ifdef PRELOADED_BL33_BASE
830                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
831		incompatible build options. EL3_PAYLOAD_BASE has priority.")
832	endif
833	ifneq (${GENERATE_COT},0)
834                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
835                build options.")
836	endif
837	ifneq (${TRUSTED_BOARD_BOOT},0)
838                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
839                incompatible \ build options.")
840	endif
841endif #(EL3_PAYLOAD_BASE)
842
843ifeq (${NEED_BL33},yes)
844	ifdef EL3_PAYLOAD_BASE
845                $(warning "BL33 image is not needed when option \
846                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
847	endif
848	ifdef PRELOADED_BL33_BASE
849                $(warning "BL33 image is not needed when option \
850                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
851	endif
852endif #(NEED_BL33)
853
854# When building for systems with hardware-assisted coherency, there's no need to
855# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
856ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
857        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
858endif
859
860#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
861ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
862        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
863endif
864
865# RAS_EXTENSION is deprecated, provide alternate build options
866ifeq ($(RAS_EXTENSION),1)
867        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
868        and RAS_FFH_SUPPORT instead")
869endif
870
871# RAS firmware first handling requires that EAs are handled in EL3 first
872ifeq ($(RAS_FFH_SUPPORT),1)
873	ifneq ($(ENABLE_FEAT_RAS),1)
874                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
875	endif
876	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
877                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
878	endif
879endif #(RAS_FFH_SUPPORT)
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	ERROR_DEPRECATED \
1182	FAULT_INJECTION_SUPPORT \
1183	GENERATE_COT \
1184	GICV2_G0_FOR_EL3 \
1185	HANDLE_EA_EL3_FIRST_NS \
1186	HARDEN_SLS \
1187	HW_ASSISTED_COHERENCY \
1188	MEASURED_BOOT \
1189	DRTM_SUPPORT \
1190	NS_TIMER_SWITCH \
1191	OVERRIDE_LIBC \
1192	PL011_GENERIC_UART \
1193	PLAT_RSS_NOT_SUPPORTED \
1194	PROGRAMMABLE_RESET_ADDRESS \
1195	PSCI_EXTENDED_STATE_ID \
1196	PSCI_OS_INIT_MODE \
1197	RESET_TO_BL31 \
1198	SAVE_KEYS \
1199	SEPARATE_CODE_AND_RODATA \
1200	SEPARATE_BL2_NOLOAD_REGION \
1201	SEPARATE_NOBITS_REGION \
1202	SPIN_ON_BL1_EXIT \
1203	SPM_MM \
1204	SPMC_AT_EL3 \
1205	SPMC_AT_EL3_SEL0_SP \
1206	SPMD_SPM_AT_SEL2 \
1207	ENABLE_SPMD_LP \
1208	TRANSFER_LIST \
1209	TRUSTED_BOARD_BOOT \
1210	USE_COHERENT_MEM \
1211	USE_DEBUGFS \
1212	ARM_IO_IN_DTB \
1213	SDEI_IN_FCONF \
1214	SEC_INT_DESC_IN_FCONF \
1215	USE_ROMLIB \
1216	USE_TBBR_DEFS \
1217	WARMBOOT_ENABLE_DCACHE_EARLY \
1218	RESET_TO_BL2 \
1219	BL2_IN_XIP_MEM \
1220	BL2_INV_DCACHE \
1221	USE_SPINLOCK_CAS \
1222	ENCRYPT_BL31 \
1223	ENCRYPT_BL32 \
1224	ERRATA_SPECULATIVE_AT \
1225	RAS_TRAP_NS_ERR_REC_ACCESS \
1226	COT_DESC_IN_DTB \
1227	USE_SP804_TIMER \
1228	PSA_FWU_SUPPORT \
1229	ENABLE_MPMM \
1230	ENABLE_MPMM_FCONF \
1231	FEATURE_DETECTION \
1232	TRNG_SUPPORT \
1233	ERRATA_ABI_SUPPORT \
1234	ERRATA_NON_ARM_INTERCONNECT \
1235	CONDITIONAL_CMO \
1236	RAS_FFH_SUPPORT \
1237	PSA_CRYPTO	\
1238	ENABLE_CONSOLE_GETC \
1239)))
1240
1241# Numeric_Flags
1242$(eval $(call assert_numerics,\
1243    $(sort \
1244	ARM_ARCH_MAJOR \
1245	ARM_ARCH_MINOR \
1246	BRANCH_PROTECTION \
1247	CTX_INCLUDE_PAUTH_REGS \
1248	CTX_INCLUDE_MTE_REGS \
1249	CTX_INCLUDE_NEVE_REGS \
1250	CRYPTO_SUPPORT \
1251	DISABLE_MTPMU \
1252	ENABLE_BRBE_FOR_NS \
1253	ENABLE_TRBE_FOR_NS \
1254	ENABLE_BTI \
1255	ENABLE_PAUTH \
1256	ENABLE_FEAT_AMU \
1257	ENABLE_FEAT_AMUv1p1 \
1258	ENABLE_FEAT_CSV2_2 \
1259	ENABLE_FEAT_RAS	\
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_MPAM_FOR_LOWER_ELS \
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_MPAM_FOR_LOWER_ELS \
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	ENCRYPT_BL31 \
1343	ENCRYPT_BL32 \
1344	ERROR_DEPRECATED \
1345	FAULT_INJECTION_SUPPORT \
1346	GICV2_G0_FOR_EL3 \
1347	HANDLE_EA_EL3_FIRST_NS \
1348	HW_ASSISTED_COHERENCY \
1349	LOG_LEVEL \
1350	MEASURED_BOOT \
1351	DRTM_SUPPORT \
1352	NS_TIMER_SWITCH \
1353	PL011_GENERIC_UART \
1354	PLAT_${PLAT} \
1355	PLAT_RSS_NOT_SUPPORTED \
1356	PROGRAMMABLE_RESET_ADDRESS \
1357	PSCI_EXTENDED_STATE_ID \
1358	PSCI_OS_INIT_MODE \
1359	ENABLE_FEAT_RAS \
1360	RAS_FFH_SUPPORT \
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)))
1433
1434ifeq (${SANITIZE_UB},trap)
1435        $(eval $(call add_define,MONITOR_TRAPS))
1436endif #(SANITIZE_UB)
1437
1438# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1439ifdef EL3_PAYLOAD_BASE
1440        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1441else
1442# Define the PRELOADED_BL33_BASE flag only if it is provided and
1443# EL3_PAYLOAD_BASE is not defined, as it has priority.
1444	ifdef PRELOADED_BL33_BASE
1445                $(eval $(call add_define,PRELOADED_BL33_BASE))
1446	endif
1447endif #(EL3_PAYLOAD_BASE)
1448
1449# Define the DYN_DISABLE_AUTH flag only if set.
1450ifeq (${DYN_DISABLE_AUTH},1)
1451        $(eval $(call add_define,DYN_DISABLE_AUTH))
1452endif
1453
1454ifneq ($(findstring armlink,$(notdir $(LD))),)
1455        $(eval $(call add_define,USE_ARM_LINK))
1456endif
1457
1458# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1459ifeq (${SPD},spmd)
1460ifdef SP_LAYOUT_FILE
1461	-include $(BUILD_PLAT)/sp_gen.mk
1462	FIP_DEPS += sp
1463	CRT_DEPS += sp
1464	NEED_SP_PKG := yes
1465else
1466	ifeq (${SPMD_SPM_AT_SEL2},1)
1467                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1468	endif
1469endif #(SP_LAYOUT_FILE)
1470endif #(SPD)
1471
1472################################################################################
1473# Build targets
1474################################################################################
1475
1476.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1477.SUFFIXES:
1478
1479all: msg_start
1480
1481msg_start:
1482	@echo "Building ${PLAT}"
1483
1484ifeq (${ERROR_DEPRECATED},0)
1485# Check if deprecated declarations and cpp warnings should be treated as error or not.
1486ifneq ($(findstring clang,$(notdir $(CC))),)
1487    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1488else
1489    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1490endif
1491endif #(!ERROR_DEPRECATED)
1492
1493$(eval $(call MAKE_LIB_DIRS))
1494$(eval $(call MAKE_LIB,c))
1495
1496# Expand build macros for the different images
1497ifeq (${NEED_BL1},yes)
1498BL1_SOURCES := $(sort ${BL1_SOURCES})
1499$(eval $(call MAKE_BL,bl1))
1500endif #(NEED_BL1)
1501
1502ifeq (${NEED_BL2},yes)
1503
1504ifeq (${RESET_TO_BL2}, 0)
1505FIP_BL2_ARGS := tb-fw
1506endif
1507
1508BL2_SOURCES := $(sort ${BL2_SOURCES})
1509
1510$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1511	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1512
1513endif #(NEED_BL2)
1514
1515ifeq (${NEED_SCP_BL2},yes)
1516$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1517endif #(NEED_SCP_BL2)
1518
1519ifeq (${NEED_BL31},yes)
1520BL31_SOURCES += ${SPD_SOURCES}
1521# Sort BL31 source files to remove duplicates
1522BL31_SOURCES := $(sort ${BL31_SOURCES})
1523ifneq (${DECRYPTION_SUPPORT},none)
1524$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1525	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1526else
1527$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1528	$(eval $(call MAKE_BL,bl31,soc-fw)))
1529endif #(DECRYPTION_SUPPORT)
1530endif #(NEED_BL31)
1531
1532# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1533# build system will call TOOL_ADD_IMG to print a warning message and abort the
1534# process. Note that the dependency on BL32 applies to the FIP only.
1535ifeq (${NEED_BL32},yes)
1536# Sort BL32 source files to remove duplicates
1537BL32_SOURCES := $(sort ${BL32_SOURCES})
1538BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1539
1540ifneq (${DECRYPTION_SUPPORT},none)
1541$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1542	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1543else
1544$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1545	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1546endif #(DECRYPTION_SUPPORT)
1547endif #(NEED_BL32)
1548
1549# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1550# needs to be built from RMM_SOURCES.
1551ifeq (${NEED_RMM},yes)
1552# Sort RMM source files to remove duplicates
1553RMM_SOURCES := $(sort ${RMM_SOURCES})
1554BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1555
1556$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1557	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1558endif #(NEED_RMM)
1559
1560# Add the BL33 image if required by the platform
1561ifeq (${NEED_BL33},yes)
1562$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1563endif #(NEED_BL33)
1564
1565ifeq (${NEED_BL2U},yes)
1566$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1567	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1568endif #(NEED_BL2U)
1569
1570# Expand build macros for the different images
1571ifeq (${NEED_FDT},yes)
1572    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1573endif #(NEED_FDT)
1574
1575# Add Secure Partition packages
1576ifeq (${NEED_SP_PKG},yes)
1577$(BUILD_PLAT)/sp_gen.mk : ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1578	${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1579sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1580	@${ECHO_BLANK_LINE}
1581	@echo "Built SP Images successfully"
1582	@${ECHO_BLANK_LINE}
1583endif #(NEED_SP_PKG)
1584
1585locate-checkpatch:
1586ifndef CHECKPATCH
1587	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1588else
1589ifeq (,$(wildcard ${CHECKPATCH}))
1590	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1591endif
1592endif #(CHECKPATCH)
1593
1594clean:
1595	@echo "  CLEAN"
1596	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
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)) clean
1603endif #(UNIX_MK)
1604	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1605	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1606	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1607
1608realclean distclean:
1609	@echo "  REALCLEAN"
1610	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1611	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1612ifdef UNIX_MK
1613	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1614else
1615# Clear the MAKEFLAGS as we do not want
1616# to pass the gnumake flags to nmake.
1617	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1618endif #(UNIX_MK)
1619	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1620	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1621	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1622
1623checkcodebase:		locate-checkpatch
1624	@echo "  CHECKING STYLE"
1625	@if test -d .git ; then						\
1626		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1627		while read GIT_FILE ;					\
1628		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1629		done ;							\
1630	else								\
1631		 find . -type f -not -iwholename "*.git*"		\
1632		 -not -iwholename "*build*"				\
1633		 -not -iwholename "*libfdt*"				\
1634		 -not -iwholename "*libc*"				\
1635		 -not -iwholename "*docs*"				\
1636		 -not -iwholename "*.rst"				\
1637		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1638	fi
1639
1640checkpatch:		locate-checkpatch
1641	@echo "  CHECKING STYLE"
1642	@if test -n "${CHECKPATCH_OPTS}"; then				\
1643		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1644	fi
1645	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1646	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1647	do								\
1648		printf "\n[*] Checking style of '$$commit'\n\n";	\
1649		git log --format=email "$$commit~..$$commit"		\
1650			-- ${CHECK_PATHS} |				\
1651			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1652		git diff --format=email "$$commit~..$$commit"		\
1653			-- ${CHECK_PATHS} |				\
1654			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1655	done
1656
1657certtool: ${CRTTOOL}
1658
1659${CRTTOOL}: FORCE
1660	${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
1661	@${ECHO_BLANK_LINE}
1662	@echo "Built $@ successfully"
1663	@${ECHO_BLANK_LINE}
1664
1665ifneq (${GENERATE_COT},0)
1666certificates: ${CRT_DEPS} ${CRTTOOL}
1667	${Q}${CRTTOOL} ${CRT_ARGS}
1668	@${ECHO_BLANK_LINE}
1669	@echo "Built $@ successfully"
1670	@echo "Certificates can be found in ${BUILD_PLAT}"
1671	@${ECHO_BLANK_LINE}
1672endif #(GENERATE_COT)
1673
1674${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1675	$(eval ${CHECK_FIP_CMD})
1676	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1677	${Q}${FIPTOOL} info $@
1678	@${ECHO_BLANK_LINE}
1679	@echo "Built $@ successfully"
1680	@${ECHO_BLANK_LINE}
1681
1682ifneq (${GENERATE_COT},0)
1683fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1684	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1685	@${ECHO_BLANK_LINE}
1686	@echo "Built $@ successfully"
1687	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1688	@${ECHO_BLANK_LINE}
1689endif #(GENERATE_COT)
1690
1691${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1692	$(eval ${CHECK_FWU_FIP_CMD})
1693	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1694	${Q}${FIPTOOL} info $@
1695	@${ECHO_BLANK_LINE}
1696	@echo "Built $@ successfully"
1697	@${ECHO_BLANK_LINE}
1698
1699fiptool: ${FIPTOOL}
1700fip: ${BUILD_PLAT}/${FIP_NAME}
1701fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1702
1703${FIPTOOL}: FORCE
1704ifdef UNIX_MK
1705	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
1706else
1707# Clear the MAKEFLAGS as we do not want
1708# to pass the gnumake flags to nmake.
1709	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1710endif #(UNIX_MK)
1711
1712romlib.bin: libraries FORCE
1713	${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
1714
1715memmap: all
1716ifdef UNIX_MK
1717	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1718		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1719else
1720	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1721		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1722endif
1723
1724doc:
1725	@echo "  BUILD DOCUMENTATION"
1726	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1727
1728enctool: ${ENCTOOL}
1729
1730${ENCTOOL}: FORCE
1731	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
1732	@${ECHO_BLANK_LINE}
1733	@echo "Built $@ successfully"
1734	@${ECHO_BLANK_LINE}
1735
1736cscope:
1737	@echo "  CSCOPE"
1738	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1739	${Q}cscope -b -q -k
1740
1741help:
1742	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1743	@echo ""
1744	@echo "PLAT is used to specify which platform you wish to build."
1745	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1746	@echo ""
1747	@echo "platform = ${PLATFORM_LIST}"
1748	@echo ""
1749	@echo "Please refer to the User Guide for a list of all supported options."
1750	@echo "Note that the build system doesn't track dependencies for build "
1751	@echo "options. Therefore, if any of the build options are changed "
1752	@echo "from a previous build, a clean build must be performed."
1753	@echo ""
1754	@echo "Supported Targets:"
1755	@echo "  all            Build all individual bootloader binaries"
1756	@echo "  bl1            Build the BL1 binary"
1757	@echo "  bl2            Build the BL2 binary"
1758	@echo "  bl2u           Build the BL2U binary"
1759	@echo "  bl31           Build the BL31 binary"
1760	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1761	@echo "                 this builds secure payload specified by AARCH32_SP"
1762	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1763	@echo "  fip            Build the Firmware Image Package (FIP)"
1764	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1765	@echo "  checkcodebase  Check the coding style of the entire source tree"
1766	@echo "  checkpatch     Check the coding style on changes in the current"
1767	@echo "                 branch against BASE_COMMIT (default origin/master)"
1768	@echo "  clean          Clean the build for the selected platform"
1769	@echo "  cscope         Generate cscope index"
1770	@echo "  distclean      Remove all build artifacts for all platforms"
1771	@echo "  certtool       Build the Certificate generation tool"
1772	@echo "  enctool        Build the Firmware encryption tool"
1773	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1774	@echo "  sp             Build the Secure Partition Packages"
1775	@echo "  sptool         Build the Secure Partition Package creation tool"
1776	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1777	@echo "  memmap         Print the memory map of the built binaries"
1778	@echo "  doc            Build html based documentation using Sphinx tool"
1779	@echo ""
1780	@echo "Note: most build targets require PLAT to be set to a specific platform."
1781	@echo ""
1782	@echo "example: build all targets for the FVP platform:"
1783	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1784
1785.PHONY: FORCE
1786FORCE:;
1787