blob: bccd45a8ebc1a718cfe5662b2e61342dbeb3f281 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Alexei Fedorov52fd7332020-01-08 14:02:18 +00002# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# TFTF Version
8VERSION_MAJOR := 2
Madhukar Pappireddy0ab15ae2020-04-19 23:58:39 -05009VERSION_MINOR := 3
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
Leonardo Sandoval667fd722020-09-11 12:50:19 -050011MAKE_HELPERS_DIRECTORY := make_helpers/
12include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
13
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020014################################################################################
15# Default values for build configurations, and their dependencies
16################################################################################
17
Leonardo Sandoval667fd722020-09-11 12:50:19 -050018include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20PLAT := ${DEFAULT_PLAT}
21
22# Assertions enabled for DEBUG builds by default
23ENABLE_ASSERTIONS := ${DEBUG}
24
25################################################################################
26# Checkpatch script options
27################################################################################
28
29CHECKCODE_ARGS := --no-patch
30# Do not check the coding style on imported library files or documentation files
31INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Mark Dykese7810b52020-06-03 15:46:55 -050032 include/lib/libfdt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000033 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 $(wildcard include/lib/*)))
35LIB_DIRS_TO_CHECK := $(sort $(filter-out \
36 lib/compiler-rt \
Mark Dykese7810b52020-06-03 15:46:55 -050037 lib/libfdt% \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000038 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020039 $(wildcard lib/*)))
40ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
41 lib \
42 include \
43 docs \
44 %.md \
45 %.rst, \
46 $(wildcard *)))
47CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
48 ${INC_LIB_DIRS_TO_CHECK} \
49 ${LIB_DIRS_TO_CHECK}
50
51ifeq (${V},0)
52 Q=@
53else
54 Q=
55endif
56export Q
57
58ifneq (${DEBUG}, 0)
59 BUILD_TYPE := debug
60 # Use LOG_LEVEL_INFO by default for debug builds
61 LOG_LEVEL := 40
62else
63 BUILD_TYPE := release
64 # Use LOG_LEVEL_ERROR by default for release builds
65 LOG_LEVEL := 20
66endif
67
68# Default build string (git branch and commit)
69ifeq (${BUILD_STRING},)
70 BUILD_STRING := $(shell git log -n 1 --pretty=format:"%h")
71endif
72
73VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
74
75BUILD_BASE := ./build
76BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
77
78PLAT_MAKEFILE := platform.mk
79# Generate the platforms list by recursively searching for all directories
80# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
81# char and strip out the final '|'.
82PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
83 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
84 sed -r 's/\|$$//')
85
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020086DOCS_PATH := docs
87
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020088ifeq (${PLAT},)
89 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
90endif
91PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
92PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
93ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
94 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
95endif
96
97.PHONY: all
98all: msg_start
99
100.PHONY: msg_start
101msg_start:
102 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200103 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200104
105# Include test images makefiles.
106include tftf/framework/framework.mk
107include tftf/tests/tests.mk
108include fwu/ns_bl1u/ns_bl1u.mk
109include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100110
111# Only platform fvp supports cactus_mm, ivy, quark
112ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000113include spm/cactus_mm/cactus_mm.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000114include spm/ivy/ivy.mk
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000115include spm/quark/quark.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100116endif
117
118# cactus is supported on platforms: fvp, tc0
119ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
120include spm/cactus/cactus.mk
121endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200122
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000123################################################################################
124# Include libc
125################################################################################
126include lib/libc/libc.mk
127
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200128# Include platform specific makefile last because:
129# - the platform makefile may use all previous definitions in this file.
130# - the platform makefile may wish overwriting some of them.
131include ${PLAT_MAKEFILE_FULL}
132
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200133.SUFFIXES:
134
135################################################################################
136# Build options checks
137################################################################################
138$(eval $(call assert_boolean,DEBUG))
139$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
140$(eval $(call assert_boolean,FIRMWARE_UPDATE))
141$(eval $(call assert_boolean,FWU_BL_TEST))
142$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200143$(eval $(call assert_boolean,USE_NVM))
144
145################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100146# Process build options
147################################################################################
148
149# Process BRANCH_PROTECTION value and set
150# Pointer Authentication and Branch Target Identification flags
151include branch_protection.mk
152
153################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200154# Add definitions to the cpp preprocessor based on the current build options.
155# This is done after including the platform specific makefile to allow the
156# platform to overwrite the default options
157################################################################################
158$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
159$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
160$(eval $(call add_define,TFTF_DEFINES,DEBUG))
161$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100162$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000163$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200164$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
165$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
166$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200167$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
168
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200169################################################################################
170
171# Assembler, compiler and linker flags shared across all test images.
172COMMON_ASFLAGS :=
173COMMON_CFLAGS :=
174COMMON_LDFLAGS :=
175
176ifeq (${DEBUG},1)
177COMMON_CFLAGS += -g
178COMMON_ASFLAGS += -g -Wa,--gdwarf-2
179endif
180
Joel Hutton6a6f4832019-04-08 15:46:36 +0100181# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
182ifeq (${ARM_ARCH_MINOR},0)
183march32-directive = -march=armv8-a
184march64-directive = -march=armv8-a
185else
186march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a
187march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a
188endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200189
Joel Hutton6a6f4832019-04-08 15:46:36 +0100190COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
191COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
192
193COMMON_ASFLAGS_aarch32 := ${march32-directive}
194COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200195
196COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
197 -Werror -Wmissing-include-dirs \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000198 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
199 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200200COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
201 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
202 -std=gnu99 -Os
203COMMON_CFLAGS += -ffunction-sections -fdata-sections
204
205# Get the content of CFLAGS user defined value last so they are appended after
206# the options defined in the Makefile
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000207COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200208
209COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
210
211CC := ${CROSS_COMPILE}gcc
212CPP := ${CROSS_COMPILE}cpp
213AS := ${CROSS_COMPILE}gcc
214AR := ${CROSS_COMPILE}ar
215LD := ${CROSS_COMPILE}ld
216OC := ${CROSS_COMPILE}objcopy
217OD := ${CROSS_COMPILE}objdump
218NM := ${CROSS_COMPILE}nm
219PP := ${CROSS_COMPILE}gcc
220
221################################################################################
222
Mark Dykese7810b52020-06-03 15:46:55 -0500223TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200224TFTF_INCLUDES += ${PLAT_INCLUDES}
225TFTF_CFLAGS += ${COMMON_CFLAGS}
226TFTF_ASFLAGS += ${COMMON_ASFLAGS}
227TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500228TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200229
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100230ifneq (${BP_OPTION},none)
231TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
232NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
233NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
234CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
235CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
236IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
237QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000238endif
239
Mark Dykese7810b52020-06-03 15:46:55 -0500240ifeq ($(SMC_FUZZING), 1)
241TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
242endif
243
Olivier Deprez231115d2020-02-03 11:27:01 +0100244#####################################################################################
245ifneq ($(findstring gcc,$(notdir $(LD))),)
246 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
247else
248 PIE_LDFLAGS += -pie --no-dynamic-linker
249endif
250
251#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000252NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200253NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
254NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
255NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
256NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
257
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000258NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200259NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
260NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
261NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
262NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
263
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000264CACTUS_MM_SOURCES += ${LIBC_SRCS}
265CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
266CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
267CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
268CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
269
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000270CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200271CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100272CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200273CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100274CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200275
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000276IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000277IVY_INCLUDES += ${PLAT_INCLUDES}
278IVY_CFLAGS += ${COMMON_CFLAGS}
279IVY_ASFLAGS += ${COMMON_ASFLAGS}
280IVY_LDFLAGS += ${COMMON_LDFLAGS}
281
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000282QUARK_SOURCES += ${LIBC_SRCS}
283QUARK_INCLUDES += ${PLAT_INCLUDES}
284QUARK_CFLAGS += ${COMMON_CFLAGS}
285QUARK_ASFLAGS += ${COMMON_ASFLAGS}
286QUARK_LDFLAGS += ${COMMON_LDFLAGS}
287
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200288.PHONY: locate-checkpatch
289locate-checkpatch:
290ifndef CHECKPATCH
291 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
292else
293ifeq (,$(wildcard ${CHECKPATCH}))
294 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
295endif
296endif
297
298.PHONY: clean
299clean:
300 @echo " CLEAN"
301 ${Q}rm -rf ${BUILD_PLAT}
302 ${MAKE} -C el3_payload clean
303
304.PHONY: realclean distclean
305realclean distclean:
306 @echo " REALCLEAN"
307 ${Q}rm -rf ${BUILD_BASE}
308 ${Q}rm -f ${CURDIR}/cscope.*
309 ${MAKE} -C el3_payload distclean
310
311.PHONY: checkcodebase
312checkcodebase: locate-checkpatch
313 @echo " CHECKING STYLE"
314 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500315 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200316 while read GIT_FILE ; \
317 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
318 done ; \
319 else \
320 find . -type f -not -iwholename "*.git*" \
321 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500322 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000323 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200324 -not -iwholename "*docs*" \
325 -not -iwholename "*.md" \
326 -not -iwholename "*.rst" \
327 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
328 fi
329
330.PHONY: checkpatch
331checkpatch: locate-checkpatch
332 @echo " CHECKING STYLE"
333 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
334 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
335 printf "\n[*] Checking style of '$$commit'\n\n"; \
336 git log --format=email "$$commit~..$$commit" \
337 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
338 git diff --format=email "$$commit~..$$commit" \
339 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
340 done
341
342ifneq (${FIRMWARE_UPDATE},1)
343.PHONY: ns_bl1u ns_bl2u
344ns_bl1u ns_bl2u:
345 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
346 on this platform."
347 @exit 1
348endif
349
350ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000351.PHONY: cactus_mm
352cactus_mm:
353 @echo "ERROR: $@ is supported only on AArch64 FVP."
354 @exit 1
355
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000356.PHONY: ivy
357ivy:
358 @echo "ERROR: $@ is supported only on AArch64 FVP."
359 @exit 1
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000360
361.PHONY: quark
362quark:
363 @echo "ERROR: $@ is supported only on AArch64 FVP."
364 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200365endif
366
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100367ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
368.PHONY: cactus
369cactus:
370 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
371 @exit 1
372endif
373
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200374MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
375
376define MAKE_C
377
378$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
379$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
380
Bence Szépkúti537b3582019-11-29 18:23:56 +0100381$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200382 @echo " CC $$<"
383 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
384
385-include $(DEP)
386endef
387
388
389define MAKE_S
390
391$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
392$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
393
Bence Szépkúti537b3582019-11-29 18:23:56 +0100394$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200395 @echo " AS $$<"
396 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
397
398-include $(DEP)
399endef
400
401
402define MAKE_LD
403
404$(eval DEP := $(1).d)
405
Bence Szépkúti537b3582019-11-29 18:23:56 +0100406$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200407 @echo " PP $$<"
408 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
409
410-include $(DEP)
411endef
412
413
414define MAKE_OBJS
415 $(eval C_OBJS := $(filter %.c,$(2)))
416 $(eval REMAIN := $(filter-out %.c,$(2)))
417 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
418
419 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
420 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
421 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
422
423 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
424endef
425
426
427# NOTE: The line continuation '\' is required in the next define otherwise we
428# end up with a line-feed characer at the end of the last c filename.
429# Also bare this issue in mind if extending the list of supported filetypes.
430define SOURCES_TO_OBJS
431 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
432 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
433endef
434
435define uppercase
436$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
437endef
438
439define MAKE_IMG
440 $(eval IMG_PREFIX := $(call uppercase, $(1)))
441 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
442 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
443 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500444 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200445 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
446 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
447 $(eval ELF := $(BUILD_DIR)/$(1).elf)
448 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
449 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
450
451 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
452 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
453
454$(BUILD_DIR) :
455 $$(Q)mkdir -p "$$@"
456
457$(ELF) : $(OBJS) $(LINKERFILE)
458 @echo " LD $$@"
459 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
460 const char version_string[] = "${VERSION_STRING}";' | \
461 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
462 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
463 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
464
465$(DUMP) : $(ELF)
466 @echo " OD $$@"
467 $${Q}$${OD} -dx $$< > $$@
468
469$(BIN) : $(ELF)
470 @echo " BIN $$@"
471 $$(Q)$$(OC) -O binary $$< $$@
472 @echo
473 @echo "Built $$@ successfully"
474 @echo
475
476.PHONY : $(1)
477$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
478
479all : $(1)
480
481endef
482
483$(AUTOGEN_DIR):
484 $(Q)mkdir -p "$@"
485
486$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
487 @echo " AUTOGEN $@"
488 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
Mark Dykese7810b52020-06-03 15:46:55 -0500489ifeq ($(SMC_FUZZING), 1)
490 $(Q)mkdir -p ${BUILD_PLAT}/smcf
491 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
492 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
493 --redefine-sym _binary___build_fvp_debug_smcf_dtb_start=_binary___dtb_start \
494 --redefine-sym _binary___build_fvp_debug_smcf_dtb_end=_binary___dtb_end
495endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200496
497$(eval $(call MAKE_IMG,tftf))
498
499ifeq ($(FIRMWARE_UPDATE), 1)
500 $(eval $(call MAKE_IMG,ns_bl1u))
501 $(eval $(call MAKE_IMG,ns_bl2u))
502endif
503
504ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000505 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200506 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000507 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000508 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200509endif
510
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100511ifeq (${ARCH}-${PLAT},aarch64-tc0)
512 $(eval $(call MAKE_IMG,cactus))
513endif
514
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200515# The EL3 test payload is only supported in AArch64. It has an independent build
516# system.
517.PHONY: el3_payload
518ifneq (${ARCH},aarch32)
519el3_payload: $(BUILD_DIR)
520 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
521 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
522
523all: el3_payload
524endif
525
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200526doc:
527 @echo " BUILD DOCUMENTATION"
528 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
529
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200530.PHONY: cscope
531cscope:
532 @echo " CSCOPE"
533 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
534 ${Q}cscope -b -q -k
535
536.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500537.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200538help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500539 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandovald8711ca2020-07-14 11:00:31 -0500540<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500541 echo ""
542 echo "PLAT is used to specify which platform you wish to build."
543 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
544 echo ""
545 echo "Supported Targets:"
546 echo " all Build all supported binaries for this platform"
547 echo " (i.e. TFTF and FWU images)"
548 echo " tftf Build the TFTF image"
549 echo " ns_bl1u Build the NS_BL1U image"
550 echo " ns_bl2u Build the NS_BL2U image"
551 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
552 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
553 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
554 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
555 echo " el3_payload Build the EL3 test payload"
556 echo " checkcodebase Check the coding style of the entire source tree"
557 echo " checkpatch Check the coding style on changes in the current"
558 echo " branch against BASE_COMMIT (default origin/master)"
559 echo " doc Build html based documentation using Sphinx tool"
560 echo " clean Clean the build for the selected platform"
561 echo " cscope Generate cscope index"
562 echo " distclean Remove all build artifacts for all platforms"
563 echo " help_tests List all possible sets of tests"
564 echo ""
565 echo "note: most build targets require PLAT to be set to a specific platform."
566 echo ""
567 echo "example: build all targets for the FVP platform:"
568 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"