1#
2# Copyright (c) 2015-2018, Google, Inc. All rights reserved
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17#
18#  This makefile containts rules for  building ATF image for Trusty.
19#  It is expected that it will be included by the project that requres ATF
20#  support and the caller will configure the following variables:
21#
22#      ATF_ROOT       - Root of arm-trusted-firmware project
23#      ATF_BUILD_BASE - location that will be used to store temp files and
24#                       build results.
25#      ATF_PLAT       - ATF platform to build
26#      ATF_DEBUG      - ATF debug level
27#      ATF_WITH_TRUSTY_GENERIC_SERVICES - Add Trusty generic services
28#      ATF_TOOLCHAIN_PREFIX - AArch64 toolchain to use for building ATF
29#
30#  The following variable is returned to the caller:
31#      ATF_OUT_DIR    - Directory containing ATF images
32#      ATF_BUILD_BASE - location that will be used to store temp files and
33#                       build results.
34#
35#
36
37# set location of resulting ATF image
38ifneq ($(ATF_DEBUG), 0)
39ATF_OUT_DIR := $(ATF_BUILD_BASE)/$(ATF_PLAT)/debug
40else
41ATF_OUT_DIR:=$(ATF_BUILD_BASE)/$(ATF_PLAT)/release
42endif
43ATF_BIN := $(ATF_OUT_DIR)/bl31.bin
44
45ATF_WITH_TRUSTY_GENERIC_SERVICES ?= false
46
47ifeq (true,$(call TOBOOL,$(HAFNIUM)))
48ATF_MAKE_ARGS := SPD=spmd
49ATF_MAKE_ARGS += SPMD_SPM_AT_SEL2=1
50ATF_MAKE_ARGS += BL32=$(BL32_BIN)
51ATF_MAKE_ARGS += BL33=$(TEST_RUNNER_BIN)
52ATF_MAKE_ARGS += SP_LAYOUT_FILE=$(HAFNIUM_OUT_DIR)/sp_layout.json
53ATF_MAKE_ARGS += QEMU_TOS_FW_CONFIG_DTS=$(HAFNIUM_OUT_DIR)/tos_fw_config.dts
54ATF_MAKE_ARGS += QEMU_TB_FW_CONFIG_DTS=$(HAFNIUM_OUT_DIR)/tb_fw_config.dts
55# Symlink the Hafnium DTBs to where ATF will look for them.
56HAFNIUM_DTBS := tb_fw_config.dtb tos_fw_config.dtb
57HAFNIUM_DTBS_SRCS := $(addprefix $(ATF_OUT_DIR)/fdts/, $(HAFNIUM_DTBS))
58$(HAFNIUM_DTBS_SRCS): $(ATF_BIN)
59HAFNIUM_DTBS_OUT := $(addprefix $(ATF_OUT_DIR)/, $(HAFNIUM_DTBS))
60$(HAFNIUM_DTBS_OUT): $(ATF_OUT_DIR)/%.dtb: $(ATF_OUT_DIR)/fdts/%.dtb
61	ln -sf $< $@
62EXTRA_BUILDDEPS += $(HAFNIUM_DTBS_OUT)
63else
64ATF_MAKE_ARGS := SPD=trusty
65ATF_MAKE_ARGS += SPMD_SPM_AT_SEL2=0
66endif
67ATF_MAKE_ARGS += CC=$(CLANG_BINDIR)/clang
68ATF_MAKE_ARGS += CROSS_COMPILE=$(ATF_TOOLCHAIN_PREFIX)
69ATF_MAKE_ARGS += PLAT=$(ATF_PLAT)
70ATF_MAKE_ARGS += DEBUG=$(ATF_DEBUG)
71ATF_MAKE_ARGS += BUILD_BASE=$(ATF_BUILD_BASE)
72ATF_MAKE_ARGS += QEMU_USE_GIC_DRIVER=QEMU_GICV$(GIC_VERSION)
73# On aarch32, we skip EL2, see 27d8e1e75a2f45d7c23
74ifeq (true,$(call TOBOOL,$(KERNEL_32BIT)))
75ATF_MAKE_ARGS += INIT_UNUSED_NS_EL2=1
76endif
77
78ifeq (true,$(call TOBOOL,$(ATF_WITH_TRUSTY_GENERIC_SERVICES)))
79ATF_MAKE_ARGS += TRUSTY_SPD_WITH_GENERIC_SERVICES=1
80endif
81
82$(ATF_BIN): ATF_ROOT:=$(ATF_ROOT)
83$(ATF_BIN): ATF_MAKE_ARGS:=$(ATF_MAKE_ARGS)
84$(ATF_BIN): .PHONY
85	$(MAKE) -C $(ATF_ROOT) $(ATF_MAKE_ARGS) all sp
86
87# Add ATF_BIN to the list of project dependencies
88EXTRA_BUILDDEPS += $(ATF_BIN)
89
90ATF_ROOT:=
91ATF_PLAT:=
92ATF_DEBUG:=
93ATF_WITH_TRUSTY_GENERIC_SERVICES:=
94ATF_TOOLCHAIN_PREFIX:=
95ATF_BIN:=
96ATF_MAKE_ARGS:=
97