2016-08-02 23:25:47 +00:00
|
|
|
modules :=
|
|
|
|
pwd := $(shell pwd)
|
|
|
|
packages := $(pwd)/packages
|
|
|
|
build := $(pwd)/build
|
|
|
|
config := $(pwd)/build
|
|
|
|
|
|
|
|
all:
|
|
|
|
|
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
|
|
|
|
|
|
|
|
define outputs =
|
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
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate the targets for a module.
|
|
|
|
#
|
|
|
|
# Special variables like $@ must be written as $$@ to avoid
|
|
|
|
# expansion during the first evaluation.
|
|
|
|
#
|
|
|
|
define define_module =
|
|
|
|
# Fetch and verify the source tar file
|
|
|
|
$(packages)/$($1_tar):
|
|
|
|
wget -O "$$@" $($1_url)
|
|
|
|
$(packages)/.$1_verify: $(packages)/$($1_tar)
|
|
|
|
echo "$($1_hash) $$^" | sha256sum --check -
|
|
|
|
touch "$$@"
|
|
|
|
|
|
|
|
# Unpack the tar file and touch the canary so that we know
|
|
|
|
# that the files are all present
|
2016-08-03 14:47:48 +00:00
|
|
|
$(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 "$$@"
|
|
|
|
|
|
|
|
# Copy our stored config file into the unpacked directory
|
|
|
|
$(build)/$($1_dir)/.config: config/$1.config $(build)/$($1_dir)/.canary
|
|
|
|
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-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
|
|
|
|
#
|
|
|
|
define initrd_bin =
|
|
|
|
initrd/bin/$(notdir $1): $1
|
2016-08-03 12:40:51 +00:00
|
|
|
@if [ ! -d initrd/bin ]; then mkdir "initrd/bin"; fi
|
2016-08-03 01:23:18 +00:00
|
|
|
cmp --quiet "$$@" "$$^" || \
|
|
|
|
cp -a "$$^" "$$@"
|
|
|
|
initrd_bins += initrd/bin/$(notdir $1)
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach _, $(call outputs,kexec), $(eval $(call initrd_bin,$_)))
|
2016-08-06 21:13:22 +00:00
|
|
|
#$(foreach _, $(call outputs,tpmtotp), $(eval $(call initrd_bin,$_)))
|
|
|
|
#$(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
|
|
|
|
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-08-03 01:39:24 +00:00
|
|
|
initrd_libs: $(initrd_bins)
|
2016-08-06 21:13:22 +00:00
|
|
|
-find initrd/bin -type f -print0 \
|
|
|
|
| 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
|
|
|
|
# Note the touch and sort operation on the find output -- this
|
|
|
|
# ensures that the files always have the same timestamp and
|
|
|
|
# appear in the same order.
|
|
|
|
#
|
2016-08-03 14:47:48 +00:00
|
|
|
# If there is in /dev/console, initrd can't startup.
|
|
|
|
# We have to force it to be included into the cpio image.
|
2016-08-06 21:13:22 +00:00
|
|
|
# Since we are picking up the system's /dev/console, the
|
|
|
|
# timestamp will not be reproducible.
|
2016-08-03 01:23:18 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
initrd.cpio: $(initrd_bins) initrd_libs
|
2016-08-04 22:07:36 +00:00
|
|
|
find ./initrd -print0 \
|
|
|
|
| xargs -0 touch --no-dereference -d "1970-01-01"
|
2016-08-03 14:47:48 +00:00
|
|
|
cd ./initrd ; \
|
|
|
|
( \
|
|
|
|
echo "/dev" ; \
|
|
|
|
echo "/dev/console"; \
|
|
|
|
find . \
|
|
|
|
) \
|
|
|
|
| sort \
|
|
|
|
| cpio --quiet -H newc -o \
|
2016-08-03 01:23:18 +00:00
|
|
|
> "../$@.tmp"
|
|
|
|
if ! cmp --quiet "$@" "$@.tmp"; then \
|
|
|
|
mv "$@.tmp" "$@"; \
|
|
|
|
else \
|
|
|
|
echo "$@: Unchanged"; \
|
|
|
|
rm "$@.tmp"; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# hack for the linux kernel to depend on the initrd image
|
|
|
|
# this will change once coreboot can link in the initrd separately
|
|
|
|
$(call outputs,linux): initrd.cpio
|
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
|
|
|
|
|