@@ -120,7 +120,15 @@ 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 )
123126else
127+ BUILD_LINUX_WITH_COREBOOT_TOOLCHAIN = 0
128+ CROSS_COMPILE ?= $(LINUX_GCC_TUPLE )
129+ endif
130+ else
131+ CROSS_COMPILE =
124132# FIXME: Also need to fix behavior when we're not cross-compilng, but system's
125133# go version doesn't match the version we're using to build the initramfs...
126134# INITRAMFS_BUILD_GOROOT ?= $(INITRAMFS_BUILD_DIR)/go
@@ -201,8 +209,8 @@ $(COREBOOT_TOOLCHAIN_OUT)/bin/iasl: $(COREBOOT_DEPS_FLAG) $(COREBOOT_PATCH_FLAG)
201209 tar xf $(COREBOOT_TOOLCHAIN_CACHE ) -C $(dir $(COREBOOT_TOOLCHAIN_OUT ) ) ; \
202210 touch $@ ; \
203211 else \
204- COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR ) CPUS=$(NPROC ) MAKE=$(MAKE ) ARCH=$(ARCH ) TOOLS_DIR= $( TOOLS_DIR ) \
205- $(TOOLS_DIR ) /build_toolchain.sh; \
212+ COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR ) CPUS=$(NPROC ) MAKE=$(MAKE ) ARCH=$(COREBOOT_TOOLCHAIN_ARCH ) \
213+ TOOLS_DIR= $( TOOLS_DIR ) $(TOOLS_DIR ) /build_toolchain.sh coreboot ; \
206214 fi
207215
208216# Creates coreboot config file using the user-provided one and feeding it to make olddefconfig.
@@ -236,19 +244,28 @@ wipe-coreboot:
236244# Top-level initramfs target, for use by humans.
237245kernel : $(KERNEL_OUT )
238246
247+ kernel_toolchain : $(COREBOOT_DEPS_FLAG ) $(COREBOOT_PATCH_FLAG )
248+ ifeq "$(BUILD_LINUX_WITH_COREBOOT_TOOLCHAIN ) " "1"
249+ echo 'Building cross toolchain for Linux'
250+ COREBOOT_BUILD_DIR=$(COREBOOT_BUILD_DIR) CPUS=$(NPROC) MAKE=$(MAKE) ARCH=$(LINUX_ARCH) \
251+ TOOLS_DIR=$(TOOLS_DIR) $(TOOLS_DIR)/build_toolchain.sh linux;
252+ else
253+ echo 'Building Linux with toolchain tuple: $(CROSS_COMPILE)'
254+ endif
255+
239256# Kernel build target. Requires initrmafs image, config and patches.
240257ifneq "$(INITRAMFS_IN ) " ""
241- $(KERNEL_OUT ) : $(INITRAMFS_IN ) $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG )
258+ $(KERNEL_OUT ) : $(INITRAMFS_IN ) $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG ) kernel_toolchain
242259else
243- $(KERNEL_OUT ) : $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG )
260+ $(KERNEL_OUT ) : $(KERNEL_CONFIG_OUT ) $(KERNEL_PATCH_FLAG ) $( KERNEL_TOOLCHAIN ) $( KERNEL_TOOLCHAIN )
244261endif
245262 @# If lzma(1) is not available, kernel build will fall back to gzip and we don't want that.
246263 @if ! lzma -h > /dev/null 2>/dev/null; then \
247264 echo ' *** Please install the lzma CLI utility.' >&2; \
248265 echo ' *** In RedHat distros it`s provided by xz-lzma-compat, in Debian/Ubuntu it`s provided by xz-utils.' >&2; \
249266 exit 1; \
250267 fi
251- MAKEFLAGS= $(MAKE) -C $(KERNEL_BUILD_DIR) -j$(NPROC) KCFLAGS=-pipe
268+ ARCH=$(LINUX_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) MAKEFLAGS= $(MAKE) -C $(KERNEL_BUILD_DIR) -j$(NPROC) KCFLAGS=-pipe
252269 [ "$@" = "$(KERNEL_OUT_DEFAULT)" ] || cp -v "$(KERNEL_OUT_DEFAULT)" "$@"
253270
254271ifeq "$(ALWAYS_BUILD_KERNEL ) " "1"
@@ -258,7 +275,7 @@ endif
258275$(KERNEL_CONFIG_OUT ) : $(KERNEL_CONFIG ) $(KERNEL_DEPS_FLAG )
259276 cp $(KERNEL_CONFIG ) $@
260277 sed -i " s|CONFIG_INITRAMFS_SOURCE=.*|CONFIG_INITRAMFS_SOURCE=\" $( INITRAMFS_IN) \" |" $@
261- MAKEFLAGS= $(MAKE ) -C $(KERNEL_BUILD_DIR ) olddefconfig
278+ ARCH= $( LINUX_ARCH ) MAKEFLAGS= $(MAKE ) -C $(KERNEL_BUILD_DIR ) olddefconfig
262279
263280$(KERNEL_PATCH_FLAG ) : $(realpath $(wildcard $(PATCHES_DIR ) /kernel-* ) )
264281 $(call patch,$(KERNEL_BUILD_DIR ) ,$^ )
0 commit comments