xref: /rk3399_ARM-atf/Makefile (revision 8ca61538a0fe3aed6764a012317cbf61f09ebb61)
1#
2# Copyright (c) 2013-2020, 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			:= 3
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
125        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
126endif
127
128# USE_SPINLOCK_CAS requires AArch64 build
129ifeq (${USE_SPINLOCK_CAS},1)
130ifneq (${ARCH},aarch64)
131        $(error USE_SPINLOCK_CAS requires AArch64)
132else
133        $(info USE_SPINLOCK_CAS is an experimental feature)
134endif
135endif
136
137# USE_DEBUGFS experimental feature recommended only in debug builds
138ifeq (${USE_DEBUGFS},1)
139ifeq (${DEBUG},1)
140        $(warning DEBUGFS experimental feature is enabled.)
141else
142        $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
143endif
144endif
145
146ifneq (${DECRYPTION_SUPPORT},none)
147ENC_ARGS += -f ${FW_ENC_STATUS}
148ENC_ARGS += -k ${ENC_KEY}
149ENC_ARGS += -n ${ENC_NONCE}
150FIP_DEPS += enctool
151FWU_FIP_DEPS += enctool
152endif
153
154################################################################################
155# Toolchain
156################################################################################
157
158HOSTCC			:=	gcc
159export HOSTCC
160
161CC			:=	${CROSS_COMPILE}gcc
162CPP			:=	${CROSS_COMPILE}cpp
163AS			:=	${CROSS_COMPILE}gcc
164AR			:=	${CROSS_COMPILE}ar
165LINKER			:=	${CROSS_COMPILE}ld
166OC			:=	${CROSS_COMPILE}objcopy
167OD			:=	${CROSS_COMPILE}objdump
168NM			:=	${CROSS_COMPILE}nm
169PP			:=	${CROSS_COMPILE}gcc -E
170DTC			:=	dtc
171
172# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
173ifneq ($(strip $(wildcard ${LD}.bfd) \
174	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
175LINKER			:=	${LINKER}.bfd
176endif
177
178ifeq (${ARM_ARCH_MAJOR},7)
179target32-directive	= 	-target arm-none-eabi
180# Will set march32-directive from platform configuration
181else
182target32-directive	= 	-target armv8a-none-eabi
183
184# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
185ifeq (${ARM_ARCH_MINOR},0)
186march32-directive	= 	-march=armv8-a
187march64-directive	= 	-march=armv8-a
188else
189march32-directive	= 	-march=armv8.${ARM_ARCH_MINOR}-a
190march64-directive	= 	-march=armv8.${ARM_ARCH_MINOR}-a
191endif
192endif
193
194# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
195ifeq ($(ARCH), aarch64)
196ifeq ($(shell test $(ARM_ARCH_MAJOR) -gt 8; echo $$?),0)
197mem_tag_arch_support	= 	yes
198else ifeq ($(shell test $(ARM_ARCH_MAJOR) -eq 8 -a $(ARM_ARCH_MINOR) -ge 5; \
199	   echo $$?),0)
200mem_tag_arch_support	= 	yes
201endif
202endif
203
204# Enabled required option for memory stack tagging. Currently, these options are
205# enabled only for clang and armclang compiler.
206ifeq (${SUPPORT_STACK_MEMTAG},yes)
207ifdef mem_tag_arch_support
208ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
209march64-directive       =       -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a+memtag
210ifeq ($(notdir $(CC)),armclang)
211TF_CFLAGS		+=	-mmemtag-stack
212else ifeq ($(notdir $(CC)),clang)
213TF_CFLAGS		+=	-fsanitize=memtag
214endif
215endif
216else
217$(error "Error: stack memory tagging is not supported for architecture \
218	${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
219endif
220endif
221
222ifneq ($(findstring armclang,$(notdir $(CC))),)
223TF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
224TF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi $(march64-directive)
225LD			=	$(LINKER)
226AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
227CPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
228PP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
229else ifneq ($(findstring clang,$(notdir $(CC))),)
230CLANG_CCDIR		=	$(if $(filter-out ./,$(dir $(CC))),$(dir $(CC)),)
231TF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
232TF_CFLAGS_aarch64	=	-target aarch64-elf $(march64-directive)
233LD			=	$(CLANG_CCDIR)ld.lld
234ifeq (, $(shell which $(LD)))
235$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker")
236endif
237AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
238CPP			=	$(CC) -E
239PP			=	$(CC) -E
240else ifneq ($(findstring gcc,$(notdir $(CC))),)
241TF_CFLAGS_aarch32	=	$(march32-directive)
242TF_CFLAGS_aarch64	=	$(march64-directive)
243ifeq ($(ENABLE_LTO),1)
244	# Enable LTO only for aarch64
245	ifeq (${ARCH},aarch64)
246		LTO_CFLAGS	=	-flto
247		# Use gcc as a wrapper for the ld, recommended for LTO
248		LINKER		:=	${CROSS_COMPILE}gcc
249	endif
250endif
251LD			=	$(LINKER)
252else
253TF_CFLAGS_aarch32	=	$(march32-directive)
254TF_CFLAGS_aarch64	=	$(march64-directive)
255LD			=	$(LINKER)
256endif
257
258# Process Debug flag
259$(eval $(call add_define,DEBUG))
260ifneq (${DEBUG}, 0)
261        BUILD_TYPE	:=	debug
262        TF_CFLAGS	+= 	-g
263
264        ifneq ($(findstring clang,$(notdir $(CC))),)
265             ASFLAGS		+= 	-g
266        else
267             ASFLAGS		+= 	-g -Wa,--gdwarf-2
268        endif
269
270        # Use LOG_LEVEL_INFO by default for debug builds
271        LOG_LEVEL	:=	40
272else
273        BUILD_TYPE	:=	release
274        # Use LOG_LEVEL_NOTICE by default for release builds
275        LOG_LEVEL	:=	20
276endif
277
278# Default build string (git branch and commit)
279ifeq (${BUILD_STRING},)
280        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
281endif
282VERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
283
284ifeq (${AARCH32_INSTRUCTION_SET},A32)
285TF_CFLAGS_aarch32	+=	-marm
286else ifeq (${AARCH32_INSTRUCTION_SET},T32)
287TF_CFLAGS_aarch32	+=	-mthumb
288else
289$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
290endif
291
292TF_CFLAGS_aarch32	+=	-mno-unaligned-access
293TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
294
295ifneq (${BP_OPTION},none)
296TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
297endif
298
299ASFLAGS_aarch32		=	$(march32-directive)
300ASFLAGS_aarch64		=	$(march64-directive)
301
302# General warnings
303WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
304				-Wdisabled-optimization	-Wvla -Wshadow	\
305				-Wno-unused-parameter -Wredundant-decls
306
307# Additional warnings
308# Level 1
309WARNING1 := -Wextra
310WARNING1 += -Wmissing-format-attribute
311WARNING1 += -Wmissing-prototypes
312WARNING1 += -Wold-style-definition
313
314# Level 2
315WARNING2 := -Waggregate-return
316WARNING2 += -Wcast-align
317WARNING2 += -Wnested-externs
318
319WARNING3 := -Wbad-function-cast
320WARNING3 += -Wcast-qual
321WARNING3 += -Wconversion
322WARNING3 += -Wpacked
323WARNING3 += -Wpointer-arith
324WARNING3 += -Wswitch-default
325
326ifeq (${W},1)
327WARNINGS += $(WARNING1)
328else ifeq (${W},2)
329WARNINGS += $(WARNING1) $(WARNING2)
330else ifeq (${W},3)
331WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
332endif
333
334# Compiler specific warnings
335ifeq ($(findstring clang,$(notdir $(CC))),)
336# not using clang
337WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
338				-Wpacked-bitfield-compat -Wshift-overflow=2 \
339				-Wlogical-op
340else
341# using clang
342WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
343				-Wlogical-op-parentheses
344endif
345
346ifneq (${E},0)
347ERRORS := -Werror
348endif
349
350CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
351				$(ERRORS) $(WARNINGS)
352ASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
353				-ffreestanding -Wa,--fatal-warnings
354TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
355				-ffunction-sections -fdata-sections		\
356				-ffreestanding -fno-builtin -fno-common		\
357				-Os -std=gnu99
358
359ifeq (${SANITIZE_UB},on)
360TF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
361endif
362ifeq (${SANITIZE_UB},trap)
363TF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
364				-fsanitize-undefined-trap-on-error
365endif
366
367GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
368
369# LD = armlink
370ifneq ($(findstring armlink,$(notdir $(LD))),)
371TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
372TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
373TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
374
375# LD = gcc (used when GCC LTO is enabled)
376else ifneq ($(findstring gcc,$(notdir $(LD))),)
377# Pass ld options with Wl or Xlinker switches
378TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
379TF_LDFLAGS		+=	-Wl,--gc-sections
380ifeq ($(ENABLE_LTO),1)
381	ifeq (${ARCH},aarch64)
382		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
383	endif
384endif
385# GCC automatically adds fix-cortex-a53-843419 flag when used to link
386# which breaks some builds, so disable if errata fix is not explicitly enabled
387ifneq (${ERRATA_A53_843419},1)
388	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
389endif
390TF_LDFLAGS		+= 	-nostdlib
391TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
392
393# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
394else
395TF_LDFLAGS		+=	--fatal-warnings -O1
396TF_LDFLAGS		+=	--gc-sections
397# ld.lld doesn't recognize the errata flags,
398# therefore don't add those in that case
399ifeq ($(findstring ld.lld,$(notdir $(LD))),)
400TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
401endif
402endif
403
404DTC_FLAGS		+=	-I dts -O dtb
405DTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
406				-x assembler-with-cpp $(DEFINES)
407
408ifeq ($(MEASURED_BOOT),1)
409DTC_CPPFLAGS		+=	-DMEASURED_BOOT -DBL2_HASH_SIZE=${TCG_DIGEST_SIZE}
410endif
411
412################################################################################
413# Common sources and include directories
414################################################################################
415include lib/compiler-rt/compiler-rt.mk
416
417BL_COMMON_SOURCES	+=	common/bl_common.c			\
418				common/tf_log.c				\
419				common/${ARCH}/debug.S			\
420				drivers/console/multi_console.c		\
421				lib/${ARCH}/cache_helpers.S		\
422				lib/${ARCH}/misc_helpers.S		\
423				plat/common/plat_bl_common.c		\
424				plat/common/plat_log_common.c		\
425				plat/common/${ARCH}/plat_common.c	\
426				plat/common/${ARCH}/platform_helpers.S	\
427				${COMPILER_RT_SRCS}
428
429ifeq ($(notdir $(CC)),armclang)
430BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
431endif
432
433ifeq (${SANITIZE_UB},on)
434BL_COMMON_SOURCES	+=	plat/common/ubsan.c
435endif
436
437INCLUDES		+=	-Iinclude				\
438				-Iinclude/arch/${ARCH}			\
439				-Iinclude/lib/cpus/${ARCH}		\
440				-Iinclude/lib/el3_runtime/${ARCH}	\
441				${PLAT_INCLUDES}			\
442				${SPD_INCLUDES}
443
444include common/backtrace/backtrace.mk
445
446################################################################################
447# Generic definitions
448################################################################################
449
450include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
451
452BUILD_BASE		:=	./build
453BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
454
455SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
456
457# Platforms providing their own TBB makefile may override this value
458INCLUDE_TBBR_MK		:=	1
459
460
461################################################################################
462# Include SPD Makefile if one has been specified
463################################################################################
464
465ifneq (${SPD},none)
466    ifeq (${ARCH},aarch32)
467        $(error "Error: SPD is incompatible with AArch32.")
468    endif
469
470    ifdef EL3_PAYLOAD_BASE
471        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
472        $(warning "The SPD and its BL32 companion will be present but ignored.")
473    endif
474
475    ifeq (${SPD},spmd)
476        $(warning "SPMD is an experimental feature")
477        # SPMD is located in std_svc directory
478        SPD_DIR := std_svc
479
480        ifeq ($(SPMD_SPM_AT_SEL2),1)
481            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
482                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
483            endif
484        endif
485    else
486        # All other SPDs in spd directory
487        SPD_DIR := spd
488    endif
489
490    # We expect to locate an spd.mk under the specified SPD directory
491    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
492
493    ifeq (${SPD_MAKE},)
494        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
495    endif
496    $(info Including ${SPD_MAKE})
497    include ${SPD_MAKE}
498
499    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
500    # Makefile would set NEED_BL32 to "yes". In this case, the build system
501    # supports two mutually exclusive options:
502    # * BL32 is built from source: then BL32_SOURCES must contain the list
503    #   of source files to build BL32
504    # * BL32 is a prebuilt binary: then BL32 must point to the image file
505    #   that will be included in the FIP
506    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
507    # over the sources.
508endif
509
510################################################################################
511# Include the platform specific Makefile after the SPD Makefile (the platform
512# makefile may use all previous definitions in this file)
513################################################################################
514
515include ${PLAT_MAKEFILE_FULL}
516
517$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
518
519ifeq (${ARM_ARCH_MAJOR},7)
520include make_helpers/armv7-a-cpus.mk
521endif
522
523PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
524ifneq ($(PIE_FOUND),)
525	TF_CFLAGS	+=	-fno-PIE
526endif
527
528ifneq ($(findstring gcc,$(notdir $(LD))),)
529	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
530else
531	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
532endif
533
534ifeq ($(ENABLE_PIE),1)
535ifeq ($(BL2_AT_EL3),1)
536ifneq ($(BL2_IN_XIP_MEM),1)
537	BL2_CFLAGS	+=	-fpie
538	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
539endif
540endif
541	BL31_CFLAGS	+=	-fpie
542	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
543ifeq ($(ARCH),aarch64)
544	BL32_CFLAGS	+=	-fpie
545	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
546endif
547endif
548
549ifeq (${ARCH},aarch64)
550BL1_CPPFLAGS += -DIMAGE_AT_EL3
551ifeq ($(BL2_AT_EL3),1)
552BL2_CPPFLAGS += -DIMAGE_AT_EL3
553else
554BL2_CPPFLAGS += -DIMAGE_AT_EL1
555endif
556BL2U_CPPFLAGS += -DIMAGE_AT_EL1
557BL31_CPPFLAGS += -DIMAGE_AT_EL3
558BL32_CPPFLAGS += -DIMAGE_AT_EL1
559endif
560
561# Include the CPU specific operations makefile, which provides default
562# values for all CPU errata workarounds and CPU specific optimisations.
563# This can be overridden by the platform.
564include lib/cpus/cpu-ops.mk
565
566ifeq (${ARCH},aarch32)
567NEED_BL32 := yes
568
569################################################################################
570# Build `AARCH32_SP` as BL32 image for AArch32
571################################################################################
572ifneq (${AARCH32_SP},none)
573# We expect to locate an sp.mk under the specified AARCH32_SP directory
574AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
575
576ifeq (${AARCH32_SP_MAKE},)
577  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
578endif
579
580$(info Including ${AARCH32_SP_MAKE})
581include ${AARCH32_SP_MAKE}
582endif
583
584endif
585
586################################################################################
587# Include libc if not overridden
588################################################################################
589ifeq (${OVERRIDE_LIBC},0)
590include lib/libc/libc.mk
591endif
592
593################################################################################
594# Check incompatible options
595################################################################################
596
597ifdef EL3_PAYLOAD_BASE
598        ifdef PRELOADED_BL33_BASE
599                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
600                incompatible build options. EL3_PAYLOAD_BASE has priority.")
601        endif
602        ifneq (${GENERATE_COT},0)
603                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
604        endif
605        ifneq (${TRUSTED_BOARD_BOOT},0)
606                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
607        endif
608endif
609
610ifeq (${NEED_BL33},yes)
611        ifdef EL3_PAYLOAD_BASE
612                $(warning "BL33 image is not needed when option \
613                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
614        endif
615        ifdef PRELOADED_BL33_BASE
616                $(warning "BL33 image is not needed when option \
617                PRELOADED_BL33_BASE is used and won't be added to the FIP \
618                file.")
619        endif
620endif
621
622# When building for systems with hardware-assisted coherency, there's no need to
623# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
624ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
625$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
626endif
627
628#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
629ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
630$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
631endif
632
633# For RAS_EXTENSION, require that EAs are handled in EL3 first
634ifeq ($(RAS_EXTENSION),1)
635    ifneq ($(HANDLE_EA_EL3_FIRST),1)
636        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
637    endif
638endif
639
640# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
641ifeq ($(FAULT_INJECTION_SUPPORT),1)
642    ifneq ($(RAS_EXTENSION),1)
643        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
644    endif
645endif
646
647# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
648ifeq ($(DYN_DISABLE_AUTH), 1)
649    ifeq (${TRUSTED_BOARD_BOOT}, 0)
650        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
651    endif
652endif
653
654# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
655ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
656$(error "SDEI_IN_FCONF is an experimental feature and is only supported when \
657	SDEI_SUPPORT is enabled")
658endif
659
660# If pointer authentication is used in the firmware, make sure that all the
661# registers associated to it are also saved and restored.
662# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
663ifeq ($(ENABLE_PAUTH),1)
664    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
665        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
666    endif
667endif
668
669ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
670    ifneq (${ARCH},aarch64)
671        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
672    else
673        $(info CTX_INCLUDE_PAUTH_REGS is an experimental feature)
674    endif
675endif
676
677ifeq ($(ENABLE_PAUTH),1)
678    $(info Pointer Authentication is an experimental feature)
679endif
680
681ifeq ($(ENABLE_BTI),1)
682    $(info Branch Protection is an experimental feature)
683endif
684
685ifeq ($(CTX_INCLUDE_MTE_REGS),1)
686    ifneq (${ARCH},aarch64)
687        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
688    else
689        $(info CTX_INCLUDE_MTE_REGS is an experimental feature)
690    endif
691endif
692
693ifeq ($(MEASURED_BOOT),1)
694    ifneq (${TRUSTED_BOARD_BOOT},1)
695        $(error MEASURED_BOOT requires TRUSTED_BOARD_BOOT=1)
696    else
697        $(info MEASURED_BOOT is an experimental feature)
698    endif
699endif
700
701ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
702    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
703        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
704    endif
705endif
706
707ifneq (${DECRYPTION_SUPPORT},none)
708    ifeq (${TRUSTED_BOARD_BOOT}, 0)
709        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
710    else
711        $(info DECRYPTION_SUPPORT is an experimental feature)
712    endif
713endif
714
715################################################################################
716# Process platform overrideable behaviour
717################################################################################
718
719# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
720# Certificate generation tools. This flag can be overridden by the platform.
721ifdef BL2_SOURCES
722        ifdef EL3_PAYLOAD_BASE
723                # If booting an EL3 payload there is no need for a BL33 image
724                # in the FIP file.
725                NEED_BL33		:=	no
726        else
727                ifdef PRELOADED_BL33_BASE
728                        # If booting a BL33 preloaded image there is no need of
729                        # another one in the FIP file.
730                        NEED_BL33		:=	no
731                else
732                        NEED_BL33		?=	yes
733                endif
734        endif
735endif
736
737# If SCP_BL2 is given, we always want FIP to include it.
738ifdef SCP_BL2
739        NEED_SCP_BL2		:=	yes
740endif
741
742# For AArch32, BL31 is not currently supported.
743ifneq (${ARCH},aarch32)
744    ifdef BL31_SOURCES
745        # When booting an EL3 payload, there is no need to compile the BL31 image nor
746        # put it in the FIP.
747        ifndef EL3_PAYLOAD_BASE
748            NEED_BL31 := yes
749        endif
750    endif
751endif
752
753# Process TBB related flags
754ifneq (${GENERATE_COT},0)
755        # Common cert_create options
756        ifneq (${CREATE_KEYS},0)
757                $(eval CRT_ARGS += -n)
758                $(eval FWU_CRT_ARGS += -n)
759                ifneq (${SAVE_KEYS},0)
760                        $(eval CRT_ARGS += -k)
761                        $(eval FWU_CRT_ARGS += -k)
762                endif
763        endif
764        # Include TBBR makefile (unless the platform indicates otherwise)
765        ifeq (${INCLUDE_TBBR_MK},1)
766                include make_helpers/tbbr/tbbr_tools.mk
767        endif
768endif
769
770ifneq (${FIP_ALIGN},0)
771FIP_ARGS += --align ${FIP_ALIGN}
772endif
773
774################################################################################
775# Include libraries' Makefile that are used in all BL
776################################################################################
777
778include lib/stack_protector/stack_protector.mk
779
780################################################################################
781# Auxiliary tools (fiptool, cert_create, etc)
782################################################################################
783
784# Variables for use with Certificate Generation Tool
785CRTTOOLPATH		?=	tools/cert_create
786CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
787
788# Variables for use with Firmware Encryption Tool
789ENCTOOLPATH		?=	tools/encrypt_fw
790ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
791
792# Variables for use with Firmware Image Package
793FIPTOOLPATH		?=	tools/fiptool
794FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
795
796# Variables for use with sptool
797SPTOOLPATH		?=	tools/sptool
798SPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
799SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
800
801# Variables for use with ROMLIB
802ROMLIBPATH		?=	lib/romlib
803
804# Variable for use with Python
805PYTHON			?=	python3
806
807# Variables for use with PRINT_MEMORY_MAP
808PRINT_MEMORY_MAP_PATH		?=	tools/memory
809PRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
810
811# Variables for use with documentation build using Sphinx tool
812DOCS_PATH		?=	docs
813
814################################################################################
815# Include BL specific makefiles
816################################################################################
817ifdef BL1_SOURCES
818NEED_BL1 := yes
819include bl1/bl1.mk
820endif
821
822ifdef BL2_SOURCES
823NEED_BL2 := yes
824include bl2/bl2.mk
825endif
826
827ifdef BL2U_SOURCES
828NEED_BL2U := yes
829include bl2u/bl2u.mk
830endif
831
832ifeq (${NEED_BL31},yes)
833ifdef BL31_SOURCES
834include bl31/bl31.mk
835endif
836endif
837
838ifdef FDT_SOURCES
839NEED_FDT := yes
840endif
841
842################################################################################
843# Build options checks
844################################################################################
845
846$(eval $(call assert_boolean,ALLOW_RO_XLAT_TABLES))
847$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
848$(eval $(call assert_boolean,CREATE_KEYS))
849$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
850$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
851$(eval $(call assert_boolean,CTX_INCLUDE_PAUTH_REGS))
852$(eval $(call assert_boolean,CTX_INCLUDE_MTE_REGS))
853$(eval $(call assert_boolean,CTX_INCLUDE_EL2_REGS))
854$(eval $(call assert_boolean,DEBUG))
855$(eval $(call assert_boolean,DYN_DISABLE_AUTH))
856$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING))
857$(eval $(call assert_boolean,ENABLE_AMU))
858$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
859$(eval $(call assert_boolean,ENABLE_MPAM_FOR_LOWER_ELS))
860$(eval $(call assert_boolean,ENABLE_PIE))
861$(eval $(call assert_boolean,ENABLE_PMF))
862$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
863$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
864$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
865$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
866$(eval $(call assert_boolean,ERROR_DEPRECATED))
867$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT))
868$(eval $(call assert_boolean,GENERATE_COT))
869$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
870$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST))
871$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
872$(eval $(call assert_boolean,INVERTED_MEMMAP))
873$(eval $(call assert_boolean,MEASURED_BOOT))
874$(eval $(call assert_boolean,NS_TIMER_SWITCH))
875$(eval $(call assert_boolean,OVERRIDE_LIBC))
876$(eval $(call assert_boolean,PL011_GENERIC_UART))
877$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
878$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
879$(eval $(call assert_boolean,RAS_EXTENSION))
880$(eval $(call assert_boolean,RESET_TO_BL31))
881$(eval $(call assert_boolean,SAVE_KEYS))
882$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
883$(eval $(call assert_boolean,SEPARATE_NOBITS_REGION))
884$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
885$(eval $(call assert_boolean,SPM_MM))
886$(eval $(call assert_boolean,SPMD_SPM_AT_SEL2))
887$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
888$(eval $(call assert_boolean,USE_COHERENT_MEM))
889$(eval $(call assert_boolean,USE_DEBUGFS))
890$(eval $(call assert_boolean,ARM_IO_IN_DTB))
891$(eval $(call assert_boolean,SDEI_IN_FCONF))
892$(eval $(call assert_boolean,SEC_INT_DESC_IN_FCONF))
893$(eval $(call assert_boolean,USE_ROMLIB))
894$(eval $(call assert_boolean,USE_TBBR_DEFS))
895$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
896$(eval $(call assert_boolean,BL2_AT_EL3))
897$(eval $(call assert_boolean,BL2_IN_XIP_MEM))
898$(eval $(call assert_boolean,BL2_INV_DCACHE))
899$(eval $(call assert_boolean,USE_SPINLOCK_CAS))
900$(eval $(call assert_boolean,ENCRYPT_BL31))
901$(eval $(call assert_boolean,ENCRYPT_BL32))
902$(eval $(call assert_boolean,ERRATA_SPECULATIVE_AT))
903
904$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
905$(eval $(call assert_numeric,ARM_ARCH_MINOR))
906$(eval $(call assert_numeric,BRANCH_PROTECTION))
907$(eval $(call assert_numeric,FW_ENC_STATUS))
908
909ifdef KEY_SIZE
910        $(eval $(call assert_numeric,KEY_SIZE))
911endif
912
913ifeq ($(filter $(SANITIZE_UB), on off trap),)
914        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
915endif
916
917################################################################################
918# Add definitions to the cpp preprocessor based on the current build options.
919# This is done after including the platform specific makefile to allow the
920# platform to overwrite the default options
921################################################################################
922
923$(eval $(call add_define,ALLOW_RO_XLAT_TABLES))
924$(eval $(call add_define,ARM_ARCH_MAJOR))
925$(eval $(call add_define,ARM_ARCH_MINOR))
926$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
927$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
928$(eval $(call add_define,CTX_INCLUDE_FPREGS))
929$(eval $(call add_define,CTX_INCLUDE_PAUTH_REGS))
930$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
931$(eval $(call add_define,CTX_INCLUDE_MTE_REGS))
932$(eval $(call add_define,CTX_INCLUDE_EL2_REGS))
933$(eval $(call add_define,DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT}))
934$(eval $(call add_define,ENABLE_AMU))
935$(eval $(call add_define,ENABLE_ASSERTIONS))
936$(eval $(call add_define,ENABLE_BTI))
937$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS))
938$(eval $(call add_define,ENABLE_PAUTH))
939$(eval $(call add_define,ENABLE_PIE))
940$(eval $(call add_define,ENABLE_PMF))
941$(eval $(call add_define,ENABLE_PSCI_STAT))
942$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
943$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
944$(eval $(call add_define,ENABLE_SVE_FOR_NS))
945$(eval $(call add_define,ENCRYPT_BL31))
946$(eval $(call add_define,ENCRYPT_BL32))
947$(eval $(call add_define,ERROR_DEPRECATED))
948$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
949$(eval $(call add_define,GICV2_G0_FOR_EL3))
950$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
951$(eval $(call add_define,HW_ASSISTED_COHERENCY))
952$(eval $(call add_define,LOG_LEVEL))
953$(eval $(call add_define,MEASURED_BOOT))
954$(eval $(call add_define,NS_TIMER_SWITCH))
955$(eval $(call add_define,PL011_GENERIC_UART))
956$(eval $(call add_define,PLAT_${PLAT}))
957$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
958$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
959$(eval $(call add_define,RAS_EXTENSION))
960$(eval $(call add_define,RESET_TO_BL31))
961$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
962$(eval $(call add_define,SEPARATE_NOBITS_REGION))
963$(eval $(call add_define,RECLAIM_INIT_CODE))
964$(eval $(call add_define,SPD_${SPD}))
965$(eval $(call add_define,SPIN_ON_BL1_EXIT))
966$(eval $(call add_define,SPM_MM))
967$(eval $(call add_define,SPMD_SPM_AT_SEL2))
968$(eval $(call add_define,TRUSTED_BOARD_BOOT))
969$(eval $(call add_define,USE_COHERENT_MEM))
970$(eval $(call add_define,USE_DEBUGFS))
971$(eval $(call add_define,ARM_IO_IN_DTB))
972$(eval $(call add_define,SDEI_IN_FCONF))
973$(eval $(call add_define,SEC_INT_DESC_IN_FCONF))
974$(eval $(call add_define,USE_ROMLIB))
975$(eval $(call add_define,USE_TBBR_DEFS))
976$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
977$(eval $(call add_define,BL2_AT_EL3))
978$(eval $(call add_define,BL2_IN_XIP_MEM))
979$(eval $(call add_define,BL2_INV_DCACHE))
980$(eval $(call add_define,USE_SPINLOCK_CAS))
981$(eval $(call add_define,ERRATA_SPECULATIVE_AT))
982
983ifeq (${SANITIZE_UB},trap)
984        $(eval $(call add_define,MONITOR_TRAPS))
985endif
986
987# Define the EL3_PAYLOAD_BASE flag only if it is provided.
988ifdef EL3_PAYLOAD_BASE
989        $(eval $(call add_define,EL3_PAYLOAD_BASE))
990else
991        # Define the PRELOADED_BL33_BASE flag only if it is provided and
992        # EL3_PAYLOAD_BASE is not defined, as it has priority.
993        ifdef PRELOADED_BL33_BASE
994                $(eval $(call add_define,PRELOADED_BL33_BASE))
995        endif
996endif
997
998# Define the DYN_DISABLE_AUTH flag only if set.
999ifeq (${DYN_DISABLE_AUTH},1)
1000$(eval $(call add_define,DYN_DISABLE_AUTH))
1001endif
1002
1003ifneq ($(findstring armlink,$(notdir $(LD))),)
1004$(eval $(call add_define,USE_ARM_LINK))
1005endif
1006
1007# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1008ifeq (${SPD},spmd)
1009ifdef SP_LAYOUT_FILE
1010        ifeq (${SPMD_SPM_AT_SEL2},0)
1011            $(error "SPMD with SPM at S-EL1 does not require SP_LAYOUT_FILE")
1012        endif
1013        -include $(BUILD_PLAT)/sp_gen.mk
1014        FIP_DEPS += sp
1015        CRT_DEPS += sp
1016        NEED_SP_PKG := yes
1017else
1018        ifeq (${SPMD_SPM_AT_SEL2},1)
1019            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1020        endif
1021endif
1022endif
1023
1024################################################################################
1025# Build targets
1026################################################################################
1027
1028.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1029.SUFFIXES:
1030
1031all: msg_start
1032
1033msg_start:
1034	@echo "Building ${PLAT}"
1035
1036ifeq (${ERROR_DEPRECATED},0)
1037# Check if deprecated declarations and cpp warnings should be treated as error or not.
1038ifneq ($(findstring clang,$(notdir $(CC))),)
1039    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1040else
1041    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1042endif
1043# __ASSEMBLY__ is deprecated in favor of the compiler-builtin __ASSEMBLER__.
1044ASFLAGS	+= -D__ASSEMBLY__
1045# AARCH32/AARCH64 macros are deprecated in favor of the compiler-builtin __aarch64__.
1046ifeq (${ARCH},aarch32)
1047        $(eval $(call add_define,AARCH32))
1048else
1049        $(eval $(call add_define,AARCH64))
1050endif
1051endif # !ERROR_DEPRECATED
1052
1053$(eval $(call MAKE_LIB_DIRS))
1054$(eval $(call MAKE_LIB,c))
1055
1056# Expand build macros for the different images
1057ifeq (${NEED_BL1},yes)
1058$(eval $(call MAKE_BL,1))
1059endif
1060
1061ifeq (${NEED_BL2},yes)
1062ifeq (${BL2_AT_EL3}, 0)
1063FIP_BL2_ARGS := tb-fw
1064endif
1065
1066$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1067	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
1068endif
1069
1070ifeq (${NEED_SCP_BL2},yes)
1071$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1072endif
1073
1074ifeq (${NEED_BL31},yes)
1075BL31_SOURCES += ${SPD_SOURCES}
1076# Sort BL31 source files to remove duplicates
1077BL31_SOURCES := $(sort ${BL31_SOURCES})
1078ifneq (${DECRYPTION_SUPPORT},none)
1079$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1080	$(eval $(call MAKE_BL,31,soc-fw,,$(ENCRYPT_BL31))))
1081else
1082$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1083	$(eval $(call MAKE_BL,31,soc-fw)))
1084endif
1085endif
1086
1087# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1088# build system will call TOOL_ADD_IMG to print a warning message and abort the
1089# process. Note that the dependency on BL32 applies to the FIP only.
1090ifeq (${NEED_BL32},yes)
1091# Sort BL32 source files to remove duplicates
1092BL32_SOURCES := $(sort ${BL32_SOURCES})
1093BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1094
1095ifneq (${DECRYPTION_SUPPORT},none)
1096$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw,,$(ENCRYPT_BL32))),\
1097	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1098else
1099$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
1100	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1101endif
1102endif
1103
1104# Add the BL33 image if required by the platform
1105ifeq (${NEED_BL33},yes)
1106$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1107endif
1108
1109ifeq (${NEED_BL2U},yes)
1110$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1111	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
1112endif
1113
1114# Expand build macros for the different images
1115ifeq (${NEED_FDT},yes)
1116    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1117endif
1118
1119# Add Secure Partition packages
1120ifeq (${NEED_SP_PKG},yes)
1121$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1122	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT)
1123sp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1124	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1125	@${ECHO_BLANK_LINE}
1126	@echo "Built SP Images successfully"
1127	@${ECHO_BLANK_LINE}
1128endif
1129
1130locate-checkpatch:
1131ifndef CHECKPATCH
1132	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1133else
1134ifeq (,$(wildcard ${CHECKPATCH}))
1135	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1136endif
1137endif
1138
1139clean:
1140	@echo "  CLEAN"
1141	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1142	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1143	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1144	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1145	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1146
1147realclean distclean:
1148	@echo "  REALCLEAN"
1149	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1150	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1151	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1152	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
1153	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1154	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1155	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1156
1157checkcodebase:		locate-checkpatch
1158	@echo "  CHECKING STYLE"
1159	@if test -d .git ; then						\
1160		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1161		while read GIT_FILE ;					\
1162		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1163		done ;							\
1164	else								\
1165		 find . -type f -not -iwholename "*.git*"		\
1166		 -not -iwholename "*build*"				\
1167		 -not -iwholename "*libfdt*"				\
1168		 -not -iwholename "*libc*"				\
1169		 -not -iwholename "*docs*"				\
1170		 -not -iwholename "*.rst"				\
1171		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1172	fi
1173
1174checkpatch:		locate-checkpatch
1175	@echo "  CHECKING STYLE"
1176	@if test -n "${CHECKPATCH_OPTS}"; then				\
1177		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1178	fi
1179	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1180	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
1181		printf "\n[*] Checking style of '$$commit'\n\n";	\
1182		git log --format=email "$$commit~..$$commit"		\
1183			-- ${CHECK_PATHS} |				\
1184			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1185		git diff --format=email "$$commit~..$$commit"		\
1186			-- ${CHECK_PATHS} |				\
1187			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1188	done
1189
1190certtool: ${CRTTOOL}
1191
1192.PHONY: ${CRTTOOL}
1193${CRTTOOL}:
1194	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} --no-print-directory -C ${CRTTOOLPATH}
1195	@${ECHO_BLANK_LINE}
1196	@echo "Built $@ successfully"
1197	@${ECHO_BLANK_LINE}
1198
1199ifneq (${GENERATE_COT},0)
1200certificates: ${CRT_DEPS} ${CRTTOOL}
1201	${Q}${CRTTOOL} ${CRT_ARGS}
1202	@${ECHO_BLANK_LINE}
1203	@echo "Built $@ successfully"
1204	@echo "Certificates can be found in ${BUILD_PLAT}"
1205	@${ECHO_BLANK_LINE}
1206endif
1207
1208${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1209	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1210	${Q}${FIPTOOL} info $@
1211	@${ECHO_BLANK_LINE}
1212	@echo "Built $@ successfully"
1213	@${ECHO_BLANK_LINE}
1214
1215ifneq (${GENERATE_COT},0)
1216fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1217	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1218	@${ECHO_BLANK_LINE}
1219	@echo "Built $@ successfully"
1220	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1221	@${ECHO_BLANK_LINE}
1222endif
1223
1224${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1225	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1226	${Q}${FIPTOOL} info $@
1227	@${ECHO_BLANK_LINE}
1228	@echo "Built $@ successfully"
1229	@${ECHO_BLANK_LINE}
1230
1231fiptool: ${FIPTOOL}
1232fip: ${BUILD_PLAT}/${FIP_NAME}
1233fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1234
1235.PHONY: ${FIPTOOL}
1236${FIPTOOL}:
1237	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
1238
1239sptool: ${SPTOOL}
1240.PHONY: ${SPTOOL}
1241${SPTOOL}:
1242	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${SPTOOLPATH}
1243
1244.PHONY: libraries
1245romlib.bin: libraries
1246	${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
1247
1248# Call print_memory_map tool
1249memmap: all
1250	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1251
1252doc:
1253	@echo "  BUILD DOCUMENTATION"
1254	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1255
1256enctool: ${ENCTOOL}
1257
1258.PHONY: ${ENCTOOL}
1259${ENCTOOL}:
1260	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 --no-print-directory -C ${ENCTOOLPATH}
1261	@${ECHO_BLANK_LINE}
1262	@echo "Built $@ successfully"
1263	@${ECHO_BLANK_LINE}
1264
1265cscope:
1266	@echo "  CSCOPE"
1267	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1268	${Q}cscope -b -q -k
1269
1270help:
1271	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1272	@echo ""
1273	@echo "PLAT is used to specify which platform you wish to build."
1274	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1275	@echo ""
1276	@echo "platform = ${PLATFORM_LIST}"
1277	@echo ""
1278	@echo "Please refer to the User Guide for a list of all supported options."
1279	@echo "Note that the build system doesn't track dependencies for build "
1280	@echo "options. Therefore, if any of the build options are changed "
1281	@echo "from a previous build, a clean build must be performed."
1282	@echo ""
1283	@echo "Supported Targets:"
1284	@echo "  all            Build all individual bootloader binaries"
1285	@echo "  bl1            Build the BL1 binary"
1286	@echo "  bl2            Build the BL2 binary"
1287	@echo "  bl2u           Build the BL2U binary"
1288	@echo "  bl31           Build the BL31 binary"
1289	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1290	@echo "                 this builds secure payload specified by AARCH32_SP"
1291	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1292	@echo "  fip            Build the Firmware Image Package (FIP)"
1293	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1294	@echo "  checkcodebase  Check the coding style of the entire source tree"
1295	@echo "  checkpatch     Check the coding style on changes in the current"
1296	@echo "                 branch against BASE_COMMIT (default origin/master)"
1297	@echo "  clean          Clean the build for the selected platform"
1298	@echo "  cscope         Generate cscope index"
1299	@echo "  distclean      Remove all build artifacts for all platforms"
1300	@echo "  certtool       Build the Certificate generation tool"
1301	@echo "  enctool        Build the Firmware encryption tool"
1302	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1303	@echo "  sp             Build the Secure Partition Packages"
1304	@echo "  sptool         Build the Secure Partition Package creation tool"
1305	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1306	@echo "  memmap         Print the memory map of the built binaries"
1307	@echo "  doc            Build html based documentation using Sphinx tool"
1308	@echo ""
1309	@echo "Note: most build targets require PLAT to be set to a specific platform."
1310	@echo ""
1311	@echo "example: build all targets for the FVP platform:"
1312	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1313