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