blob: 7938318de85e7c8b2516a2d6a21a2bb299ed93cb [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 \
62 platform_helpers.o
63
Ryan Harkin25cff832014-01-13 12:37:03 +000064ARCH ?= aarch64
Achin Gupta4f6ad662013-10-25 09:08:21 +010065
Ryan Harkin25cff832014-01-13 12:37:03 +000066# By default, build all platforms available
67PLAT ?= all
Achin Gupta4f6ad662013-10-25 09:08:21 +010068
Ryan Harkin25cff832014-01-13 12:37:03 +000069BUILD_BASE := ./build
70BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
71BUILD_BL1 := ${BUILD_PLAT}/bl1
72BUILD_BL2 := ${BUILD_PLAT}/bl2
73BUILD_BL31 := ${BUILD_PLAT}/bl31
74BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31}
Achin Gupta4f6ad662013-10-25 09:08:21 +010075
Ryan Harkin25cff832014-01-13 12:37:03 +000076PLATFORMS := $(shell ls -I common plat/)
Ryan Harkin72ee3312014-01-15 16:55:07 +000077HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g')
78
Ryan Harkin25cff832014-01-13 12:37:03 +000079ifeq (${PLAT},)
80 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
81endif
82ifeq ($(findstring ${PLAT},${PLATFORMS} all),)
83 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
84endif
85
86ifeq (${PLAT},all)
87all: ${PLATFORMS}
88else
89all: msg_start bl1 bl2 bl31
90endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010091
Ryan Harkin25cff832014-01-13 12:37:03 +000092msg_start:
93 @echo "Building ${PLAT}"
Achin Gupta4f6ad662013-10-25 09:08:21 +010094
Ryan Harkin25cff832014-01-13 12:37:03 +000095${PLATFORMS}:
96 ${MAKE} PLAT=$@ all
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
Ryan Harkin25cff832014-01-13 12:37:03 +000098ifneq (${PLAT},all)
99 $(info Including ${PLAT}/platform.mk)
100 include plat/${PLAT}/platform.mk
101 $(info Including bl1.mk)
102 include bl1/bl1.mk
103 $(info Including bl2.mk)
104 include bl2/bl2.mk
105 $(info Including bl31.mk)
106 include bl31/bl31.mk
107endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
Ian Spray36eaaf32014-01-30 17:25:28 +0000109.PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31 cscope locate-checkpatch checkcodebase checkpatch
James Morrisseyeaaeece2013-11-01 13:56:59 +0000110.SUFFIXES:
111
112
Ryan Harkin25cff832014-01-13 12:37:03 +0000113BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
114BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
115BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
James Morrisseyeaaeece2013-11-01 13:56:59 +0000116BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE})
117BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE})
118BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE})
119BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE})
120BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE})
121BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE})
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000123INCLUDES += -Ilib/include/ \
124 -Iinclude/${ARCH}/ \
125 -Iinclude/ \
126 -Iarch/system/gic \
127 -Icommon/psci \
128 -Iinclude/stdlib \
129 -Iinclude/stdlib/sys \
130 -Iplat/${PLAT} \
131 ${PLAT_INCLUDES}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132
Harry Liebel0af6d642013-12-20 18:51:12 +0000133ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
Sandrine Bailleuxdf64a552014-02-11 13:31:33 +0000134 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES} \
135 -DDEBUG=${DEBUG}
Harry Liebel4f603682014-01-14 18:11:48 +0000136CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \
137 -Werror -mgeneral-regs-only -std=c99 -c -Os \
138 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
Sandrine Bailleux3e850a82013-11-20 11:50:48 +0000140LDFLAGS += --fatal-warnings -O1
James Morrisseyeaaeece2013-11-01 13:56:59 +0000141BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT}
142BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT}
143BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144
145
146vpath %.ld.S bl1:bl2:bl31
147vpath %.c bl1:bl2:bl31
148vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
149vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
150
151
James Morrisseyeaaeece2013-11-01 13:56:59 +0000152ifneq (${DEBUG}, 0)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100153#CFLAGS += -g -O0
154CFLAGS += -g
155# -save-temps -fverbose-asm
156ASFLAGS += -g -Wa,--gdwarf-2
157endif
158
159
James Morrisseyeaaeece2013-11-01 13:56:59 +0000160CC := ${CROSS_COMPILE}gcc
161CPP := ${CROSS_COMPILE}cpp
162AS := ${CROSS_COMPILE}gcc
163AR := ${CROSS_COMPILE}ar
164LD := ${CROSS_COMPILE}ld
165OC := ${CROSS_COMPILE}objcopy
166OD := ${CROSS_COMPILE}objdump
167NM := ${CROSS_COMPILE}nm
168PP := ${CROSS_COMPILE}gcc -E ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100169
170
Ryan Harkin25cff832014-01-13 12:37:03 +0000171bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin
172bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin
173bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174
Ian Spray36eaaf32014-01-30 17:25:28 +0000175BASE_COMMIT ?= origin/master
176
Ryan Harkin25cff832014-01-13 12:37:03 +0000177ifeq (${PLAT},all)
178 ifeq (${MAKECMDGOALS},clean)
179 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
180 endif
181endif
Ian Spray36eaaf32014-01-30 17:25:28 +0000182
183locate-checkpatch:
184ifndef CHECKPATCH
185 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
186else
187ifeq (,$(wildcard ${CHECKPATCH}))
188 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
189endif
190endif
191
Achin Gupta4f6ad662013-10-25 09:08:21 +0100192clean:
193 @echo " CLEAN"
Ryan Harkin25cff832014-01-13 12:37:03 +0000194 ${Q}rm -rf ${BUILD_PLAT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100195
James Morrisseyeaaeece2013-11-01 13:56:59 +0000196realclean distclean:
197 @echo " REALCLEAN"
198 ${Q}rm -rf ${BUILD_BASE}
Joakim Bech35fab8c2014-01-23 14:51:49 +0100199 ${Q}rm -f ${CURDIR}/cscope.*
Achin Gupta4f6ad662013-10-25 09:08:21 +0100200
201dump:
202 @echo " OBJDUMP"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000203 ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump
204 ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump
205 ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump
206
Ian Spray36eaaf32014-01-30 17:25:28 +0000207checkcodebase: locate-checkpatch
208 @echo " CHECKING STYLE"
209 @if test -d .git ; then \
210 git ls-files | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ; \
211 else \
212 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
213 fi
214
215checkpatch: locate-checkpatch
216 @echo " CHECKING STYLE"
217 @git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true
218
James Morrisseyeaaeece2013-11-01 13:56:59 +0000219${BUILD_DIRS}:
220 ${Q}mkdir -p "$@"
Achin Gupta4f6ad662013-10-25 09:08:21 +0100221
James Morrisseyeaaeece2013-11-01 13:56:59 +0000222
223${BUILD_BL1}/%.o: %.S
224 @echo " AS $<"
225 ${Q}${AS} ${ASFLAGS} -c $< -o $@
226
227${BUILD_BL2}/%.o: %.S
228 @echo " AS $<"
229 ${Q}${AS} ${ASFLAGS} -c $< -o $@
230
231${BUILD_BL31}/%.o: %.S
Achin Gupta4f6ad662013-10-25 09:08:21 +0100232 @echo " AS $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000233 ${Q}${AS} ${ASFLAGS} -c $< -o $@
234
235${BUILD_BL1}/%.o: %.c
236 @echo " CC $<"
237 ${Q}${CC} ${CFLAGS} -c $< -o $@
238
239${BUILD_BL2}/%.o: %.c
240 @echo " CC $<"
241 ${Q}${CC} ${CFLAGS} -c $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100242
James Morrisseyeaaeece2013-11-01 13:56:59 +0000243${BUILD_BL31}/%.o: %.c
Achin Gupta4f6ad662013-10-25 09:08:21 +0100244 @echo " CC $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000245 ${Q}${CC} ${CFLAGS} -c $< -o $@
246
247${BUILD_BL1}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000248 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000249 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
250
251${BUILD_BL2}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000252 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000253 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100254
James Morrisseyeaaeece2013-11-01 13:56:59 +0000255${BUILD_BL31}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000256 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000257 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100258
259
James Morrisseyeaaeece2013-11-01 13:56:59 +0000260${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100261 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000262 ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS}
263
264${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE}
265 @echo " LD $@"
266 ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100267
James Morrisseyeaaeece2013-11-01 13:56:59 +0000268${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100269 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000270 ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS}
271
Ryan Harkin25cff832014-01-13 12:37:03 +0000272${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf
273 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000274 ${Q}${OC} -O binary $< $@
275 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100276 @echo "Built $@ successfully"
277 @echo
278
Ryan Harkin25cff832014-01-13 12:37:03 +0000279${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf
280 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000281 ${Q}${OC} -O binary $< $@
282 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100283 @echo "Built $@ successfully"
284 @echo
285
Ryan Harkin25cff832014-01-13 12:37:03 +0000286${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf
287 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000288 ${Q}${OC} -O binary $< $@
289 @echo
290 @echo "Built $@ successfully"
291 @echo
Ryan Harkin72ee3312014-01-15 16:55:07 +0000292
Joakim Bech35fab8c2014-01-23 14:51:49 +0100293cscope:
294 @echo " CSCOPE"
295 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
296 ${Q}cscope -b -q -k
297
Ryan Harkin72ee3312014-01-15 16:55:07 +0000298help:
Ian Spray36eaaf32014-01-30 17:25:28 +0000299 @echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch|dump>"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000300 @echo ""
301 @echo "PLAT is used to specify which platform you wish to build."
302 @echo ""
303 @echo "Supported Targets:"
Ian Spray36eaaf32014-01-30 17:25:28 +0000304 @echo " all Build the BL1, BL2 and BL31 binaries"
305 @echo " bl1 Build the BL1 binary"
306 @echo " bl2 Build the BL2 binary"
307 @echo " bl31 Build the BL31 binary"
308 @echo " checkcodebase Check the coding style of the entire source tree"
309 @echo " checkpatch Check the coding style on changes in the current"
310 @echo " branch against BASE_COMMIT (default origin/master)"
311 @echo " clean Clean the build for the selected platform"
Joakim Bech35fab8c2014-01-23 14:51:49 +0100312 @echo " cscope Generate cscope index"
Ian Spray36eaaf32014-01-30 17:25:28 +0000313 @echo " distclean Remove all build artifacts for all platforms"
314 @echo " dump Generate object file dumps"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000315 @echo ""
316 @echo "note: most build targets require PLAT to be set to a specific platform."
317 @echo ""
318 @echo "example: build all targets for the FVP platform:"
319 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"