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