xref: /rk3399_ARM-atf/Makefile (revision 0d3a27e7f6ee3fa1be4c705927bcf9cad3750809)
1#
2# Copyright (c) 2013-2017, 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			:= 1
11VERSION_MINOR			:= 4
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
29ifdef ASM_ASSERTION
30        $(warning ASM_ASSERTION is removed, use ENABLE_ASSERTIONS instead.)
31endif
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34
35# Assertions enabled for DEBUG builds by default
36ENABLE_ASSERTIONS		:= ${DEBUG}
37ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
38PLAT				:= ${DEFAULT_PLAT}
39
40################################################################################
41# Checkpatch script options
42################################################################################
43
44CHECKCODE_ARGS		:=	--no-patch
45# Do not check the coding style on imported library files or documentation files
46INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
47					include/lib/libfdt		\
48					include/lib/stdlib,		\
49					$(wildcard include/lib/*)))
50INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
51					include/lib,			\
52					$(wildcard include/*)))
53LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
54					lib/compiler-rt			\
55					lib/libfdt%			\
56					lib/stdlib,			\
57					$(wildcard lib/*)))
58ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					lib				\
60					include				\
61					docs				\
62					%.md,				\
63					$(wildcard *)))
64CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
65				${INC_DIRS_TO_CHECK}			\
66				${INC_LIB_DIRS_TO_CHECK}		\
67				${LIB_DIRS_TO_CHECK}
68
69
70################################################################################
71# Process build options
72################################################################################
73
74# Verbose flag
75ifeq (${V},0)
76        Q:=@
77        CHECKCODE_ARGS	+=	--no-summary --terse
78else
79        Q:=
80endif
81export Q
82
83# Process Debug flag
84$(eval $(call add_define,DEBUG))
85ifneq (${DEBUG}, 0)
86        BUILD_TYPE	:=	debug
87        TF_CFLAGS	+= 	-g
88        ASFLAGS		+= 	-g -Wa,--gdwarf-2
89        # Use LOG_LEVEL_INFO by default for debug builds
90        LOG_LEVEL	:=	40
91else
92        BUILD_TYPE	:=	release
93        $(eval $(call add_define,NDEBUG))
94        # Use LOG_LEVEL_NOTICE by default for release builds
95        LOG_LEVEL	:=	20
96endif
97
98# Default build string (git branch and commit)
99ifeq (${BUILD_STRING},)
100        BUILD_STRING	:=	$(shell git describe --always --dirty --tags 2> /dev/null)
101endif
102VERSION_STRING		:=	v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
103
104# The cert_create tool cannot generate certificates individually, so we use the
105# target 'certificates' to create them all
106ifneq (${GENERATE_COT},0)
107        FIP_DEPS += certificates
108        FWU_FIP_DEPS += fwu_certificates
109endif
110
111
112################################################################################
113# Toolchain
114################################################################################
115
116HOSTCC			:=	gcc
117export HOSTCC
118
119CC			:=	${CROSS_COMPILE}gcc
120CPP			:=	${CROSS_COMPILE}cpp
121AS			:=	${CROSS_COMPILE}gcc
122AR			:=	${CROSS_COMPILE}ar
123LD			:=	${CROSS_COMPILE}ld
124OC			:=	${CROSS_COMPILE}objcopy
125OD			:=	${CROSS_COMPILE}objdump
126NM			:=	${CROSS_COMPILE}nm
127PP			:=	${CROSS_COMPILE}gcc -E
128DTC			?=	dtc
129
130ifeq (${ARM_ARCH_MAJOR},7)
131target32-directive	= 	-target arm-none-eabi
132# Will set march32-directive from platform configuration
133else
134target32-directive	= 	-target armv8a-none-eabi
135march32-directive	= 	-march=armv8-a
136endif
137
138ifeq ($(notdir $(CC)),armclang)
139TF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
140TF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi -march=armv8-a
141else ifneq ($(findstring clang,$(notdir $(CC))),)
142TF_CFLAGS_aarch32	=	$(target32-directive)
143TF_CFLAGS_aarch64	=	-target aarch64-elf
144else
145TF_CFLAGS_aarch32	=	$(march32-directive)
146TF_CFLAGS_aarch64	=	-march=armv8-a
147endif
148
149TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
150
151ASFLAGS_aarch32		=	$(march32-directive)
152ASFLAGS_aarch64		=	-march=armv8-a
153
154CPPFLAGS		=	${DEFINES} ${INCLUDES} -nostdinc		\
155				-Wmissing-include-dirs -Werror
156ASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
157				-D__ASSEMBLY__ -ffreestanding 			\
158				-Wa,--fatal-warnings
159TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
160				-ffreestanding -fno-builtin -Wall -std=gnu99	\
161				-Os -ffunction-sections -fdata-sections
162
163GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
164PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
165
166ifeq ($(PIE_FOUND),1)
167TF_CFLAGS		+=	-fno-PIE
168endif
169
170TF_LDFLAGS		+=	--fatal-warnings -O1
171TF_LDFLAGS		+=	--gc-sections
172TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
173
174DTC_FLAGS		+=	-I dts -O dtb
175
176################################################################################
177# Common sources and include directories
178################################################################################
179include lib/compiler-rt/compiler-rt.mk
180include lib/stdlib/stdlib.mk
181
182BL_COMMON_SOURCES	+=	common/bl_common.c			\
183				common/tf_log.c				\
184				common/tf_printf.c			\
185				common/tf_snprintf.c			\
186				common/${ARCH}/debug.S			\
187				lib/${ARCH}/cache_helpers.S		\
188				lib/${ARCH}/misc_helpers.S		\
189				plat/common/plat_log_common.c		\
190				plat/common/${ARCH}/plat_common.c	\
191				plat/common/${ARCH}/platform_helpers.S	\
192				${COMPILER_RT_SRCS}			\
193				${STDLIB_SRCS}
194
195INCLUDES		+=	-Iinclude/bl1				\
196				-Iinclude/bl31				\
197				-Iinclude/common			\
198				-Iinclude/common/${ARCH}		\
199				-Iinclude/drivers			\
200				-Iinclude/drivers/arm			\
201				-Iinclude/drivers/auth			\
202				-Iinclude/drivers/io			\
203				-Iinclude/drivers/ti/uart		\
204				-Iinclude/lib				\
205				-Iinclude/lib/${ARCH}			\
206				-Iinclude/lib/cpus			\
207				-Iinclude/lib/cpus/${ARCH}		\
208				-Iinclude/lib/el3_runtime		\
209				-Iinclude/lib/el3_runtime/${ARCH}	\
210				-Iinclude/lib/extensions		\
211				-Iinclude/lib/pmf			\
212				-Iinclude/lib/psci			\
213				-Iinclude/lib/xlat_tables		\
214				-Iinclude/plat/common			\
215				-Iinclude/services			\
216				${PLAT_INCLUDES}			\
217				${SPD_INCLUDES}				\
218				-Iinclude/tools_share
219
220
221################################################################################
222# Generic definitions
223################################################################################
224
225include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
226
227BUILD_BASE		:=	./build
228BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
229
230SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
231
232# Platforms providing their own TBB makefile may override this value
233INCLUDE_TBBR_MK		:=	1
234
235
236################################################################################
237# Include SPD Makefile if one has been specified
238################################################################################
239
240ifneq (${SPD},none)
241ifeq (${ARCH},aarch32)
242	$(error "Error: SPD is incompatible with AArch32.")
243endif
244ifdef EL3_PAYLOAD_BASE
245        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
246        $(warning "The SPD and its BL32 companion will be present but ignored.")
247endif
248        # We expect to locate an spd.mk under the specified SPD directory
249        SPD_MAKE	:=	$(wildcard services/spd/${SPD}/${SPD}.mk)
250
251        ifeq (${SPD_MAKE},)
252                $(error Error: No services/spd/${SPD}/${SPD}.mk located)
253        endif
254        $(info Including ${SPD_MAKE})
255        include ${SPD_MAKE}
256
257        # If there's BL32 companion for the chosen SPD, we expect that the SPD's
258        # Makefile would set NEED_BL32 to "yes". In this case, the build system
259        # supports two mutually exclusive options:
260        # * BL32 is built from source: then BL32_SOURCES must contain the list
261        #   of source files to build BL32
262        # * BL32 is a prebuilt binary: then BL32 must point to the image file
263        #   that will be included in the FIP
264        # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
265        # over the sources.
266endif
267
268################################################################################
269# Include libraries' Makefile that are used in all BL
270################################################################################
271
272include lib/stack_protector/stack_protector.mk
273
274
275################################################################################
276# Include the platform specific Makefile after the SPD Makefile (the platform
277# makefile may use all previous definitions in this file)
278################################################################################
279
280include ${PLAT_MAKEFILE_FULL}
281
282$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
283
284ifeq (${ARM_ARCH_MAJOR},7)
285include make_helpers/armv7-a-cpus.mk
286endif
287
288# Platform compatibility is not supported in AArch32
289ifneq (${ARCH},aarch32)
290# If the platform has not defined ENABLE_PLAT_COMPAT, then enable it by default
291ifndef ENABLE_PLAT_COMPAT
292ENABLE_PLAT_COMPAT := 1
293endif
294
295# Include the platform compatibility helpers for PSCI
296ifneq (${ENABLE_PLAT_COMPAT}, 0)
297include plat/compat/plat_compat.mk
298endif
299endif
300
301# Include the CPU specific operations makefile, which provides default
302# values for all CPU errata workarounds and CPU specific optimisations.
303# This can be overridden by the platform.
304include lib/cpus/cpu-ops.mk
305
306ifeq (${ARCH},aarch32)
307NEED_BL32 := yes
308
309################################################################################
310# Build `AARCH32_SP` as BL32 image for AArch32
311################################################################################
312ifneq (${AARCH32_SP},none)
313# We expect to locate an sp.mk under the specified AARCH32_SP directory
314AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
315
316ifeq (${AARCH32_SP_MAKE},)
317  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
318endif
319
320$(info Including ${AARCH32_SP_MAKE})
321include ${AARCH32_SP_MAKE}
322endif
323
324endif
325
326################################################################################
327# Check incompatible options
328################################################################################
329
330ifdef EL3_PAYLOAD_BASE
331        ifdef PRELOADED_BL33_BASE
332                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
333                incompatible build options. EL3_PAYLOAD_BASE has priority.")
334        endif
335        ifneq (${GENERATE_COT},0)
336                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
337        endif
338        ifneq (${TRUSTED_BOARD_BOOT},0)
339                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
340        endif
341endif
342
343ifeq (${NEED_BL33},yes)
344        ifdef EL3_PAYLOAD_BASE
345                $(warning "BL33 image is not needed when option \
346                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
347        endif
348        ifdef PRELOADED_BL33_BASE
349                $(warning "BL33 image is not needed when option \
350                PRELOADED_BL33_BASE is used and won't be added to the FIP \
351                file.")
352        endif
353endif
354
355# For AArch32, LOAD_IMAGE_V2 must be enabled.
356ifeq (${ARCH},aarch32)
357    ifeq (${LOAD_IMAGE_V2}, 0)
358        $(error "For AArch32, LOAD_IMAGE_V2 must be enabled.")
359    endif
360endif
361
362# When building for systems with hardware-assisted coherency, there's no need to
363# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
364ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
365$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
366endif
367
368################################################################################
369# Process platform overrideable behaviour
370################################################################################
371
372# Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
373# supplied for the FIP and Certificate generation tools. This flag can be
374# overridden by the platform.
375ifdef BL2_SOURCES
376        ifdef EL3_PAYLOAD_BASE
377                # If booting an EL3 payload there is no need for a BL33 image
378                # in the FIP file.
379                NEED_BL33		:=	no
380        else
381                ifdef PRELOADED_BL33_BASE
382                        # If booting a BL33 preloaded image there is no need of
383                        # another one in the FIP file.
384                        NEED_BL33		:=	no
385                else
386                        NEED_BL33		?=	yes
387                endif
388        endif
389endif
390
391# If SCP_BL2 is given, we always want FIP to include it.
392ifdef SCP_BL2
393        NEED_SCP_BL2		:=	yes
394endif
395
396# For AArch32, BL31 is not currently supported.
397ifneq (${ARCH},aarch32)
398    ifdef BL31_SOURCES
399        # When booting an EL3 payload, there is no need to compile the BL31 image nor
400        # put it in the FIP.
401        ifndef EL3_PAYLOAD_BASE
402            NEED_BL31 := yes
403        endif
404    endif
405endif
406
407# Process TBB related flags
408ifneq (${GENERATE_COT},0)
409        # Common cert_create options
410        ifneq (${CREATE_KEYS},0)
411                $(eval CRT_ARGS += -n)
412                $(eval FWU_CRT_ARGS += -n)
413                ifneq (${SAVE_KEYS},0)
414                        $(eval CRT_ARGS += -k)
415                        $(eval FWU_CRT_ARGS += -k)
416                endif
417        endif
418        # Include TBBR makefile (unless the platform indicates otherwise)
419        ifeq (${INCLUDE_TBBR_MK},1)
420                include make_helpers/tbbr/tbbr_tools.mk
421        endif
422endif
423
424ifneq (${FIP_ALIGN},0)
425FIP_ARGS += --align ${FIP_ALIGN}
426endif
427
428################################################################################
429# Auxiliary tools (fiptool, cert_create, etc)
430################################################################################
431
432# Variables for use with Certificate Generation Tool
433CRTTOOLPATH		?=	tools/cert_create
434CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
435
436# Variables for use with Firmware Image Package
437FIPTOOLPATH		?=	tools/fiptool
438FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
439
440################################################################################
441# Include BL specific makefiles
442################################################################################
443ifdef BL1_SOURCES
444NEED_BL1 := yes
445include bl1/bl1.mk
446endif
447
448ifdef BL2_SOURCES
449NEED_BL2 := yes
450include bl2/bl2.mk
451endif
452
453ifdef BL2U_SOURCES
454NEED_BL2U := yes
455include bl2u/bl2u.mk
456endif
457
458ifeq (${NEED_BL31},yes)
459ifdef BL31_SOURCES
460include bl31/bl31.mk
461endif
462endif
463
464ifdef FDT_SOURCES
465NEED_FDT := yes
466endif
467
468################################################################################
469# Build options checks
470################################################################################
471
472$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
473$(eval $(call assert_boolean,CREATE_KEYS))
474$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
475$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
476$(eval $(call assert_boolean,DEBUG))
477$(eval $(call assert_boolean,DISABLE_PEDANTIC))
478$(eval $(call assert_boolean,ENABLE_AMU))
479$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
480$(eval $(call assert_boolean,ENABLE_PLAT_COMPAT))
481$(eval $(call assert_boolean,ENABLE_PMF))
482$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
483$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
484$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
485$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
486$(eval $(call assert_boolean,ERROR_DEPRECATED))
487$(eval $(call assert_boolean,GENERATE_COT))
488$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
489$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
490$(eval $(call assert_boolean,LOAD_IMAGE_V2))
491$(eval $(call assert_boolean,NS_TIMER_SWITCH))
492$(eval $(call assert_boolean,PL011_GENERIC_UART))
493$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
494$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
495$(eval $(call assert_boolean,RESET_TO_BL31))
496$(eval $(call assert_boolean,SAVE_KEYS))
497$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
498$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
499$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
500$(eval $(call assert_boolean,USE_COHERENT_MEM))
501$(eval $(call assert_boolean,USE_TBBR_DEFS))
502$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
503$(eval $(call assert_boolean,BL2_AT_EL3))
504
505$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
506$(eval $(call assert_numeric,ARM_ARCH_MINOR))
507
508################################################################################
509# Add definitions to the cpp preprocessor based on the current build options.
510# This is done after including the platform specific makefile to allow the
511# platform to overwrite the default options
512################################################################################
513
514$(eval $(call add_define,ARM_ARCH_MAJOR))
515$(eval $(call add_define,ARM_ARCH_MINOR))
516$(eval $(call add_define,ARM_GIC_ARCH))
517$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
518$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
519$(eval $(call add_define,CTX_INCLUDE_FPREGS))
520$(eval $(call add_define,ENABLE_AMU))
521$(eval $(call add_define,ENABLE_ASSERTIONS))
522$(eval $(call add_define,ENABLE_PLAT_COMPAT))
523$(eval $(call add_define,ENABLE_PMF))
524$(eval $(call add_define,ENABLE_PSCI_STAT))
525$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
526$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
527$(eval $(call add_define,ENABLE_SVE_FOR_NS))
528$(eval $(call add_define,ERROR_DEPRECATED))
529$(eval $(call add_define,GICV2_G0_FOR_EL3))
530$(eval $(call add_define,HW_ASSISTED_COHERENCY))
531$(eval $(call add_define,LOAD_IMAGE_V2))
532$(eval $(call add_define,LOG_LEVEL))
533$(eval $(call add_define,NS_TIMER_SWITCH))
534$(eval $(call add_define,PL011_GENERIC_UART))
535$(eval $(call add_define,PLAT_${PLAT}))
536$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
537$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
538$(eval $(call add_define,RESET_TO_BL31))
539$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
540$(eval $(call add_define,ENABLE_SPM))
541$(eval $(call add_define,SPD_${SPD}))
542$(eval $(call add_define,SPIN_ON_BL1_EXIT))
543$(eval $(call add_define,TRUSTED_BOARD_BOOT))
544$(eval $(call add_define,USE_COHERENT_MEM))
545$(eval $(call add_define,USE_TBBR_DEFS))
546$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
547$(eval $(call add_define,BL2_AT_EL3))
548
549# Define the EL3_PAYLOAD_BASE flag only if it is provided.
550ifdef EL3_PAYLOAD_BASE
551        $(eval $(call add_define,EL3_PAYLOAD_BASE))
552else
553        # Define the PRELOADED_BL33_BASE flag only if it is provided and
554        # EL3_PAYLOAD_BASE is not defined, as it has priority.
555        ifdef PRELOADED_BL33_BASE
556                $(eval $(call add_define,PRELOADED_BL33_BASE))
557        endif
558endif
559# Define the AARCH32/AARCH64 flag based on the ARCH flag
560ifeq (${ARCH},aarch32)
561        $(eval $(call add_define,AARCH32))
562else
563        $(eval $(call add_define,AARCH64))
564endif
565
566################################################################################
567# Build targets
568################################################################################
569
570.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip fwu_fip certtool dtbs
571.SUFFIXES:
572
573all: msg_start
574
575msg_start:
576	@echo "Building ${PLAT}"
577
578# Check if deprecated declarations should be treated as error or not.
579ifeq (${ERROR_DEPRECATED},0)
580    TF_CFLAGS		+= 	-Wno-error=deprecated-declarations
581endif
582
583# Expand build macros for the different images
584ifeq (${NEED_BL1},yes)
585$(eval $(call MAKE_BL,1))
586endif
587
588ifeq (${NEED_BL2},yes)
589ifeq (${BL2_AT_EL3}, 0)
590FIP_BL2_ARGS := tb-fw
591endif
592
593$(if ${BL2}, $(eval $(call MAKE_TOOL_ARGS,2,${BL2},${FIP_BL2_ARGS})),\
594	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
595endif
596
597ifeq (${NEED_SCP_BL2},yes)
598$(eval $(call FIP_ADD_IMG,SCP_BL2,--scp-fw))
599endif
600
601ifeq (${NEED_BL31},yes)
602BL31_SOURCES += ${SPD_SOURCES}
603$(if ${BL31}, $(eval $(call MAKE_TOOL_ARGS,31,${BL31},soc-fw)),\
604	$(eval $(call MAKE_BL,31,soc-fw)))
605endif
606
607# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
608# build system will call FIP_ADD_IMG to print a warning message and abort the
609# process. Note that the dependency on BL32 applies to the FIP only.
610ifeq (${NEED_BL32},yes)
611$(if ${BL32}, $(eval $(call MAKE_TOOL_ARGS,32,${BL32},tos-fw)),\
612	$(if ${BL32_SOURCES}, $(eval $(call MAKE_BL,32,tos-fw)),\
613		$(eval $(call FIP_ADD_IMG,BL32,--tos-fw))))
614endif
615
616# Add the BL33 image if required by the platform
617ifeq (${NEED_BL33},yes)
618$(eval $(call FIP_ADD_IMG,BL33,--nt-fw))
619endif
620
621ifeq (${NEED_BL2U},yes)
622BL2U_PATH	:= $(if ${BL2U},${BL2U},$(call IMG_BIN,2u))
623$(if ${BL2U}, ,$(eval $(call MAKE_BL,2u)))
624$(eval $(call FWU_FIP_ADD_PAYLOAD,${BL2U_PATH},--ap-fwu-cfg))
625endif
626
627# Expand build macros for the different images
628ifeq (${NEED_FDT},yes)
629$(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
630$(eval $(call MAKE_FDT))
631dtbs: $(DTBS)
632endif
633
634locate-checkpatch:
635ifndef CHECKPATCH
636	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
637else
638ifeq (,$(wildcard ${CHECKPATCH}))
639	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
640endif
641endif
642
643clean:
644	@echo "  CLEAN"
645	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
646	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
647	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
648
649realclean distclean:
650	@echo "  REALCLEAN"
651	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
652	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
653	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
654	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
655
656checkcodebase:		locate-checkpatch
657	@echo "  CHECKING STYLE"
658	@if test -d .git ; then						\
659		git ls-files | grep -E -v 'libfdt|stdlib|docs|\.md' |	\
660		while read GIT_FILE ;					\
661		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
662		done ;							\
663	else								\
664		 find . -type f -not -iwholename "*.git*"		\
665		 -not -iwholename "*build*"				\
666		 -not -iwholename "*libfdt*"				\
667		 -not -iwholename "*stdlib*"				\
668		 -not -iwholename "*docs*"				\
669		 -not -iwholename "*.md"				\
670		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
671	fi
672
673checkpatch:		locate-checkpatch
674	@echo "  CHECKING STYLE"
675	${Q}git format-patch --stdout ${BASE_COMMIT}..HEAD -- ${CHECK_PATHS} | ${CHECKPATCH} - || true
676
677certtool: ${CRTTOOL}
678
679.PHONY: ${CRTTOOL}
680${CRTTOOL}:
681	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH}
682	@${ECHO_BLANK_LINE}
683	@echo "Built $@ successfully"
684	@${ECHO_BLANK_LINE}
685
686ifneq (${GENERATE_COT},0)
687certificates: ${CRT_DEPS} ${CRTTOOL}
688	${Q}${CRTTOOL} ${CRT_ARGS}
689	@${ECHO_BLANK_LINE}
690	@echo "Built $@ successfully"
691	@echo "Certificates can be found in ${BUILD_PLAT}"
692	@${ECHO_BLANK_LINE}
693endif
694
695${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
696	${Q}${FIPTOOL} create ${FIP_ARGS} $@
697	${Q}${FIPTOOL} info $@
698	@${ECHO_BLANK_LINE}
699	@echo "Built $@ successfully"
700	@${ECHO_BLANK_LINE}
701
702ifneq (${GENERATE_COT},0)
703fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
704	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
705	@${ECHO_BLANK_LINE}
706	@echo "Built $@ successfully"
707	@echo "FWU certificates can be found in ${BUILD_PLAT}"
708	@${ECHO_BLANK_LINE}
709endif
710
711${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
712	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
713	${Q}${FIPTOOL} info $@
714	@${ECHO_BLANK_LINE}
715	@echo "Built $@ successfully"
716	@${ECHO_BLANK_LINE}
717
718fiptool: ${FIPTOOL}
719fip: ${BUILD_PLAT}/${FIP_NAME}
720fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
721
722.PHONY: ${FIPTOOL}
723${FIPTOOL}:
724	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
725
726cscope:
727	@echo "  CSCOPE"
728	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
729	${Q}cscope -b -q -k
730
731help:
732	@echo "usage: ${MAKE} PLAT=<${PLATFORM_LIST}> [OPTIONS] [TARGET]"
733	@echo ""
734	@echo "PLAT is used to specify which platform you wish to build."
735	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
736	@echo ""
737	@echo "Please refer to the User Guide for a list of all supported options."
738	@echo "Note that the build system doesn't track dependencies for build "
739	@echo "options. Therefore, if any of the build options are changed "
740	@echo "from a previous build, a clean build must be performed."
741	@echo ""
742	@echo "Supported Targets:"
743	@echo "  all            Build all individual bootloader binaries"
744	@echo "  bl1            Build the BL1 binary"
745	@echo "  bl2            Build the BL2 binary"
746	@echo "  bl2u           Build the BL2U binary"
747	@echo "  bl31           Build the BL31 binary"
748	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
749	@echo "                 this builds secure payload specified by AARCH32_SP"
750	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
751	@echo "  fip            Build the Firmware Image Package (FIP)"
752	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
753	@echo "  checkcodebase  Check the coding style of the entire source tree"
754	@echo "  checkpatch     Check the coding style on changes in the current"
755	@echo "                 branch against BASE_COMMIT (default origin/master)"
756	@echo "  clean          Clean the build for the selected platform"
757	@echo "  cscope         Generate cscope index"
758	@echo "  distclean      Remove all build artifacts for all platforms"
759	@echo "  certtool       Build the Certificate generation tool"
760	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
761	@echo "  dtbs           Build the Flattened device tree (if required for the platform)"
762	@echo ""
763	@echo "Note: most build targets require PLAT to be set to a specific platform."
764	@echo ""
765	@echo "example: build all targets for the FVP platform:"
766	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
767