blob: 1ebc172a8d427317cb6f31d2904a8e82fe72c212 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001#
Dan Handleye83b0ca2014-01-14 18:17:09 +00002# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# Redistributions of source code must retain the above copyright notice, this
8# list of conditions and the following disclaimer.
9#
10# Redistributions in binary form must reproduce the above copyright notice,
11# this list of conditions and the following disclaimer in the documentation
12# and/or other materials provided with the distribution.
13#
14# Neither the name of ARM nor the names of its contributors may be used
15# to endorse or promote products derived from this software without specific
16# prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31# Decrease the verbosity of the make script
32# can be made verbose by passing V=1 at the make command line
33ifdef V
James Morrisseyeaaeece2013-11-01 13:56:59 +000034 KBUILD_VERBOSE = ${V}
Achin Gupta4f6ad662013-10-25 09:08:21 +010035else
36 KBUILD_VERBOSE = 0
37endif
38
Ian Spray36eaaf32014-01-30 17:25:28 +000039CHECKPATCH_ARGS = --no-tree --no-signoff
40CHECKCODE_ARGS = --no-patch --no-tree --no-signoff
41
James Morrisseyeaaeece2013-11-01 13:56:59 +000042ifeq "${KBUILD_VERBOSE}" "0"
Achin Gupta4f6ad662013-10-25 09:08:21 +010043 Q=@
Ian Spray36eaaf32014-01-30 17:25:28 +000044 CHECKCODE_ARGS += --no-summary --terse
Achin Gupta4f6ad662013-10-25 09:08:21 +010045else
46 Q=
47endif
48
49DEBUG ?= 0
James Morrisseyeaaeece2013-11-01 13:56:59 +000050
51ifneq (${DEBUG}, 0)
52 BUILD_TYPE := debug
53else
54 BUILD_TYPE := release
55endif
56
Ryan Harkind7a6b0f2014-01-13 14:40:13 +000057BL_COMMON_OBJS := misc_helpers.o \
58 cache_helpers.o \
59 tlb_helpers.o \
60 std.o \
61 bl_common.o \
James Morrisseyf2f9bb52014-02-10 16:18:59 +000062 platform_helpers.o \
63 io_storage.o
Ryan Harkind7a6b0f2014-01-13 14:40:13 +000064
Ryan Harkin25cff832014-01-13 12:37:03 +000065ARCH ?= aarch64
Achin Gupta4f6ad662013-10-25 09:08:21 +010066
Ryan Harkin25cff832014-01-13 12:37:03 +000067# By default, build all platforms available
68PLAT ?= all
Achin Gupta4f6ad662013-10-25 09:08:21 +010069
Ryan Harkin25cff832014-01-13 12:37:03 +000070BUILD_BASE := ./build
71BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
72BUILD_BL1 := ${BUILD_PLAT}/bl1
73BUILD_BL2 := ${BUILD_PLAT}/bl2
74BUILD_BL31 := ${BUILD_PLAT}/bl31
75BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31}
Achin Gupta4f6ad662013-10-25 09:08:21 +010076
Ryan Harkin25cff832014-01-13 12:37:03 +000077PLATFORMS := $(shell ls -I common plat/)
Ryan Harkin72ee3312014-01-15 16:55:07 +000078HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g')
79
Ryan Harkin25cff832014-01-13 12:37:03 +000080ifeq (${PLAT},)
81 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
82endif
83ifeq ($(findstring ${PLAT},${PLATFORMS} all),)
84 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
85endif
86
87ifeq (${PLAT},all)
88all: ${PLATFORMS}
89else
Harry Liebelf58ad362014-01-10 18:00:33 +000090all: msg_start bl1 bl2 bl31 fip
Ryan Harkin25cff832014-01-13 12:37:03 +000091endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010092
Ryan Harkin25cff832014-01-13 12:37:03 +000093msg_start:
94 @echo "Building ${PLAT}"
Achin Gupta4f6ad662013-10-25 09:08:21 +010095
Ryan Harkin25cff832014-01-13 12:37:03 +000096${PLATFORMS}:
97 ${MAKE} PLAT=$@ all
Achin Gupta4f6ad662013-10-25 09:08:21 +010098
Ryan Harkin25cff832014-01-13 12:37:03 +000099ifneq (${PLAT},all)
100 $(info Including ${PLAT}/platform.mk)
101 include plat/${PLAT}/platform.mk
102 $(info Including bl1.mk)
103 include bl1/bl1.mk
104 $(info Including bl2.mk)
105 include bl2/bl2.mk
106 $(info Including bl31.mk)
107 include bl31/bl31.mk
108endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100109
Harry Liebelf58ad362014-01-10 18:00:33 +0000110.PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31 cscope locate-checkpatch checkcodebase checkpatch fiptool fip locate-bl33
James Morrisseyeaaeece2013-11-01 13:56:59 +0000111.SUFFIXES:
112
113
Ryan Harkin25cff832014-01-13 12:37:03 +0000114BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
115BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
116BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
James Morrisseyeaaeece2013-11-01 13:56:59 +0000117BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE})
118BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE})
119BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE})
120BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE})
121BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE})
122BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE})
Achin Gupta4f6ad662013-10-25 09:08:21 +0100123
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000124
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000125INCLUDES += -Ilib/include/ \
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000126 -Idrivers/io \
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000127 -Iinclude/${ARCH}/ \
128 -Iinclude/ \
129 -Iarch/system/gic \
130 -Icommon/psci \
131 -Iinclude/stdlib \
132 -Iinclude/stdlib/sys \
133 -Iplat/${PLAT} \
134 ${PLAT_INCLUDES}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135
Harry Liebel0af6d642013-12-20 18:51:12 +0000136ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
Sandrine Bailleuxdf64a552014-02-11 13:31:33 +0000137 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES} \
138 -DDEBUG=${DEBUG}
Harry Liebel4f603682014-01-14 18:11:48 +0000139CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \
140 -Werror -mgeneral-regs-only -std=c99 -c -Os \
141 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100142
Sandrine Bailleux3e850a82013-11-20 11:50:48 +0000143LDFLAGS += --fatal-warnings -O1
James Morrisseyeaaeece2013-11-01 13:56:59 +0000144BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT}
145BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT}
146BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100147
148
149vpath %.ld.S bl1:bl2:bl31
150vpath %.c bl1:bl2:bl31
151vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
152vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
153
154
James Morrisseyeaaeece2013-11-01 13:56:59 +0000155ifneq (${DEBUG}, 0)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100156#CFLAGS += -g -O0
157CFLAGS += -g
158# -save-temps -fverbose-asm
159ASFLAGS += -g -Wa,--gdwarf-2
James Morrissey40a6f642014-02-10 14:24:36 +0000160else
161CFLAGS += -DNDEBUG=1
Achin Gupta4f6ad662013-10-25 09:08:21 +0100162endif
163
164
James Morrisseyeaaeece2013-11-01 13:56:59 +0000165CC := ${CROSS_COMPILE}gcc
166CPP := ${CROSS_COMPILE}cpp
167AS := ${CROSS_COMPILE}gcc
168AR := ${CROSS_COMPILE}ar
169LD := ${CROSS_COMPILE}ld
170OC := ${CROSS_COMPILE}objcopy
171OD := ${CROSS_COMPILE}objdump
172NM := ${CROSS_COMPILE}nm
173PP := ${CROSS_COMPILE}gcc -E ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174
175
Ryan Harkin25cff832014-01-13 12:37:03 +0000176bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin
177bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin
178bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin
Achin Gupta4f6ad662013-10-25 09:08:21 +0100179
Ian Spray36eaaf32014-01-30 17:25:28 +0000180BASE_COMMIT ?= origin/master
181
Harry Liebelf58ad362014-01-10 18:00:33 +0000182# Variables for use with Firmware Image Package
183FIPTOOLPATH ?= tools/fip_create
184FIPTOOL ?= ${FIPTOOLPATH}/fip_create
185fiptool: ${FIPTOOL}
186fip: ${BUILD_PLAT}/fip.bin
187
Ryan Harkin25cff832014-01-13 12:37:03 +0000188ifeq (${PLAT},all)
189 ifeq (${MAKECMDGOALS},clean)
190 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
191 endif
192endif
Ian Spray36eaaf32014-01-30 17:25:28 +0000193
194locate-checkpatch:
195ifndef CHECKPATCH
196 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
197else
198ifeq (,$(wildcard ${CHECKPATCH}))
199 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
200endif
201endif
202
Harry Liebelf58ad362014-01-10 18:00:33 +0000203locate-bl33:
204ifndef BL33
205 $(error "Please set BL33 to point to the Normal World binary, eg: BL33=../uefi/FVP_AARCH64_EFI.fd")
206else
207ifeq (,$(wildcard ${BL33}))
208 $(error "The file BL33 points to cannot be found (${BL33})")
209endif
210endif
211
212
Achin Gupta4f6ad662013-10-25 09:08:21 +0100213clean:
214 @echo " CLEAN"
Ryan Harkin25cff832014-01-13 12:37:03 +0000215 ${Q}rm -rf ${BUILD_PLAT}
Harry Liebelf58ad362014-01-10 18:00:33 +0000216 ${Q}make -C ${FIPTOOLPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +0100217
James Morrisseyeaaeece2013-11-01 13:56:59 +0000218realclean distclean:
219 @echo " REALCLEAN"
220 ${Q}rm -rf ${BUILD_BASE}
Joakim Bech35fab8c2014-01-23 14:51:49 +0100221 ${Q}rm -f ${CURDIR}/cscope.*
Harry Liebelf58ad362014-01-10 18:00:33 +0000222 ${Q}make -C ${FIPTOOLPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +0100223
224dump:
225 @echo " OBJDUMP"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000226 ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump
227 ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump
228 ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump
229
Ian Spray36eaaf32014-01-30 17:25:28 +0000230checkcodebase: locate-checkpatch
231 @echo " CHECKING STYLE"
232 @if test -d .git ; then \
233 git ls-files | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ; \
234 else \
235 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
236 fi
237
238checkpatch: locate-checkpatch
239 @echo " CHECKING STYLE"
240 @git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true
241
Harry Liebelf58ad362014-01-10 18:00:33 +0000242${FIPTOOL}:
243 @echo " BUILDING FIRMWARE IMAGE PACKAGE TOOL $@"
244 @echo
245 ${Q}make -C ${FIPTOOLPATH}
246 @echo
247
James Morrisseyeaaeece2013-11-01 13:56:59 +0000248${BUILD_DIRS}:
249 ${Q}mkdir -p "$@"
Achin Gupta4f6ad662013-10-25 09:08:21 +0100250
James Morrisseyeaaeece2013-11-01 13:56:59 +0000251
252${BUILD_BL1}/%.o: %.S
253 @echo " AS $<"
254 ${Q}${AS} ${ASFLAGS} -c $< -o $@
255
256${BUILD_BL2}/%.o: %.S
257 @echo " AS $<"
258 ${Q}${AS} ${ASFLAGS} -c $< -o $@
259
260${BUILD_BL31}/%.o: %.S
Achin Gupta4f6ad662013-10-25 09:08:21 +0100261 @echo " AS $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000262 ${Q}${AS} ${ASFLAGS} -c $< -o $@
263
264${BUILD_BL1}/%.o: %.c
265 @echo " CC $<"
266 ${Q}${CC} ${CFLAGS} -c $< -o $@
267
268${BUILD_BL2}/%.o: %.c
269 @echo " CC $<"
270 ${Q}${CC} ${CFLAGS} -c $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100271
James Morrisseyeaaeece2013-11-01 13:56:59 +0000272${BUILD_BL31}/%.o: %.c
Achin Gupta4f6ad662013-10-25 09:08:21 +0100273 @echo " CC $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000274 ${Q}${CC} ${CFLAGS} -c $< -o $@
275
276${BUILD_BL1}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000277 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000278 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
279
280${BUILD_BL2}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000281 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000282 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100283
James Morrisseyeaaeece2013-11-01 13:56:59 +0000284${BUILD_BL31}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000285 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000286 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100287
288
James Morrisseyeaaeece2013-11-01 13:56:59 +0000289${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100290 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000291 ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS}
292
293${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE}
294 @echo " LD $@"
295 ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100296
James Morrisseyeaaeece2013-11-01 13:56:59 +0000297${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100298 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000299 ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS}
300
Ryan Harkin25cff832014-01-13 12:37:03 +0000301${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf
302 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000303 ${Q}${OC} -O binary $< $@
304 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100305 @echo "Built $@ successfully"
306 @echo
307
Ryan Harkin25cff832014-01-13 12:37:03 +0000308${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf
309 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000310 ${Q}${OC} -O binary $< $@
311 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100312 @echo "Built $@ successfully"
313 @echo
314
Ryan Harkin25cff832014-01-13 12:37:03 +0000315${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf
316 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000317 ${Q}${OC} -O binary $< $@
318 @echo
319 @echo "Built $@ successfully"
320 @echo
Ryan Harkin72ee3312014-01-15 16:55:07 +0000321
Harry Liebelf58ad362014-01-10 18:00:33 +0000322${BUILD_PLAT}/fip.bin: bl2 bl31 locate-bl33 ${FIPTOOL}
323 @echo " CREATE FIRMWARE IMAGE PACKAGE $@"
324 @echo
325 ${Q}${FIPTOOL} --dump \
326 --bl2 ${BUILD_PLAT}/bl2.bin \
327 --bl31 ${BUILD_PLAT}/bl31.bin \
328 --bl33 ${BL33} \
329 $@
330 @echo
331
332
Joakim Bech35fab8c2014-01-23 14:51:49 +0100333cscope:
334 @echo " CSCOPE"
335 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
336 ${Q}cscope -b -q -k
337
Ryan Harkin72ee3312014-01-15 16:55:07 +0000338help:
Ian Spray36eaaf32014-01-30 17:25:28 +0000339 @echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch|dump>"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000340 @echo ""
341 @echo "PLAT is used to specify which platform you wish to build."
342 @echo ""
343 @echo "Supported Targets:"
Ian Spray36eaaf32014-01-30 17:25:28 +0000344 @echo " all Build the BL1, BL2 and BL31 binaries"
345 @echo " bl1 Build the BL1 binary"
346 @echo " bl2 Build the BL2 binary"
347 @echo " bl31 Build the BL31 binary"
348 @echo " checkcodebase Check the coding style of the entire source tree"
349 @echo " checkpatch Check the coding style on changes in the current"
350 @echo " branch against BASE_COMMIT (default origin/master)"
351 @echo " clean Clean the build for the selected platform"
Harry Liebelf58ad362014-01-10 18:00:33 +0000352 @echo " cscope Generate cscope index"
Ian Spray36eaaf32014-01-30 17:25:28 +0000353 @echo " distclean Remove all build artifacts for all platforms"
354 @echo " dump Generate object file dumps"
Harry Liebelf58ad362014-01-10 18:00:33 +0000355 @echo " fiptool Build the Firmware Image Package(FIP) creation tool"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000356 @echo ""
357 @echo "note: most build targets require PLAT to be set to a specific platform."
358 @echo ""
359 @echo "example: build all targets for the FVP platform:"
360 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"