blob: 738a926dcb42e6f9d90dd2b8c035c4876c7ada18 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Daniel Boulby9a8c4242022-05-03 16:36:51 +01002# Copyright (c) 2018-2022, 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
Jayanth Dodderi Chidanand52439d52022-05-03 15:05:11 +01009VERSION_MINOR := 7
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
Leonardo Sandovale1693b42020-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 Sandovale1693b42020-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 Dykes9f5c50b2020-06-03 15:46:55 -050032 include/lib/libfdt \
Ambroise Vincenta2ede622019-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 Dykes9f5c50b2020-06-03 15:46:55 -050037 lib/libfdt% \
Ambroise Vincenta2ede622019-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},)
Manish V Badarkhef0e77d42022-05-24 22:54:45 +010070 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071endif
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 Bailleux7fb2e0a2020-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
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -050097
98EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
99EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
100
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101.PHONY: all
102all: msg_start
103
104.PHONY: msg_start
105msg_start:
106 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200107 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200108
109# Include test images makefiles.
110include tftf/framework/framework.mk
111include tftf/tests/tests.mk
112include fwu/ns_bl1u/ns_bl1u.mk
113include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100114
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100115# Only platform fvp supports cactus_mm, quark
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100116ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000117include spm/cactus_mm/cactus_mm.mk
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000118include spm/quark/quark.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100119endif
120
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100121# cactus and ivy are supported on platforms: fvp, tc0
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100122ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
123include spm/cactus/cactus.mk
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100124include spm/ivy/ivy.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100125endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200126
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000127################################################################################
128# Include libc
129################################################################################
130include lib/libc/libc.mk
131
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200132# Include platform specific makefile last because:
133# - the platform makefile may use all previous definitions in this file.
134# - the platform makefile may wish overwriting some of them.
135include ${PLAT_MAKEFILE_FULL}
136
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137.SUFFIXES:
138
139################################################################################
140# Build options checks
141################################################################################
142$(eval $(call assert_boolean,DEBUG))
143$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
144$(eval $(call assert_boolean,FIRMWARE_UPDATE))
145$(eval $(call assert_boolean,FWU_BL_TEST))
146$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200147$(eval $(call assert_boolean,USE_NVM))
148
149################################################################################
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100150# Process build options
151################################################################################
152
153# Process BRANCH_PROTECTION value and set
154# Pointer Authentication and Branch Target Identification flags
155include branch_protection.mk
156
157################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200158# Add definitions to the cpp preprocessor based on the current build options.
159# This is done after including the platform specific makefile to allow the
160# platform to overwrite the default options
161################################################################################
162$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
163$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
164$(eval $(call add_define,TFTF_DEFINES,DEBUG))
165$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100166$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000167$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200168$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
169$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
170$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200171$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
172
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200173################################################################################
174
175# Assembler, compiler and linker flags shared across all test images.
176COMMON_ASFLAGS :=
177COMMON_CFLAGS :=
178COMMON_LDFLAGS :=
179
180ifeq (${DEBUG},1)
Daniel Boulby9a8c4242022-05-03 16:36:51 +0100181COMMON_CFLAGS += -g -gdwarf-4
182COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200183endif
184
Joel Hutton87530242019-04-08 15:46:36 +0100185# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
186ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovfceac732020-12-07 18:13:28 +0000187march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
188march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton87530242019-04-08 15:46:36 +0100189else
Alexei Fedorovfceac732020-12-07 18:13:28 +0000190march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
191march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton87530242019-04-08 15:46:36 +0100192endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200193
Alexei Fedorovfceac732020-12-07 18:13:28 +0000194# Get architecture feature modifiers
195arch-features = ${ARM_ARCH_FEATURE}
196
197# Set the compiler's architecture feature modifiers
198ifneq ($(arch-features), none)
199ifeq ($(ARCH), aarch32)
200march32-directive := $(march32-directive)+$(arch-features)
201else
202march64-directive := $(march64-directive)+$(arch-features)
203endif
204# Print features
205$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
206endif # arch-features
207
Joel Hutton87530242019-04-08 15:46:36 +0100208COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
209COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
210
211COMMON_ASFLAGS_aarch32 := ${march32-directive}
212COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200213
214COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
215 -Werror -Wmissing-include-dirs \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000216 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
217 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200218COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
219 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
220 -std=gnu99 -Os
221COMMON_CFLAGS += -ffunction-sections -fdata-sections
222
223# Get the content of CFLAGS user defined value last so they are appended after
224# the options defined in the Makefile
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000225COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200226
227COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
228
229CC := ${CROSS_COMPILE}gcc
230CPP := ${CROSS_COMPILE}cpp
231AS := ${CROSS_COMPILE}gcc
232AR := ${CROSS_COMPILE}ar
233LD := ${CROSS_COMPILE}ld
234OC := ${CROSS_COMPILE}objcopy
235OD := ${CROSS_COMPILE}objdump
236NM := ${CROSS_COMPILE}nm
237PP := ${CROSS_COMPILE}gcc
238
239################################################################################
240
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500241TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200242TFTF_INCLUDES += ${PLAT_INCLUDES}
243TFTF_CFLAGS += ${COMMON_CFLAGS}
244TFTF_ASFLAGS += ${COMMON_ASFLAGS}
245TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500246TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200247
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100248ifneq (${BP_OPTION},none)
249TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
250NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
251NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
252CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
253CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
254IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
255QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000256endif
257
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500258ifeq ($(SMC_FUZZING), 1)
259TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
260endif
261
Olivier Deprezdb70c452020-02-03 11:27:01 +0100262#####################################################################################
263ifneq ($(findstring gcc,$(notdir $(LD))),)
264 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
265else
266 PIE_LDFLAGS += -pie --no-dynamic-linker
267endif
268
269#####################################################################################
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000270NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200271NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
272NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
273NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
274NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
275
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000276NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200277NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
278NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
279NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
280NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
281
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000282CACTUS_MM_SOURCES += ${LIBC_SRCS}
283CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
284CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
285CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
286CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
287
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000288CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200289CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100290CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200291CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100292CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200293
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000294IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000295IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phippscd924f72020-08-24 11:32:32 +0100296IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000297IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phippscd924f72020-08-24 11:32:32 +0100298IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000299
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000300QUARK_SOURCES += ${LIBC_SRCS}
301QUARK_INCLUDES += ${PLAT_INCLUDES}
302QUARK_CFLAGS += ${COMMON_CFLAGS}
303QUARK_ASFLAGS += ${COMMON_ASFLAGS}
304QUARK_LDFLAGS += ${COMMON_LDFLAGS}
305
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200306.PHONY: locate-checkpatch
307locate-checkpatch:
308ifndef CHECKPATCH
309 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
310else
311ifeq (,$(wildcard ${CHECKPATCH}))
312 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
313endif
314endif
315
316.PHONY: clean
317clean:
318 @echo " CLEAN"
319 ${Q}rm -rf ${BUILD_PLAT}
320 ${MAKE} -C el3_payload clean
321
322.PHONY: realclean distclean
323realclean distclean:
324 @echo " REALCLEAN"
325 ${Q}rm -rf ${BUILD_BASE}
326 ${Q}rm -f ${CURDIR}/cscope.*
327 ${MAKE} -C el3_payload distclean
328
329.PHONY: checkcodebase
330checkcodebase: locate-checkpatch
331 @echo " CHECKING STYLE"
332 @if test -d .git ; then \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500333 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200334 while read GIT_FILE ; \
335 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
336 done ; \
337 else \
338 find . -type f -not -iwholename "*.git*" \
339 -not -iwholename "*build*" \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500340 -not -iwholename "*libfdt*" \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000341 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200342 -not -iwholename "*docs*" \
343 -not -iwholename "*.md" \
344 -not -iwholename "*.rst" \
345 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
346 fi
347
348.PHONY: checkpatch
349checkpatch: locate-checkpatch
350 @echo " CHECKING STYLE"
351 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
352 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
353 printf "\n[*] Checking style of '$$commit'\n\n"; \
354 git log --format=email "$$commit~..$$commit" \
355 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
356 git diff --format=email "$$commit~..$$commit" \
357 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
358 done
359
360ifneq (${FIRMWARE_UPDATE},1)
361.PHONY: ns_bl1u ns_bl2u
362ns_bl1u ns_bl2u:
363 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
364 on this platform."
365 @exit 1
366endif
367
368ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000369.PHONY: cactus_mm
370cactus_mm:
371 @echo "ERROR: $@ is supported only on AArch64 FVP."
372 @exit 1
373
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000374.PHONY: quark
375quark:
376 @echo "ERROR: $@ is supported only on AArch64 FVP."
377 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200378endif
379
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100380ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
381.PHONY: cactus
382cactus:
383 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
384 @exit 1
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100385
386.PHONY: ivy
387ivy:
388 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
389 @exit 1
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100390endif
391
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200392MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
393
394define MAKE_C
395
396$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
397$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
398
Bence Szépkúti25671c22019-11-29 18:23:56 +0100399$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200400 @echo " CC $$<"
401 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
402
403-include $(DEP)
404endef
405
406
407define MAKE_S
408
409$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
410$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
411
Bence Szépkúti25671c22019-11-29 18:23:56 +0100412$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200413 @echo " AS $$<"
414 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
415
416-include $(DEP)
417endef
418
419
420define MAKE_LD
421
422$(eval DEP := $(1).d)
423
Bence Szépkúti25671c22019-11-29 18:23:56 +0100424$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200425 @echo " PP $$<"
426 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
427
428-include $(DEP)
429endef
430
431
432define MAKE_OBJS
433 $(eval C_OBJS := $(filter %.c,$(2)))
434 $(eval REMAIN := $(filter-out %.c,$(2)))
435 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
436
437 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
438 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
439 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
440
441 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
442endef
443
444
445# NOTE: The line continuation '\' is required in the next define otherwise we
446# end up with a line-feed characer at the end of the last c filename.
447# Also bare this issue in mind if extending the list of supported filetypes.
448define SOURCES_TO_OBJS
449 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
450 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
451endef
452
453define uppercase
454$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
455endef
456
457define MAKE_IMG
458 $(eval IMG_PREFIX := $(call uppercase, $(1)))
459 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
460 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
461 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500462 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200463 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
464 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
465 $(eval ELF := $(BUILD_DIR)/$(1).elf)
466 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
467 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
468
469 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
470 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
471
472$(BUILD_DIR) :
473 $$(Q)mkdir -p "$$@"
474
475$(ELF) : $(OBJS) $(LINKERFILE)
476 @echo " LD $$@"
477 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
478 const char version_string[] = "${VERSION_STRING}";' | \
479 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
480 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
481 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
482
483$(DUMP) : $(ELF)
484 @echo " OD $$@"
485 $${Q}$${OD} -dx $$< > $$@
486
487$(BIN) : $(ELF)
488 @echo " BIN $$@"
489 $$(Q)$$(OC) -O binary $$< $$@
490 @echo
491 @echo "Built $$@ successfully"
492 @echo
493
494.PHONY : $(1)
495$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
496
497all : $(1)
498
499endef
500
501$(AUTOGEN_DIR):
502 $(Q)mkdir -p "$@"
503
504$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
505 @echo " AUTOGEN $@"
506 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 Dykes9f5c50b2020-06-03 15:46:55 -0500507ifeq ($(SMC_FUZZING), 1)
508 $(Q)mkdir -p ${BUILD_PLAT}/smcf
509 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
510 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow0128e1a2b2021-06-23 16:10:22 -0500511 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
512 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500513endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200514
515$(eval $(call MAKE_IMG,tftf))
516
517ifeq ($(FIRMWARE_UPDATE), 1)
518 $(eval $(call MAKE_IMG,ns_bl1u))
519 $(eval $(call MAKE_IMG,ns_bl2u))
520endif
521
522ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000523 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200524 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000525 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000526 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200527endif
528
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100529ifeq (${ARCH}-${PLAT},aarch64-tc0)
530 $(eval $(call MAKE_IMG,cactus))
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100531 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100532endif
533
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200534# The EL3 test payload is only supported in AArch64. It has an independent build
535# system.
536.PHONY: el3_payload
537ifneq (${ARCH},aarch32)
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -0500538ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200539el3_payload: $(BUILD_DIR)
540 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
541 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
542
543all: el3_payload
544endif
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -0500545endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200546
Sandrine Bailleux7fb2e0a2020-04-21 14:45:00 +0200547doc:
548 @echo " BUILD DOCUMENTATION"
549 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
550
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200551.PHONY: cscope
552cscope:
553 @echo " CSCOPE"
554 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
555 ${Q}cscope -b -q -k
556
557.PHONY: help
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500558.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200559help:
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500560 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandoval5c882ba2020-07-14 11:00:31 -0500561<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500562 echo ""
563 echo "PLAT is used to specify which platform you wish to build."
564 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
565 echo ""
566 echo "Supported Targets:"
567 echo " all Build all supported binaries for this platform"
568 echo " (i.e. TFTF and FWU images)"
569 echo " tftf Build the TFTF image"
570 echo " ns_bl1u Build the NS_BL1U image"
571 echo " ns_bl2u Build the NS_BL2U image"
572 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
573 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
574 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
575 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
576 echo " el3_payload Build the EL3 test payload"
577 echo " checkcodebase Check the coding style of the entire source tree"
578 echo " checkpatch Check the coding style on changes in the current"
579 echo " branch against BASE_COMMIT (default origin/master)"
580 echo " doc Build html based documentation using Sphinx tool"
581 echo " clean Clean the build for the selected platform"
582 echo " cscope Generate cscope index"
583 echo " distclean Remove all build artifacts for all platforms"
584 echo " help_tests List all possible sets of tests"
585 echo ""
586 echo "note: most build targets require PLAT to be set to a specific platform."
587 echo ""
588 echo "example: build all targets for the FVP platform:"
589 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"