Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | # |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | # |
| 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 | |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 31 | # |
| 32 | # Default values for build configurations |
| 33 | # |
| 34 | |
| 35 | # Build verbosity |
| 36 | V := 0 |
| 37 | # Debug build |
| 38 | DEBUG := 0 |
| 39 | # Build architecture |
| 40 | ARCH := aarch64 |
| 41 | # Build platform |
| 42 | DEFAULT_PLAT := fvp |
| 43 | PLAT := ${DEFAULT_PLAT} |
| 44 | # SPD choice |
| 45 | SPD := none |
| 46 | # Base commit to perform code check on |
| 47 | BASE_COMMIT := origin/master |
Jeenu Viswambharan | 2da8d8b | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 48 | # NS timer register save and restore |
| 49 | NS_TIMER_SWITCH := 0 |
Vikram Kanigiri | dbad1ba | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 50 | # By default, Bl1 acts as the reset handler, not BL31 |
| 51 | RESET_TO_BL31 := 0 |
Juan Castillo | 0f21c54 | 2014-06-25 17:26:36 +0100 | [diff] [blame] | 52 | # Include FP registers in cpu context |
| 53 | CTX_INCLUDE_FPREGS := 0 |
Sandrine Bailleux | 2b98e78 | 2014-07-17 17:23:14 +0100 | [diff] [blame] | 54 | # Determine the version of ARM GIC architecture to use for interrupt management |
| 55 | # in EL3. The platform port can change this value if needed. |
| 56 | ARM_GIC_ARCH := 2 |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 57 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 58 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 59 | # Checkpatch ignores |
| 60 | CHECK_IGNORE = --ignore COMPLEX_MACRO |
| 61 | |
| 62 | CHECKPATCH_ARGS = --no-tree --no-signoff ${CHECK_IGNORE} |
| 63 | CHECKCODE_ARGS = --no-patch --no-tree --no-signoff ${CHECK_IGNORE} |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 64 | |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 65 | ifeq (${V},0) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 66 | Q=@ |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 67 | CHECKCODE_ARGS += --no-summary --terse |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 68 | else |
| 69 | Q= |
| 70 | endif |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 71 | export Q |
| 72 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 73 | ifneq (${DEBUG}, 0) |
| 74 | BUILD_TYPE := debug |
| 75 | else |
| 76 | BUILD_TYPE := release |
| 77 | endif |
| 78 | |
Dan Handley | bee8241 | 2014-04-15 18:20:09 +0100 | [diff] [blame] | 79 | BL_COMMON_SOURCES := common/bl_common.c \ |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 80 | common/debug.c \ |
Soby Mathew | b79af93 | 2014-06-12 17:23:58 +0100 | [diff] [blame] | 81 | common/tf_printf.c \ |
Dan Handley | bee8241 | 2014-04-15 18:20:09 +0100 | [diff] [blame] | 82 | lib/aarch64/cache_helpers.S \ |
| 83 | lib/aarch64/misc_helpers.S \ |
Dan Handley | bee8241 | 2014-04-15 18:20:09 +0100 | [diff] [blame] | 84 | lib/aarch64/xlat_helpers.c \ |
| 85 | lib/stdlib/std.c \ |
| 86 | lib/io_storage.c \ |
| 87 | plat/common/aarch64/platform_helpers.S |
Ryan Harkin | d7a6b0f | 2014-01-13 14:40:13 +0000 | [diff] [blame] | 88 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 89 | BUILD_BASE := ./build |
| 90 | BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 91 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 92 | PLATFORMS := $(shell ls -I common plat/) |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 93 | SPDS := $(shell ls -I none services/spd) |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 94 | HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g') |
| 95 | |
Jeenu Viswambharan | 289e0da | 2014-05-16 11:38:10 +0100 | [diff] [blame] | 96 | # Convenience function for adding build definitions |
| 97 | # $(eval $(call add_define,FOO)) will have: |
| 98 | # -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise |
| 99 | define add_define |
| 100 | DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) |
| 101 | endef |
| 102 | |
| 103 | # Convenience function for verifying option has a boolean value |
| 104 | # $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 |
| 105 | define assert_boolean |
| 106 | $(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean)) |
| 107 | endef |
| 108 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 109 | ifeq (${PLAT},) |
| 110 | $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.") |
| 111 | endif |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 112 | ifeq ($(findstring ${PLAT},${PLATFORMS}),) |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 113 | $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}") |
| 114 | endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 116 | all: msg_start |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 117 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 118 | msg_start: |
| 119 | @echo "Building ${PLAT}" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 120 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 121 | include plat/${PLAT}/platform.mk |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 122 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 123 | ifdef BL1_SOURCES |
| 124 | NEED_BL1 := yes |
| 125 | include bl1/bl1.mk |
| 126 | endif |
| 127 | |
| 128 | ifdef BL2_SOURCES |
| 129 | NEED_BL2 := yes |
| 130 | include bl2/bl2.mk |
| 131 | endif |
| 132 | |
| 133 | ifdef BL31_SOURCES |
| 134 | NEED_BL31 := yes |
| 135 | include bl31/bl31.mk |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 136 | endif |
| 137 | |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 138 | # Include SPD Makefile if one has been specified |
| 139 | ifneq (${SPD},none) |
| 140 | # We expect to locate an spd.mk under the specified SPD directory |
| 141 | SPD_MAKE := $(shell m="services/spd/${SPD}/${SPD}.mk"; [ -f "$$m" ] && echo "$$m") |
| 142 | |
| 143 | ifeq (${SPD_MAKE},) |
| 144 | $(error Error: No services/spd/${SPD}/${SPD}.mk located) |
| 145 | endif |
| 146 | $(info Including ${SPD_MAKE}) |
| 147 | include ${SPD_MAKE} |
| 148 | |
| 149 | # If there's BL32 companion for the chosen SPD, and the SPD wants to build the |
| 150 | # BL2 from source, we expect that the SPD's Makefile would set NEED_BL32 |
| 151 | # variable to "yes" |
| 152 | endif |
| 153 | |
Sandrine Bailleux | 08c7ed0 | 2014-03-21 13:16:35 +0000 | [diff] [blame] | 154 | .PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 155 | .SUFFIXES: |
| 156 | |
Sandrine Bailleux | a0df63e | 2014-06-23 13:37:53 +0100 | [diff] [blame] | 157 | INCLUDES += -Iinclude/bl31 \ |
Dan Handley | 4ecca33 | 2014-04-09 12:48:25 +0100 | [diff] [blame] | 158 | -Iinclude/bl31/services \ |
| 159 | -Iinclude/bl32 \ |
| 160 | -Iinclude/bl32/payloads \ |
| 161 | -Iinclude/common \ |
| 162 | -Iinclude/drivers \ |
| 163 | -Iinclude/drivers/arm \ |
| 164 | -Iinclude/lib \ |
| 165 | -Iinclude/lib/aarch64 \ |
Dan Handley | 5f0cdb0 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 166 | -Iinclude/plat/common \ |
Ryan Harkin | d7a6b0f | 2014-01-13 14:40:13 +0000 | [diff] [blame] | 167 | -Iinclude/stdlib \ |
| 168 | -Iinclude/stdlib/sys \ |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 169 | ${PLAT_INCLUDES} \ |
| 170 | ${SPD_INCLUDES} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 171 | |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 172 | # Process DEBUG flag |
| 173 | $(eval $(call assert_boolean,DEBUG)) |
| 174 | $(eval $(call add_define,DEBUG)) |
| 175 | ifeq (${DEBUG},0) |
| 176 | $(eval $(call add_define,NDEBUG)) |
| 177 | else |
| 178 | CFLAGS += -g |
| 179 | ASFLAGS += -g -Wa,--gdwarf-2 |
| 180 | endif |
| 181 | |
Jeenu Viswambharan | 2da8d8b | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 182 | # Process NS_TIMER_SWITCH flag |
| 183 | $(eval $(call assert_boolean,NS_TIMER_SWITCH)) |
| 184 | $(eval $(call add_define,NS_TIMER_SWITCH)) |
| 185 | |
Vikram Kanigiri | dbad1ba | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 186 | # Process RESET_TO_BL31 flag |
| 187 | $(eval $(call assert_boolean,RESET_TO_BL31)) |
| 188 | $(eval $(call add_define,RESET_TO_BL31)) |
| 189 | |
Juan Castillo | 0f21c54 | 2014-06-25 17:26:36 +0100 | [diff] [blame] | 190 | # Process CTX_INCLUDE_FPREGS flag |
| 191 | $(eval $(call assert_boolean,CTX_INCLUDE_FPREGS)) |
| 192 | $(eval $(call add_define,CTX_INCLUDE_FPREGS)) |
| 193 | |
Sandrine Bailleux | 2b98e78 | 2014-07-17 17:23:14 +0100 | [diff] [blame] | 194 | # Process ARM_GIC_ARCH flag |
| 195 | $(eval $(call add_define,ARM_GIC_ARCH)) |
| 196 | |
| 197 | |
Harry Liebel | 0af6d64 | 2013-12-20 18:51:12 +0000 | [diff] [blame] | 198 | ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ |
Sandrine Bailleux | a0df63e | 2014-06-23 13:37:53 +0100 | [diff] [blame] | 199 | -Werror -Wmissing-include-dirs \ |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 200 | -mgeneral-regs-only -D__ASSEMBLY__ \ |
| 201 | ${DEFINES} ${INCLUDES} |
| 202 | CFLAGS += -nostdinc -pedantic -ffreestanding -Wall \ |
Sandrine Bailleux | a0df63e | 2014-06-23 13:37:53 +0100 | [diff] [blame] | 203 | -Werror -Wmissing-include-dirs \ |
| 204 | -mgeneral-regs-only -std=c99 -c -Os \ |
Jeenu Viswambharan | e35c404 | 2014-05-15 14:40:58 +0100 | [diff] [blame] | 205 | ${DEFINES} ${INCLUDES} |
Andrew Thoelke | dccc537 | 2014-03-18 07:13:52 +0000 | [diff] [blame] | 206 | CFLAGS += -ffunction-sections -fdata-sections |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 207 | |
Sandrine Bailleux | 3e850a8 | 2013-11-20 11:50:48 +0000 | [diff] [blame] | 208 | LDFLAGS += --fatal-warnings -O1 |
Andrew Thoelke | dccc537 | 2014-03-18 07:13:52 +0000 | [diff] [blame] | 209 | LDFLAGS += --gc-sections |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 210 | |
| 211 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 212 | CC := ${CROSS_COMPILE}gcc |
| 213 | CPP := ${CROSS_COMPILE}cpp |
| 214 | AS := ${CROSS_COMPILE}gcc |
| 215 | AR := ${CROSS_COMPILE}ar |
| 216 | LD := ${CROSS_COMPILE}ld |
| 217 | OC := ${CROSS_COMPILE}objcopy |
| 218 | OD := ${CROSS_COMPILE}objdump |
| 219 | NM := ${CROSS_COMPILE}nm |
| 220 | PP := ${CROSS_COMPILE}gcc -E ${CFLAGS} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 221 | |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 222 | # Variables for use with Firmware Image Package |
| 223 | FIPTOOLPATH ?= tools/fip_create |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 224 | FIPTOOL ?= ${FIPTOOLPATH}/fip_create |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 225 | fiptool: ${FIPTOOL} |
| 226 | fip: ${BUILD_PLAT}/fip.bin |
| 227 | |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 228 | locate-checkpatch: |
| 229 | ifndef CHECKPATCH |
| 230 | $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl") |
| 231 | else |
| 232 | ifeq (,$(wildcard ${CHECKPATCH})) |
| 233 | $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl") |
| 234 | endif |
| 235 | endif |
| 236 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 237 | clean: |
| 238 | @echo " CLEAN" |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 239 | ${Q}rm -rf ${BUILD_PLAT} |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 240 | ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 241 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 242 | realclean distclean: |
| 243 | @echo " REALCLEAN" |
| 244 | ${Q}rm -rf ${BUILD_BASE} |
Joakim Bech | 35fab8c | 2014-01-23 14:51:49 +0100 | [diff] [blame] | 245 | ${Q}rm -f ${CURDIR}/cscope.* |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 246 | ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 247 | |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 248 | checkcodebase: locate-checkpatch |
| 249 | @echo " CHECKING STYLE" |
| 250 | @if test -d .git ; then \ |
Juan Castillo | 4f2104f | 2014-06-13 17:05:10 +0100 | [diff] [blame] | 251 | git ls-files | grep -v stdlib | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ; \ |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 252 | else \ |
Juan Castillo | 4f2104f | 2014-06-13 17:05:10 +0100 | [diff] [blame] | 253 | find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -not -iwholename "*stdlib*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 254 | fi |
| 255 | |
| 256 | checkpatch: locate-checkpatch |
| 257 | @echo " CHECKING STYLE" |
| 258 | @git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true |
| 259 | |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 260 | ${FIPTOOL}: |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 261 | ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 262 | @echo |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 263 | @echo "Built $@ successfully" |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 264 | @echo |
| 265 | |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 266 | define match_goals |
| 267 | $(strip $(foreach goal,$(1),$(filter $(goal),$(MAKECMDGOALS)))) |
| 268 | endef |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 269 | |
Sandrine Bailleux | 8d2296f | 2014-03-21 14:17:51 +0000 | [diff] [blame] | 270 | # List of rules that involve building things |
| 271 | BUILD_TARGETS := all bl1 bl2 bl31 bl32 fip |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 272 | |
Sandrine Bailleux | 8d2296f | 2014-03-21 14:17:51 +0000 | [diff] [blame] | 273 | # Does the list of goals specified on the command line include a build target? |
| 274 | ifneq ($(call match_goals,${BUILD_TARGETS}),) |
| 275 | IS_ANYTHING_TO_BUILD := 1 |
| 276 | endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 277 | |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 278 | define MAKE_C |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 279 | |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 280 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
| 281 | $(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 282 | |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 283 | $(OBJ) : $(2) |
| 284 | @echo " CC $$<" |
| 285 | $$(Q)$$(CC) $$(CFLAGS) -c $$< -o $$@ |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 286 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 287 | |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 288 | $(PREREQUISITES) : $(2) |
| 289 | @echo " DEPS $$@" |
| 290 | @mkdir -p $(1) |
| 291 | $$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$< |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 292 | |
Sandrine Bailleux | 8d2296f | 2014-03-21 14:17:51 +0000 | [diff] [blame] | 293 | ifdef IS_ANYTHING_TO_BUILD |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 294 | -include $(PREREQUISITES) |
| 295 | endif |
| 296 | |
| 297 | endef |
| 298 | |
| 299 | |
| 300 | define MAKE_S |
| 301 | |
| 302 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
| 303 | $(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) |
| 304 | |
| 305 | $(OBJ) : $(2) |
| 306 | @echo " AS $$<" |
| 307 | $$(Q)$$(AS) $$(ASFLAGS) -c $$< -o $$@ |
| 308 | |
| 309 | $(PREREQUISITES) : $(2) |
| 310 | @echo " DEPS $$@" |
| 311 | @mkdir -p $(1) |
| 312 | $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(OBJ) -MF $$@ $$< |
| 313 | |
Sandrine Bailleux | 8d2296f | 2014-03-21 14:17:51 +0000 | [diff] [blame] | 314 | ifdef IS_ANYTHING_TO_BUILD |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 315 | -include $(PREREQUISITES) |
| 316 | endif |
| 317 | |
| 318 | endef |
| 319 | |
| 320 | |
| 321 | define MAKE_LD |
| 322 | |
| 323 | $(eval PREREQUISITES := $(1).d) |
| 324 | |
| 325 | $(1) : $(2) |
| 326 | @echo " PP $$<" |
| 327 | $$(Q)$$(AS) $$(ASFLAGS) -P -E -o $$@ $$< |
| 328 | |
| 329 | $(PREREQUISITES) : $(2) |
| 330 | @echo " DEPS $$@" |
| 331 | @mkdir -p $$(dir $$@) |
| 332 | $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(1) -MF $$@ $$< |
| 333 | |
Sandrine Bailleux | 8d2296f | 2014-03-21 14:17:51 +0000 | [diff] [blame] | 334 | ifdef IS_ANYTHING_TO_BUILD |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 335 | -include $(PREREQUISITES) |
| 336 | endif |
| 337 | |
| 338 | endef |
| 339 | |
| 340 | |
| 341 | define MAKE_OBJS |
| 342 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 343 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 344 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj)))) |
| 345 | |
| 346 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 347 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 348 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj)))) |
| 349 | |
| 350 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 351 | endef |
| 352 | |
| 353 | |
| 354 | # NOTE: The line continuation '\' is required in the next define otherwise we |
| 355 | # end up with a line-feed characer at the end of the last c filename. |
| 356 | # Also bare this issue in mind if extending the list of supported filetypes. |
| 357 | define SOURCES_TO_OBJS |
| 358 | $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ |
| 359 | $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) |
| 360 | endef |
| 361 | |
| 362 | define MAKE_BL |
| 363 | $(eval BUILD_DIR := ${BUILD_PLAT}/bl$(1)) |
| 364 | $(eval SOURCES := $(BL$(1)_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES)) |
| 365 | $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) |
| 366 | $(eval LINKERFILE := $(BUILD_DIR)/bl$(1).ld) |
| 367 | $(eval MAPFILE := $(BUILD_DIR)/bl$(1).map) |
| 368 | $(eval ELF := $(BUILD_DIR)/bl$(1).elf) |
| 369 | $(eval DUMP := $(BUILD_DIR)/bl$(1).dump) |
| 370 | $(eval BIN := $(BUILD_PLAT)/bl$(1).bin) |
| 371 | |
| 372 | $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES))) |
| 373 | $(eval $(call MAKE_LD,$(LINKERFILE),$(BL$(1)_LINKERFILE))) |
| 374 | |
| 375 | $(BUILD_DIR) : |
| 376 | $$(Q)mkdir -p "$$@" |
| 377 | |
| 378 | $(ELF) : $(OBJS) $(LINKERFILE) |
| 379 | @echo " LD $$@" |
Jon Medhurst | fb05246 | 2014-02-17 12:18:24 +0000 | [diff] [blame] | 380 | @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__;' | \ |
| 381 | $$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 382 | $$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \ |
Jeenu Viswambharan | 9f98aa1 | 2014-03-11 11:06:45 +0000 | [diff] [blame] | 383 | $(BUILD_DIR)/build_message.o $(OBJS) |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 384 | |
| 385 | $(DUMP) : $(ELF) |
| 386 | @echo " OD $$@" |
| 387 | $${Q}$${OD} -dx $$< > $$@ |
| 388 | |
| 389 | $(BIN) : $(ELF) |
| 390 | @echo " BIN $$@" |
| 391 | $$(Q)$$(OC) -O binary $$< $$@ |
| 392 | @echo |
| 393 | @echo "Built $$@ successfully" |
| 394 | @echo |
| 395 | |
| 396 | .PHONY : bl$(1) |
| 397 | bl$(1) : $(BUILD_DIR) $(BIN) $(DUMP) |
| 398 | |
| 399 | all : bl$(1) |
| 400 | |
| 401 | $(eval FIP_DEPS += $(if $2,$(BIN),)) |
| 402 | $(eval FIP_ARGS += $(if $2,--bl$(1) $(BIN),)) |
| 403 | |
| 404 | endef |
| 405 | |
| 406 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 407 | ifeq (${NEED_BL1},yes) |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 408 | $(eval $(call MAKE_BL,1)) |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 409 | endif |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 410 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 411 | ifeq (${NEED_BL2},yes) |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 412 | $(eval $(call MAKE_BL,2,in_fip)) |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 413 | endif |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 414 | |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 415 | ifeq (${NEED_BL31},yes) |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 416 | BL31_SOURCES += ${SPD_SOURCES} |
| 417 | $(eval $(call MAKE_BL,31,in_fip)) |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 418 | endif |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 419 | |
| 420 | ifeq (${NEED_BL32},yes) |
| 421 | $(eval $(call MAKE_BL,32,in_fip)) |
| 422 | endif |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 423 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 424 | ifeq (${NEED_BL30},yes) |
| 425 | FIP_DEPS += ${BL30} |
| 426 | FIP_ARGS += --bl30 ${BL30} |
| 427 | endif |
| 428 | |
| 429 | ifeq (${NEED_BL30},yes) |
| 430 | # If BL3-0 is needed by the platform then 'BL30' variable must be defined. |
| 431 | check_bl30: |
| 432 | $(if ${BL30},,$(error "To build a FIP for platform ${PLAT}, please set BL30 to point to the SCP firmware")) |
| 433 | else |
| 434 | # If BL3-0 is not needed by the platform but the user still specified the path |
| 435 | # to a BL3-0 image then warn him that it will be ignored. |
| 436 | check_bl30: |
| 437 | $(if ${BL30},$(warning "BL3-0 is not supported on platform ${PLAT}, it will just be ignored"),) |
| 438 | endif |
| 439 | |
| 440 | ${BUILD_PLAT}/fip.bin: ${FIP_DEPS} ${BL33} ${FIPTOOL} check_bl30 |
Jon Medhurst | 4bfc2d2 | 2014-02-13 15:19:28 +0000 | [diff] [blame] | 441 | $(if ${BL33},,$(error "To build a FIP, please set BL33 to point to the Normal World binary, eg: BL33=../uefi/FVP_AARCH64_EFI.fd")) |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 442 | ${Q}${FIPTOOL} --dump \ |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 443 | ${FIP_ARGS} \ |
Jon Medhurst | 6d55d10 | 2014-02-12 15:54:48 +0000 | [diff] [blame] | 444 | --bl33 ${BL33} \ |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 445 | $@ |
| 446 | @echo |
Jeenu Viswambharan | 2f2cef4 | 2014-02-19 09:38:18 +0000 | [diff] [blame] | 447 | @echo "Built $@ successfully" |
| 448 | @echo |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 449 | |
| 450 | |
Joakim Bech | 35fab8c | 2014-01-23 14:51:49 +0100 | [diff] [blame] | 451 | cscope: |
| 452 | @echo " CSCOPE" |
| 453 | ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files |
| 454 | ${Q}cscope -b -q -k |
| 455 | |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 456 | help: |
Sandrine Bailleux | 08c7ed0 | 2014-03-21 13:16:35 +0000 | [diff] [blame] | 457 | @echo "usage: ${MAKE} PLAT=<${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch>" |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 458 | @echo "" |
| 459 | @echo "PLAT is used to specify which platform you wish to build." |
Sandrine Bailleux | 08c7ed0 | 2014-03-21 13:16:35 +0000 | [diff] [blame] | 460 | @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}" |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 461 | @echo "" |
| 462 | @echo "Supported Targets:" |
Jeenu Viswambharan | 8aa559c | 2014-02-21 11:42:08 +0000 | [diff] [blame] | 463 | @echo " all Build the BL1, BL2 and BL31 binaries" |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 464 | @echo " bl1 Build the BL1 binary" |
Jeenu Viswambharan | 8aa559c | 2014-02-21 11:42:08 +0000 | [diff] [blame] | 465 | @echo " bl2 Build the BL2 binary" |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 466 | @echo " bl31 Build the BL31 binary" |
| 467 | @echo " checkcodebase Check the coding style of the entire source tree" |
| 468 | @echo " checkpatch Check the coding style on changes in the current" |
| 469 | @echo " branch against BASE_COMMIT (default origin/master)" |
| 470 | @echo " clean Clean the build for the selected platform" |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 471 | @echo " cscope Generate cscope index" |
Ian Spray | 36eaaf3 | 2014-01-30 17:25:28 +0000 | [diff] [blame] | 472 | @echo " distclean Remove all build artifacts for all platforms" |
Harry Liebel | f58ad36 | 2014-01-10 18:00:33 +0000 | [diff] [blame] | 473 | @echo " fiptool Build the Firmware Image Package(FIP) creation tool" |
Ryan Harkin | 72ee331 | 2014-01-15 16:55:07 +0000 | [diff] [blame] | 474 | @echo "" |
| 475 | @echo "note: most build targets require PLAT to be set to a specific platform." |
| 476 | @echo "" |
| 477 | @echo "example: build all targets for the FVP platform:" |
| 478 | @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all" |