Skip to content

Commit abc61a4

Browse files
committed
Makefile.inc: Make Go variables cross-compiler friendly
GOARCH needs to reflect the target architecture. GOROOT needs to point at GOROOT that is compatible with the host. Signed-off-by: David Hendricks <david.hendricks@gmail.com>
1 parent f06344c commit abc61a4

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Makefile.inc

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ INITRAMFS_BUILD_DIR := $(PLATFORM_BUILD_DIR)/initramfs
7272
INITRAMFS_DEPS_FLAG := $(PLATFORM_BUILD_DIR)/.initramfs-deps
7373
INITRAMFS_PATCH_FLAG := $(PLATFORM_BUILD_DIR)/.initramfs-patch
7474
ifndef INITRAMFS_OUT
75-
INITRAMFS_OUT := $(INITRAMFS_BUILD_DIR)/initramfs_linuxboot.$(ARCH).cpio
75+
INITRAMFS_OUT := $(INITRAMFS_BUILD_DIR)/initramfs_linuxboot.$(GOARCH).cpio
7676
endif
7777
# By default, build initramfs but a prebuilt one can be provided via INITRAMFS_IN.
7878
INITRAMFS_IN ?= $(INITRAMFS_OUT)
@@ -102,6 +102,31 @@ ifdef COREBOOT_BLOBS_DIR
102102
COREBOOT_BLOBS_DIR := $(realpath $(COREBOOT_BLOBS_DIR))
103103
endif
104104

105+
# FIXME: Go needs to be run on the host architecture (GOARCH is used for cross-
106+
# compiling Go programs). However, the target platform's config will likely want
107+
# to use a Go tarball for that target architecture. For now, override this with
108+
# whatever the host has installed. THIS IS A GROSS HACK.
109+
#
110+
# We might change the json schema to specify only Go version, but not point at
111+
# a particular tarball (which includes architecture in the name). This would
112+
# also require changing the download verification scheme to something like GPG
113+
# signature instead of sha255sum, since the hash will obviously be different
114+
# among tarballs for different architectures.
115+
#
116+
# FIXME #2: It's not clear if we want to always use the coreboot toolchain when
117+
# cross compiling Linux. It's certainly an easy approach, though.
118+
#
119+
# FIXME #3: Some distros add the version number of the tool as a suffix, for
120+
# example "x86_64-linux-gnu-gcc-10".
121+
ifeq ($(CROSS_COMPILING), 1)
122+
INITRAMFS_BUILD_GOROOT ?= /usr/local/go
123+
else
124+
# FIXME: Also need to fix behavior when we're not cross-compilng, but system's
125+
# go version doesn't match the version we're using to build the initramfs...
126+
#INITRAMFS_BUILD_GOROOT ?= $(INITRAMFS_BUILD_DIR)/go
127+
INITRAMFS_BUILD_GOROOT ?= /usr/local/go
128+
endif
129+
105130
UROOT_BOOT_CMDS := fbnetboot localboot systemboot
106131
UROOT_EXP_CMDS := cbmem dmidecode modprobe ipmidump
107132
UROOT_BASE_CMDS ?= \
@@ -256,10 +281,11 @@ initramfs: $(INITRAMFS_OUT)
256281
# Initramfs build target.
257282
$(INITRAMFS_OUT): $(INITRAMFS_DEPS_FLAG) $(INITRAMFS_PATCH_FLAG)
258283
GO111MODULE=off \
259-
GOROOT=$(INITRAMFS_BUILD_DIR)/go \
284+
GOARCH=$(GOARCH) \
285+
GOROOT=$(INITRAMFS_BUILD_GOROOT) \
260286
GOCACHE=$(INITRAMFS_BUILD_DIR)/go/.cache \
261287
GOPATH=$(INITRAMFS_BUILD_DIR)/gopath:$(UROOT_ADDITIONAL_GOPATH) \
262-
$(INITRAMFS_BUILD_DIR)/go/bin/go run github.com/u-root/u-root \
288+
$(GOROOT)/bin/go run github.com/u-root/u-root \
263289
-build=bb -o $@ -uinitcmd=$(UINIT_CMD) \
264290
$(addprefix -files=,$(BASE_FILES) $(UROOT_ADDITIONAL_FILES)) \
265291
$(UROOT_ADDITIONAL_CMDS) \

examples/qemu/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
# LICENSE file in the root directory of this source tree.
66

77
ARCH ?= $(shell uname -m)
8+
ifneq ($(ARCH), $(shell uname -m))
9+
CROSS_COMPILING := 1
10+
else
11+
CROSS_COMPILING := 0
12+
endif
813

914
ifeq ($(ARCH), x86_64)
10-
ARCH = amd64
1115
LINUX_ARCH := $(ARCH)
1216
LINUX_IMAGE_RELATIVE_PATH := arch/x86/boot/bzImage
17+
GOARCH := amd64
1318
PLATFORM := qemu-amd64
1419
QEMU_SYSTEM := qemu-system-$(ARCH)
1520
endif

0 commit comments

Comments
 (0)