Skip to content

Commit

Permalink
musl-cross-make: replace all cross compilers with musl-cross-make
Browse files Browse the repository at this point in the history
Signed-off-by: Trammell Hudson <[email protected]>
  • Loading branch information
osresearch committed Jan 8, 2020
1 parent 8af849c commit 791d064
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 96 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ SHELL := /bin/bash
# be defined prior to any other module.
include modules/musl-cross

musl_dep := musl
heads_cc := $(INSTALL)/bin/musl-gcc \
musl_dep := musl-cross
heads_cc := $(CROSS)gcc \
-fdebug-prefix-map=$(pwd)=heads \
-gno-record-gcc-switches \
-D__MUSL__ \
-I$(INSTALL)/include \
-L$(INSTALL)/lib \

CROSS_TOOLS_NOCC := \
AR="$(CROSS)ar" \
Expand Down Expand Up @@ -145,8 +147,9 @@ all:
FORCE:

# Make helpers to operate on lists of things
# Prefix is "smart" and doesn't add the prefix for absolute file paths
define prefix =
$(foreach _, $2, $1$_)
$(foreach _, $2, $(if $(patsubst /%,,$_),$1$_,$_))
endef
define map =
$(foreach _,$2,$(eval $(call $1,$_)))
Expand Down Expand Up @@ -410,6 +413,7 @@ endef

# Only some modules have binaries that we install
# Shouldn't this be specified in the module file?
#bin_modules-$(CONFIG_MUSL) += musl-cross
bin_modules-$(CONFIG_KEXEC) += kexec
bin_modules-$(CONFIG_TPMTOTP) += tpmtotp
bin_modules-$(CONFIG_PCIUTILS) += pciutils
Expand Down Expand Up @@ -451,8 +455,7 @@ endif
$(COREBOOT_UTIL_DIR)/cbmem/cbmem \
$(COREBOOT_UTIL_DIR)/superiotool/superiotool \
$(COREBOOT_UTIL_DIR)/inteltool/inteltool \
: $(build)/$(coreboot_base_dir)/.canary \
$(build)/$(musl_dir)/.build
: $(build)/$(coreboot_base_dir)/.canary
+$(call do,MAKE,$(notdir $@),\
$(MAKE) -C "$(dir $@)" $(CROSS_TOOLS) \
)
Expand Down Expand Up @@ -564,7 +567,6 @@ modules.clean:
real.clean:
for dir in \
$(module_dirs) \
$(musl_dir) \
$(kernel_headers) \
; do \
if [ ! -z "$$dir" ]; then \
Expand Down
Binary file modified blobs/dev.cpio
Binary file not shown.
1 change: 1 addition & 0 deletions config/coreboot-kgpe-d16.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="heads"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_USE_OPTION_TABLE=y
# CONFIG_COLLECT_TIMESTAMPS is not set
CONFIG_VENDOR_ASUS=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-librem13v2.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="4.8.1-Purism-1-heads-beta"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_USE_BLOBS=y
CONFIG_MEASURED_BOOT=y
CONFIG_VENDOR_PURISM=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-librem13v4.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="4.8.1-Purism-1-heads-beta"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_USE_BLOBS=y
CONFIG_MEASURED_BOOT=y
CONFIG_VENDOR_PURISM=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-librem15v3.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="4.8.1-Purism-1-heads-beta"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_USE_BLOBS=y
CONFIG_MEASURED_BOOT=y
CONFIG_VENDOR_PURISM=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-librem15v4.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="4.8.1-Purism-1-heads-beta"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_USE_BLOBS=y
CONFIG_MEASURED_BOOT=y
CONFIG_VENDOR_PURISM=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-qemu.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="-heads"
CONFIG_ANY_TOOLCHAIN=y
# CONFIG_INCLUDE_CONFIG_FILE is not set
CONFIG_CBFS_SIZE=0x700000
# CONFIG_POST_IO is not set
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-x220.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="heads"
CONFIG_ANY_TOOLCHAIN=y
# CONFIG_INCLUDE_CONFIG_FILE is not set
# CONFIG_COLLECT_TIMESTAMPS is not set
CONFIG_USE_BLOBS=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-x230-flash.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="heads"
CONFIG_ANY_TOOLCHAIN=y
# CONFIG_INCLUDE_CONFIG_FILE is not set
# CONFIG_COLLECT_TIMESTAMPS is not set
CONFIG_USE_BLOBS=y
Expand Down
1 change: 1 addition & 0 deletions config/coreboot-x230.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_LOCALVERSION="heads"
CONFIG_ANY_TOOLCHAIN=y
# CONFIG_INCLUDE_CONFIG_FILE is not set
# CONFIG_COLLECT_TIMESTAMPS is not set
CONFIG_USE_BLOBS=y
Expand Down
45 changes: 15 additions & 30 deletions modules/coreboot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ coreboot_tar := coreboot-$(coreboot_version).tar.xz
coreboot_url := https://www.coreboot.org/releases/$(coreboot_tar)
coreboot_hash := f0ddf4db0628c1fe1e8348c40084d9cbeb5771400c963fd419cda3995b69ad23

# Coreboot builds are specialized on a per-target basis.
# coreboot builds are specialized on a per-target basis.
# The builds are done in a per-target subdirectory
CONFIG_COREBOOT_CONFIG ?= config/coreboot-$(BOARD).config

Expand All @@ -29,45 +29,30 @@ coreboot_configure := \
CFLAGS_x86_32="$(EXTRA_FLAGS)" \
CFLAGS_x86_64="$(EXTRA_FLAGS)" \

COREBOOT_IASL="$(build)/$(coreboot_base_dir)/util/crossgcc/xgcc/bin/iasl"

# coreboot is built with the 32-bit compiler; ideally we could use the same
# x86_64-linux-musl -m32 to build it, but this causes some link errors that need
# to be tracked down.
# CROSS="$(CROSS)" \

coreboot_target := \
-C "$(build)/$(coreboot_base_dir)" \
obj="$(build)/$(coreboot_dir)" \
CROSS="$(dir $(CROSS))i386-linux-musl-" \
IASL="$(COREBOOT_IASL)" \
DOTCONFIG="$(build)/$(coreboot_dir)/.config" \
BUILD_TIMELESS=1 \
CFLAGS_x86_32="$(EXTRA_FLAGS)" \
CFLAGS_x86_64="$(EXTRA_FLAGS)" \
$(MAKE_JOBS)

coreboot_output := coreboot.rom
coreboot_depend += linux initrd

COREBOOT_XGCC_REL := $(coreboot_base_dir)/util/crossgcc/xgcc
COREBOOT_XGCC_PATH := $(build)/$(COREBOOT_XGCC_REL)
COREBOOT_XGCC := $(COREBOOT_XGCC_PATH)/bin/i386-elf-gcc

# hack to force a build dependency on the cross compiler
coreboot-gcc $(build)/$(coreboot_dir)/.configured: $(COREBOOT_XGCC)

ifeq "$(TOOLCHAIN)" ""
# Force a rebuild of the entire coreboot toolchain
$(COREBOOT_XGCC): $(build)/$(coreboot_base_dir)/.canary
echo '******* Building crossgcc-i386 (this might take a while) ******'
$(MAKE) -C "$(build)/$(coreboot_base_dir)" CPUS=`nproc` crossgcc-i386
#echo '******* Building crossgcc-arm (this might take a while) ******'
#$(MAKE) -C "$(build)/$(coreboot_base_dir)" crossgcc-arm
else
# Use the pre-build one from the external toolchain build
$(COREBOOT_XGCC): $(build)/$(coreboot_base_dir)/.canary
if [ ! -e "$(TOOLCHAIN)/build/$(COREBOOT_XGCC_REL)" ]; then \
echo >&2 "ERROR: TOOLCHAIN=$(TOOLCHAIN) does not have coreboot" ; \
exit 1 ; \
fi
if [ ! -e "$(COREBOOT_XGCC_PATH)" ]; then \
ln -s \
"$(TOOLCHAIN)/build/$(COREBOOT_XGCC_REL)" \
"$(COREBOOT_XGCC_PATH)" ; \
fi
endif
coreboot_depend += linux initrd $(musl_dep)

$(build)/$(coreboot_dir)/.configured: $(COREBOOT_IASL)
$(COREBOOT_IASL): $(build)/$(coreboot_base_dir)/.canary
$(MAKE) -C "$(build)/$(coreboot_base_dir)" CPUS=`nproc` iasl

# Force a rebuild if the inputs have changed
$(build)/$(coreboot_dir)/.build: \
Expand Down
41 changes: 0 additions & 41 deletions modules/musl

This file was deleted.

55 changes: 36 additions & 19 deletions modules/musl-cross
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
CONFIG_MUSL ?= y

ifeq "$(MUSL_CROSS_ONCE)" ""
MUSL_CROSS_ONCE := 1
modules-$(CONFIG_MUSL) += musl-cross

musl-cross_version := 38e52db
musl-cross_dir := musl-cross-$(musl-cross_version)
musl-cross_url := https://github.com/richfelker/musl-cross-make/archive/$(musl-cross_version).tar.gz
musl-cross_tar := musl-cross-$(musl-cross_version).tar.gz
musl-cross_hash := b4b85d6d3ddab0f2b8650a53e775673f8c346fa2fb07d652a9880bd206ade100


ifneq "$(CROSS)" ""

# check that $(CROSS)gcc exists or else things just won't work
ifneq "y" "$(shell [ -x '$(CROSS)gcc' ] && echo y)"
$(error $(CROSS)gcc does not exist - can not build)
else
$(info Using $(CROSS)gcc)
endif

# The cross compiler has already been built, so the musl-cross target
# is a NOP.
#musl-cross.intermediate:
# is a NOP. We really don't need to check out this code tree, but it is easier
# if we have a target for it.
musl-cross_target := --version

musl-cross_dir := musl-cross-ext
$(build)/$(musl-cross_dir)/.build:
mkdir -p $(dir $@)
touch $@
# Ask the compiler where to find its own libc.so
musl-cross_libraries := \
$(shell $(CROSS)gcc --print-file-name=libc.so) \

else

# Force a full build of the cross compiler
# have to build both x86_64 and i386 versions for coreboot

modules-y += musl-cross
musl-cross_version := 1952975
musl-cross_dir := musl-cross
musl-cross_url := https://github.com/GregorR/musl-cross/archive/$(musl-cross_version).tar.gz
musl-cross_tar := musl-cross-$(musl-cross_version).tar.gz
musl-cross_hash := dea10cfe4bfe5f5b131d8f98e65127cf5093477af56054d15563e858dc3b25cb
musl-cross_configure := \
/bin/echo -e >> Makefile 'both:' ; \
/bin/echo -e >> Makefile '\t$$$$(MAKE) TARGET=x86_64-linux-musl install' ; \
/bin/echo -e >> Makefile '\t$$$$(MAKE) TARGET=i386-linux-musl install' ; \

CROSS_TOP := crossgcc/x86_64-linux-musl/bin/x86_64-linux-musl-
CROSS := $(build)/../$(CROSS_TOP)
musl-cross_output := ../../$(CROSS_TOP)gcc
CROSS_PATH ?= $(pwd)/crossgcc

musl-cross_configure := \
/bin/echo -e > Makefile \
'$(musl-cross_output):\n\tCC_BASE_PREFIX="$(pwd)/crossgcc" ./build.sh'
musl-cross_target := \
OUTPUT="$(CROSS_PATH)" \
MAKE="$(MAKE)" \
both

CROSS := $(CROSS_PATH)/bin/x86_64-linux-musl-
musl-cross_libraries := $(CROSS_PATH)/x86_64-linux-musl/lib/libc.so

endif

musl-cross_target :=

musl-cross_output := $(CROSS)gcc

## Fake a target so that musl will force a header install by the
## Linux kernel sources.
$(build)/$(musl-cross_dir)/.build: $(INSTALL)/include/linux/limits.h


endif
27 changes: 27 additions & 0 deletions patches/coreboot-4.8.1/0010-cross-compiler-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--- clean/coreboot-4.8.1/Makefile 2018-05-16 21:00:17.000000000 +0200
+++ coreboot-4.8.1/Makefile 2020-01-08 17:01:32.998287979 +0100
@@ -152,6 +152,24 @@

-include .xcompile

+ifneq "$(CROSS)" ""
+ $(info coreboot: Using $(CROSS)gcc)
+ CROSS_COMPILE_x86_32 := $(CROSS)
+ CC_x86_32 := $(CROSS_COMPILE_x86_32)gcc
+ CPP_x86_32 := $(CROSS_COMPILE_x86_32)cpp
+ AS_x86_32 := $(CROSS_COMPILE_x86_32)as --32
+ LD_x86_32 := $(CROSS_COMPILE_x86_32)ld.bfd -b elf32-i386 -melf_i386
+ NM_x86_32 := $(CROSS_COMPILE_x86_32)nm
+ OBJCOPY_x86_32 := $(CROSS_COMPILE_x86_32)objcopy
+ OBJDUMP_x86_32 := $(CROSS_COMPILE_x86_32)objdump
+ READELF_x86_32 := $(CROSS_COMPILE_x86_32)readelf
+ STRIP_x86_32 := $(CROSS_COMPILE_x86_32)strip
+ AR_x86_32 := $(CROSS_COMPILE_x86_32)ar
+ GNATBIND_x86_32 := $(CROSS_COMPILE_x86_32)gnatbind
+ COMPILER_RT_x86_32 := $(shell $(CC_x86_32) --print-libgcc-file-name)
+endif
+
+
ifneq ($(XCOMPILE_COMPLETE),1)
$(shell rm -f .xcompile)
$(error .xcompile deleted because it's invalid. \

0 comments on commit 791d064

Please sign in to comment.