blob: 95f556af904f969e062902c5b3293d83e7bf1641 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Ruari Phipps9f1952c2020-08-24 11:32:32 +01002# Copyright (c) 2018-2021, 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 Pappireddy9a150a82021-05-12 16:55:21 -05009VERSION_MINOR := 5
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
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100111# Only platform fvp supports cactus_mm, quark
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100112ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000113include spm/cactus_mm/cactus_mm.mk
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000114include spm/quark/quark.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100115endif
116
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100117# cactus and ivy are supported on platforms: fvp, tc0
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100118ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
119include spm/cactus/cactus.mk
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100120include spm/ivy/ivy.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100121endif
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)
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000183march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
184march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100185else
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000186march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
187march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100188endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200189
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000190# Get architecture feature modifiers
191arch-features = ${ARM_ARCH_FEATURE}
192
193# Set the compiler's architecture feature modifiers
194ifneq ($(arch-features), none)
195ifeq ($(ARCH), aarch32)
196march32-directive := $(march32-directive)+$(arch-features)
197else
198march64-directive := $(march64-directive)+$(arch-features)
199endif
200# Print features
201$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
202endif # arch-features
203
Joel Hutton6a6f4832019-04-08 15:46:36 +0100204COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
205COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
206
207COMMON_ASFLAGS_aarch32 := ${march32-directive}
208COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200209
210COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
211 -Werror -Wmissing-include-dirs \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000212 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
213 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200214COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
215 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
216 -std=gnu99 -Os
217COMMON_CFLAGS += -ffunction-sections -fdata-sections
218
219# Get the content of CFLAGS user defined value last so they are appended after
220# the options defined in the Makefile
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000221COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200222
223COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
224
225CC := ${CROSS_COMPILE}gcc
226CPP := ${CROSS_COMPILE}cpp
227AS := ${CROSS_COMPILE}gcc
228AR := ${CROSS_COMPILE}ar
229LD := ${CROSS_COMPILE}ld
230OC := ${CROSS_COMPILE}objcopy
231OD := ${CROSS_COMPILE}objdump
232NM := ${CROSS_COMPILE}nm
233PP := ${CROSS_COMPILE}gcc
234
235################################################################################
236
Mark Dykese7810b52020-06-03 15:46:55 -0500237TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200238TFTF_INCLUDES += ${PLAT_INCLUDES}
239TFTF_CFLAGS += ${COMMON_CFLAGS}
240TFTF_ASFLAGS += ${COMMON_ASFLAGS}
241TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500242TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200243
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100244ifneq (${BP_OPTION},none)
245TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
246NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
247NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
248CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
249CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
250IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
251QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000252endif
253
Mark Dykese7810b52020-06-03 15:46:55 -0500254ifeq ($(SMC_FUZZING), 1)
255TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
256endif
257
Olivier Deprez231115d2020-02-03 11:27:01 +0100258#####################################################################################
259ifneq ($(findstring gcc,$(notdir $(LD))),)
260 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
261else
262 PIE_LDFLAGS += -pie --no-dynamic-linker
263endif
264
265#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000266NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200267NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
268NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
269NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
270NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
271
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000272NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200273NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
274NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
275NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
276NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
277
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000278CACTUS_MM_SOURCES += ${LIBC_SRCS}
279CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
280CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
281CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
282CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
283
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000284CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200285CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100286CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200287CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100288CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200289
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000290IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000291IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100292IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000293IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100294IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000295
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000296QUARK_SOURCES += ${LIBC_SRCS}
297QUARK_INCLUDES += ${PLAT_INCLUDES}
298QUARK_CFLAGS += ${COMMON_CFLAGS}
299QUARK_ASFLAGS += ${COMMON_ASFLAGS}
300QUARK_LDFLAGS += ${COMMON_LDFLAGS}
301
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200302.PHONY: locate-checkpatch
303locate-checkpatch:
304ifndef CHECKPATCH
305 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
306else
307ifeq (,$(wildcard ${CHECKPATCH}))
308 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
309endif
310endif
311
312.PHONY: clean
313clean:
314 @echo " CLEAN"
315 ${Q}rm -rf ${BUILD_PLAT}
316 ${MAKE} -C el3_payload clean
317
318.PHONY: realclean distclean
319realclean distclean:
320 @echo " REALCLEAN"
321 ${Q}rm -rf ${BUILD_BASE}
322 ${Q}rm -f ${CURDIR}/cscope.*
323 ${MAKE} -C el3_payload distclean
324
325.PHONY: checkcodebase
326checkcodebase: locate-checkpatch
327 @echo " CHECKING STYLE"
328 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500329 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200330 while read GIT_FILE ; \
331 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
332 done ; \
333 else \
334 find . -type f -not -iwholename "*.git*" \
335 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500336 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000337 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200338 -not -iwholename "*docs*" \
339 -not -iwholename "*.md" \
340 -not -iwholename "*.rst" \
341 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
342 fi
343
344.PHONY: checkpatch
345checkpatch: locate-checkpatch
346 @echo " CHECKING STYLE"
347 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
348 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
349 printf "\n[*] Checking style of '$$commit'\n\n"; \
350 git log --format=email "$$commit~..$$commit" \
351 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
352 git diff --format=email "$$commit~..$$commit" \
353 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
354 done
355
356ifneq (${FIRMWARE_UPDATE},1)
357.PHONY: ns_bl1u ns_bl2u
358ns_bl1u ns_bl2u:
359 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
360 on this platform."
361 @exit 1
362endif
363
364ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000365.PHONY: cactus_mm
366cactus_mm:
367 @echo "ERROR: $@ is supported only on AArch64 FVP."
368 @exit 1
369
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000370.PHONY: quark
371quark:
372 @echo "ERROR: $@ is supported only on AArch64 FVP."
373 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200374endif
375
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100376ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
377.PHONY: cactus
378cactus:
379 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
380 @exit 1
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100381
382.PHONY: ivy
383ivy:
384 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
385 @exit 1
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100386endif
387
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200388MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
389
390define MAKE_C
391
392$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
393$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
394
Bence Szépkúti537b3582019-11-29 18:23:56 +0100395$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200396 @echo " CC $$<"
397 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
398
399-include $(DEP)
400endef
401
402
403define MAKE_S
404
405$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
406$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
407
Bence Szépkúti537b3582019-11-29 18:23:56 +0100408$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200409 @echo " AS $$<"
410 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
411
412-include $(DEP)
413endef
414
415
416define MAKE_LD
417
418$(eval DEP := $(1).d)
419
Bence Szépkúti537b3582019-11-29 18:23:56 +0100420$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200421 @echo " PP $$<"
422 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
423
424-include $(DEP)
425endef
426
427
428define MAKE_OBJS
429 $(eval C_OBJS := $(filter %.c,$(2)))
430 $(eval REMAIN := $(filter-out %.c,$(2)))
431 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
432
433 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
434 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
435 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
436
437 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
438endef
439
440
441# NOTE: The line continuation '\' is required in the next define otherwise we
442# end up with a line-feed characer at the end of the last c filename.
443# Also bare this issue in mind if extending the list of supported filetypes.
444define SOURCES_TO_OBJS
445 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
446 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
447endef
448
449define uppercase
450$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
451endef
452
453define MAKE_IMG
454 $(eval IMG_PREFIX := $(call uppercase, $(1)))
455 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
456 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
457 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500458 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200459 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
460 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
461 $(eval ELF := $(BUILD_DIR)/$(1).elf)
462 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
463 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
464
465 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
466 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
467
468$(BUILD_DIR) :
469 $$(Q)mkdir -p "$$@"
470
471$(ELF) : $(OBJS) $(LINKERFILE)
472 @echo " LD $$@"
473 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
474 const char version_string[] = "${VERSION_STRING}";' | \
475 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
476 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
477 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
478
479$(DUMP) : $(ELF)
480 @echo " OD $$@"
481 $${Q}$${OD} -dx $$< > $$@
482
483$(BIN) : $(ELF)
484 @echo " BIN $$@"
485 $$(Q)$$(OC) -O binary $$< $$@
486 @echo
487 @echo "Built $$@ successfully"
488 @echo
489
490.PHONY : $(1)
491$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
492
493all : $(1)
494
495endef
496
497$(AUTOGEN_DIR):
498 $(Q)mkdir -p "$@"
499
500$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
501 @echo " AUTOGEN $@"
502 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 -0500503ifeq ($(SMC_FUZZING), 1)
504 $(Q)mkdir -p ${BUILD_PLAT}/smcf
505 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
506 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow01d5c79cc2021-06-23 16:10:22 -0500507 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
508 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykese7810b52020-06-03 15:46:55 -0500509endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200510
511$(eval $(call MAKE_IMG,tftf))
512
513ifeq ($(FIRMWARE_UPDATE), 1)
514 $(eval $(call MAKE_IMG,ns_bl1u))
515 $(eval $(call MAKE_IMG,ns_bl2u))
516endif
517
518ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000519 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200520 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000521 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000522 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200523endif
524
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100525ifeq (${ARCH}-${PLAT},aarch64-tc0)
526 $(eval $(call MAKE_IMG,cactus))
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100527 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100528endif
529
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200530# The EL3 test payload is only supported in AArch64. It has an independent build
531# system.
532.PHONY: el3_payload
533ifneq (${ARCH},aarch32)
534el3_payload: $(BUILD_DIR)
535 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
536 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
537
538all: el3_payload
539endif
540
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200541doc:
542 @echo " BUILD DOCUMENTATION"
543 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
544
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200545.PHONY: cscope
546cscope:
547 @echo " CSCOPE"
548 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
549 ${Q}cscope -b -q -k
550
551.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500552.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200553help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500554 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandovald8711ca2020-07-14 11:00:31 -0500555<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500556 echo ""
557 echo "PLAT is used to specify which platform you wish to build."
558 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
559 echo ""
560 echo "Supported Targets:"
561 echo " all Build all supported binaries for this platform"
562 echo " (i.e. TFTF and FWU images)"
563 echo " tftf Build the TFTF image"
564 echo " ns_bl1u Build the NS_BL1U image"
565 echo " ns_bl2u Build the NS_BL2U image"
566 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
567 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
568 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
569 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
570 echo " el3_payload Build the EL3 test payload"
571 echo " checkcodebase Check the coding style of the entire source tree"
572 echo " checkpatch Check the coding style on changes in the current"
573 echo " branch against BASE_COMMIT (default origin/master)"
574 echo " doc Build html based documentation using Sphinx tool"
575 echo " clean Clean the build for the selected platform"
576 echo " cscope Generate cscope index"
577 echo " distclean Remove all build artifacts for all platforms"
578 echo " help_tests List all possible sets of tests"
579 echo ""
580 echo "note: most build targets require PLAT to be set to a specific platform."
581 echo ""
582 echo "example: build all targets for the FVP platform:"
583 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"