blob: 455a81f695122bcf6ab2057ad4cc41a0c50f6844 [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
11################################################################################
12# Default values for build configurations, and their dependencies
13################################################################################
14
15include defaults.mk
16
17PLAT := ${DEFAULT_PLAT}
18
19# Assertions enabled for DEBUG builds by default
20ENABLE_ASSERTIONS := ${DEBUG}
21
22################################################################################
23# Checkpatch script options
24################################################################################
25
26CHECKCODE_ARGS := --no-patch
27# Do not check the coding style on imported library files or documentation files
28INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Mark Dykese7810b52020-06-03 15:46:55 -050029 include/lib/libfdt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000030 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020031 $(wildcard include/lib/*)))
32LIB_DIRS_TO_CHECK := $(sort $(filter-out \
33 lib/compiler-rt \
Mark Dykese7810b52020-06-03 15:46:55 -050034 lib/libfdt% \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000035 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020036 $(wildcard lib/*)))
37ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
38 lib \
39 include \
40 docs \
41 %.md \
42 %.rst, \
43 $(wildcard *)))
44CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
45 ${INC_LIB_DIRS_TO_CHECK} \
46 ${LIB_DIRS_TO_CHECK}
47
48ifeq (${V},0)
49 Q=@
50else
51 Q=
52endif
53export Q
54
55ifneq (${DEBUG}, 0)
56 BUILD_TYPE := debug
57 # Use LOG_LEVEL_INFO by default for debug builds
58 LOG_LEVEL := 40
59else
60 BUILD_TYPE := release
61 # Use LOG_LEVEL_ERROR by default for release builds
62 LOG_LEVEL := 20
63endif
64
65# Default build string (git branch and commit)
66ifeq (${BUILD_STRING},)
67 BUILD_STRING := $(shell git log -n 1 --pretty=format:"%h")
68endif
69
70VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
71
72BUILD_BASE := ./build
73BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
74
75PLAT_MAKEFILE := platform.mk
76# Generate the platforms list by recursively searching for all directories
77# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
78# char and strip out the final '|'.
79PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
80 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
81 sed -r 's/\|$$//')
82
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020083DOCS_PATH := docs
84
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020085# Convenience function for adding build definitions
86# $(eval $(call add_define,BAR_DEFINES,FOO)) will have:
87# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
88# inside the BAR_DEFINES variable.
89define add_define
90$(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),)
91endef
92
93# Convenience function for verifying option has a boolean value
94# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
95define assert_boolean
96$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
97endef
98
Alexei Fedorov7cc25872020-06-02 16:35:36 +010099# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
100# $(2) and assign the sequence to $(1)
101define CREATE_SEQ
102$(if $(word $(2), $($(1))),\
103 $(eval $(1) += $(words $($(1))))\
104 $(eval $(1) := $(filter-out 0,$($(1)))),\
105 $(eval $(1) += $(words $($(1))))\
106 $(call CREATE_SEQ,$(1),$(2))\
107)
108endef
109
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200110ifeq (${PLAT},)
111 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
112endif
113PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
114PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
115ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
116 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
117endif
118
119.PHONY: all
120all: msg_start
121
122.PHONY: msg_start
123msg_start:
124 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200125 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200126
127# Include test images makefiles.
128include tftf/framework/framework.mk
129include tftf/tests/tests.mk
130include fwu/ns_bl1u/ns_bl1u.mk
131include fwu/ns_bl2u/ns_bl2u.mk
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000132include spm/cactus_mm/cactus_mm.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200133include spm/cactus/cactus.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000134include spm/ivy/ivy.mk
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000135include spm/quark/quark.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200136
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000137################################################################################
138# Include libc
139################################################################################
140include lib/libc/libc.mk
141
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200142# Include platform specific makefile last because:
143# - the platform makefile may use all previous definitions in this file.
144# - the platform makefile may wish overwriting some of them.
145include ${PLAT_MAKEFILE_FULL}
146
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200147.SUFFIXES:
148
149################################################################################
150# Build options checks
151################################################################################
152$(eval $(call assert_boolean,DEBUG))
153$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
154$(eval $(call assert_boolean,FIRMWARE_UPDATE))
155$(eval $(call assert_boolean,FWU_BL_TEST))
156$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200157$(eval $(call assert_boolean,USE_NVM))
158
159################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100160# Process build options
161################################################################################
162
163# Process BRANCH_PROTECTION value and set
164# Pointer Authentication and Branch Target Identification flags
165include branch_protection.mk
166
167################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200168# Add definitions to the cpp preprocessor based on the current build options.
169# This is done after including the platform specific makefile to allow the
170# platform to overwrite the default options
171################################################################################
172$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
173$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
174$(eval $(call add_define,TFTF_DEFINES,DEBUG))
175$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100176$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000177$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200178$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
179$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
180$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200181$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
182
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200183################################################################################
184
185# Assembler, compiler and linker flags shared across all test images.
186COMMON_ASFLAGS :=
187COMMON_CFLAGS :=
188COMMON_LDFLAGS :=
189
190ifeq (${DEBUG},1)
191COMMON_CFLAGS += -g
192COMMON_ASFLAGS += -g -Wa,--gdwarf-2
193endif
194
Joel Hutton6a6f4832019-04-08 15:46:36 +0100195# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
196ifeq (${ARM_ARCH_MINOR},0)
197march32-directive = -march=armv8-a
198march64-directive = -march=armv8-a
199else
200march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a
201march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a
202endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200203
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}
292IVY_CFLAGS += ${COMMON_CFLAGS}
293IVY_ASFLAGS += ${COMMON_ASFLAGS}
294IVY_LDFLAGS += ${COMMON_LDFLAGS}
295
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
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200370.PHONY: cactus
371cactus:
372 @echo "ERROR: $@ is supported only on AArch64 FVP."
373 @exit 1
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000374
375.PHONY: ivy
376ivy:
377 @echo "ERROR: $@ is supported only on AArch64 FVP."
378 @exit 1
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000379
380.PHONY: quark
381quark:
382 @echo "ERROR: $@ is supported only on AArch64 FVP."
383 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200384endif
385
386MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
387
388define MAKE_C
389
390$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
391$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
392
Bence Szépkúti537b3582019-11-29 18:23:56 +0100393$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200394 @echo " CC $$<"
395 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
396
397-include $(DEP)
398endef
399
400
401define MAKE_S
402
403$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
404$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
405
Bence Szépkúti537b3582019-11-29 18:23:56 +0100406$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200407 @echo " AS $$<"
408 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
409
410-include $(DEP)
411endef
412
413
414define MAKE_LD
415
416$(eval DEP := $(1).d)
417
Bence Szépkúti537b3582019-11-29 18:23:56 +0100418$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200419 @echo " PP $$<"
420 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
421
422-include $(DEP)
423endef
424
425
426define MAKE_OBJS
427 $(eval C_OBJS := $(filter %.c,$(2)))
428 $(eval REMAIN := $(filter-out %.c,$(2)))
429 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
430
431 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
432 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
433 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
434
435 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
436endef
437
438
439# NOTE: The line continuation '\' is required in the next define otherwise we
440# end up with a line-feed characer at the end of the last c filename.
441# Also bare this issue in mind if extending the list of supported filetypes.
442define SOURCES_TO_OBJS
443 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
444 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
445endef
446
447define uppercase
448$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
449endef
450
451define MAKE_IMG
452 $(eval IMG_PREFIX := $(call uppercase, $(1)))
453 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
454 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
455 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500456 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200457 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
458 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
459 $(eval ELF := $(BUILD_DIR)/$(1).elf)
460 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
461 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
462
463 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
464 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
465
466$(BUILD_DIR) :
467 $$(Q)mkdir -p "$$@"
468
469$(ELF) : $(OBJS) $(LINKERFILE)
470 @echo " LD $$@"
471 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
472 const char version_string[] = "${VERSION_STRING}";' | \
473 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
474 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
475 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
476
477$(DUMP) : $(ELF)
478 @echo " OD $$@"
479 $${Q}$${OD} -dx $$< > $$@
480
481$(BIN) : $(ELF)
482 @echo " BIN $$@"
483 $$(Q)$$(OC) -O binary $$< $$@
484 @echo
485 @echo "Built $$@ successfully"
486 @echo
487
488.PHONY : $(1)
489$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
490
491all : $(1)
492
493endef
494
495$(AUTOGEN_DIR):
496 $(Q)mkdir -p "$@"
497
498$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
499 @echo " AUTOGEN $@"
500 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 -0500501ifeq ($(SMC_FUZZING), 1)
502 $(Q)mkdir -p ${BUILD_PLAT}/smcf
503 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
504 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
505 --redefine-sym _binary___build_fvp_debug_smcf_dtb_start=_binary___dtb_start \
506 --redefine-sym _binary___build_fvp_debug_smcf_dtb_end=_binary___dtb_end
507endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200508
509$(eval $(call MAKE_IMG,tftf))
510
511ifeq ($(FIRMWARE_UPDATE), 1)
512 $(eval $(call MAKE_IMG,ns_bl1u))
513 $(eval $(call MAKE_IMG,ns_bl2u))
514endif
515
516ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000517 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200518 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000519 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000520 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200521endif
522
523# The EL3 test payload is only supported in AArch64. It has an independent build
524# system.
525.PHONY: el3_payload
526ifneq (${ARCH},aarch32)
527el3_payload: $(BUILD_DIR)
528 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
529 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
530
531all: el3_payload
532endif
533
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200534doc:
535 @echo " BUILD DOCUMENTATION"
536 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
537
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200538.PHONY: cscope
539cscope:
540 @echo " CSCOPE"
541 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
542 ${Q}cscope -b -q -k
543
544.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500545.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200546help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500547 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandovald8711ca2020-07-14 11:00:31 -0500548<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500549 echo ""
550 echo "PLAT is used to specify which platform you wish to build."
551 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
552 echo ""
553 echo "Supported Targets:"
554 echo " all Build all supported binaries for this platform"
555 echo " (i.e. TFTF and FWU images)"
556 echo " tftf Build the TFTF image"
557 echo " ns_bl1u Build the NS_BL1U image"
558 echo " ns_bl2u Build the NS_BL2U image"
559 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
560 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
561 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
562 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
563 echo " el3_payload Build the EL3 test payload"
564 echo " checkcodebase Check the coding style of the entire source tree"
565 echo " checkpatch Check the coding style on changes in the current"
566 echo " branch against BASE_COMMIT (default origin/master)"
567 echo " doc Build html based documentation using Sphinx tool"
568 echo " clean Clean the build for the selected platform"
569 echo " cscope Generate cscope index"
570 echo " distclean Remove all build artifacts for all platforms"
571 echo " help_tests List all possible sets of tests"
572 echo ""
573 echo "note: most build targets require PLAT to be set to a specific platform."
574 echo ""
575 echo "example: build all targets for the FVP platform:"
576 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"