2016-08-02 23:25:47 +00:00
|
|
|
modules :=
|
|
|
|
pwd := $(shell pwd)
|
|
|
|
packages := $(pwd)/packages
|
|
|
|
build := $(pwd)/build
|
|
|
|
config := $(pwd)/build
|
|
|
|
|
2016-11-23 17:11:08 +00:00
|
|
|
# Currently supported targets are x230, chell and qemu
|
|
|
|
TARGET ?= x230
|
2016-08-14 20:02:15 +00:00
|
|
|
|
2016-11-23 17:11:08 +00:00
|
|
|
all: $(TARGET).rom
|
2016-08-02 23:25:47 +00:00
|
|
|
|
2016-08-03 12:40:51 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
all: $(modules)
|
|
|
|
|
|
|
|
define prefix =
|
|
|
|
$(foreach _, $2, $1$_)
|
|
|
|
endef
|
|
|
|
|
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
|
|
|
|
|
|
|
#
|
|
|
|
# Generate the targets for a module.
|
|
|
|
#
|
|
|
|
# Special variables like $@ must be written as $$@ to avoid
|
|
|
|
# expansion during the first evaluation.
|
|
|
|
#
|
|
|
|
define define_module =
|
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.
|
|
|
|
$(build)/$($1_dir)/.canary:
|
|
|
|
git clone "$($1_repo)" "$(build)/$($1_dir)"
|
|
|
|
touch "$$@"
|
|
|
|
else
|
|
|
|
# Fetch and verify the source tar file
|
|
|
|
$(packages)/$($1_tar):
|
2016-08-02 23:25:47 +00:00
|
|
|
wget -O "$$@" $($1_url)
|
2016-08-19 15:31:07 +00:00
|
|
|
$(packages)/.$1_verify: $(packages)/$($1_tar)
|
2016-08-02 23:25:47 +00:00
|
|
|
echo "$($1_hash) $$^" | sha256sum --check -
|
|
|
|
touch "$$@"
|
|
|
|
|
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
|
|
|
|
$(build)/$($1_dir)/.canary: $(packages)/.$1_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 \
|
|
|
|
( cd $(build)/$($1_dir) ; patch -p1 ) < patches/$1-$($1_version).patch; \
|
|
|
|
fi
|
2016-08-02 23:25:47 +00:00
|
|
|
touch "$$@"
|
2016-08-19 15:31:07 +00:00
|
|
|
endif
|
2016-08-02 23:25:47 +00:00
|
|
|
|
|
|
|
# Copy our stored config file into the unpacked directory
|
2016-11-23 17:11:08 +00:00
|
|
|
$(build)/$($1_dir)/.config: config/$($1_config) $(build)/$($1_dir)/.canary
|
2016-08-02 23:25:47 +00:00
|
|
|
cp "$$<" "$$@"
|
|
|
|
|
|
|
|
# Use the module's configure variable to build itself
|
|
|
|
$(build)/$($1_dir)/.configured: \
|
|
|
|
$(build)/$($1_dir)/.canary \
|
|
|
|
$(build)/$($1_dir)/.config
|
|
|
|
cd "$(build)/$($1_dir)" ; $($1_configure)
|
|
|
|
touch "$$@"
|
|
|
|
|
2016-08-03 01:23:18 +00:00
|
|
|
# Build the target after any dependencies
|
|
|
|
$(call outputs,$1): \
|
|
|
|
$(build)/$($1_dir)/.configured \
|
|
|
|
$(call outputs,$($1_depends))
|
2016-08-02 23:25:47 +00:00
|
|
|
make -C "$(build)/$($1_dir)" $($1_target)
|
2016-08-03 01:23:18 +00:00
|
|
|
|
|
|
|
# Short hand target for the module
|
2016-08-02 23:25:47 +00:00
|
|
|
$1: $(call outputs,$1)
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach _, $(modules), $(eval $(call define_module,$_)))
|
2016-07-25 14:08:53 +00:00
|
|
|
|
2016-09-10 21:36:36 +00:00
|
|
|
initrd_lib_dir := initrd/lib/x86_64-linux-gnu
|
|
|
|
initrd_bin_dir := initrd/bin
|
|
|
|
|
|
|
|
#
|
|
|
|
# Install a file into the initrd, if it changed from
|
|
|
|
# the destination file.
|
|
|
|
#
|
|
|
|
define install =
|
2016-09-26 18:55:48 +00:00
|
|
|
cmp --quiet "$1" "$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
|
2016-09-26 18:55:48 +00:00
|
|
|
@if [ ! -d "$(initrd_bin_dir)" ]; \
|
|
|
|
then mkdir -p "$(initrd_bin_dir)"; \
|
|
|
|
fi
|
|
|
|
$(call install,$$<,$$@)
|
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
|
2016-09-26 18:55:48 +00:00
|
|
|
@if [ ! -d "$(initrd_lib_dir)" ]; \
|
|
|
|
then mkdir -p "$(initrd_lib_dir)"; \
|
|
|
|
fi
|
|
|
|
$(call install,$$<,$$@)
|
2016-09-10 21:36:36 +00:00
|
|
|
initrd_libs += $(initrd_lib_dir)/$(notdir $1)
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach _, $(call bins,kexec), $(eval $(call initrd_bin_add,$_)))
|
|
|
|
$(foreach _, $(call bins,tpmtotp), $(eval $(call initrd_bin_add,$_)))
|
|
|
|
|
|
|
|
$(foreach _, $(call libs,tpmtotp), $(eval $(call initrd_lib_add,$_)))
|
|
|
|
$(foreach _, $(call libs,mbedtls), $(eval $(call initrd_lib_add,$_)))
|
|
|
|
$(foreach _, $(call libs,qrencode), $(eval $(call initrd_lib_add,$_)))
|
|
|
|
|
2016-08-06 21:13:22 +00:00
|
|
|
#$(foreach _, $(call outputs,xen), $(eval $(call initrd_bin,$_)))
|
2016-08-03 01:23:18 +00:00
|
|
|
|
|
|
|
# hack to install busybox into the initrd
|
|
|
|
initrd_bins += initrd/bin/busybox
|
|
|
|
|
|
|
|
initrd/bin/busybox: $(build)/$(busybox_dir)/busybox
|
|
|
|
cmp --quiet "$@" "$^" || \
|
|
|
|
make \
|
|
|
|
-C $(build)/$(busybox_dir) \
|
|
|
|
CONFIG_PREFIX="$(pwd)/initrd" \
|
|
|
|
install
|
|
|
|
|
2016-08-04 21:38:00 +00:00
|
|
|
# hack to build cbmem from coreboot
|
|
|
|
initrd_bins += initrd/bin/cbmem
|
|
|
|
initrd/bin/cbmem: $(build)/$(coreboot_dir)/util/cbmem/cbmem
|
|
|
|
cmp --quiet "$^" "$@" \
|
|
|
|
|| cp "$^" "$@"
|
|
|
|
$(build)/$(coreboot_dir)/util/cbmem/cbmem: $(build)/$(coreboot_dir)/.canary
|
|
|
|
make -C "$(dir $@)"
|
|
|
|
|
2016-08-06 21:13:22 +00:00
|
|
|
# Mounting dm-verity file systems requires dm-verity to be installed
|
|
|
|
# We use gpgv to verify the signature on the root hash.
|
|
|
|
# Both of these should be brought in as modules instead of from /sbin
|
2016-11-23 15:46:04 +00:00
|
|
|
#initrd_bins += initrd/bin/cryptsetup
|
|
|
|
initrd/bin/cryptsetup: /sbin/cryptsetup
|
|
|
|
cp "$<" "$@"
|
2016-08-06 21:13:22 +00:00
|
|
|
initrd_bins += initrd/bin/dmsetup
|
|
|
|
initrd/bin/dmsetup: /sbin/dmsetup
|
|
|
|
cp "$<" "$@"
|
|
|
|
initrd_bins += initrd/bin/gpgv
|
|
|
|
initrd/bin/gpgv: /usr/bin/gpgv
|
|
|
|
cp "$<" "$@"
|
2016-08-03 01:23:18 +00:00
|
|
|
|
|
|
|
# Update all of the libraries in the initrd based on the executables
|
|
|
|
# that were installed.
|
2016-09-10 21:36:36 +00:00
|
|
|
initrd_lib_install: $(initrd_bins) $(initrd_libs)
|
|
|
|
-find initrd/bin -type f -a ! -name '*.sh' -print0 \
|
2016-08-06 21:13:22 +00:00
|
|
|
| xargs -0 strip
|
2016-08-03 01:23:18 +00:00
|
|
|
./populate-lib \
|
2016-08-03 01:53:23 +00:00
|
|
|
./initrd/lib/x86_64-linux-gnu/ \
|
2016-08-03 01:23:18 +00:00
|
|
|
initrd/bin/* \
|
|
|
|
initrd/sbin/* \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
|
|
#
|
2016-11-23 17:11:08 +00:00
|
|
|
# If there is no /dev/console, initrd can't startup.
|
2016-08-03 14:47:48 +00:00
|
|
|
# We have to force it to be included into the cpio image.
|
2016-11-23 17:11:08 +00:00
|
|
|
# Since we are picking up the system's /dev/console, there
|
|
|
|
# is a chance the build will not be reproducible (although
|
|
|
|
# unlikely that their device file has a different major/minor)
|
2016-08-03 01:23:18 +00:00
|
|
|
#
|
|
|
|
#
|
2016-09-10 21:36:36 +00:00
|
|
|
initrd.cpio: $(initrd_bins) $(initrd_libs) initrd_lib_install
|
2016-08-03 14:47:48 +00:00
|
|
|
cd ./initrd ; \
|
|
|
|
( \
|
|
|
|
echo "/dev" ; \
|
|
|
|
echo "/dev/console"; \
|
|
|
|
find . \
|
|
|
|
) \
|
|
|
|
| cpio --quiet -H newc -o \
|
2016-08-14 20:02:15 +00:00
|
|
|
| ../cpio-clean \
|
2016-08-03 01:23:18 +00:00
|
|
|
> "../$@.tmp"
|
|
|
|
if ! cmp --quiet "$@" "$@.tmp"; then \
|
|
|
|
mv "$@.tmp" "$@"; \
|
|
|
|
else \
|
|
|
|
echo "$@: Unchanged"; \
|
|
|
|
rm "$@.tmp"; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-08-14 20:02:15 +00:00
|
|
|
# populate the coreboot initrd image from the one we built.
|
|
|
|
# 4.4 doesn't allow this, but building from head does.
|
2016-08-03 01:23:18 +00:00
|
|
|
$(call outputs,linux): initrd.cpio
|
2016-08-14 20:02:15 +00:00
|
|
|
#$(call outputs,coreboot): $(build)/$(coreboot_dir)/initrd.cpio.xz
|
|
|
|
$(build)/$(coreboot_dir)/initrd.cpio.xz: initrd.cpio
|
2016-09-09 17:26:52 +00:00
|
|
|
xz --extreme < "$<" > "$@"
|
2016-08-03 01:59:14 +00:00
|
|
|
|
|
|
|
# hack for the coreboot to find the linux kernel
|
|
|
|
$(build)/$(coreboot_dir)/bzImage: $(call outputs,linux)
|
2016-08-03 12:40:51 +00:00
|
|
|
cmp --quiet "$@" "$^" || \
|
|
|
|
cp -a "$^" "$@"
|
|
|
|
$(call outputs,coreboot): $(build)/$(coreboot_dir)/bzImage
|
|
|
|
|
2016-08-06 21:13:22 +00:00
|
|
|
|
|
|
|
# The CoreBoot gcc won't work for us since it doesn't have libc
|
|
|
|
#XGCC := $(build)/$(coreboot_dir)/util/crossgcc/xgcc/
|
|
|
|
#export CC := $(XGCC)/bin/x86_64-elf-gcc
|
|
|
|
#export LDFLAGS := -L/lib/x86_64-linux-gnu
|
|
|
|
|
2016-11-23 17:11:08 +00:00
|
|
|
x230.rom: $(build)/$(coreboot_dir)/x230/coreboot.rom
|
2016-08-14 20:02:15 +00:00
|
|
|
dd if="$<" of="$@" bs=1M skip=8
|
|
|
|
|
2016-11-23 17:11:08 +00:00
|
|
|
qemu.rom: $(build)/$(coreboot_dir)/qemu/coreboot.rom
|
|
|
|
cp -a "$<" "$@"
|