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