@@ -120,6 +120,13 @@ endif
120120# example "x86_64-linux-gnu-gcc-10".
121121ifeq ($(CROSS_COMPILING ) , 1)
122122INITRAMFS_BUILD_GOROOT ?= /usr/local/go
123+ ifeq ($(shell which $(LINUX_GCC_TUPLE ) gcc) ,)
124+ BUILD_LINUX_WITH_COREBOOT_TOOLCHAIN = 1
125+ CROSS_COMPILE ?= $(COREBOOT_BUILD_DIR ) /util/crossgcc/xgcc/bin/$(LINUX_GCC_TUPLE )
126+ else
127+ BUILD_LINUX_WITH_COREBOOT_TOOLCHAIN = 0
128+ CROSS_COMPILE ?= $(LINUX_GCC_TUPLE )
129+ endif
123130else
124131# FIXME: Also need to fix behavior when we're not cross-compilng, but system's
125132# go version doesn't match the version we're using to build the initramfs...
@@ -201,8 +208,8 @@ $(COREBOOT_TOOLCHAIN_OUT)/bin/iasl: $(COREBOOT_DEPS_FLAG) $(COREBOOT_PATCH_FLAG)
201208 tar xf $(COREBOOT_TOOLCHAIN_CACHE ) -C $(dir $(COREBOOT_TOOLCHAIN_OUT ) ) ; \
202209 touch $@ ; \
203210 else \
204- COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR ) CPUS=$(NPROC ) MAKE=$(MAKE ) ARCH=$(ARCH ) TOOLS_DIR= $( TOOLS_DIR ) \
205- $(TOOLS_DIR ) /build_toolchain.sh; \
211+ COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR ) CPUS=$(NPROC ) MAKE=$(MAKE ) ARCH=$(COREBOOT_TOOLCHAIN_ARCH ) \
212+ TOOLS_DIR= $( TOOLS_DIR ) $(TOOLS_DIR ) /build_toolchain.sh coreboot ; \
206213 fi
207214
208215# Creates coreboot config file using the user-provided one and feeding it to make olddefconfig.
@@ -236,19 +243,28 @@ wipe-coreboot:
236243# Top-level initramfs target, for use by humans.
237244kernel : $(KERNEL_OUT )
238245
246+ kernel_toolchain : $(COREBOOT_DEPS_FLAG ) $(COREBOOT_PATCH_FLAG )
247+ ifeq "$(BUILD_LINUX_WITH_COREBOOT_TOOLCHAIN ) " "1"
248+ echo 'Building cross toolchain for Linux'
249+ COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR) CPUS=$(NPROC) MAKE=$(MAKE) ARCH=$(LINUX_ARCH) \
250+ TOOLS_DIR=$(TOOLS_DIR) $(TOOLS_DIR)/build_toolchain.sh linux;
251+ else
252+ echo 'Building Linux with toolchain tuple: $(CROSS_COMPILE)'
253+ endif
254+
239255# Kernel build target. Requires initrmafs image, config and patches.
240256ifneq "$(INITRAMFS_IN ) " ""
241- $(KERNEL_OUT ) : $(INITRAMFS_IN ) $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG )
257+ $(KERNEL_OUT ) : $(INITRAMFS_IN ) $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG ) kernel_toolchain
242258else
243- $(KERNEL_OUT ) : $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG )
259+ $(KERNEL_OUT ) : $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG ) $( KERNEL_TOOLCHAIN ) $( KERNEL_TOOLCHAIN )
244260endif
245261 @# If lzma(1) is not available, kernel build will fall back to gzip and we don't want that.
246262 @if ! lzma -h > /dev/null 2>/dev/null; then \
247263 echo ' *** Please install the lzma CLI utility.' >&2; \
248264 echo ' *** In RedHat distros it`s provided by xz-lzma-compat, in Debian/Ubuntu it`s provided by xz-utils.' >&2; \
249265 exit 1; \
250266 fi
251- MAKEFLAGS= $(MAKE) -C $(KERNEL_BUILD_DIR) -j$(NPROC) KCFLAGS=-pipe
267+ ARCH=$(LINUX_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) MAKEFLAGS= $(MAKE) -C $(KERNEL_BUILD_DIR) -j$(NPROC) KCFLAGS=-pipe
252268 [ "$@" = "$(KERNEL_OUT_DEFAULT)" ] || cp -v "$(KERNEL_OUT_DEFAULT)" "$@"
253269
254270ifeq "$(ALWAYS_BUILD_KERNEL ) " "1"
@@ -258,7 +274,7 @@ endif
258274$(KERNEL_CONFIG_OUT ) : $(KERNEL_CONFIG ) $(KERNEL_DEPS_FLAG )
259275 cp $(KERNEL_CONFIG ) $@
260276 sed -i " s|CONFIG_INITRAMFS_SOURCE=.*|CONFIG_INITRAMFS_SOURCE=\" $( INITRAMFS_IN) \" |" $@
261- MAKEFLAGS= $(MAKE ) -C $(KERNEL_BUILD_DIR ) olddefconfig
277+ ARCH= $( LINUX_ARCH ) MAKEFLAGS= $(MAKE ) -C $(KERNEL_BUILD_DIR ) olddefconfig
262278
263279$(KERNEL_PATCH_FLAG ) : $(realpath $(wildcard $(PATCHES_DIR ) /kernel-* ) )
264280 $(call patch,$(KERNEL_BUILD_DIR ) ,$^ )
0 commit comments