2018-02-08 00:03:40 +00:00
|
|
|
all:
|
2018-02-02 20:56:46 +00:00
|
|
|
-include .config
|
|
|
|
|
2018-05-02 18:30:58 +00:00
|
|
|
ifneq "$(TOOLCHAIN)" ""
|
|
|
|
$(info Using $(TOOLCHAIN) for cross compiler and packages)
|
|
|
|
packages := $(TOOLCHAIN)/packages
|
|
|
|
CROSS := $(TOOLCHAIN)/crossgcc/x86_64-linux-musl/bin/x86_64-linux-musl-
|
|
|
|
endif
|
|
|
|
|
2017-03-31 15:18:46 +00:00
|
|
|
modules-y :=
|
2016-08-02 23:25:47 +00:00
|
|
|
pwd := $(shell pwd)
|
2018-03-08 06:16:28 +00:00
|
|
|
packages ?= $(pwd)/packages
|
2016-08-02 23:25:47 +00:00
|
|
|
build := $(pwd)/build
|
2018-02-05 16:27:45 +00:00
|
|
|
config := $(pwd)/config
|
2016-12-28 17:45:12 +00:00
|
|
|
INSTALL := $(pwd)/install
|
2017-02-28 23:02:10 +00:00
|
|
|
log_dir := $(build)/log
|
2017-03-29 20:58:45 +00:00
|
|
|
|
2018-04-19 23:37:45 +00:00
|
|
|
# Controls how many parallel jobs are invoked in subshells
|
|
|
|
CPUS := $(shell nproc)
|
|
|
|
#MAKE_JOBS ?= -j$(CPUS) --max-load 16
|
|
|
|
|
|
|
|
# Create the log directory if it doesn't already exist
|
2018-04-20 00:06:36 +00:00
|
|
|
BUILD_LOG := $(shell mkdir -p "$(log_dir)" )
|
2018-04-19 23:37:45 +00:00
|
|
|
|
2018-04-19 21:41:50 +00:00
|
|
|
# Check that we have a correct version of make
|
2018-05-02 19:41:11 +00:00
|
|
|
# that matches at least the major version
|
2018-04-19 21:41:50 +00:00
|
|
|
LOCAL_MAKE_VERSION := $(shell $(MAKE) --version | head -1 | cut -d' ' -f3)
|
|
|
|
include modules/make
|
|
|
|
|
2018-05-02 19:41:11 +00:00
|
|
|
ifneq "" "$(filter $(make_version)%,$(LOCAL_MAKE_VERSION))"
|
2018-04-19 21:41:50 +00:00
|
|
|
|
2018-04-19 23:37:45 +00:00
|
|
|
# This is the correct version of Make
|
2018-04-19 21:41:50 +00:00
|
|
|
|
2018-02-08 00:03:40 +00:00
|
|
|
BOARD ?= qemu-coreboot
|
2018-03-12 09:26:23 +00:00
|
|
|
CONFIG := $(pwd)/boards/$(BOARD)/$(BOARD).config
|
2018-02-05 16:27:45 +00:00
|
|
|
|
2018-04-20 00:06:36 +00:00
|
|
|
# Create the board output directory if it doesn't already exist
|
|
|
|
BOARD_LOG := $(shell mkdir -p "$(build)/$(BOARD)" )
|
|
|
|
|
2018-02-05 16:27:45 +00:00
|
|
|
ifneq "y" "$(shell [ -r '$(CONFIG)' ] && echo y)"
|
|
|
|
$(error $(CONFIG): board configuration does not exist)
|
|
|
|
endif
|
|
|
|
|
|
|
|
include $(CONFIG)
|
|
|
|
|
2018-02-13 22:46:48 +00:00
|
|
|
# Unless otherwise specified, we are building for heads
|
|
|
|
CONFIG_HEADS ?= y
|
|
|
|
|
2018-02-02 20:56:46 +00:00
|
|
|
# Some things want usernames, we use the current checkout
|
|
|
|
# so that they are reproducible
|
|
|
|
GIT_HASH := $(shell git rev-parse HEAD)
|
2018-05-04 18:36:56 +00:00
|
|
|
GIT_STATUS := $(shell \
|
|
|
|
if git diff --exit-code >/dev/null ; then \
|
|
|
|
echo clean ; \
|
|
|
|
else \
|
|
|
|
echo dirty ; \
|
|
|
|
fi)
|
2018-02-02 20:56:46 +00:00
|
|
|
|
2017-03-31 16:06:59 +00:00
|
|
|
# Timestamps should be in ISO format
|
|
|
|
DATE=`date --rfc-3339=seconds`
|
|
|
|
|
2017-02-28 23:02:10 +00:00
|
|
|
# If V is set in the environment, do not redirect the tee
|
|
|
|
# command to /dev/null.
|
|
|
|
ifeq "$V" ""
|
|
|
|
VERBOSE_REDIRECT := > /dev/null
|
2017-03-29 19:15:03 +00:00
|
|
|
# Not verbose, so we only show the header
|
|
|
|
define do =
|
2018-02-05 16:27:45 +00:00
|
|
|
@echo "$(DATE) $1 $(2:$(pwd)/%=%)"
|
2017-03-29 19:15:03 +00:00
|
|
|
@$3
|
|
|
|
endef
|
|
|
|
else
|
|
|
|
# Verbose, so we display what we are doing
|
|
|
|
define do =
|
2018-02-05 16:27:45 +00:00
|
|
|
@echo "$(DATE) $1 $(2:$(pwd)/%=%)"
|
2017-03-29 19:15:03 +00:00
|
|
|
$3
|
|
|
|
endef
|
2017-02-28 23:02:10 +00:00
|
|
|
endif
|
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)
|
|
|
|
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
|
|
|
|
|
|
|
$(shell mkdir -p "$(initrd_lib_dir)" "$(initrd_bin_dir)")
|
|
|
|
|
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
|
|
|
|
SHELL := /bin/bash
|
|
|
|
.SHELLFLAGS := -o pipefail -c
|
|
|
|
|
2018-03-16 16:59:24 +00:00
|
|
|
# Include the musl-cross module early so that $(CROSS) will
|
|
|
|
# be defined prior to any other module.
|
|
|
|
include modules/musl-cross
|
|
|
|
|
2016-12-29 23:23:08 +00:00
|
|
|
musl_dep := musl
|
2017-01-28 18:14:56 +00:00
|
|
|
heads_cc := $(INSTALL)/bin/musl-gcc \
|
|
|
|
-fdebug-prefix-map=$(pwd)=heads \
|
|
|
|
-gno-record-gcc-switches \
|
2018-02-26 16:42:07 +00:00
|
|
|
-D__MUSL__ \
|
2017-01-28 18:14:56 +00:00
|
|
|
|
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" \
|
2018-03-29 21:21:51 +00:00
|
|
|
PKG_CONFIG_PATH="$(INSTALL)/lib/pkgconfig" \
|
|
|
|
PKG_CONFIG_SYSROOT_DIR="$(INSTALL)" \
|
2017-04-08 17:23:34 +00:00
|
|
|
|
|
|
|
CROSS_TOOLS := \
|
|
|
|
CC="$(heads_cc)" \
|
|
|
|
$(CROSS_TOOLS_NOCC) \
|
|
|
|
|
2017-01-31 19:57:41 +00:00
|
|
|
|
2016-12-29 23:23:08 +00:00
|
|
|
|
2017-11-20 22:28:35 +00:00
|
|
|
ifeq "$(CONFIG_COREBOOT)" "y"
|
2018-02-05 16:56:15 +00:00
|
|
|
all: $(build)/$(BOARD)/coreboot.rom
|
2018-02-05 16:27:45 +00:00
|
|
|
else ifeq "$(CONFIG_LINUXBOOT)" "y"
|
|
|
|
all: $(build)/$(BOARD)/linuxboot.rom
|
2017-11-20 22:28:35 +00:00
|
|
|
else
|
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
|
|
|
endif
|
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
|
|
|
|
2017-03-29 20:58:45 +00:00
|
|
|
# Make helpers to operate on lists of things
|
|
|
|
define prefix =
|
|
|
|
$(foreach _, $2, $1$_)
|
|
|
|
endef
|
|
|
|
define map =
|
|
|
|
$(foreach _,$2,$(eval $(call $1,$_)))
|
|
|
|
endef
|
|
|
|
|
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
|
|
|
include modules/*
|
2016-08-02 23:25:47 +00:00
|
|
|
|
2016-09-10 21:36:36 +00:00
|
|
|
define 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
|
|
|
endef
|
2016-09-10 21:36:36 +00:00
|
|
|
define libs =
|
|
|
|
$(foreach m,$1,$(call prefix,$(build)/$($m_dir)/,$($m_libraries)))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define outputs =
|
|
|
|
$(foreach m,$1,\
|
|
|
|
$(call bins,$m)\
|
|
|
|
$(call libs,$m)\
|
|
|
|
)
|
|
|
|
endef
|
2016-08-02 23:25:47 +00:00
|
|
|
|
2018-02-05 16:27:45 +00:00
|
|
|
#
|
|
|
|
# Build a cpio from a directory
|
|
|
|
#
|
|
|
|
define 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
|
|
|
|
endef
|
|
|
|
|
|
|
|
define 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 ; \
|
2018-05-04 18:36:56 +00:00
|
|
|
cp -a "$1" "$2" ; \
|
2018-02-05 16:27:45 +00:00
|
|
|
)
|
2018-05-02 15:38:39 +00:00
|
|
|
@sha256sum "$(2:$(pwd)/%=%)"
|
2018-02-05 16:27:45 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
define 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)))
|
2018-05-02 15:38:39 +00:00
|
|
|
|
2016-08-19 15:31:07 +00:00
|
|
|
ifneq ("$($1_repo)","")
|
|
|
|
# Checkout the tree instead and touch the canary file so that we know
|
|
|
|
# that the files are all present. No signature hashes are checked in
|
|
|
|
# this case, since we don't have a stable version to compare against.
|
2018-05-02 15:38:39 +00:00
|
|
|
$(build)/$($1_base_dir)/.canary:
|
2018-05-02 18:30:58 +00:00
|
|
|
git clone $($1_repo) "$(build)/$($1_base_dir)"
|
2017-01-31 16:56:14 +00:00
|
|
|
if [ -r patches/$1.patch ]; then \
|
2018-05-02 15:38:39 +00:00
|
|
|
( cd $(build)/$($1_base_dir) ; patch -p1 ) \
|
2018-07-17 10:22:52 +00:00
|
|
|
< patches/$1.patch \
|
|
|
|
|| exit 1 ; \
|
2017-01-31 16:56:14 +00:00
|
|
|
fi
|
2018-03-08 20:37:17 +00:00
|
|
|
if [ -d patches/$1 ] && \
|
|
|
|
[ -r patches/$1 ] ; then \
|
|
|
|
for patch in patches/$1/*.patch ; do \
|
|
|
|
echo "Applying patch file : $$$$patch " ; \
|
2018-05-02 15:38:39 +00:00
|
|
|
( cd $(build)/$($1_base_dir) ; patch -p1 ) \
|
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
|
|
|
else
|
|
|
|
# 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),\
|
|
|
|
if ! wget -O "$$@" $($1_url) ; then \
|
|
|
|
rm -f "$$@" ; \
|
|
|
|
exit 1 ; \
|
|
|
|
fi \
|
|
|
|
)
|
2017-07-18 18:03:43 +00:00
|
|
|
$(packages)/.$1-$($1_version)_verify: $(packages)/$($1_tar)
|
2017-01-27 20:47:08 +00:00
|
|
|
echo "$($1_hash) $$^" | sha256sum --check -
|
2017-03-29 20:58:45 +00:00
|
|
|
@touch "$$@"
|
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
|
2018-05-02 15:38:39 +00:00
|
|
|
$(build)/$($1_base_dir)/.canary: $(packages)/.$1-$($1_version)_verify
|
2016-08-03 12:52:23 +00:00
|
|
|
tar -xf "$(packages)/$($1_tar)" -C "$(build)"
|
2016-08-03 22:10:44 +00:00
|
|
|
if [ -r patches/$1-$($1_version).patch ]; then \
|
2018-05-02 18:30:58 +00:00
|
|
|
( cd $(build)/$($1_base_dir) ; patch -p1 ) \
|
2018-07-17 10:22:52 +00:00
|
|
|
< patches/$1-$($1_version).patch \
|
|
|
|
|| exit 1 ; \
|
2016-08-03 22:10:44 +00:00
|
|
|
fi
|
2018-03-08 20:37:17 +00:00
|
|
|
if [ -d patches/$1-$($1_version) ] && \
|
|
|
|
[ -r patches/$1-$($1_version) ] ; then \
|
|
|
|
for patch in patches/$1-$($1_version)/*.patch ; do \
|
|
|
|
echo "Applying patch file : $$$$patch " ; \
|
2018-05-02 15:38:39 +00:00
|
|
|
( cd $(build)/$($1_base_dir) ; patch -p1 ) \
|
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) \
|
2017-04-07 14:34:57 +00:00
|
|
|
modules/$1
|
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
|
|
|
endef
|
|
|
|
|
2017-03-31 15:18:46 +00:00
|
|
|
$(call map, define_module, $(modules-y))
|
2016-07-25 14:08:53 +00:00
|
|
|
|
2017-04-08 19:19:26 +00:00
|
|
|
# hack to force musl-cross to be built before musl
|
2018-05-02 18:30:58 +00:00
|
|
|
#$(build)/$(musl_dir)/.configured: $(build)/$(musl-cross_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.
|
|
|
|
#
|
|
|
|
define install =
|
2017-03-29 20:58:45 +00:00
|
|
|
@-mkdir -p "$(dir $2)"
|
2017-04-08 21:46:54 +00:00
|
|
|
$(call do,INSTALL,$2,cp -a "$1" "$2")
|
2016-09-10 21:36:36 +00:00
|
|
|
endef
|
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
|
|
|
define initrd_bin_add =
|
|
|
|
$(initrd_bin_dir)/$(notdir $1): $1
|
2018-02-05 16:27:45 +00:00
|
|
|
$(call do,INSTALL-BIN,$$(<:$(pwd)/%=%),cp -a "$$<" "$$@")
|
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
|
|
|
endef
|
|
|
|
|
2016-09-10 21:36:36 +00:00
|
|
|
|
|
|
|
define 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)
|
|
|
|
endef
|
|
|
|
|
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?
|
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
|
|
|
|
bin_modules-$(CONFIG_CRYPTSETUP) += cryptsetup
|
|
|
|
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
|
2018-05-11 21:08:31 +00:00
|
|
|
bin_modules-$(CONFIG_NITROKEY) += nitrokey-hotp-verification
|
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
|
|
|
|
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
|
|
|
ifeq ($(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
|
|
|
endif
|
|
|
|
|
2018-03-02 14:37:31 +00:00
|
|
|
$(COREBOOT_UTIL_DIR)/cbmem/cbmem \
|
|
|
|
$(COREBOOT_UTIL_DIR)/superiotool/superiotool \
|
|
|
|
$(COREBOOT_UTIL_DIR)/inteltool/inteltool \
|
2018-05-02 15:38:39 +00:00
|
|
|
: $(build)/$(coreboot_base_dir)/.canary \
|
|
|
|
$(build)/$(musl_dir)/.build
|
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
|
|
|
|
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" "$@" ; \
|
|
|
|
sha256sum "$(@:$(pwd)/%=%)" ; \
|
|
|
|
else \
|
|
|
|
echo "$(DATE) UNCHANGED $(@:$(pwd)/%=%)" ; \
|
|
|
|
rm "$@.tmp" ; \
|
|
|
|
fi
|
2016-11-29 16:19:48 +00:00
|
|
|
|
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) \
|
|
|
|
$(initrd_libs) \
|
2018-05-04 18:36:56 +00:00
|
|
|
$(initrd_tmp_dir)/etc/config \
|
|
|
|
|
|
|
|
$(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) \
|
|
|
|
>> $@ ; \
|
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
|
|
|
|
modules-slow := musl musl-cross kernel_headers
|
|
|
|
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 \
|
|
|
|
$(MAKE) -C "build/$$dir" clean ; \
|
|
|
|
rm "build/$$dir/.configured" ; \
|
2017-01-04 15:31:27 +00:00
|
|
|
done
|
2017-01-27 21:17:03 +00:00
|
|
|
|
2017-04-08 21:46:54 +00:00
|
|
|
real.clean:
|
|
|
|
for dir in \
|
|
|
|
$(module_dirs) \
|
|
|
|
$(musl_dir) \
|
|
|
|
$(kernel_headers) \
|
|
|
|
; do \
|
|
|
|
if [ ! -z "$$dir" ]; then \
|
|
|
|
rm -rf "build/$$dir"; \
|
|
|
|
fi; \
|
|
|
|
done
|
2017-04-09 05:38:22 +00:00
|
|
|
rm -rf ./install
|
2017-04-08 21:46:54 +00:00
|
|
|
|
2017-04-08 19:19:26 +00:00
|
|
|
|
2017-01-27 21:17:03 +00:00
|
|
|
else
|
|
|
|
# Wrong make version detected -- build our local version
|
|
|
|
# and re-invoke the Makefile with it instead.
|
2017-03-31 17:28:20 +00:00
|
|
|
$(eval $(shell echo >&2 "$(DATE) Wrong make detected: $(LOCAL_MAKE_VERSION)"))
|
2017-01-27 21:17:03 +00:00
|
|
|
HEADS_MAKE := $(build)/$(make_dir)/make
|
|
|
|
|
|
|
|
# Once we have a proper Make, we can just pass arguments into it
|
2018-02-13 18:20:04 +00:00
|
|
|
all bootstrap linux cpio: $(HEADS_MAKE)
|
2018-04-19 23:37:45 +00:00
|
|
|
LANG=C MAKE=$(HEADS_MAKE) $(HEADS_MAKE) $(MAKE_JOBS) $@
|
2018-05-02 15:38:39 +00:00
|
|
|
%.clean %.vol: $(HEADS_MAKE)
|
2017-01-27 21:17:03 +00:00
|
|
|
LANG=C MAKE=$(HEADS_MAKE) $(HEADS_MAKE) $@
|
|
|
|
|
|
|
|
# How to download and build the correct version of make
|
|
|
|
$(HEADS_MAKE): $(build)/$(make_dir)/Makefile
|
2017-03-29 20:58:45 +00:00
|
|
|
make -C "$(dir $@)" $(MAKE_JOBS) \
|
2017-02-28 23:02:10 +00:00
|
|
|
2>&1 \
|
|
|
|
| tee "$(log_dir)/make.log" \
|
|
|
|
$(VERBOSE_REDIRECT)
|
|
|
|
|
2017-01-27 21:17:03 +00:00
|
|
|
$(build)/$(make_dir)/Makefile: $(packages)/$(make_tar)
|
|
|
|
tar xf "$<" -C build/
|
2017-03-29 20:58:45 +00:00
|
|
|
cd "$(dir $@)" ; ./configure \
|
2017-02-28 23:02:10 +00:00
|
|
|
2>&1 \
|
|
|
|
| tee "$(log_dir)/make.configure.log" \
|
|
|
|
$(VERBOSE_REDIRECT)
|
|
|
|
|
2017-01-27 21:17:03 +00:00
|
|
|
$(packages)/$(make_tar):
|
|
|
|
wget -O "$@" "$(make_url)"
|
|
|
|
if ! echo "$(make_hash) $@" | sha256sum --check -; then \
|
|
|
|
$(MV) "$@" "$@.failed"; \
|
|
|
|
false; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
endif
|