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