Skip to content

Commit

Permalink
Merge remote-tracking branch 'JonathonHall-Purism/reuse-toolchains' i…
Browse files Browse the repository at this point in the history
…nto HEAD
  • Loading branch information
tlaurion committed Aug 15, 2023
2 parents 5362205 + a5689c4 commit 89b9e5e
Show file tree
Hide file tree
Showing 41 changed files with 127 additions and 135,777 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ define define_module =
# if they have not defined a separate base dir, define it
# as the same as their build dir.
$(eval $1_base_dir = $(or $($1_base_dir),$($1_dir)))
# Dynamically defined modules must tell us what module file defined them
$(eval $1_module_file = $(or $($1_module_file),$1))

ifneq ("$($1_repo)","")
$(eval $1_patch_name = $1$(if $($1_patch_version),-$($1_patch_version),))
Expand Down Expand Up @@ -334,8 +336,11 @@ define define_module =
touch "$(build)/$($1_base_dir)/.patched"; \
fi
else
$(eval $1_patch_version ?= $($1_version))
$(eval $1_patch_name = $1-$($1_patch_version))
# Versioned modules (each version a separate module) don't need to include
# the version a second time. (The '-' separator is also omitted then.)
# $1_patch_version can still be defined manually.
$(eval $1_patch_version ?= $(if $(filter %-$($1_version),$1),,$($1_version)))
$(eval $1_patch_name = $1$(if $($1_patch_version),-,)$($1_patch_version))
# Fetch and verify the source tar file
# wget creates it early, so we have to cleanup if it fails
$(packages)/$($1_tar):
Expand Down Expand Up @@ -400,7 +405,7 @@ define define_module =
$(build)/$($1_base_dir)/.canary \
$(foreach d,$($1_config_wait),$(build)/$($d_dir)/.build) \
$($1_config_file_path) \
modules/$1
modules/$($1_module_file)
@echo "$(DATE) CONFIG $1"
@( \
cd "$(build)/$($1_dir)" ; \
Expand Down
1 change: 0 additions & 1 deletion boards/librem_13v2/librem_13v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_13v2.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_13v4/librem_13v4.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_13v4.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_14/librem_14.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_14.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_15v3/librem_15v3.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_15v3.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_15v4/librem_15v4.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_15v4.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_l1um_v2/librem_l1um_v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_l1um_v2.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=6.1.8
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_mini/librem_mini.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_mini.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
1 change: 0 additions & 1 deletion boards/librem_mini_v2/librem_mini_v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIG_COREBOOT_CONFIG=config/coreboot-librem_mini_v2.config
export CONFIG_COREBOOT=y
export CONFIG_COREBOOT_VERSION=purism
export CONFIG_LINUX_VERSION=5.10.5
export CONFIG_PURISM_BLOBS=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
210 changes: 119 additions & 91 deletions modules/coreboot
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
modules-$(CONFIG_COREBOOT) += coreboot

ifeq "$(CONFIG_COREBOOT)" "y"

CONFIG_COREBOOT_ROM ?= coreboot.rom
Expand All @@ -8,64 +6,99 @@ CONFIG_COREBOOT_BOOTBLOCK ?=
ifeq "$(CONFIG_TARGET_ARCH)" "x86"
COREBOOT_TARGET := i386
LINUX_IMAGE_FILE := bzImage
COREBOOT_TARGET_CROSS :=
else ifeq "$(CONFIG_TARGET_ARCH)" "ppc64"
COREBOOT_TARGET := ppc64
LINUX_IMAGE_FILE := zImage
# skiboot payload needs the Heads toolchain as it is little-endian (like
# Linux), but coreboot is big-endian on PPC64.
COREBOOT_TARGET_CROSS := CROSS=$(CROSS)
else
$(error "$(CONFIG_TARGET_ARCH) target isn't supported by this module")
endif

ifeq "$(CONFIG_COREBOOT_VERSION)" "4.8.1"
coreboot_version := 4.8.1
coreboot_hash := f0ddf4db0628c1fe1e8348c40084d9cbeb5771400c963fd419cda3995b69ad23
coreboot-blobs_hash := 18aa509ae3af005a05d7b1e0b0246dc640249c14fc828f5144b6fd20bb10e295
else ifeq "$(CONFIG_COREBOOT_VERSION)" "4.11"
coreboot_version := 4.11
coreboot_hash := 97fd859b4c39a25534fe33c30eb86e54a233952e08a024c55858d11598a8ad87
coreboot-blobs_hash := aa7855c5bd385b3360dadc043ea6bc93f564e6e4840d9b3ee5b9e696bbd055db
coreboot_depends := $(if $(CONFIG_PURISM_BLOBS), purism-blobs)
else ifeq "$(CONFIG_COREBOOT_VERSION)" "4.13"
coreboot_version := 4.13
coreboot_hash := 4779da645a25ddebc78f1bd2bd0b740fb1e6479572648d4650042a2b9502856a
coreboot-blobs_hash := 060656b46a7859d038ddeec3f7e086e85f146a50b280c4babec23c1188264dc8
coreboot_depends := $(if $(CONFIG_PURISM_BLOBS), purism-blobs)
else ifeq "$(CONFIG_COREBOOT_VERSION)" "4.17"
coreboot_version := 4.17
coreboot_hash := 95da11d1c6a450385101a68799258a398ce965f4e46cce6fe8d5ebd74e50c125
coreboot-blobs_hash := a2277fe7a2b2aab5da0aa335158460e00b852382f6736f2179992805702eb607
coreboot_depends := $(if $(CONFIG_PURISM_BLOBS), purism-blobs)
EXTRA_FLAGS := -fdebug-prefix-map=$(pwd)=heads -gno-record-gcc-switches -Wno-error=packed-not-aligned -Wno-error=address-of-packed-member
else ifeq "$(CONFIG_COREBOOT_VERSION)" "4.19"
coreboot_version := 4.19
coreboot_hash := 65ccb2f46535b996e0066a1b76f81c8cf1ff3e27df84b3f97d8ad7b3e7cf0a43
coreboot-blobs_hash := 30214caed07b25f11e47bec022ff6234841376e36689eb674de2330a3e980cbc
coreboot_depends := $(if $(CONFIG_PURISM_BLOBS), purism-blobs)
EXTRA_FLAGS := -fdebug-prefix-map=$(pwd)=heads -gno-record-gcc-switches -Wno-error=packed-not-aligned -Wno-error=address-of-packed-member
else ifeq "$(CONFIG_COREBOOT_VERSION)" "talos_2"
coreboot_version = git
coreboot_patch_version = talos_2
coreboot_commit_hash = c8aed443c631042ad2b0326c35cd0b774752b924
coreboot_repo := https://github.com/Dasharo/coreboot
else ifeq "$(CONFIG_COREBOOT_VERSION)" "nitrokey"
coreboot_version = git
coreboot_commit_hash = 6328eebb101fd0ded7168e1377da6a1a82a8e2da
coreboot_repo := https://github.com/Nitrokey/coreboot
coreboot_depends := $(if $(CONFIG_NITROKEY_BLOBS), nitrokey-blobs)
else ifeq "$(CONFIG_COREBOOT_VERSION)" "purism"
coreboot_version := git
coreboot_repo := https://source.puri.sm/coreboot/coreboot
coreboot_commit_hash := a899f08d2789db1dd9b02cff34179c4d38e6d0e3
EXTRA_FLAGS := -fdebug-prefix-map=$(pwd)=heads -gno-record-gcc-switches -Wno-error=packed-not-aligned -Wno-error=address-of-packed-member
else
# Each coreboot version is defined as a separate module, but only the needed
# modules become dependencies of the current board. One coreboot version is
# selected for the toolchain build and firmware build. These can be the same
# (when using a coreboot release) or different (when using a fork that reuses a
# release's toolchain).

# Define a coreboot module. Parameters:
# $1 - module version
# $2 - toolchain coreboot version - if nonempty, uses the toolchain from this
# version (use for forks to avoid building extra copies of the same
# toolchain)
#
# For a coreboot release:
# - the version is the coreboot release version
# - set coreboot-<version>_hash to the tarball hash
# - set coreboot-blobs-<version>_hash to the blobs tarball hash
#
# For a git fork:
# - the version is the name of the fork (just controls the build directory used)
# - set coreboot-<version>_repo to the git repo address
# - set coreboot-<version>_commit_hash to the git commit
define coreboot_module =
coreboot-$(1)_version := $(1)
coreboot-$(1)_module_file := coreboot
coreboot-$(1)_base_dir := coreboot-$(1)
coreboot-$(1)_dir := coreboot-$(1)/$(BOARD)
coreboot-$(1)_toolchain := $(2)
# These are ignored if this version is a git fork
coreboot-$(1)_tar := coreboot-$(1).tar.xz
coreboot-$(1)_url := https://www.coreboot.org/releases/coreboot-$(1).tar.xz
# These are only used for releases, git forks don't use upstream blobs
coreboot-blobs-$(1)_version := $(1)
coreboot-blobs-$(1)_module_file := coreboot
coreboot-blobs-$(1)_dir := coreboot-$(1)/3rdparty
coreboot-blobs-$(1)_tar := coreboot-blobs-$(1).tar.xz
coreboot-blobs-$(1)_url := https://www.coreboot.org/releases/coreboot-blobs-$(1).tar.xz
coreboot-blobs-$(1)_tar_opt := --strip 2
endef

# coreboot releases

coreboot-4.11_hash := 97fd859b4c39a25534fe33c30eb86e54a233952e08a024c55858d11598a8ad87
coreboot-blobs-4.11_hash := aa7855c5bd385b3360dadc043ea6bc93f564e6e4840d9b3ee5b9e696bbd055db
$(eval $(call coreboot_module,4.11,))

coreboot-4.19_hash := 65ccb2f46535b996e0066a1b76f81c8cf1ff3e27df84b3f97d8ad7b3e7cf0a43
coreboot-blobs-4.19_hash := 30214caed07b25f11e47bec022ff6234841376e36689eb674de2330a3e980cbc
$(eval $(call coreboot_module,4.19,))

coreboot-4.20.1_hash := b41539a8c2eab2fec752157eb4acbd0e2a637a7203530c12e66b43a5c3c3a931
coreboot-blobs-4.20.1_hash := 30f9d8618e78d483d0903976982485e70825ca3469efd17902c9246aaefd7c4a
$(eval $(call coreboot_module,4.20.1,))

# coreboot git forks

# talos_2 could use the 4.20.1 toolchain, but it's the only ppc64 fork, so
# there is no point preparing another coreboot module that won't be shared with
# anything.
coreboot-talos_2_repo := https://github.com/Dasharo/coreboot
coreboot-talos_2_commit_hash := c8aed443c631042ad2b0326c35cd0b774752b924
$(eval $(call coreboot_module,talos_2,))

# Similarly, purism is based on 4.20.1, but nothing builds against 4.20.1 itself
# or any other fork - no benefit to sharing the toolchain yet.
coreboot-purism_repo := https://source.puri.sm/firmware/coreboot.git
coreboot-purism_commit_hash := a899f08d2789db1dd9b02cff34179c4d38e6d0e3
$(eval $(call coreboot_module,purism,))

# Check that the board configured the coreboot version correctly
ifeq "$(CONFIG_COREBOOT_VERSION)" ""
$(error "$(BOARD): does not specify coreboot version under CONFIG_COREBOOT_VERSION")
else ifeq "$(coreboot-$(CONFIG_COREBOOT_VERSION)_dir)" ""
$(error "$(BOARD): coreboot version $(CONFIG_COREBOOT_VERSION) not known"
endif

#coreboot_version := git
#coreboot_repo := https://github.com/osresearch/coreboot
coreboot_base_dir := coreboot-$(coreboot_version)
coreboot_dir := $(coreboot_base_dir)/$(BOARD)
coreboot_tar := coreboot-$(coreboot_version).tar.xz
coreboot_url := https://www.coreboot.org/releases/$(coreboot_tar)
coreboot_module := coreboot-$(CONFIG_COREBOOT_VERSION)
modules-y += $(coreboot_module)
# Don't make everyone type $($(coreboot_module)_dir)
coreboot_dir := $($(coreboot_module)_dir)
coreboot_base_dir := $($(coreboot_module)_base_dir)

$(coreboot_module)_depends += $(if $(CONFIG_PURISM_BLOBS), purism-blobs)

# coreboot builds are specialized on a per-target basis.
# The builds are done in a per-target subdirectory
Expand All @@ -76,7 +109,22 @@ $(build)/$(coreboot_dir)/.configured: $(CONFIG_COREBOOT_CONFIG)

EXTRA_FLAGS ?= -fdebug-prefix-map=$(pwd)=heads -gno-record-gcc-switches -Wno-error=packed-not-aligned -Wno-address-of-packed-member

coreboot_configure := \
# Select the coreboot version to use for the toolchain
ifeq "$($(coreboot_module)_toolchain)" ""
# Use the same module
coreboot_toolchain_module := $(coreboot_module)
else
# Use a different module
coreboot_toolchain_module := coreboot-$($(coreboot_module)_toolchain)
modules-y += $(coreboot_toolchain_module)
# The toolchain module won't build anything for this board, we just need
# the module prepped so we can hook up the toolchain target
$(coreboot_toolchain_module)_output := .nobuild
$(coreboot-toolchain_module)_configure := echo -e 'all:\n\ttouch .nobuild' > Makefile.nobuild
$(coreboot-toolchain_module)_target := -f Makefile.nobuild
endif

$(coreboot_module)_configure := \
mkdir -p "$(build)/$(coreboot_dir)" \
&& $(call install_config,$(pwd)/$(CONFIG_COREBOOT_CONFIG),$(build)/$(coreboot_dir)/.config) \
&& echo 'CONFIG_LOCALVERSION="$(BRAND_NAME)-$(HEADS_GIT_VERSION)"' >> $(build)/$(coreboot_dir)/.config \
Expand All @@ -89,40 +137,30 @@ coreboot_configure := \
CFLAGS_x86_32="$(EXTRA_FLAGS)" \
CFLAGS_x86_64="$(EXTRA_FLAGS)" \

COREBOOT_IASL="$(build)/$(coreboot_base_dir)/util/crossgcc/xgcc/bin/iasl"
# Create a dependency from coreboot to the toolchain. Use .heads-toolchain to
# mark that the toolchain was built.
COREBOOT_TOOLCHAIN=$(build)/$($(coreboot_toolchain_module)_base_dir)/.heads-toolchain
$(COREBOOT_TOOLCHAIN): $(build)/$($(coreboot_toolchain_module)_base_dir)/.canary
$(MAKE) -C "$(build)/$($(coreboot_toolchain_module)_base_dir)" CPUS=$(CPUS) "crossgcc-$(COREBOOT_TARGET)"
touch "$@"

# coreboot for x86 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)" \
ifeq "$(CONFIG_TARGET_ARCH)" "x86"
COREBOOT_CROSS := $(dir $(CROSS))i386-linux-musl-
else
COREBOOT_CROSS := $(CROSS)
endif
$(build)/$(coreboot_dir)/.configured: $(COREBOOT_TOOLCHAIN)

coreboot_target := \
# Build with the cross toolchain from the toolchain module (which might be the
# same coreboot module or a different one).
$(coreboot_module)_target := \
-C "$(build)/$(coreboot_base_dir)" \
obj="$(build)/$(coreboot_dir)" \
CROSS="$(COREBOOT_CROSS)" \
IASL="$(COREBOOT_IASL)" \
DOTCONFIG="$(build)/$(coreboot_dir)/.config" \
xcompile="$(build)/$(coreboot_base_dir)/.xcompile" \
XGCCPATH="$(build)/$($(coreboot_toolchain_module)_base_dir)/util/crossgcc/xgcc/bin/" \
$(COREBOOT_TARGET_CROSS) \
BUILD_TIMELESS=1 \
CFLAGS_x86_32="$(EXTRA_FLAGS)" \
CFLAGS_x86_64="$(EXTRA_FLAGS)" \
$(MAKE_JOBS)

coreboot_output := $(CONFIG_COREBOOT_ROM)
coreboot_output += $(CONFIG_COREBOOT_BOOTBLOCK)
coreboot_depend += linux initrd $(musl_dep)

COREBOOT_TOOLCHAIN=$(build)/$(coreboot_base_dir)/.xcompile
$(COREBOOT_TOOLCHAIN): $(build)/$(coreboot_base_dir)/.canary
$(MAKE) -C "$(build)/$(coreboot_base_dir)" CPUS=$(CPUS) "crossgcc-$(COREBOOT_TARGET)"

$(build)/$(coreboot_dir)/.configured: $(COREBOOT_TOOLCHAIN)
$(coreboot_module)_output := $(CONFIG_COREBOOT_ROM)
$(coreboot_module)_output += $(CONFIG_COREBOOT_BOOTBLOCK)

# Force a rebuild if the inputs have changed
$(build)/$(coreboot_dir)/.build: \
Expand Down Expand Up @@ -193,27 +231,17 @@ coreboot.modify_and_save_oldconfig_in_place:

# if we are not building from a git checkout,
# we must also download the coreboot-blobs tree
ifneq "$(coreboot_version)" "git"

coreboot_depends += coreboot-blobs
modules-y += coreboot-blobs
ifeq "$($(coreboot_module)_repo)" ""

coreboot-blobs_version := $(coreboot_version)
coreboot-blobs_tar := coreboot-blobs-$(coreboot-blobs_version).tar.xz
coreboot-blobs_url := https://www.coreboot.org/releases/$(coreboot-blobs_tar)
coreboot-blobs_module := coreboot-blobs-$(CONFIG_COREBOOT_VERSION)

ifeq "$(CONFIG_COREBOOT_VERSION)" "4.8.1"
coreboot-blobs_tar_opt := --strip 3
coreboot-blobs_dir := coreboot-$(coreboot-blobs_version)/3rdparty/blobs
else
coreboot-blobs_tar_opt := --strip 2
coreboot-blobs_dir := coreboot-$(coreboot-blobs_version)/3rdparty
endif
$(coreboot_module)_depends += $(coreboot-blobs_module)
modules-y += $(coreboot-blobs_module)

## there is nothing to build for the blobs, this should be
## made easier to make happen
coreboot-blobs_output := .built
coreboot-blobs_configure := echo -e 'all:\n\ttouch .built' > Makefile
$(coreboot-blobs_module)_output := .built
$(coreboot-blobs_module)_configure := echo -e 'all:\n\ttouch .built' > Makefile

endif
endif
Loading

0 comments on commit 89b9e5e

Please sign in to comment.