2020-10-21 15:04:27 +00:00
# Need to set CB_OUTPUT_FILE before board .config included so
# that target overrides in x230/x430-flash (eg) are properly handled
GIT_HASH := $( shell git rev-parse HEAD)
GIT_STATUS := $( shell \
if git diff --exit-code >/dev/null ; then \
echo clean ; \
else \
echo dirty ; \
fi )
2022-10-20 15:00:33 +00:00
HEADS_GIT_VERSION := $( shell git describe --abbrev= 7 --tags --dirty)
2020-10-21 15:04:27 +00:00
2023-06-21 18:19:41 +00:00
# Override BRAND_NAME to set the name displayed in the UI, filenames, versions, etc.
BRAND_NAME ?= Heads
2018-02-08 00:03:40 +00:00
all :
2018-02-02 20:56:46 +00:00
- i n c l u d e . c o n f i g
2017-03-31 15:18:46 +00:00
modules-y :=
2016-08-02 23:25:47 +00:00
pwd := $( shell pwd )
2018-02-05 16:27:45 +00:00
config := $( pwd ) /config
2021-07-22 22:25:55 +00:00
# These are dynamic, must not expand right here
build = $( pwd ) /build/$( CONFIG_TARGET_ARCH)
packages = $( pwd ) /packages/$( CONFIG_TARGET_ARCH)
INSTALL = $( pwd ) /install/$( CONFIG_TARGET_ARCH)
log_dir = $( build) /log
2021-07-22 22:24:55 +00:00
board_build = $( build) /$( BOARD)
2017-03-29 20:58:45 +00:00
CircleCI + Makefile: remove limitation to loadavg of 16 in Makefile, test CPUS=8 to maximize loadavg on CircleCI with 4 CPUs & 8GB ram
See first lines of output of any make command. Change aimed to be respectful of CI resource (8GB ram 4CPUs)
With CPUS=8 AVAILABLE_MEM_GB=4, CircleCI outputs:
!!!!!! BUILD SYSTEM INFO !!!!!!
System CPUS: 36
System Available Memory: 4 GB
System Load Average: 12.99
----------------------------------------------------------------------
Used **CPUS**: 8
Used **LOADAVG**: 8
Used **AVAILABLE_MEM_GB**: 4 GB
----------------------------------------------------------------------
**MAKE_JOBS**: -j8 --max-load 8
Variables available for override (use 'make VAR_NAME=value'):
**CPUS** (default: number of processors, e.g., 'make CPUS=4')
**LOADAVG** (default: same as CPUS, e.g., 'make LOADAVG=4')
**AVAILABLE_MEM_GB** (default: memory available on the system in GB, e.g., 'make AVAILABLE_MEM_GB=4')
**MEM_PER_JOB_GB** (default: 1GB per job, e.g., 'make MEM_PER_JOB_GB=2')
----------------------------------------------------------------------
Let's try without any limitation...
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
2024-04-23 18:31:54 +00:00
# Estimated memory required per job in GB (e.g., 1GB for gcc)
MEM_PER_JOB_GB ?= 1
2018-04-19 23:37:45 +00:00
# Controls how many parallel jobs are invoked in subshells
2024-04-24 18:49:13 +00:00
CPUS ?= $( shell nproc)
AVAILABLE_MEM_GB ?= $( shell cat /proc/meminfo | grep MemAvailable | awk '{print int($$2 / 1024)}' )
CircleCI + Makefile: remove limitation to loadavg of 16 in Makefile, test CPUS=8 to maximize loadavg on CircleCI with 4 CPUs & 8GB ram
See first lines of output of any make command. Change aimed to be respectful of CI resource (8GB ram 4CPUs)
With CPUS=8 AVAILABLE_MEM_GB=4, CircleCI outputs:
!!!!!! BUILD SYSTEM INFO !!!!!!
System CPUS: 36
System Available Memory: 4 GB
System Load Average: 12.99
----------------------------------------------------------------------
Used **CPUS**: 8
Used **LOADAVG**: 8
Used **AVAILABLE_MEM_GB**: 4 GB
----------------------------------------------------------------------
**MAKE_JOBS**: -j8 --max-load 8
Variables available for override (use 'make VAR_NAME=value'):
**CPUS** (default: number of processors, e.g., 'make CPUS=4')
**LOADAVG** (default: same as CPUS, e.g., 'make LOADAVG=4')
**AVAILABLE_MEM_GB** (default: memory available on the system in GB, e.g., 'make AVAILABLE_MEM_GB=4')
**MEM_PER_JOB_GB** (default: 1GB per job, e.g., 'make MEM_PER_JOB_GB=2')
----------------------------------------------------------------------
Let's try without any limitation...
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
2024-04-23 18:31:54 +00:00
# Calculate the maximum number of jobs based on available memory
MAX_JOBS_MEM := $( shell echo $$ ( ( $( AVAILABLE_MEM_GB) / $( MEM_PER_JOB_GB) ) ) )
# Use the minimum of the system's CPUs and the calculated max jobs based on memory
CPUS := $( shell echo $$ ( ( $( CPUS) < $( MAX_JOBS_MEM) ? $( CPUS) : $( MAX_JOBS_MEM) ) ) )
# Load average can be adjusted to be higher than CPUS to allow for some CPU overcommit
# Multiply by 3 and then divide by 2 to achieve the effect of multiplying by 1.5 using integer arithmetic
LOADAVG ?= $( shell echo $$ ( ( ( $( CPUS) * 3) / 2 ) ) )
# Construct MAKE_JOBS with dynamic CPU count and load average
2024-04-24 18:49:13 +00:00
MAKE_JOBS := -j$( CPUS) --load-average= $( LOADAVG) # Add other flags as needed to be more adaptive to CIs
CircleCI + Makefile: remove limitation to loadavg of 16 in Makefile, test CPUS=8 to maximize loadavg on CircleCI with 4 CPUs & 8GB ram
See first lines of output of any make command. Change aimed to be respectful of CI resource (8GB ram 4CPUs)
With CPUS=8 AVAILABLE_MEM_GB=4, CircleCI outputs:
!!!!!! BUILD SYSTEM INFO !!!!!!
System CPUS: 36
System Available Memory: 4 GB
System Load Average: 12.99
----------------------------------------------------------------------
Used **CPUS**: 8
Used **LOADAVG**: 8
Used **AVAILABLE_MEM_GB**: 4 GB
----------------------------------------------------------------------
**MAKE_JOBS**: -j8 --max-load 8
Variables available for override (use 'make VAR_NAME=value'):
**CPUS** (default: number of processors, e.g., 'make CPUS=4')
**LOADAVG** (default: same as CPUS, e.g., 'make LOADAVG=4')
**AVAILABLE_MEM_GB** (default: memory available on the system in GB, e.g., 'make AVAILABLE_MEM_GB=4')
**MEM_PER_JOB_GB** (default: 1GB per job, e.g., 'make MEM_PER_JOB_GB=2')
----------------------------------------------------------------------
Let's try without any limitation...
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
2024-04-23 18:31:54 +00:00
# Print out the settings and compare system values with actual ones used
$( info ----------------------------------------------------------------------)
$( info !!!!!! BUILD SYSTEM INFO !!!!!!)
2024-04-24 18:49:13 +00:00
$(info System CPUS : $( shell nproc ) )
CircleCI + Makefile: remove limitation to loadavg of 16 in Makefile, test CPUS=8 to maximize loadavg on CircleCI with 4 CPUs & 8GB ram
See first lines of output of any make command. Change aimed to be respectful of CI resource (8GB ram 4CPUs)
With CPUS=8 AVAILABLE_MEM_GB=4, CircleCI outputs:
!!!!!! BUILD SYSTEM INFO !!!!!!
System CPUS: 36
System Available Memory: 4 GB
System Load Average: 12.99
----------------------------------------------------------------------
Used **CPUS**: 8
Used **LOADAVG**: 8
Used **AVAILABLE_MEM_GB**: 4 GB
----------------------------------------------------------------------
**MAKE_JOBS**: -j8 --max-load 8
Variables available for override (use 'make VAR_NAME=value'):
**CPUS** (default: number of processors, e.g., 'make CPUS=4')
**LOADAVG** (default: same as CPUS, e.g., 'make LOADAVG=4')
**AVAILABLE_MEM_GB** (default: memory available on the system in GB, e.g., 'make AVAILABLE_MEM_GB=4')
**MEM_PER_JOB_GB** (default: 1GB per job, e.g., 'make MEM_PER_JOB_GB=2')
----------------------------------------------------------------------
Let's try without any limitation...
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
2024-04-23 18:31:54 +00:00
$(info System Available Memory : $( AVAILABLE_MEM_GB ) GB )
$(info System Load Average : $( shell uptime | awk '{print $ $ 10}') )
$( info ----------------------------------------------------------------------)
$(info Used **CPUS** : $( CPUS ) )
$(info Used **LOADAVG** : $( LOADAVG ) )
$(info Used **AVAILABLE_MEM_GB** : $( AVAILABLE_MEM_GB ) GB )
$( info ----------------------------------------------------------------------)
$(info **MAKE_JOBS** : $( MAKE_JOBS ) )
$( info )
$(info Variables available for override (use 'make VAR_NAME=value') : )
$(info **CPUS** (default : number of processors , e .g ., 'make CPUS =4'))
$(info **LOADAVG** (default : 1.5 times CPUS , e .g ., 'make LOADAVG =54'))
$(info **AVAILABLE_MEM_GB** (default : memory available on the system in GB , e .g ., 'make AVAILABLE_MEM_GB =4'))
$(info **MEM_PER_JOB_GB** (default : 1GB per job , e .g ., 'make MEM_PER_JOB_GB =2'))
$( info ----------------------------------------------------------------------)
$( info !!!!!! Build starts !!!!!!)
2018-04-19 23:37:45 +00:00
2022-01-31 15:57:24 +00:00
# Timestamps should be in ISO format
DATE = ` date --rfc-3339= seconds`
2023-06-23 18:00:02 +00:00
BOARD ?= qemu-coreboot-fbwhiptail-tpm1
2018-03-12 09:26:23 +00:00
CONFIG := $( pwd ) /boards/$( BOARD) /$( BOARD) .config
2018-02-05 16:27:45 +00:00
i f n e q "y" "$(shell [ -r '$(CONFIG)' ] && echo y)"
$(error $(CONFIG) : board configuration does not exist )
e n d i f
2021-07-22 22:25:55 +00:00
# By default, we are building for x86, up to a board to change this variable
CONFIG_TARGET_ARCH := x86
2023-11-14 17:14:18 +00:00
# Legacy flash boards have to be handled specifically for some functionality
# (e.g. they don't generate upgrade packages, lack bash, etc.) Use this to
# guard behavior that is specific to legacy flash boards only. Don't use it for
# behavior that might be needed for other boards, use specific configs instead.
CONFIG_LEGACY_FLASH := n
2018-02-05 16:27:45 +00:00
i n c l u d e $( CONFIG )
2023-12-18 18:34:55 +00:00
# Include site-local/config only if it exists, downstreams can set configs for
# all boards, including overriding values specified by boards. site-local is
# not a part of the upstream distribution but is for downstreams to insert
# customizations at well-defined points, like in coreboot:
# https://doc.coreboot.org/tutorial/managing_local_additions.html
- i n c l u d e $( pwd ) / s i t e - l o c a l / c o n f i g
CB_OUTPUT_BASENAME := $( shell echo $( BRAND_NAME) | tr A-Z a-z) -$( BOARD) -$( HEADS_GIT_VERSION)
CB_OUTPUT_FILE := $( CB_OUTPUT_BASENAME) .rom
CB_OUTPUT_FILE_GPG_INJ := $( CB_OUTPUT_BASENAME) -gpg-injected.rom
CB_BOOTBLOCK_FILE := $( CB_OUTPUT_BASENAME) .bootblock
CB_UPDATE_PKG_FILE := $( CB_OUTPUT_BASENAME) .zip
LB_OUTPUT_FILE := linuxboot-$( BOARD) -$( HEADS_GIT_VERSION) .rom
2018-02-13 22:46:48 +00:00
# Unless otherwise specified, we are building for heads
CONFIG_HEADS ?= y
2023-03-01 21:07:03 +00:00
# Unless otherwise specified, we are building bash to have non-interactive shell for scripts (arrays and bashisms)
CONFIG_BASH ?= y
2024-01-09 14:43:28 +00:00
# USB keyboards can be ignored, optionally supported, or required.
#
# To optionally support USB keyboards, export CONFIG_SUPPORT_USB_KEYBOARD=y. To
# default the setting to 'on', also export CONFIG_USER_USB_KEYBOARD=y.
#
# To require USB keyboard support (not user-configurable, for boards with no
# built-in keyboard), export CONFIG_USB_KEYBOARD_REQUIRED=y.
i f e q "$(CONFIG_USB_KEYBOARD_REQUIRED)" "y"
# CONFIG_USB_KEYBOARD_REQUIRED implies CONFIG_SUPPORT_USB_KEYBOARD.
export CONFIG_SUPPORT_USB_KEYBOARD = y
e n d i f
2021-07-18 17:34:20 +00:00
# Determine arch part for a host triplet
i f e q "$(CONFIG_TARGET_ARCH)" "x86"
MUSL_ARCH := x86_64
e l s e i f e q "$(CONFIG_TARGET_ARCH)" "ppc64"
MUSL_ARCH := powerpc64le
e l s e
$(error "Unexpected value of $$(CONFIG_TARGET_ARCH) : $( CONFIG_TARGET_ARCH ) ")
e n d i f
2023-12-18 20:24:21 +00:00
i f n e q "$(BOARD_TARGETS)" ""
2024-01-04 18:48:52 +00:00
i n c l u d e $( foreach TARGET ,$ ( BOARD_TARGETS ) ,targets /$ ( TARGET ) .mk )
2023-12-18 20:24:21 +00:00
e n d i f
2021-07-22 22:25:55 +00:00
# Create directories if they don't already exist
BUILD_LOG := $( shell mkdir -p " $( log_dir) " )
PACKAGES := $( shell mkdir -p " $( packages) " )
2018-09-18 16:08:16 +00:00
# record the build date / git hashes and other files here
2021-07-22 22:24:55 +00:00
HASHES := $( board_build) /hashes.txt
2023-06-27 14:01:01 +00:00
SIZES := $( board_build) /sizes.txt
2018-09-18 16:08:16 +00:00
# Create the board output directory if it doesn't already exist
BOARD_LOG := $( shell \
2021-07-22 22:24:55 +00:00
mkdir -p " $( board_build) " ; \
2018-09-18 16:08:16 +00:00
echo " $( DATE) $( GIT_HASH) $( GIT_STATUS) " > " $( HASHES) " ; \
2023-06-27 14:01:01 +00:00
echo " $( DATE) $( GIT_HASH) $( GIT_STATUS) " > " $( SIZES) " ; \
2018-09-18 16:08:16 +00:00
)
2021-07-18 17:35:59 +00:00
i f e q "y" "$(CONFIG_LINUX_BUNDLED)"
# Create empty initrd for initial kernel "without" initrd.
2021-07-22 22:24:55 +00:00
$( shell cpio -o < /dev /null > $ ( board_build ) /initrd .cpio )
2021-07-18 17:35:59 +00:00
e n d i f
2017-03-31 16:06:59 +00:00
2017-02-28 23:02:10 +00:00
# If V is set in the environment, do not redirect the tee
# command to /dev/null.
i f e q "$V" ""
VERBOSE_REDIRECT := > /dev/null
2017-03-29 19:15:03 +00:00
# Not verbose, so we only show the header
d e f i n e do =
2018-02-05 16:27:45 +00:00
@echo " $( DATE) $1 $( 2:$( pwd ) /%= %) "
2017-03-29 19:15:03 +00:00
@$3
e n d e f
e l s e
# Verbose, so we display what we are doing
d e f i n e do =
2018-02-05 16:27:45 +00:00
@echo " $( DATE) $1 $( 2:$( pwd ) /%= %) "
2017-03-29 19:15:03 +00:00
$3
e n d e f
2017-02-28 23:02:10 +00:00
e n d i f
2016-08-02 23:25:47 +00:00
2017-03-29 19:15:03 +00:00
2017-03-31 15:18:46 +00:00
# Create a temporary directory for the initrd
2018-05-02 15:38:39 +00:00
initrd_dir := $( BOARD)
initrd_tmp_dir := $( shell mktemp -d)
2024-06-12 13:42:17 +00:00
initrd_data_dir := $( initrd_tmp_dir) /etc/terminfo/l
2018-05-02 15:38:39 +00:00
initrd_lib_dir := $( initrd_tmp_dir) /lib
initrd_bin_dir := $( initrd_tmp_dir) /bin
modules-y += initrd
2017-03-31 15:18:46 +00:00
2024-06-12 13:42:17 +00:00
$( shell mkdir -p "$ ( initrd_lib_dir ) " "$ ( initrd_bin_dir ) " "$ ( initrd_data_dir ) ")
2017-03-31 15:18:46 +00:00
2017-01-27 21:17:03 +00:00
# We are running our own version of make,
# proceed with the build.
2017-03-20 18:47:47 +00:00
# Force pipelines to fail if any of the commands in the pipe fail
2022-12-28 14:58:57 +00:00
SHELL := /usr/bin/env bash
2017-03-20 18:47:47 +00:00
.SHELLFLAGS := -o pipefail -c
2024-11-06 13:03:42 +00:00
# Include the musl-cross-make module early so that $(CROSS) will
2018-03-16 16:59:24 +00:00
# be defined prior to any other module.
2024-11-06 13:03:42 +00:00
i n c l u d e m o d u l e s / m u s l - c r o s s - m a k e
2018-03-16 16:59:24 +00:00
2024-11-06 13:03:42 +00:00
musl_dep := musl-cross-make
2022-08-25 18:43:31 +00:00
target := $( shell echo $( CROSS) | grep -Eoe '([^/]*?)-linux-musl' )
arch := $( subst -linux-musl, , $( target) )
2020-01-08 16:08:15 +00:00
heads_cc := $( CROSS) gcc \
2017-01-28 18:14:56 +00:00
-fdebug-prefix-map= $( pwd ) = heads \
-gno-record-gcc-switches \
2018-02-26 16:42:07 +00:00
-D__MUSL__ \
2023-06-30 18:20:23 +00:00
--sysroot $( INSTALL) \
2020-10-21 14:04:00 +00:00
-isystem $( INSTALL) /include \
2020-01-08 16:08:15 +00:00
-L$( INSTALL) /lib \
2017-01-28 18:14:56 +00:00
2023-02-21 18:46:03 +00:00
# Cross-compiling with pkg-config requires clearing PKG_CONFIG_PATH and setting
# both PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR.
# https://autotools.info/pkgconfig/cross-compiling.html
2017-04-08 17:23:34 +00:00
CROSS_TOOLS_NOCC := \
AR = " $( CROSS) ar " \
LD = " $( CROSS) ld " \
STRIP = " $( CROSS) strip " \
NM = " $( CROSS) nm " \
OBJCOPY = " $( CROSS) objcopy " \
OBJDUMP = " $( CROSS) objdump " \
2023-02-21 18:46:03 +00:00
PKG_CONFIG_PATH = \
PKG_CONFIG_LIBDIR = " $( INSTALL) /lib/pkgconfig " \
2018-03-29 21:21:51 +00:00
PKG_CONFIG_SYSROOT_DIR = " $( INSTALL) " \
2017-04-08 17:23:34 +00:00
CROSS_TOOLS := \
CC = " $( heads_cc) " \
$( CROSS_TOOLS_NOCC) \
2022-08-25 18:43:31 +00:00
# Targets to build payload only
.PHONY : payload
payload : $( build ) /$( BOARD ) /bzImage $( build ) /$( initrd_dir ) /initrd .cpio .xz
2016-12-29 23:23:08 +00:00
2020-10-21 15:04:27 +00:00
i f e q ( $( CONFIG_COREBOOT ) , y )
2021-07-20 20:48:08 +00:00
2023-11-14 17:14:18 +00:00
# Legacy flash boards don't generate an update package, the only purpose of
# those boards is to be flashed over vendor firmware via an exploit.
i f n e q ( $( CONFIG_LEGACY_FLASH ) , y )
2023-11-14 19:44:36 +00:00
# talos-2 builds its own update package, which is not integrated with the ZIP
# method currently
i f n e q ( $( BOARD ) , t a l o s - 2 )
2023-11-13 21:42:05 +00:00
# Coreboot targets create an update package that can be applied with integrity
# verification before flashing (see flash-gui.sh). The ZIP package format
# allows other metadata that might be needed to added in the future without
# breaking backward compatibility.
$(board_build)/$(CB_UPDATE_PKG_FILE) : $( board_build ) /$( CB_OUTPUT_FILE )
rm -rf " $( board_build) /update_pkg "
mkdir -p " $( board_build) /update_pkg "
cp " $< " " $( board_build) /update_pkg/ "
cd " $( board_build) /update_pkg " && sha256sum " $( CB_OUTPUT_FILE) " >sha256sum.txt
cd " $( board_build) /update_pkg " && zip -9 " $@ " " $( CB_OUTPUT_FILE) " sha256sum.txt
2024-11-03 16:26:24 +00:00
# Only add the hash and size if split_8mb4mb.mk is not included
i f e q ( $( wildcard split_ 8mb 4mb .mk ) , )
2023-11-13 21:42:05 +00:00
all : $( board_build ) /$( CB_OUTPUT_FILE ) $( board_build ) /$( CB_UPDATE_PKG_FILE )
2024-11-03 16:26:24 +00:00
@sha256sum $( board_build) /$( CB_OUTPUT_FILE) | tee -a " $( HASHES) "
@stat -c "%8s:%n" $( board_build) /$( CB_OUTPUT_FILE) | tee -a " $( SIZES) "
e l s e
all : $( board_build ) /$( CB_OUTPUT_FILE ) $( board_build ) /$( CB_UPDATE_PKG_FILE )
e n d i f
2023-11-14 18:26:18 +00:00
e n d i f
2023-11-14 19:44:36 +00:00
e n d i f
2023-11-14 18:26:18 +00:00
2021-07-20 20:48:08 +00:00
i f n e q ( $( CONFIG_COREBOOT_BOOTBLOCK ) , )
2021-07-22 22:24:55 +00:00
all : $( board_build ) /$( CB_BOOTBLOCK_FILE )
2021-07-20 20:48:08 +00:00
e n d i f
2020-10-21 15:04:27 +00:00
e l s e i f e q ( $( CONFIG_LINUXBOOT ) , y )
2021-07-22 22:24:55 +00:00
all : $( board_build ) /$( LB_OUTPUT_FILE )
2017-11-20 22:28:35 +00:00
e l s e
2018-02-05 16:27:45 +00:00
$(error "$(BOARD) : neither CONFIG_COREBOOT nor CONFIG_LINUXBOOT is set ?")
2017-11-20 22:28:35 +00:00
e n d i f
2016-11-29 16:19:48 +00:00
2022-08-25 18:43:31 +00:00
all payload :
2018-09-18 17:07:40 +00:00
@sha256sum $< | tee -a " $( HASHES) "
2023-06-27 14:01:01 +00:00
@stat -c "%8s:%n" $< | tee -a " $( SIZES) "
2018-09-18 16:08:16 +00:00
2016-11-29 16:19:48 +00:00
# Disable all built in rules
2018-05-02 15:38:39 +00:00
.INTERMEDIATE :
2016-11-29 16:19:48 +00:00
.SUFFIXES :
2017-03-29 20:58:45 +00:00
FORCE :
2016-08-02 23:25:47 +00:00
2022-08-16 16:39:33 +00:00
# Copies config while replacing predefined placeholders with actual values
2024-05-09 21:00:38 +00:00
# This is used in a command like 'this && $(call install_config ...) && that'
# so it needs to evaluate to a shell command.
2022-08-16 16:39:33 +00:00
d e f i n e install_config =
2024-05-09 21:00:38 +00:00
$( pwd ) /bin/prepare_module_config.sh " $1 " " $2 " " $( board_build) " " $( BRAND_NAME) "
2022-08-16 16:39:33 +00:00
e n d e f
2017-03-29 20:58:45 +00:00
# Make helpers to operate on lists of things
2020-01-08 16:08:15 +00:00
# Prefix is "smart" and doesn't add the prefix for absolute file paths
2017-03-29 20:58:45 +00:00
d e f i n e prefix =
2020-01-08 16:08:15 +00:00
$( foreach _ , $ 2, $ ( if $ ( patsubst /%,,$ _ ) ,$ 1$ _ ,$ _ ) )
2017-03-29 20:58:45 +00:00
e n d e f
d e f i n e map =
$( foreach _ ,$ 2,$ ( eval $ ( call $ 1,$ _ ) ) )
e n d e f
2016-11-23 17:11:08 +00:00
# Bring in all of the module definitions;
# these are the external pieces that will be downloaded and built
# as part of creating the Heads firmware image.
2016-08-03 12:40:51 +00:00
i n c l u d e m o d u l e s / *
2016-08-02 23:25:47 +00:00
2016-09-10 21:36:36 +00:00
d e f i n e bins =
2016-08-03 12:40:51 +00:00
$( foreach m ,$ 1,$ ( call prefix ,$ ( build ) /$ ( $ m_dir ) /,$ ( $ m_output ) ) )
2016-08-02 23:25:47 +00:00
e n d e f
2024-06-12 13:42:17 +00:00
d e f i n e data =
$( foreach m ,$ 1,$ ( call prefix ,$ ( build ) /$ ( $ m_dir ) /,$ ( $ m_data ) ) )
e n d e f
2016-09-10 21:36:36 +00:00
d e f i n e libs =
$( foreach m ,$ 1,$ ( call prefix ,$ ( build ) /$ ( $ m_dir ) /,$ ( $ m_libraries ) ) )
e n d e f
d e f i n e outputs =
$( foreach m ,$ 1,\
$( call bins,$m ) \
2024-06-12 13:42:17 +00:00
$( call data,$m ) \
2016-09-10 21:36:36 +00:00
$( call libs,$m ) \
)
e n d e f
2016-08-02 23:25:47 +00:00
2018-02-05 16:27:45 +00:00
#
# Build a cpio from a directory
#
d e f i n e do-cpio =
2018-05-02 15:38:39 +00:00
$( call do ,CPIO ,$1 ,\
2018-02-05 16:27:45 +00:00
( cd " $2 " ; \
find . \
| cpio \
--quiet \
-H newc \
-o \
2018-03-15 15:46:42 +00:00
) \
| ./bin/cpio-clean \
> " $1 .tmp " \
2018-02-05 16:27:45 +00:00
)
@if ! cmp --quiet " $1 .tmp " " $1 " ; then \
mv " $1 .tmp " " $1 " ; \
else \
2018-05-02 15:38:39 +00:00
echo " $( DATE) UNCHANGED $( 1:$( pwd ) /%= %) " ; \
2018-02-05 16:27:45 +00:00
rm " $1 .tmp " ; \
fi
2018-09-18 17:07:40 +00:00
@sha256sum " $1 " | tee -a " $( HASHES) "
2023-06-27 14:01:01 +00:00
@stat -c "%8s:%n" " $1 " | tee -a " $( SIZES) "
2018-09-18 17:07:40 +00:00
$( call do ,HASHES , $1 ,\
2018-09-18 16:08:16 +00:00
( cd " $2 " ; \
2018-09-18 17:07:40 +00:00
echo "-----" ; \
2018-09-18 16:08:16 +00:00
find . -type f -print0 \
2018-09-18 17:07:40 +00:00
| xargs -0 sha256sum ; \
echo "-----" ; \
2018-09-18 16:35:19 +00:00
) >> " $( HASHES) " \
2018-09-18 16:08:16 +00:00
)
2023-06-27 14:01:01 +00:00
$( call do ,SIZES , $1 ,\
( cd " $2 " ; \
echo "-----" ; \
find . -type f -print0 \
| xargs -0 stat -c "%8s:%n" ; \
echo "-----" ; \
) >> " $( SIZES) " \
)
2018-02-05 16:27:45 +00:00
e n d e f
d e f i n e do-copy =
2018-05-04 18:36:56 +00:00
$( call do ,INSTALL ,$1 = > $2 ,\
if cmp --quiet " $1 " " $2 " ; then \
2018-05-02 15:38:39 +00:00
echo " $( DATE) UNCHANGED $( 1:$( pwd ) /%= %) " ; \
2018-05-04 16:31:21 +00:00
fi ; \
2023-02-21 20:15:25 +00:00
cp -a --remove-destination " $1 " " $2 " ; \
2018-02-05 16:27:45 +00:00
)
2018-05-02 15:38:39 +00:00
@sha256sum " $( 2:$( pwd ) /%= %) "
2023-06-27 14:01:01 +00:00
@stat -c "%8s:%n" " $( 2:$( pwd ) /%= %) "
2018-02-05 16:27:45 +00:00
e n d e f
2016-08-02 23:25:47 +00:00
#
# Generate the targets for a module.
#
# Special variables like $@ must be written as $$@ to avoid
# expansion during the first evaluation.
#
d e f i n e define_module =
2018-05-02 15:38:39 +00:00
# if they have not defined a separate base dir, define it
# as the same as their build dir.
2018-05-02 18:30:58 +00:00
$( eval $1 _base_dir = $( or $( $1 _base_dir) ,$( $1 _dir) ) )
2023-08-10 20:48:05 +00:00
# Dynamically defined modules must tell us what module file defined them
$( eval $1 _module_file = $( or $( $1 _module_file) ,$1 ) )
2018-05-02 15:38:39 +00:00
2016-08-19 15:31:07 +00:00
ifneq ( " $( $1 _repo) " ,"" )
2021-06-30 21:13:27 +00:00
$( eval $1 _patch_name = $1 $( if $( $1 _patch_version) ,-$( $1 _patch_version) ,) )
2023-06-01 21:36:16 +00:00
# First time:
# Checkout the tree instead and create the canary file with repo and
# revision so that we know that the files are all present and their
2024-07-26 15:09:29 +00:00
# version. Submodules are _not_ checked out, because coreboot has
# many submodules that won't be used, let coreboot check out its own
# submodules during build
2023-06-01 21:36:16 +00:00
#
# Other times:
# If .canary contains the same repo and revision combination, do nothing.
# Otherwise, pull a new revision and checkout with update of submodules
#
# No signature hashes are checked in this case, since we don't have a
# stable version to compare against.
#
# XXX: "git clean -dffx" is a hack for coreboot during commit switching, need
# module-specific cleanup action to get rid of it.
$( build) /$( $1 _base_dir) /.canary: FORCE
if [ ! -e " $$ @ " ] ; then \
git clone $( $1 _repo) " $( build) / $( $1 _base_dir) " ; \
2024-07-26 15:09:29 +00:00
git -C " $( build) / $( $1 _base_dir) " reset --hard $( $1 _commit_hash) ; \
2023-06-01 21:36:16 +00:00
echo -n '$($1_repo)|$($1_commit_hash)' > " $$ @ " ; \
elif [ " $$ $$ (cat " $$ @")" != '$($1_repo)|$($1_commit_hash)' ] ; then \
echo " Switching $1 to $( $1 _repo) at $( $1 _commit_hash) " && \
2023-08-18 15:39:48 +00:00
git -C " $( build) / $( $1 _base_dir) " reset --hard HEAD^ && \
echo " git fetch $( $1 _repo) $( $1 _commit_hash) --recurse-submodules=no " && \
git -C " $( build) / $( $1 _base_dir) " fetch $( $1 _repo) $( $1 _commit_hash) --recurse-submodules= no && \
echo " git reset --hard $( $1 _commit_hash) " && \
2023-06-01 21:36:16 +00:00
git -C " $( build) / $( $1 _base_dir) " reset --hard $( $1 _commit_hash) && \
2023-08-18 15:39:48 +00:00
echo "git clean" && \
2023-06-01 21:36:16 +00:00
git -C " $( build) / $( $1 _base_dir) " clean -df && \
git -C " $( build) / $( $1 _base_dir) " clean -dffx payloads util/cbmem && \
2023-08-18 15:39:48 +00:00
echo "git submodule sync" && \
2023-06-01 21:36:16 +00:00
git -C " $( build) / $( $1 _base_dir) " submodule sync && \
2023-08-18 15:39:48 +00:00
echo "git submodule update" && \
2023-06-01 21:36:16 +00:00
git -C " $( build) / $( $1 _base_dir) " submodule update --init --checkout && \
echo -n '$($1_repo)|$($1_commit_hash)' > " $$ @ " ; \
2017-01-31 16:56:14 +00:00
fi
2023-06-01 21:36:16 +00:00
if [ ! -e " $( build) / $( $1 _base_dir) /.patched " ] ; then \
if [ -r patches/$( $1 _patch_name) .patch ] ; then \
2022-08-30 21:53:57 +00:00
( git apply --verbose --reject --binary --directory build/$( CONFIG_TARGET_ARCH) /$( $1 _base_dir) ) \
2023-06-01 21:36:16 +00:00
< patches/$( $1 _patch_name) .patch \
2018-07-17 10:22:52 +00:00
|| exit 1 ; \
2023-06-01 21:36:16 +00:00
fi && \
if [ -d patches/$( $1 _patch_name) ] && \
[ -r patches/$( $1 _patch_name) ] ; then \
for patch in patches/$( $1 _patch_name) /*.patch ; do \
echo " Applying patch file : $$ $$ patch " ; \
( git apply --verbose --reject --binary --directory build/$( CONFIG_TARGET_ARCH) /$( $1 _base_dir) ) \
< $$ $$ patch \
|| exit 1 ; \
done ; \
fi && \
touch " $( build) / $( $1 _base_dir) /.patched " ; \
2018-03-08 20:37:17 +00:00
fi
2016-08-19 15:31:07 +00:00
else
2023-08-11 14:02:03 +00:00
# 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) )
2016-08-19 15:31:07 +00:00
# Fetch and verify the source tar file
2018-05-29 21:09:26 +00:00
# wget creates it early, so we have to cleanup if it fails
2016-08-19 15:31:07 +00:00
$( packages) /$( $1 _tar) :
2018-05-29 21:09:26 +00:00
$( call do ,WGET,$( $1 _url) ,\
2024-01-05 17:49:36 +00:00
WGET = " $( WGET) " bin/fetch_source_archive.sh " $( $1 _url) " " $$ @ " " $( $1 _hash) "
2018-05-29 21:09:26 +00:00
)
2024-01-05 17:49:36 +00:00
# Target to fetch all packages, for seeding mirrors
packages: $( packages) /$( $1 _tar)
2016-08-02 23:25:47 +00:00
2016-08-19 15:31:07 +00:00
# Unpack the tar file and touch the canary so that we know
# that the files are all present
2024-01-05 17:49:36 +00:00
$( build) /$( $1 _base_dir) /.canary: $( packages) /$( $1 _tar)
2019-10-29 12:15:56 +00:00
mkdir -p " $$ (dir $$ @) "
2019-12-03 09:48:10 +00:00
tar -xf " $( packages) / $( $1 _tar) " $( or $( $1 _tar_opt) ,--strip 1) -C " $$ (dir $$ @) "
2021-06-30 21:13:27 +00:00
if [ -r patches/$( $1 _patch_name) .patch ] ; then \
2022-08-30 21:53:57 +00:00
( git apply --verbose --reject --binary --directory build/$( CONFIG_TARGET_ARCH) /$( $1 _base_dir) ) \
2021-06-30 21:13:27 +00:00
< patches/$( $1 _patch_name) .patch \
2018-07-17 10:22:52 +00:00
|| exit 1 ; \
2016-08-03 22:10:44 +00:00
fi
2021-06-30 21:13:27 +00:00
if [ -d patches/$( $1 _patch_name) ] && \
[ -r patches/$( $1 _patch_name) ] ; then \
for patch in patches/$( $1 _patch_name) /*.patch ; do \
2018-03-08 20:37:17 +00:00
echo " Applying patch file : $$ $$ patch " ; \
2022-08-30 21:53:57 +00:00
( git apply --verbose --reject --binary --directory build/$( CONFIG_TARGET_ARCH) /$( $1 _base_dir) ) \
2018-07-17 10:22:52 +00:00
< $$ $$ patch \
|| exit 1 ; \
2018-03-08 20:37:17 +00:00
done ; \
fi
2017-03-29 20:58:45 +00:00
@touch " $$ @ "
2016-08-19 15:31:07 +00:00
endif
2016-08-02 23:25:47 +00:00
2018-02-05 20:28:33 +00:00
# Allow the module to override the destination configuration file
# via a relative path. Linux uses this to have a per-board build.
$( eval $1 _config_file_path := $( build) /$( $1 _dir) /$( or $( $1 _config_file) ,.config) )
2016-12-01 19:03:55 +00:00
ifeq " $( $1 _config) " ""
# There is no official .config file
2018-05-02 15:38:39 +00:00
$( $1 _config_file_path) : $( build) /$( $1 _base_dir) /.canary
2018-02-05 20:28:33 +00:00
@mkdir -p $$ ( dir $$ @)
2017-03-29 20:58:45 +00:00
@touch " $$ @ "
2016-12-01 19:03:55 +00:00
else
# Copy the stored config file into the unpacked directory
2018-05-02 15:38:39 +00:00
$( $1 _config_file_path) : $( $1 _config) $( build) /$( $1 _base_dir) /.canary
2018-02-05 20:28:33 +00:00
@mkdir -p $$ ( dir $$ @)
2018-02-05 21:27:48 +00:00
$( call do -copy,$( $1 _config) ,$$ @)
2016-11-29 16:19:48 +00:00
endif
2016-12-13 18:10:21 +00:00
2018-05-02 18:30:58 +00:00
# The first time we have to wait for all the dependencies to be built
# before we can configure the target. Once the dep has been built,
# we only depend on it for a rebuild.
$( eval $1 _config_wait := $( foreach d,$( $1 _depends) ,\
$( shell [ -r $( build) /$( $d_dir ) /.build ] || echo $d ) ) )
2016-08-02 23:25:47 +00:00
# Use the module's configure variable to build itself
2018-05-02 18:30:58 +00:00
# this has to wait for the dependencies to be built since
# cross compilers and libraries might be messed up
2018-02-05 22:27:12 +00:00
$( dir $( $1 _config_file_path) ) .configured: \
2018-05-02 15:38:39 +00:00
$( build) /$( $1 _base_dir) /.canary \
2018-05-02 18:30:58 +00:00
$( foreach d,$( $1 _config_wait) ,$( build) /$( $d_dir ) /.build) \
2018-02-05 20:28:33 +00:00
$( $1 _config_file_path) \
2023-08-10 20:48:05 +00:00
modules/$( $1 _module_file)
2017-03-29 20:58:45 +00:00
@echo " $( DATE) CONFIG $1 "
2017-03-21 18:24:00 +00:00
@( \
cd " $( build) / $( $1 _dir) " ; \
echo " $( $1 _configure) " ; \
$( $1 _configure) \
) \
2017-03-20 18:47:47 +00:00
< /dev/null \
2017-02-28 23:02:10 +00:00
2>& 1 \
| tee " $( log_dir) / $1 .configure.log " \
$( VERBOSE_REDIRECT)
2017-03-29 20:58:45 +00:00
@touch " $$ @ "
2016-08-02 23:25:47 +00:00
2018-05-02 15:38:39 +00:00
# Short hand for our module build target
$1 : \
$( build) /$( $1 _dir) /.build \
$( call outputs,$1 ) \
2016-08-02 23:25:47 +00:00
2016-11-29 16:19:48 +00:00
# Target for all of the outputs, which depend on their dependent modules
2018-05-02 15:38:39 +00:00
# being built, as well as this module being configured
2018-05-04 16:31:21 +00:00
$( call outputs,$1 ) : $( build) /$( $1 _dir) /.build
2018-05-02 15:38:39 +00:00
# If any of the outputs are missing, we should force a rebuild
# of the entire module
$( eval $1 .force = $( shell \
stat $( call outputs,$1 ) >/dev/null 2>/dev/null || echo FORCE \
) )
$( build) /$( $1 _dir) /.build: $( $1 .force) \
$( foreach d,$( $1 _depends) ,$( build) /$( $d_dir ) /.build) \
2018-02-05 22:27:12 +00:00
$( dir $( $1 _config_file_path) ) .configured \
2018-02-05 20:28:33 +00:00
2018-05-04 16:31:21 +00:00
@echo " $( DATE) MAKE $1 "
2018-03-15 22:10:15 +00:00
+@( \
2017-03-21 18:24:00 +00:00
echo " $( MAKE) \
-C \" $( build) /$( $1 _dir) \" \
$( $1 _target) " ; \
$( MAKE) \
-C " $( build) / $( $1 _dir) " \
$( $1 _target) \
2017-02-28 23:02:10 +00:00
) \
2017-03-20 18:47:47 +00:00
< /dev/null \
2017-02-28 23:02:10 +00:00
2>& 1 \
| tee " $( log_dir) / $1 .log " \
2017-03-20 18:47:47 +00:00
$( VERBOSE_REDIRECT) \
|| ( \
echo " tail $( log_dir) / $1 .log " ; \
echo "-----" ; \
tail -20 " $( log_dir) / $1 .log " ; \
exit 1; \
)
2018-05-02 15:38:39 +00:00
$( call do ,DONE,$1 ,\
touch $( build) /$( $1 _dir) /.build \
)
2016-11-29 16:19:48 +00:00
2017-01-31 16:56:14 +00:00
$1 .clean:
2017-01-31 19:57:41 +00:00
-$( RM) " $( build) / $( $1 _dir) /.configured "
2017-01-31 16:56:14 +00:00
-$( MAKE) -C " $( build) / $( $1 _dir) " clean
2016-08-02 23:25:47 +00:00
e n d e f
2017-03-31 15:18:46 +00:00
$( call map , define_module , $ ( modules -y ) )
2016-07-25 14:08:53 +00:00
2024-11-06 13:03:42 +00:00
# hack to force musl-cross-make to be built before musl
#$(build)/$(musl_dir)/.configured: $(build)/$(musl-cross-make_dir)/../../crossgcc/x86_64-linux-musl/bin/x86_64-musl-linux-gcc
2016-09-10 21:36:36 +00:00
#
# Install a file into the initrd, if it changed from
# the destination file.
#
d e f i n e install =
2017-03-29 20:58:45 +00:00
@-mkdir -p " $( dir $2 ) "
2023-02-21 20:15:25 +00:00
$( call do ,INSTALL,$2 ,cp -a --remove-destination " $1 " " $2 " )
2016-09-10 21:36:36 +00:00
e n d e f
2016-08-03 01:23:18 +00:00
#
# Files that should be copied into the initrd
# THis should probably be done in a more scalable manner
#
2016-09-10 21:36:36 +00:00
d e f i n e initrd_bin_add =
$(initrd_bin_dir)/$(notdir $1) : $1
2023-02-21 20:15:25 +00:00
$( call do ,INSTALL-BIN,$$ ( <:$( pwd ) /%= %) ,cp -a --remove-destination " $$ < " " $$ @ " )
2017-04-08 21:46:54 +00:00
@$( CROSS) strip --preserve-dates " $$ @ " 2>& -; true
2016-09-10 21:36:36 +00:00
initrd_bins += $( initrd_bin_dir) /$( notdir $1 )
2016-08-03 01:23:18 +00:00
e n d e f
2024-06-12 13:42:17 +00:00
d e f i n e initrd_data_add =
$(initrd_data_dir)/$(notdir $1) : $1
$( call do ,INSTALL-DATA,$$ ( <:$( pwd ) /%= %) ,cp -a --remove-destination " $$ < " " $$ @ " )
initrd_data += $( initrd_data_dir) /$( notdir $1 )
e n d e f
2016-09-10 21:36:36 +00:00
d e f i n e initrd_lib_add =
$(initrd_lib_dir)/$(notdir $1) : $1
2018-02-05 16:27:45 +00:00
$( call do ,INSTALL-LIB,$( 1:$( pwd ) /%= %) ,\
$( CROSS) strip --preserve-dates -o " $$ @ " " $$ < " )
2016-09-10 21:36:36 +00:00
initrd_libs += $( initrd_lib_dir) /$( notdir $1 )
e n d e f
2017-03-30 22:39:18 +00:00
# Only some modules have binaries that we install
2018-02-05 16:27:45 +00:00
# Shouldn't this be specified in the module file?
2024-11-06 13:03:42 +00:00
#bin_modules-$(CONFIG_MUSL) += musl-cross-make
2017-03-31 16:06:59 +00:00
bin_modules-$(CONFIG_KEXEC) += kexec
bin_modules-$(CONFIG_TPMTOTP) += tpmtotp
bin_modules-$(CONFIG_PCIUTILS) += pciutils
bin_modules-$(CONFIG_FLASHROM) += flashrom
2024-08-31 13:43:03 +00:00
bin_modules-$(CONFIG_FLASHPROG) += flashprog
2017-03-31 16:06:59 +00:00
bin_modules-$(CONFIG_CRYPTSETUP) += cryptsetup
2021-07-25 15:30:19 +00:00
bin_modules-$(CONFIG_CRYPTSETUP2) += cryptsetup2
2017-03-31 16:06:59 +00:00
bin_modules-$(CONFIG_GPG) += gpg
2018-09-18 09:12:47 +00:00
bin_modules-$(CONFIG_GPG2) += gpg2
2018-09-19 11:21:02 +00:00
bin_modules-$(CONFIG_PINENTRY) += pinentry
2017-03-31 16:06:59 +00:00
bin_modules-$(CONFIG_LVM2) += lvm2
2017-04-07 13:53:02 +00:00
bin_modules-$(CONFIG_DROPBEAR) += dropbear
2018-02-26 16:42:07 +00:00
bin_modules-$(CONFIG_FLASHTOOLS) += flashtools
2018-02-20 00:39:42 +00:00
bin_modules-$(CONFIG_NEWT) += newt
2018-03-06 19:57:00 +00:00
bin_modules-$(CONFIG_CAIRO) += cairo
bin_modules-$(CONFIG_FBWHIPTAIL) += fbwhiptail
2020-06-11 13:54:10 +00:00
bin_modules-$(CONFIG_HOTPKEY) += hotp-verification
2019-07-30 13:36:57 +00:00
bin_modules-$(CONFIG_MSRTOOLS) += msrtools
2020-10-19 14:47:22 +00:00
bin_modules-$(CONFIG_NKSTORECLI) += nkstorecli
2023-03-24 20:41:39 +00:00
bin_modules-$(CONFIG_UTIL_LINUX) += util-linux
2022-08-25 18:43:31 +00:00
bin_modules-$(CONFIG_OPENSSL) += openssl
bin_modules-$(CONFIG_TPM2_TOOLS) += tpm2-tools
2023-03-07 16:02:45 +00:00
bin_modules-$(CONFIG_BASH) += bash
2023-06-05 21:53:18 +00:00
bin_modules-$(CONFIG_POWERPC_UTILS) += powerpc-utils
Introduce io386 to heads and use it to finalize chipset at runtime
On some newer platforms of intel (confirmed on nehalem, sandy/ivy
bridge), coreboot after commit [2ac149d294af795710eb4bb20f093e9920604abd](https://review.coreboot.org/cgit/coreboot.git/commit/?id=2ac149d294af795710eb4bb20f093e9920604abd)
registers an SMI to lockdown some registers on the chipset, as well
as access to the SPI flash, optionally. The SMI will always be triggered
by coreboot during S3 resume, but can be triggered by either coreboot
or the payload during normal boot path.
Enabling lockdown access to SPI flash will effectly write-protect it,
but there is no runtime option for coreboot to control it, so letting
coreboot to trigger such SMI will leave the owner of the machine lost
any possibility to program the SPI flash with its own OS, and becomes
a nightmare if the machine is uneasy to disassemble, so a scheme could
be implement, in which the SMI to lockdown chipset and SPI flash is left
for a payload to trigger, and temporarily disabling such triggering in
order to program the SPI flash needs authentication.
I have implemented a passcode-protected runtime-disableable lockdown
with grub, described [here](https://github.com/hardenedlinux/Debian-GNU-Linux-Profiles/blob/master/docs/hardened_boot/grub-for-coreboot.md#update-for-coreboot-after-commit-2ac149d294af795710eb4bb20f093e9920604abd). In order to implement a similar scheme for
Heads, I wrote [io386](https://github.com/hardenedlinux/io386).
With this commit, io386 will be called before entering boot routine
to trigger the SMI to finalize the chipset and write protect the SPI
flash at the same time. Entering recovery shell will leave the flash
writable.
(The authentication routine implemented in previous revisions has been
split as an independent commit.)
Originally proposed under PR#326
2018-01-17 08:16:18 +00:00
bin_modules-$(CONFIG_IO386) += io386
2022-11-28 20:06:16 +00:00
bin_modules-$(CONFIG_IOPORT) += ioport
2023-08-09 20:06:08 +00:00
bin_modules-$(CONFIG_KBD) += kbd
2023-06-20 19:29:10 +00:00
bin_modules-$(CONFIG_ZSTD) += zstd
2023-07-19 22:48:03 +00:00
bin_modules-$(CONFIG_E2FSPROGS) += e2fsprogs
bin_modules-$(CONFIG_EXFATPROGS) += exfatprogs
2017-03-31 16:06:59 +00:00
$( foreach m , $ ( bin_modules -y ) , \
2017-03-30 22:39:18 +00:00
$( call map,initrd_bin_add,$( call bins,$m ) ) \
)
2016-09-10 21:36:36 +00:00
2024-06-12 13:42:17 +00:00
# Install the data for every module that we have built
$( foreach m , $ ( modules -y ) , \
$( call map,initrd_data_add,$( call data,$m ) ) \
)
2017-03-29 19:15:03 +00:00
# Install the libraries for every module that we have built
2017-03-31 15:18:46 +00:00
$( foreach m , $ ( modules -y ) , \
2017-03-30 22:39:18 +00:00
$( call map,initrd_lib_add,$( call libs,$m ) ) \
)
2016-09-10 21:36:36 +00:00
2017-03-29 20:58:45 +00:00
#
2016-08-04 21:38:00 +00:00
# hack to build cbmem from coreboot
2017-03-29 20:58:45 +00:00
# this must be built *AFTER* musl, but since coreboot depends on other things
# that depend on musl it should be ok.
#
2018-05-02 15:38:39 +00:00
COREBOOT_UTIL_DIR = $( build) /$( coreboot_base_dir) /util
2017-09-22 20:17:05 +00:00
i f e q ( $( CONFIG_COREBOOT ) , y )
2018-03-02 14:37:31 +00:00
$( eval $ ( call initrd_bin_add ,$ ( COREBOOT_UTIL_DIR ) /cbmem /cbmem ) )
2018-03-08 09:32:23 +00:00
#$(eval $(call initrd_bin_add,$(COREBOOT_UTIL_DIR)/superiotool/superiotool))
2018-03-02 14:37:31 +00:00
#$(eval $(call initrd_bin_add,$(COREBOOT_UTIL_DIR)/inteltool/inteltool))
2017-09-22 20:17:05 +00:00
e n d i f
2018-03-02 14:37:31 +00:00
$( COREBOOT_UTIL_DIR ) / c b m e m / c b m e m \
$( COREBOOT_UTIL_DIR ) / s u p e r i o t o o l / s u p e r i o t o o l \
$( COREBOOT_UTIL_DIR ) / i n t e l t o o l / i n t e l t o o l \
2024-11-06 13:03:42 +00:00
: $( build ) / $( coreboot_base_dir ) / . c a n a r y m u s l - c r o s s - m a k e
2018-03-15 22:10:15 +00:00
+$( call do ,MAKE,$( notdir $@ ) ,\
2018-03-02 14:37:31 +00:00
$( MAKE) -C " $( dir $@ ) " $( CROSS_TOOLS) \
2018-02-26 16:42:07 +00:00
)
2016-08-03 01:23:18 +00:00
2018-03-02 14:37:31 +00:00
# superio depends on zlib and pciutils
2018-05-02 15:38:39 +00:00
$(COREBOOT_UTIL_DIR)/superiotool/superiotool : \
$( build) /$( zlib_dir) /.build \
$( build) /$( pciutils_dir) /.build \
2018-03-02 14:37:31 +00:00
2016-08-03 01:23:18 +00:00
#
# initrd image creation
#
# The initrd is constructed from various bits and pieces
2016-11-23 17:11:08 +00:00
# The cpio-clean program is used ensure that the files
# always have the same timestamp and appear in the same order.
2016-08-03 01:23:18 +00:00
#
2018-03-15 15:46:42 +00:00
# The blobs/dev.cpio is also included in the Linux kernel
# and has a reproducible version of /dev/console.
#
# The xz parameters are copied from the Linux kernel build scripts.
# Without them the kernel will not decompress the initrd.
#
# The padding is to ensure that if anyone wants to cat another
# file onto the initrd then the kernel will be able to find it.
2016-08-03 01:23:18 +00:00
#
2018-02-05 16:27:45 +00:00
initrd-y += $( pwd ) /blobs/dev.cpio
2018-05-02 15:38:39 +00:00
initrd-y += $( build) /$( initrd_dir) /modules.cpio
initrd-y += $( build) /$( initrd_dir) /tools.cpio
2022-11-28 20:15:38 +00:00
initrd-y += $( build) /$( initrd_dir) /board.cpio
2018-05-02 15:38:39 +00:00
initrd-$(CONFIG_HEADS) += $( build) /$( initrd_dir) /heads.cpio
2018-02-05 16:27:45 +00:00
2018-05-02 15:38:39 +00:00
#$(build)/$(initrd_dir)/.build: $(build)/$(initrd_dir)/initrd.cpio.xz
$(build)/$(initrd_dir)/initrd.cpio.xz : $( initrd -y )
$( call do ,CPIO-XZ ,$@ ,\
2018-02-05 16:27:45 +00:00
$( pwd ) /bin/cpio-clean \
$^ \
| xz \
--check= crc32 \
--lzma2= dict = 1MiB \
-9 \
2018-05-02 15:38:39 +00:00
| dd bs = 512 conv = sync status = none > " $@ .tmp " \
2017-03-29 19:15:03 +00:00
)
2018-05-02 15:38:39 +00:00
@if ! cmp --quiet " $@ .tmp " " $@ " ; then \
mv " $@ .tmp " " $@ " ; \
else \
echo " $( DATE) UNCHANGED $( @:$( pwd ) /%= %) " ; \
rm " $@ .tmp " ; \
fi
2018-09-18 17:07:40 +00:00
@sha256sum " $( @:$( pwd ) /%= %) " | tee -a " $( HASHES) "
2023-06-27 14:01:01 +00:00
@stat -c "%8s:%n" " $( @:$( pwd ) /%= %) " | tee -a " $( SIZES) "
2016-11-29 16:19:48 +00:00
2021-07-18 17:35:59 +00:00
#
# At the moment PowerPC can only load initrd bundled with the kernel.
#
2021-07-22 22:24:55 +00:00
bundle-$(CONFIG_LINUX_BUNDLED) += $( board_build) /$( LINUX_IMAGE_FILE) .bundled
2021-07-18 17:35:59 +00:00
all : $( bundle -y )
2022-11-28 20:15:38 +00:00
# The board.cpio is built from the board's initrd/ directory. It contains
# board-specific support scripts.
i f e q ( $( wildcard $ ( pwd ) /boards /$ ( BOARD ) /initrd ) , )
$(build)/$(initrd_dir)/board.cpio :
cpio -H newc -o </dev/null >" $@ "
e l s e
$(build)/$(initrd_dir)/board.cpio : FORCE
$( call do -cpio,$@ ,$( pwd ) /boards/$( BOARD) /initrd)
e n d i f
2018-02-05 16:27:45 +00:00
#
# The heads.cpio is built from the initrd directory in the
# Heads tree.
#
2018-05-02 15:38:39 +00:00
$(build)/$(initrd_dir)/heads.cpio : FORCE
2018-02-05 16:27:45 +00:00
$( call do -cpio,$@ ,$( pwd ) /initrd)
#
# The tools initrd is made from all of the things that we've
# created during the submodule build.
#
2018-05-02 15:38:39 +00:00
$(build)/$(initrd_dir)/tools.cpio : \
2018-02-05 16:27:45 +00:00
$( initrd_bins) \
2024-06-12 13:42:17 +00:00
$( initrd_data) \
2018-02-05 16:27:45 +00:00
$( initrd_libs) \
2018-05-04 18:36:56 +00:00
$( initrd_tmp_dir) /etc/config \
2024-06-12 13:42:17 +00:00
$( info Used **BINS**: $( initrd_bins) )
2018-05-04 18:36:56 +00:00
$( call do -cpio,$@ ,$( initrd_tmp_dir) )
@$( RM) -rf " $( initrd_tmp_dir) "
2018-02-05 16:27:45 +00:00
2018-05-04 18:36:56 +00:00
$(initrd_tmp_dir)/etc/config : FORCE
@mkdir -p $( dir $@ )
2018-02-05 16:27:45 +00:00
$( call do ,INSTALL,$( CONFIG) , \
2018-02-28 19:57:46 +00:00
export \
| grep ' CONFIG_' \
2018-03-01 07:13:01 +00:00
| sed -e 's/^declare -x /export /' \
-e 's/\\\"//g' \
2018-05-04 18:36:56 +00:00
> $@ \
)
2018-05-11 21:08:31 +00:00
$( call do ,HASH,$( GIT_HASH) $( GIT_STATUS) $( BOARD) , \
2018-05-04 18:36:56 +00:00
echo export GIT_HASH = \' $( GIT_HASH) \' \
>> $@ ; \
echo export GIT_STATUS = $( GIT_STATUS) \
>> $@ ; \
2018-05-11 21:08:31 +00:00
echo export CONFIG_BOARD = $( BOARD) \
>> $@ ; \
2023-06-21 18:19:41 +00:00
echo export CONFIG_BRAND_NAME = $( BRAND_NAME) \
>> $@ ; \
2018-02-05 16:27:45 +00:00
)
2016-08-03 01:23:18 +00:00
2018-05-02 15:38:39 +00:00
# Ensure that the initrd depends on all of the modules that produce
# binaries for it
$(build)/$(initrd_dir)/tools.cpio : $( foreach d ,$ ( bin_modules -y ) ,$ ( build ) /$ ( $ d_dir ) /.build )
2017-04-03 18:53:29 +00:00
2018-02-05 16:56:15 +00:00
2018-03-29 22:05:57 +00:00
# List of all modules, excluding the slow to-build modules
2024-11-06 13:03:42 +00:00
modules-slow := musl musl-cross-make kernel_headers
2018-03-29 22:05:57 +00:00
module_dirs := $( foreach m,$( filter-out $( modules-slow) ,$( modules-y) ) ,$( $m_dir ) )
2016-08-14 20:02:15 +00:00
2018-03-29 22:05:57 +00:00
echo_modules :
echo $( module_dirs)
2017-04-08 21:46:54 +00:00
modules.clean :
for dir in $( module_dirs) \
2017-02-28 23:02:10 +00:00
; do \
2023-05-09 11:52:51 +00:00
$( MAKE) -C " build/ ${ CONFIG_TARGET_ARCH } / $$ dir " clean ; \
rm -f " build/ ${ CONFIG_TARGET_ARCH } / $$ dir/.configured " ; \
2017-01-04 15:31:27 +00:00
done
2017-01-27 21:17:03 +00:00
2023-12-30 18:29:16 +00:00
board.move_untested_to_tested :
2024-09-10 13:53:49 +00:00
@echo " Moving $( BOARD) from UNTESTED to tested status "
2023-12-30 18:29:16 +00:00
@NEW_BOARD= $$ ( echo $( BOARD) | sed 's/^UNTESTED_//' ) ; \
2024-09-10 13:53:49 +00:00
INCLUDE_BOARD = $$ ( grep " include \$ $( pwd ) /boards/ " boards/$( BOARD) /$( BOARD) .config | sed 's/.*boards\/\(.*\)\/.*/\1/' ) ; \
NEW_INCLUDE_BOARD = $$ ( echo $$ INCLUDE_BOARD | sed 's/^UNTESTED_//' ) ; \
echo " Updating config file: boards/ $( BOARD) / $( BOARD) .config " ; \
sed -i 's/$(BOARD)/' $$ { NEW_BOARD} '/g' boards/$( BOARD) /$( BOARD) .config; \
sed -i 's/' $$ INCLUDE_BOARD'/' $$ NEW_INCLUDE_BOARD'/g' boards/$( BOARD) /$( BOARD) .config; \
echo " Renaming config file to $$ {NEW_BOARD}.config " ; \
mv boards/$( BOARD) /$( BOARD) .config boards/$( BOARD) /$$ { NEW_BOARD} .config; \
echo " Renaming board directory to $$ {NEW_BOARD} " ; \
mv boards/$( BOARD) boards/$$ { NEW_BOARD} ; \
echo "Updating .circleci/config.yml" ; \
sed -i " s/ $( BOARD) / $$ {NEW_BOARD}/g " .circleci/config.yml; \
echo " Operation completed for $( BOARD) -> $$ {NEW_BOARD} "
2023-12-30 18:29:16 +00:00
2024-07-22 19:07:15 +00:00
board.move_unmaintained_to_tested :
@echo " NEW_BOARD variable will remove UNMAINTAINED_ prefix from $( BOARD) "
@NEW_BOARD= $$ ( echo $( BOARD) | sed 's/^UNMAINTAINED_//' ) ; \
echo " Renaming boards/ $$ BOARD/ $$ BOARD.config to boards/ $$ BOARD/ $$ NEW_BOARD.config " ; \
mv boards/$$ BOARD/$$ BOARD.config boards/$$ BOARD/$$ NEW_BOARD.config; \
echo " Renaming boards/ $$ BOARD to boards/ $$ NEW_BOARD " ; \
rm -rf boards/$$ NEW_BOARD; \
mv boards/$$ BOARD boards/$$ NEW_BOARD; \
echo " Replacing $$ BOARD with $$ NEW_BOARD in .circleci/config.yml " ; \
sed -i " s/ $$ BOARD/ $$ NEW_BOARD/g " .circleci/config.yml; \
echo " Board $$ BOARD has been moved to tested status as $$ NEW_BOARD " ; \
echo "Please review and update .circleci/config.yml manually if needed"
2024-03-25 20:05:27 +00:00
board.move_untested_to_unmaintained :
@echo " NEW_BOARD variable will move from UNTESTED_ to UNMAINTAINED_ from $( BOARD) "
@NEW_BOARD= $$ ( echo $( BOARD) | sed 's/^UNTESTED_/UNMAINTAINED_/g' ) ; \
echo " Renaming boards/ $$ BOARD/ $$ BOARD.config to boards/ $$ BOARD/ $$ NEW_BOARD.config " ; \
mkdir -p unmaintained_boards; \
mv boards/$$ BOARD/$$ BOARD.config unmaintained_boards/$$ BOARD/$$ NEW_BOARD.config; \
echo " Renaming boards/ $$ BOARD to unmaintainted_boards/ $$ NEW_BOARD " ; \
rm -rf boards/$$ NEW_BOARD; \
mv boards/$$ BOARD unmaintained_boards/$$ NEW_BOARD; \
echo " Replacing $$ BOARD with $$ NEW_BOARD in .circleci/config.yml. Delete manually entries " ; \
sed -i " s/ $$ BOARD/ $$ NEW_BOARD/g " .circleci/config.yml
2023-12-30 18:29:16 +00:00
board.move_tested_to_untested :
@echo " NEW_BOARD variable will add UNTESTED_ prefix to $( BOARD) "
@NEW_BOARD= UNTESTED_$( BOARD) ; \
rm -rf boards/$$ { NEW_BOARD} ; \
2024-09-09 15:52:08 +00:00
echo " changing $( BOARD) name under boards/ $( BOARD) / $( BOARD) .config to $$ {NEW_BOARD} " ; \
sed boards/$( BOARD) /$( BOARD) .config 's/$(BOARD)/$${NEW_BOARD}/g' ; \
2023-12-30 18:29:16 +00:00
echo " Renaming boards/ $( BOARD) / $( BOARD) .config to boards/ $( BOARD) / $$ {NEW_BOARD}.config " ; \
mv boards/$( BOARD) /$( BOARD) .config boards/$( BOARD) /$$ { NEW_BOARD} .config; \
echo " Renaming boards/ $( BOARD) to boards/ $$ {NEW_BOARD} " ; \
mv boards/$( BOARD) boards/$$ { NEW_BOARD} ; \
2024-09-09 15:52:08 +00:00
echo " Replacing $( BOARD) with $$ {NEW_BOARD} in .circleci/config.yml " ; \
2023-12-30 18:29:16 +00:00
sed -i " s/ $( BOARD) / $$ {NEW_BOARD}/g " .circleci/config.yml
2024-09-10 14:46:42 +00:00
board.move_tested_to_unmaintained :
@echo " Moving $( BOARD) from tested to unmaintained status "
@NEW_BOARD= UNMAINTAINED_$( BOARD) ; \
INCLUDE_BOARD = $$ ( grep " include \$ $( pwd ) /boards/ " boards/$( BOARD) /$( BOARD) .config | sed 's/.*boards\/\(.*\)\/.*/\1/' ) ; \
NEW_INCLUDE_BOARD = UNMAINTAINED_$$ { INCLUDE_BOARD} ; \
echo " Updating config file: boards/ $( BOARD) / $( BOARD) .config " ; \
sed -i 's/$(BOARD)/' $$ { NEW_BOARD} '/g' boards/$( BOARD) /$( BOARD) .config; \
if [ -n " $$ INCLUDE_BOARD " ] ; then \
sed -i 's/' $$ INCLUDE_BOARD'/' $$ NEW_INCLUDE_BOARD'/g' boards/$( BOARD) /$( BOARD) .config; \
fi ; \
echo "Creating unmaintained_boards directory if it doesn't exist" ; \
mkdir -p unmaintained_boards/$$ { NEW_BOARD} ; \
echo " Moving and renaming config file to unmaintained_boards/ $$ {NEW_BOARD}/ $$ {NEW_BOARD}.config " ; \
mv boards/$( BOARD) /$( BOARD) .config unmaintained_boards/$$ { NEW_BOARD} /$$ { NEW_BOARD} .config; \
echo " Moving board directory contents to unmaintained_boards/ $$ {NEW_BOARD} " ; \
mv boards/$( BOARD) /* unmaintained_boards/$$ { NEW_BOARD} /; \
rmdir boards/$( BOARD) ; \
echo "Updating .circleci/config.yml" ; \
sed -i " s/ $( BOARD) / $$ {NEW_BOARD}/g " .circleci/config.yml; \
echo " Operation completed for $( BOARD) -> $$ {NEW_BOARD} " ; \
echo "Please manually review and remove any unnecessary entries in .circleci/config.yml"
2022-07-07 19:11:47 +00:00
# Inject a GPG key into the image - this is most useful when testing in qemu,
# since we can't reflash the firmware in qemu to update the keychain. Instead,
# inject the public key ahead of time. Specify the location of the key with
# PUBKEY_ASC.
2021-07-22 22:24:55 +00:00
inject_gpg : $( board_build ) /$( CB_OUTPUT_FILE_GPG_INJ )
2022-07-07 19:11:47 +00:00
2021-07-22 22:24:55 +00:00
$(board_build)/$(CB_OUTPUT_BASENAME)-gpg-injected.rom : $( board_build ) /$( CB_OUTPUT_FILE )
cp " $( board_build) / $( CB_OUTPUT_FILE) " \
" $( board_build) / $( CB_OUTPUT_FILE_GPG_INJ) "
2022-07-07 19:11:47 +00:00
./bin/inject_gpg_key.sh --cbfstool " $( build) / $( coreboot_dir) /cbfstool " \
2021-07-22 22:24:55 +00:00
" $( board_build) / $( CB_OUTPUT_FILE_GPG_INJ) " " $( PUBKEY_ASC) "
2022-07-07 19:11:47 +00:00
2024-05-10 15:37:05 +00:00
#Dev cycles helpers:
2017-04-08 21:46:54 +00:00
real.clean :
for dir in \
$( module_dirs) \
$( kernel_headers) \
; do \
if [ ! -z " $$ dir " ] ; then \
2023-05-09 11:52:51 +00:00
rm -rf " build/ ${ CONFIG_TARGET_ARCH } / $$ dir " ; \
2017-04-08 21:46:54 +00:00
fi ; \
done
2018-11-21 13:24:54 +00:00
cd install && rm -rf -- *
2024-04-02 21:06:12 +00:00
real.gitclean :
2024-05-10 15:37:05 +00:00
@echo "Cleaning the repository using Git ignore file as a base..."
@echo "This will wipe everything not in the Git tree, but keep downloaded coreboot forks (detected as Git repos)."
2024-04-02 21:06:12 +00:00
git clean -fxd
2024-05-10 15:37:05 +00:00
2024-04-23 15:58:33 +00:00
real.gitclean_keep_packages :
2024-05-10 15:37:05 +00:00
@echo "Cleaning the repository using Git ignore file as a base..."
@echo "This will wipe everything not in the Git tree, but keep the 'packages' directory."
2024-04-23 15:58:33 +00:00
git clean -fxd -e "packages"
2024-05-10 15:37:05 +00:00
2024-04-23 23:34:32 +00:00
real.remove_canary_files-extract_patch_rebuild_what_changed :
2024-05-10 15:37:05 +00:00
@echo "Removing 'canary' files to force Heads to restart building board configurations..."
@echo "This will check package integrity, extract them, redo patching on files, and rebuild what needs to be rebuilt."
@echo "It will also reinstall the necessary files under './install'."
@echo "Limitations: If a patch creates a file in an extracted package directory, this approach may fail without further manual actions."
@echo "In such cases, Git will inform you about the file that couldn't be created as expected. Simply delete those files and relaunch the build."
@echo "This approach economizes time since most build artifacts do not need to be rebuilt, as the file dates should be the same as when you originally built them."
@echo "Only a minimal time is needed for rebuilding, which is also good for your SSD."
@echo "*** USE THIS APPROACH FIRST ***"
find ./build/ -type f -name ".canary" -print -delete
find ./install/*/* -print -exec rm -rf { } +
real.gitclean_keep_packages_and_build :
@echo "Cleaning the repository using Git ignore file as a base..."
@echo "This will wipe everything not in the Git tree, but keep the 'packages' and 'build' directories."
git clean -fxd -e "packages" -e "build"