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