xref: /rk3399_ARM-atf/Makefile (revision 49fe535bce258eb657ca32e34ef0c50667db044b)
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$(eval $(call assert_boolean,RAS_TRAP_LOWER_EL_ERR_ACCESS))
904
905$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
906$(eval $(call assert_numeric,ARM_ARCH_MINOR))
907$(eval $(call assert_numeric,BRANCH_PROTECTION))
908$(eval $(call assert_numeric,FW_ENC_STATUS))
909
910ifdef KEY_SIZE
911        $(eval $(call assert_numeric,KEY_SIZE))
912endif
913
914ifeq ($(filter $(SANITIZE_UB), on off trap),)
915        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
916endif
917
918################################################################################
919# Add definitions to the cpp preprocessor based on the current build options.
920# This is done after including the platform specific makefile to allow the
921# platform to overwrite the default options
922################################################################################
923
924$(eval $(call add_define,ALLOW_RO_XLAT_TABLES))
925$(eval $(call add_define,ARM_ARCH_MAJOR))
926$(eval $(call add_define,ARM_ARCH_MINOR))
927$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
928$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
929$(eval $(call add_define,CTX_INCLUDE_FPREGS))
930$(eval $(call add_define,CTX_INCLUDE_PAUTH_REGS))
931$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
932$(eval $(call add_define,CTX_INCLUDE_MTE_REGS))
933$(eval $(call add_define,CTX_INCLUDE_EL2_REGS))
934$(eval $(call add_define,DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT}))
935$(eval $(call add_define,ENABLE_AMU))
936$(eval $(call add_define,ENABLE_ASSERTIONS))
937$(eval $(call add_define,ENABLE_BTI))
938$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS))
939$(eval $(call add_define,ENABLE_PAUTH))
940$(eval $(call add_define,ENABLE_PIE))
941$(eval $(call add_define,ENABLE_PMF))
942$(eval $(call add_define,ENABLE_PSCI_STAT))
943$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
944$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
945$(eval $(call add_define,ENABLE_SVE_FOR_NS))
946$(eval $(call add_define,ENCRYPT_BL31))
947$(eval $(call add_define,ENCRYPT_BL32))
948$(eval $(call add_define,ERROR_DEPRECATED))
949$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
950$(eval $(call add_define,GICV2_G0_FOR_EL3))
951$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
952$(eval $(call add_define,HW_ASSISTED_COHERENCY))
953$(eval $(call add_define,LOG_LEVEL))
954$(eval $(call add_define,MEASURED_BOOT))
955$(eval $(call add_define,NS_TIMER_SWITCH))
956$(eval $(call add_define,PL011_GENERIC_UART))
957$(eval $(call add_define,PLAT_${PLAT}))
958$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
959$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
960$(eval $(call add_define,RAS_EXTENSION))
961$(eval $(call add_define,RESET_TO_BL31))
962$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
963$(eval $(call add_define,SEPARATE_NOBITS_REGION))
964$(eval $(call add_define,RECLAIM_INIT_CODE))
965$(eval $(call add_define,SPD_${SPD}))
966$(eval $(call add_define,SPIN_ON_BL1_EXIT))
967$(eval $(call add_define,SPM_MM))
968$(eval $(call add_define,SPMD_SPM_AT_SEL2))
969$(eval $(call add_define,TRUSTED_BOARD_BOOT))
970$(eval $(call add_define,USE_COHERENT_MEM))
971$(eval $(call add_define,USE_DEBUGFS))
972$(eval $(call add_define,ARM_IO_IN_DTB))
973$(eval $(call add_define,SDEI_IN_FCONF))
974$(eval $(call add_define,SEC_INT_DESC_IN_FCONF))
975$(eval $(call add_define,USE_ROMLIB))
976$(eval $(call add_define,USE_TBBR_DEFS))
977$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
978$(eval $(call add_define,BL2_AT_EL3))
979$(eval $(call add_define,BL2_IN_XIP_MEM))
980$(eval $(call add_define,BL2_INV_DCACHE))
981$(eval $(call add_define,USE_SPINLOCK_CAS))
982$(eval $(call add_define,ERRATA_SPECULATIVE_AT))
983$(eval $(call add_define,RAS_TRAP_LOWER_EL_ERR_ACCESS))
984
985ifeq (${SANITIZE_UB},trap)
986        $(eval $(call add_define,MONITOR_TRAPS))
987endif
988
989# Define the EL3_PAYLOAD_BASE flag only if it is provided.
990ifdef EL3_PAYLOAD_BASE
991        $(eval $(call add_define,EL3_PAYLOAD_BASE))
992else
993        # Define the PRELOADED_BL33_BASE flag only if it is provided and
994        # EL3_PAYLOAD_BASE is not defined, as it has priority.
995        ifdef PRELOADED_BL33_BASE
996                $(eval $(call add_define,PRELOADED_BL33_BASE))
997        endif
998endif
999
1000# Define the DYN_DISABLE_AUTH flag only if set.
1001ifeq (${DYN_DISABLE_AUTH},1)
1002$(eval $(call add_define,DYN_DISABLE_AUTH))
1003endif
1004
1005ifneq ($(findstring armlink,$(notdir $(LD))),)
1006$(eval $(call add_define,USE_ARM_LINK))
1007endif
1008
1009# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1010ifeq (${SPD},spmd)
1011ifdef SP_LAYOUT_FILE
1012        ifeq (${SPMD_SPM_AT_SEL2},0)
1013            $(error "SPMD with SPM at S-EL1 does not require SP_LAYOUT_FILE")
1014        endif
1015        -include $(BUILD_PLAT)/sp_gen.mk
1016        FIP_DEPS += sp
1017        CRT_DEPS += sp
1018        NEED_SP_PKG := yes
1019else
1020        ifeq (${SPMD_SPM_AT_SEL2},1)
1021            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1022        endif
1023endif
1024endif
1025
1026################################################################################
1027# Build targets
1028################################################################################
1029
1030.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1031.SUFFIXES:
1032
1033all: msg_start
1034
1035msg_start:
1036	@echo "Building ${PLAT}"
1037
1038ifeq (${ERROR_DEPRECATED},0)
1039# Check if deprecated declarations and cpp warnings should be treated as error or not.
1040ifneq ($(findstring clang,$(notdir $(CC))),)
1041    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1042else
1043    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1044endif
1045# __ASSEMBLY__ is deprecated in favor of the compiler-builtin __ASSEMBLER__.
1046ASFLAGS	+= -D__ASSEMBLY__
1047# AARCH32/AARCH64 macros are deprecated in favor of the compiler-builtin __aarch64__.
1048ifeq (${ARCH},aarch32)
1049        $(eval $(call add_define,AARCH32))
1050else
1051        $(eval $(call add_define,AARCH64))
1052endif
1053endif # !ERROR_DEPRECATED
1054
1055$(eval $(call MAKE_LIB_DIRS))
1056$(eval $(call MAKE_LIB,c))
1057
1058# Expand build macros for the different images
1059ifeq (${NEED_BL1},yes)
1060$(eval $(call MAKE_BL,1))
1061endif
1062
1063ifeq (${NEED_BL2},yes)
1064ifeq (${BL2_AT_EL3}, 0)
1065FIP_BL2_ARGS := tb-fw
1066endif
1067
1068$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1069	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
1070endif
1071
1072ifeq (${NEED_SCP_BL2},yes)
1073$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1074endif
1075
1076ifeq (${NEED_BL31},yes)
1077BL31_SOURCES += ${SPD_SOURCES}
1078# Sort BL31 source files to remove duplicates
1079BL31_SOURCES := $(sort ${BL31_SOURCES})
1080ifneq (${DECRYPTION_SUPPORT},none)
1081$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1082	$(eval $(call MAKE_BL,31,soc-fw,,$(ENCRYPT_BL31))))
1083else
1084$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1085	$(eval $(call MAKE_BL,31,soc-fw)))
1086endif
1087endif
1088
1089# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1090# build system will call TOOL_ADD_IMG to print a warning message and abort the
1091# process. Note that the dependency on BL32 applies to the FIP only.
1092ifeq (${NEED_BL32},yes)
1093# Sort BL32 source files to remove duplicates
1094BL32_SOURCES := $(sort ${BL32_SOURCES})
1095BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1096
1097ifneq (${DECRYPTION_SUPPORT},none)
1098$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw,,$(ENCRYPT_BL32))),\
1099	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1100else
1101$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
1102	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1103endif
1104endif
1105
1106# Add the BL33 image if required by the platform
1107ifeq (${NEED_BL33},yes)
1108$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1109endif
1110
1111ifeq (${NEED_BL2U},yes)
1112$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1113	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
1114endif
1115
1116# Expand build macros for the different images
1117ifeq (${NEED_FDT},yes)
1118    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1119endif
1120
1121# Add Secure Partition packages
1122ifeq (${NEED_SP_PKG},yes)
1123$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1124	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT)
1125sp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1126	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1127	@${ECHO_BLANK_LINE}
1128	@echo "Built SP Images successfully"
1129	@${ECHO_BLANK_LINE}
1130endif
1131
1132locate-checkpatch:
1133ifndef CHECKPATCH
1134	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1135else
1136ifeq (,$(wildcard ${CHECKPATCH}))
1137	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1138endif
1139endif
1140
1141clean:
1142	@echo "  CLEAN"
1143	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1144	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1145	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1146	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1147	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1148
1149realclean distclean:
1150	@echo "  REALCLEAN"
1151	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1152	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1153	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1154	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
1155	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1156	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1157	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1158
1159checkcodebase:		locate-checkpatch
1160	@echo "  CHECKING STYLE"
1161	@if test -d .git ; then						\
1162		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1163		while read GIT_FILE ;					\
1164		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1165		done ;							\
1166	else								\
1167		 find . -type f -not -iwholename "*.git*"		\
1168		 -not -iwholename "*build*"				\
1169		 -not -iwholename "*libfdt*"				\
1170		 -not -iwholename "*libc*"				\
1171		 -not -iwholename "*docs*"				\
1172		 -not -iwholename "*.rst"				\
1173		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1174	fi
1175
1176checkpatch:		locate-checkpatch
1177	@echo "  CHECKING STYLE"
1178	@if test -n "${CHECKPATCH_OPTS}"; then				\
1179		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1180	fi
1181	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1182	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
1183		printf "\n[*] Checking style of '$$commit'\n\n";	\
1184		git log --format=email "$$commit~..$$commit"		\
1185			-- ${CHECK_PATHS} |				\
1186			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1187		git diff --format=email "$$commit~..$$commit"		\
1188			-- ${CHECK_PATHS} |				\
1189			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1190	done
1191
1192certtool: ${CRTTOOL}
1193
1194.PHONY: ${CRTTOOL}
1195${CRTTOOL}:
1196	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} --no-print-directory -C ${CRTTOOLPATH}
1197	@${ECHO_BLANK_LINE}
1198	@echo "Built $@ successfully"
1199	@${ECHO_BLANK_LINE}
1200
1201ifneq (${GENERATE_COT},0)
1202certificates: ${CRT_DEPS} ${CRTTOOL}
1203	${Q}${CRTTOOL} ${CRT_ARGS}
1204	@${ECHO_BLANK_LINE}
1205	@echo "Built $@ successfully"
1206	@echo "Certificates can be found in ${BUILD_PLAT}"
1207	@${ECHO_BLANK_LINE}
1208endif
1209
1210${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1211	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1212	${Q}${FIPTOOL} info $@
1213	@${ECHO_BLANK_LINE}
1214	@echo "Built $@ successfully"
1215	@${ECHO_BLANK_LINE}
1216
1217ifneq (${GENERATE_COT},0)
1218fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1219	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1220	@${ECHO_BLANK_LINE}
1221	@echo "Built $@ successfully"
1222	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1223	@${ECHO_BLANK_LINE}
1224endif
1225
1226${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1227	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1228	${Q}${FIPTOOL} info $@
1229	@${ECHO_BLANK_LINE}
1230	@echo "Built $@ successfully"
1231	@${ECHO_BLANK_LINE}
1232
1233fiptool: ${FIPTOOL}
1234fip: ${BUILD_PLAT}/${FIP_NAME}
1235fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1236
1237.PHONY: ${FIPTOOL}
1238${FIPTOOL}:
1239	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
1240
1241sptool: ${SPTOOL}
1242.PHONY: ${SPTOOL}
1243${SPTOOL}:
1244	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${SPTOOLPATH}
1245
1246.PHONY: libraries
1247romlib.bin: libraries
1248	${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
1249
1250# Call print_memory_map tool
1251memmap: all
1252	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1253
1254doc:
1255	@echo "  BUILD DOCUMENTATION"
1256	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1257
1258enctool: ${ENCTOOL}
1259
1260.PHONY: ${ENCTOOL}
1261${ENCTOOL}:
1262	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 --no-print-directory -C ${ENCTOOLPATH}
1263	@${ECHO_BLANK_LINE}
1264	@echo "Built $@ successfully"
1265	@${ECHO_BLANK_LINE}
1266
1267cscope:
1268	@echo "  CSCOPE"
1269	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1270	${Q}cscope -b -q -k
1271
1272help:
1273	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1274	@echo ""
1275	@echo "PLAT is used to specify which platform you wish to build."
1276	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1277	@echo ""
1278	@echo "platform = ${PLATFORM_LIST}"
1279	@echo ""
1280	@echo "Please refer to the User Guide for a list of all supported options."
1281	@echo "Note that the build system doesn't track dependencies for build "
1282	@echo "options. Therefore, if any of the build options are changed "
1283	@echo "from a previous build, a clean build must be performed."
1284	@echo ""
1285	@echo "Supported Targets:"
1286	@echo "  all            Build all individual bootloader binaries"
1287	@echo "  bl1            Build the BL1 binary"
1288	@echo "  bl2            Build the BL2 binary"
1289	@echo "  bl2u           Build the BL2U binary"
1290	@echo "  bl31           Build the BL31 binary"
1291	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1292	@echo "                 this builds secure payload specified by AARCH32_SP"
1293	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1294	@echo "  fip            Build the Firmware Image Package (FIP)"
1295	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1296	@echo "  checkcodebase  Check the coding style of the entire source tree"
1297	@echo "  checkpatch     Check the coding style on changes in the current"
1298	@echo "                 branch against BASE_COMMIT (default origin/master)"
1299	@echo "  clean          Clean the build for the selected platform"
1300	@echo "  cscope         Generate cscope index"
1301	@echo "  distclean      Remove all build artifacts for all platforms"
1302	@echo "  certtool       Build the Certificate generation tool"
1303	@echo "  enctool        Build the Firmware encryption tool"
1304	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1305	@echo "  sp             Build the Secure Partition Packages"
1306	@echo "  sptool         Build the Secure Partition Package creation tool"
1307	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1308	@echo "  memmap         Print the memory map of the built binaries"
1309	@echo "  doc            Build html based documentation using Sphinx tool"
1310	@echo ""
1311	@echo "Note: most build targets require PLAT to be set to a specific platform."
1312	@echo ""
1313	@echo "example: build all targets for the FVP platform:"
1314	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1315