summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlistair Strachan2018-10-16 17:24:16 -0500
committerAlistair Strachan2018-10-16 19:57:55 -0500
commit848da4f1318cc12619512f4e66c6b281155c5f8a (patch)
tree1cbf7c027d75626768954d55f8079ab41d2697d0 /uboot.mk
parent351e67763631286964f41e000f6bfc95bbd3c49d (diff)
downloaddevice-ti-beagle-x15-848da4f1318cc12619512f4e66c6b281155c5f8a.tar.gz
device-ti-beagle-x15-848da4f1318cc12619512f4e66c6b281155c5f8a.tar.xz
device-ti-beagle-x15-848da4f1318cc12619512f4e66c6b281155c5f8a.zip
Build the x15 U-Boot binaries from source.
This change builds a config for U-Boot and then builds the MLO and u-boot.img files from the external/u-boot source tree. It uses symlinks to the host toolchain to preserve the Android build system's hermetic requirements. (The recommended configs were derived from the Things configs.) Bug: 110964307 Change-Id: I634c607ca5c07d24d46278aaf8215c70bc2e6aa0 Signed-off-by: Alistair Strachan <astrachan@google.com>
Diffstat (limited to 'uboot.mk')
-rw-r--r--uboot.mk176
1 files changed, 176 insertions, 0 deletions
diff --git a/uboot.mk b/uboot.mk
new file mode 100644
index 0000000..d43cc60
--- /dev/null
+++ b/uboot.mk
@@ -0,0 +1,176 @@
1#
2# Copyright 2015 The Android Open Source Project
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# Targets for building U-Boot
18#
19# The following must be set before including this file:
20# TARGET_UBOOT_SRC must be set the base of a U-Boot tree.
21# TARGET_UBOOT_DEFCONFIG must name a base U-Boot config.
22# TARGET_UBOOT_ARCH must be set to match U-Boot arch.
23#
24# The following may be set:
25# TARGET_UBOOT_CROSS_COMPILE_PREFIX to override toolchain.
26# TARGET_UBOOT_CONFIGS to specify a set of additional U-Boot config files.
27# TARGET_UBOOT_ENV to specify an environment to be compiled into uboot.env.
28# TARGET_UBOOT_ENV_SIZE to specify the size reserved in U-Boot for the env.
29
30ifeq ($(TARGET_UBOOT_SRC),)
31$(error TARGET_UBOOT_SRC not defined but uboot.mk included)
32endif
33
34ifeq ($(TARGET_UBOOT_DEFCONFIG),)
35$(error TARGET_UBOOT_DEFCONFIG not defined)
36endif
37
38ifeq ($(TARGET_UBOOT_ARCH),)
39$(error TARGET_UBOOT_ARCH not defined)
40endif
41
42ifeq ($(TARGET_UBOOT_ENV_SIZE),)
43ifneq ($(TARGET_UBOOT_ENV),)
44$(error If TARGET_UBOOT_ENV is set TARGET_UBOOT_ENV_SIZE must also be set. See\
45 CONFIG_ENV_SIZE in the selected U-Boot board config file.)
46endif
47endif
48
49# These may be assigned in target BoardConfig.mk.
50TARGET_UBOOT_MAKE_TARGET ?= u-boot.bin
51TARGET_UBOOT_COPY_TARGETS ?= $(TARGET_UBOOT_MAKE_TARGET)
52
53# Check target arch.
54TARGET_UBOOT_ARCH := $(strip $(TARGET_UBOOT_ARCH))
55UBOOT_ARCH := $(TARGET_UBOOT_ARCH)
56UBOOT_CC_WRAPPER := $(CC_WRAPPER)
57UBOOT_AFLAGS :=
58UBOOT_DTC := $(HOST_OUT_EXECUTABLES)/dtc
59UBOOT_DTC_ABS := $(abspath $(UBOOT_DTC))
60
61ifeq ($(TARGET_UBOOT_ARCH), arm)
62UBOOT_TOOLCHAIN_ABS := $(realpath prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.9/bin)
63UBOOT_CROSS_COMPILE := $(UBOOT_TOOLCHAIN_ABS)/arm-linux-androidkernel-
64UBOOT_SRC_ARCH := arm
65UBOOT_CFLAGS :=
66else ifeq ($(TARGET_UBOOT_ARCH), arm64)
67UBOOT_TOOLCHAIN_ABS := $(realpath prebuilts/gcc/$(HOST_PREBUILT_TAG)/aarch64/aarch64-linux-android-4.9/bin)
68UBOOT_CROSS_COMPILE := $(UBOOT_TOOLCHAIN_ABS)/aarch64-linux-androidkernel-
69UBOOT_SRC_ARCH := arm64
70UBOOT_CFLAGS :=
71else ifeq ($(TARGET_UBOOT_ARCH), i386)
72UBOOT_TOOLCHAIN_ABS := $(realpath prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/x86_64-linux-android-4.9/bin)
73UBOOT_CROSS_COMPILE := $(UBOOT_TOOLCHAIN_ABS)/x86_64-linux-androidkernel-
74UBOOT_SRC_ARCH := x86
75UBOOT_CFLAGS := -mstack-protector-guard=tls
76else ifeq ($(TARGET_UBOOT_ARCH), x86_64)
77UBOOT_TOOLCHAIN_ABS := $(realpath prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/x86_64-linux-android-4.9/bin)
78UBOOT_CROSS_COMPILE := $(UBOOT_TOOLCHAIN_ABS)/x86_64-linux-androidkernel-
79UBOOT_SRC_ARCH := x86
80UBOOT_CFLAGS := -mstack-protector-guard=tls
81else ifeq ($(TARGET_UBOOT_ARCH), mips)
82UBOOT_TOOLCHAIN_ABS := $(realpath prebuilts/gcc/$(HOST_PREBUILT_TAG)/mips/mips64el-linux-android-4.9/bin)
83UBOOT_CROSS_COMPILE := $(UBOOT_TOOLCHAIN_ABS)/mips64el-linux-androidkernel-
84UBOOT_SRC_ARCH := mips
85UBOOT_CFLAGS :=
86else
87$(error U-Boot arch not supported at present)
88endif
89
90# Allow caller to override toolchain.
91TARGET_UBOOT_CROSS_COMPILE_PREFIX := $(strip $(TARGET_UBOOT_CROSS_COMPILE_PREFIX))
92ifneq ($(TARGET_UBOOT_CROSS_COMPILE_PREFIX),)
93UBOOT_CROSS_COMPILE := $(TARGET_UBOOT_CROSS_COMPILE_PREFIX)
94endif
95
96# Use ccache if requested by USE_CCACHE variable
97UBOOT_CROSS_COMPILE_WRAPPER := $(realpath $(UBOOT_CC_WRAPPER)) $(UBOOT_CROSS_COMPILE)
98
99UBOOT_GCC_NOANDROID_CHK := $(shell (echo "int main() {return 0;}" | $(UBOOT_CROSS_COMPILE)gcc -E -mno-android - > /dev/null 2>&1 ; echo $$?))
100ifeq ($(strip $(UBOOT_GCC_NOANDROID_CHK)),0)
101UBOOT_CFLAGS += -mno-android
102UBOOT_AFLAGS += -mno-android
103endif
104
105# Set the output for the U-Boot build products.
106UBOOT_OUT := $(TARGET_OUT_INTERMEDIATES)/UBOOT_OBJ
107UBOOT_ENV_OUT := $(PRODUCT_OUT)/uboot.env
108
109# Merge all U-Boot config file sources.
110UBOOT_CONFIG_DIR := device/ti/beagle_x15/uboot_config
111UBOOT_CONFIG_DEFAULT := $(TARGET_UBOOT_SRC)/configs/$(TARGET_UBOOT_DEFCONFIG)
112UBOOT_CONFIG_RECOMMENDED := $(UBOOT_CONFIG_DIR)/recommended.config
113UBOOT_CONFIG_REQUIRED_SRC := $(UBOOT_CONFIG_DIR)/common.config
114UBOOT_CONFIG_REQUIRED := $(UBOOT_OUT)/.config.required
115UBOOT_CONFIG_SRC := $(UBOOT_CONFIG_DEFAULT) \
116 $(UBOOT_CONFIG_RECOMMENDED) \
117 $(TARGET_UBOOT_CONFIGS) \
118 $(UBOOT_CONFIG_REQUIRED)
119UBOOT_CONFIG := $(UBOOT_OUT)/.config
120UBOOT_MERGE_CONFIG := device/ti/beagle_x15/mergeconfig.sh
121# List of all the Kconfig files from the source code. Changing the Kconfig files
122# requires to reassemble the .config, so we add them as dependencies.
123UBOOT_SRC_KCONFIGS := \
124 $(call find-files-in-subdirs,.,Kconfig,$(TARGET_UBOOT_SRC))
125
126$(UBOOT_OUT):
127 mkdir -p $@
128
129define build_uboot
130 # We don't support bundling a device tree with U-Boot yet.
131 CCACHE_NODIRECT="true" PATH=$$(cd device/ti/beagle_x15/hostcc; pwd):$$PATH \
132 BISON_PKGDATADIR=$$(cd prebuilts/build-tools/common/bison; pwd) \
133 $(MAKE) -C $(TARGET_UBOOT_SRC) \
134 O=$(realpath $(UBOOT_OUT)) \
135 CROSS_COMPILE="$(UBOOT_CROSS_COMPILE_WRAPPER)" \
136 DTC="$(UBOOT_DTC_ABS)" \
137 KCFLAGS="$(UBOOT_CFLAGS)" \
138 KAFLAGS="$(UBOOT_AFLAGS)" \
139 SOURCE_DATE_EPOCH="$(BUILD_DATETIME_FROM_FILE)" \
140 $(1)
141endef
142
143# Merge the required U-Boot config elements into a single file.
144$(UBOOT_CONFIG_REQUIRED): $(UBOOT_CONFIG_REQUIRED_SRC) | $(UBOOT_OUT)
145 $(hide) cat $^ > $@
146
147# Merge the final target U-Boot config.
148$(UBOOT_CONFIG): $(UBOOT_CONFIG_SRC) $(UBOOT_SRC_KCONFIGS) | $(UBOOT_OUT)
149 $(hide) echo Merging U-Boot config
150 $(call build_uboot,mrproper)
151 PATH=$$(cd device/ti/beagle_x15/hostcc; pwd):$$PATH \
152 BISON_PKGDATADIR=$$(cd prebuilts/build-tools/common/bison; pwd) \
153 $(UBOOT_MERGE_CONFIG) \
154 $(TARGET_UBOOT_SRC) $(realpath $(UBOOT_OUT)) \
155 $(UBOOT_ARCH) $(UBOOT_CROSS_COMPILE) \
156 $(UBOOT_CONFIG_SRC)
157
158$(UBOOT_OUT)/$(TARGET_UBOOT_MAKE_TARGET): $(UBOOT_CONFIG) | $(UBOOT_OUT) $(UBOOT_DTC)
159 $(hide) echo "Building $(UBOOT_ARCH) U-Boot ..."
160 $(call build_uboot,$(TARGET_UBOOT_MAKE_TARGET))
161
162$(addprefix $(UBOOT_OUT)/,$(TARGET_UBOOT_COPY_TARGETS)): $(UBOOT_OUT)/$(TARGET_UBOOT_MAKE_TARGET)
163
164ifneq ($(TARGET_UBOOT_ENV),)
165$(UBOOT_ENV_OUT): $(TARGET_UBOOT_ENV) | $(addprefix $(UBOOT_OUT)/,$(TARGET_UBOOT_COPY_TARGETS))
166 $(UBOOT_OUT)/tools/mkenvimage -s $(TARGET_UBOOT_ENV_SIZE) -o $@ $<
167endif
168
169ALL_DEFAULT_INSTALLED_MODULES += $(addprefix $(PRODUCT_OUT)/,$(TARGET_UBOOT_COPY_TARGETS))
170
171# Produces the actual U-Boot image!
172define copy_uboot
173$$(PRODUCT_OUT)/$(1): $$(UBOOT_OUT)/$(1) | $$(ACP)
174 $$(ACP) -fp $$< $$@
175endef
176$(foreach _t,$(TARGET_UBOOT_COPY_TARGETS),$(eval $(call copy_uboot,$(_t))))