blob: 71be313288ee1a8a7d94b506fea992d98625ba8a [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
James Morrisseyeaaeece2013-11-01 13:56:59 +000039ifeq "${KBUILD_VERBOSE}" "0"
Achin Gupta4f6ad662013-10-25 09:08:21 +010040 Q=@
41else
42 Q=
43endif
44
45DEBUG ?= 0
James Morrisseyeaaeece2013-11-01 13:56:59 +000046
47ifneq (${DEBUG}, 0)
48 BUILD_TYPE := debug
49else
50 BUILD_TYPE := release
51endif
52
Ryan Harkind7a6b0f2014-01-13 14:40:13 +000053BL_COMMON_OBJS := misc_helpers.o \
54 cache_helpers.o \
55 tlb_helpers.o \
56 std.o \
57 bl_common.o \
58 platform_helpers.o
59
Ryan Harkin25cff832014-01-13 12:37:03 +000060ARCH ?= aarch64
Achin Gupta4f6ad662013-10-25 09:08:21 +010061
Ryan Harkin25cff832014-01-13 12:37:03 +000062# By default, build all platforms available
63PLAT ?= all
Achin Gupta4f6ad662013-10-25 09:08:21 +010064
Ryan Harkin25cff832014-01-13 12:37:03 +000065BUILD_BASE := ./build
66BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
67BUILD_BL1 := ${BUILD_PLAT}/bl1
68BUILD_BL2 := ${BUILD_PLAT}/bl2
69BUILD_BL31 := ${BUILD_PLAT}/bl31
70BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31}
Achin Gupta4f6ad662013-10-25 09:08:21 +010071
Ryan Harkin25cff832014-01-13 12:37:03 +000072PLATFORMS := $(shell ls -I common plat/)
73ifeq (${PLAT},)
74 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
75endif
76ifeq ($(findstring ${PLAT},${PLATFORMS} all),)
77 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
78endif
79
80ifeq (${PLAT},all)
81all: ${PLATFORMS}
82else
83all: msg_start bl1 bl2 bl31
84endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010085
Ryan Harkin25cff832014-01-13 12:37:03 +000086msg_start:
87 @echo "Building ${PLAT}"
Achin Gupta4f6ad662013-10-25 09:08:21 +010088
Ryan Harkin25cff832014-01-13 12:37:03 +000089${PLATFORMS}:
90 ${MAKE} PLAT=$@ all
Achin Gupta4f6ad662013-10-25 09:08:21 +010091
Ryan Harkin25cff832014-01-13 12:37:03 +000092ifneq (${PLAT},all)
93 $(info Including ${PLAT}/platform.mk)
94 include plat/${PLAT}/platform.mk
95 $(info Including bl1.mk)
96 include bl1/bl1.mk
97 $(info Including bl2.mk)
98 include bl2/bl2.mk
99 $(info Including bl31.mk)
100 include bl31/bl31.mk
101endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100102
Ryan Harkin25cff832014-01-13 12:37:03 +0000103.PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31
James Morrisseyeaaeece2013-11-01 13:56:59 +0000104.SUFFIXES:
105
106
Ryan Harkin25cff832014-01-13 12:37:03 +0000107BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
108BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
109BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
James Morrisseyeaaeece2013-11-01 13:56:59 +0000110BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE})
111BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE})
112BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE})
113BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE})
114BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE})
115BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE})
Achin Gupta4f6ad662013-10-25 09:08:21 +0100116
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000117INCLUDES += -Ilib/include/ \
118 -Iinclude/${ARCH}/ \
119 -Iinclude/ \
120 -Iarch/system/gic \
121 -Icommon/psci \
122 -Iinclude/stdlib \
123 -Iinclude/stdlib/sys \
124 -Iplat/${PLAT} \
125 ${PLAT_INCLUDES}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100126
Harry Liebel0af6d642013-12-20 18:51:12 +0000127ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
Harry Liebel4f603682014-01-14 18:11:48 +0000128 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES}
129CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \
130 -Werror -mgeneral-regs-only -std=c99 -c -Os \
131 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132
Sandrine Bailleux3e850a82013-11-20 11:50:48 +0000133LDFLAGS += --fatal-warnings -O1
James Morrisseyeaaeece2013-11-01 13:56:59 +0000134BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT}
135BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT}
136BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100137
138
139vpath %.ld.S bl1:bl2:bl31
140vpath %.c bl1:bl2:bl31
141vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
142vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
143
144
James Morrisseyeaaeece2013-11-01 13:56:59 +0000145ifneq (${DEBUG}, 0)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100146#CFLAGS += -g -O0
147CFLAGS += -g
148# -save-temps -fverbose-asm
149ASFLAGS += -g -Wa,--gdwarf-2
150endif
151
152
James Morrisseyeaaeece2013-11-01 13:56:59 +0000153CC := ${CROSS_COMPILE}gcc
154CPP := ${CROSS_COMPILE}cpp
155AS := ${CROSS_COMPILE}gcc
156AR := ${CROSS_COMPILE}ar
157LD := ${CROSS_COMPILE}ld
158OC := ${CROSS_COMPILE}objcopy
159OD := ${CROSS_COMPILE}objdump
160NM := ${CROSS_COMPILE}nm
161PP := ${CROSS_COMPILE}gcc -E ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100162
163
Ryan Harkin25cff832014-01-13 12:37:03 +0000164bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin
165bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin
166bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin
Achin Gupta4f6ad662013-10-25 09:08:21 +0100167
Ryan Harkin25cff832014-01-13 12:37:03 +0000168ifeq (${PLAT},all)
169 ifeq (${MAKECMDGOALS},clean)
170 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
171 endif
172endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100173clean:
174 @echo " CLEAN"
Ryan Harkin25cff832014-01-13 12:37:03 +0000175 ${Q}rm -rf ${BUILD_PLAT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100176
James Morrisseyeaaeece2013-11-01 13:56:59 +0000177realclean distclean:
178 @echo " REALCLEAN"
179 ${Q}rm -rf ${BUILD_BASE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100180
181dump:
182 @echo " OBJDUMP"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000183 ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump
184 ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump
185 ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump
186
187${BUILD_DIRS}:
188 ${Q}mkdir -p "$@"
Achin Gupta4f6ad662013-10-25 09:08:21 +0100189
James Morrisseyeaaeece2013-11-01 13:56:59 +0000190
191${BUILD_BL1}/%.o: %.S
192 @echo " AS $<"
193 ${Q}${AS} ${ASFLAGS} -c $< -o $@
194
195${BUILD_BL2}/%.o: %.S
196 @echo " AS $<"
197 ${Q}${AS} ${ASFLAGS} -c $< -o $@
198
199${BUILD_BL31}/%.o: %.S
Achin Gupta4f6ad662013-10-25 09:08:21 +0100200 @echo " AS $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000201 ${Q}${AS} ${ASFLAGS} -c $< -o $@
202
203${BUILD_BL1}/%.o: %.c
204 @echo " CC $<"
205 ${Q}${CC} ${CFLAGS} -c $< -o $@
206
207${BUILD_BL2}/%.o: %.c
208 @echo " CC $<"
209 ${Q}${CC} ${CFLAGS} -c $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100210
James Morrisseyeaaeece2013-11-01 13:56:59 +0000211${BUILD_BL31}/%.o: %.c
Achin Gupta4f6ad662013-10-25 09:08:21 +0100212 @echo " CC $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000213 ${Q}${CC} ${CFLAGS} -c $< -o $@
214
215${BUILD_BL1}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000216 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000217 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
218
219${BUILD_BL2}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000220 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000221 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100222
James Morrisseyeaaeece2013-11-01 13:56:59 +0000223${BUILD_BL31}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000224 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000225 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100226
227
James Morrisseyeaaeece2013-11-01 13:56:59 +0000228${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100229 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000230 ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS}
231
232${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE}
233 @echo " LD $@"
234 ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100235
James Morrisseyeaaeece2013-11-01 13:56:59 +0000236${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100237 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000238 ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS}
239
Ryan Harkin25cff832014-01-13 12:37:03 +0000240${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf
241 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000242 ${Q}${OC} -O binary $< $@
243 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100244 @echo "Built $@ successfully"
245 @echo
246
Ryan Harkin25cff832014-01-13 12:37:03 +0000247${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf
248 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000249 ${Q}${OC} -O binary $< $@
250 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100251 @echo "Built $@ successfully"
252 @echo
253
Ryan Harkin25cff832014-01-13 12:37:03 +0000254${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf
255 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000256 ${Q}${OC} -O binary $< $@
257 @echo
258 @echo "Built $@ successfully"
259 @echo