Skip to content

Commit

Permalink
Add LinuxBoot as a module, prep for nerf branch merge (#305)
Browse files Browse the repository at this point in the history
Move board configuration into `boards/` instead of `config/`
Fix mistake in building kernel module tree before kernel was done.
Allow per-board initrd builds (#278)
Allow per-board configurations for things (#304)
  • Loading branch information
osresearch committed Feb 5, 2018
1 parent 755c9e9 commit cf8509e
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 75 deletions.
167 changes: 99 additions & 68 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ modules-y :=
pwd := $(shell pwd)
packages := $(pwd)/packages
build := $(pwd)/build
config := $(pwd)/build
config := $(pwd)/config
INSTALL := $(pwd)/install
log_dir := $(build)/log

BOARD ?= qemu
CONFIG := $(pwd)/boards/$(BOARD).config

ifneq "y" "$(shell [ -r '$(CONFIG)' ] && echo y)"
$(error $(CONFIG): board configuration does not exist)
endif

include $(CONFIG)

# 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
BUILD_LOG := $(shell [ -d "$(log_dir)" ] || mkdir -p "$(log_dir)")
BUILD_LOG := $(shell mkdir -p "$(log_dir)" "$(build)/$(BOARD)" )

# Some things want usernames, we use the current checkout
# so that they are reproducible
Expand All @@ -28,13 +37,13 @@ ifeq "$V" ""
VERBOSE_REDIRECT := > /dev/null
# Not verbose, so we only show the header
define do =
@echo "$(DATE) $1 $2"
@echo "$(DATE) $1 $(2:$(pwd)/%=%)"
@$3
endef
else
# Verbose, so we display what we are doing
define do =
@echo "$(DATE) $1 $2"
@echo "$(DATE) $1 $(2:$(pwd)/%=%)"
$3
endef
endif
Expand All @@ -54,12 +63,12 @@ initrd_bin_dir := $(initrd_dir)/bin
$(shell mkdir -p "$(initrd_lib_dir)" "$(initrd_bin_dir)")
$(shell echo "Initrd: $initrd_dir")

ifeq "$(CONFIG)" ""
CONFIG := config/qemu-moc.config
$(eval $(shell echo >&2 "$(DATE) CONFIG is not set, defaulting to $(CONFIG)"))
endif

include $(CONFIG)
#ifeq "$(CONFIG)" ""
#CONFIG := config/qemu-moc.config
#$(eval $(shell echo >&2 "$(DATE) CONFIG is not set, defaulting to $(CONFIG)"))
#endif
#
#include $(CONFIG)

# We are running our own version of make,
# proceed with the build.
Expand All @@ -68,9 +77,6 @@ include $(CONFIG)
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c

# Currently supported targets are x230, chell and qemu
BOARD ?= qemu

# If musl-libc is being used in the initrd, set the heads_cc
# variable to point to it.
musl_dep := musl
Expand All @@ -95,8 +101,10 @@ CROSS_TOOLS := \

ifeq "$(CONFIG_COREBOOT)" "y"
all: $(BOARD).rom
else ifeq "$(CONFIG_LINUXBOOT)" "y"
all: $(build)/$(BOARD)/linuxboot.rom
else
all: linux.intermediate initrd-$(BOARD).cpio.xz
$(error "$(BOARD): neither CONFIG_COREBOOT nor CONFIG_LINUXBOOT is set?")
endif

# Disable all built in rules
Expand Down Expand Up @@ -134,6 +142,36 @@ $(foreach m,$1,\
)
endef

#
# Build a cpio from a directory
#
define do-cpio =
$(call do,CPIO,$1,\
( cd "$2"; \
find . \
| cpio \
--quiet \
-H newc \
-o \
) > "$1.tmp" \
)
@if ! cmp --quiet "$1.tmp" "$1" ; then \
mv "$1.tmp" "$1" ; \
else \
rm "$1.tmp" ; \
fi
endef

define do-copy =
$(call do,CP,$2,\
sha256sum "$(1:$(pwd)/%=%)" ; \
if ! cmp --quiet "$1" "$2" ; then \
cp -a "$1" "$2"; \
fi
)
endef


#
# Generate the targets for a module.
#
Expand Down Expand Up @@ -257,19 +295,21 @@ endef
#
define initrd_bin_add =
$(initrd_bin_dir)/$(notdir $1): $1
$(call do,INSTALL-BIN,$$<,cp -a "$$<" "$$@")
$(call do,INSTALL-BIN,$$(<:$(pwd)/%=%),cp -a "$$<" "$$@")
@$(CROSS)strip --preserve-dates "$$@" 2>&-; true
initrd_bins += $(initrd_bin_dir)/$(notdir $1)
endef


define initrd_lib_add =
$(initrd_lib_dir)/$(notdir $1): $1
$(call do,INSTALL-LIB,$$@,$(CROSS)strip --preserve-dates -o "$$@" "$$<")
$(call do,INSTALL-LIB,$(1:$(pwd)/%=%),\
$(CROSS)strip --preserve-dates -o "$$@" "$$<")
initrd_libs += $(initrd_lib_dir)/$(notdir $1)
endef

# Only some modules have binaries that we install
# Shouldn't this be specified in the module file?
bin_modules-$(CONFIG_KEXEC) += kexec
bin_modules-$(CONFIG_TPMTOTP) += tpmtotp
bin_modules-$(CONFIG_PCIUTILS) += pciutils
Expand All @@ -292,7 +332,7 @@ $(foreach m, $(modules-y), \
#$(foreach _, $(call outputs,xen), $(eval $(call initrd_bin,$_)))

# hack to install busybox into the initrd
initrd-$(BOARD).cpio: busybox.intermediate
$(build)/$(BOARD)/heads.cpio: busybox.intermediate
initrd_bins += $(initrd_bin_dir)/busybox

$(initrd_bin_dir)/busybox: $(build)/$(busybox_dir)/busybox
Expand Down Expand Up @@ -320,22 +360,6 @@ $(build)/$(coreboot_dir)/util/cbmem/cbmem: \
$(MAKE) -C "$(dir $@)" CC="$(heads_cc)" \
)

#
# Linux kernel module installation
#
# This is special cases since we have to do a special strip operation on
# the kernel modules to make them fit into the ROM image.
#
define linux_module =
$(build)/$(linux_dir)/$1: linux.intermediate
initrd-$(BOARD).cpio: $(initrd_lib_dir)/modules/$(notdir $1)
$(initrd_lib_dir)/modules/$(notdir $1): $(build)/$(linux_dir)/$1
@-mkdir -p "$(initrd_lib_dir)/modules"
$(call do,INSTALL-MODULE,$$@,$(CROSS)strip --preserve-dates --strip-debug -o "$$@" "$$<")
endef
$(call map,linux_module,$(linux_modules-y))


#
# initrd image creation
#
Expand All @@ -349,24 +373,47 @@ $(call map,linux_module,$(linux_modules-y))
# is a chance the build will not be reproducible (although
# unlikely that their device file has a different major/minor)
#
#
initrd-$(BOARD).cpio: $(initrd_bins) $(initrd_libs) blobs/dev.cpio FORCE
$(call do,OVERLAY,initrd,\
tar -C ./initrd -cf - . | tar -C "$(initrd_dir)" -xf - \
)
$(call do,INSTALL,$(CONFIG),cp "$(CONFIG)" "$(initrd_dir)/etc/config")
$(call do,CPIO,$@, \
cd "$(initrd_dir)"; \
find . \
| cpio --quiet -H newc -o \
| $(pwd)/bin/cpio-clean \
$(pwd)/blobs/dev.cpio \
- \
> "$(pwd)/$@" \

initrd-y += $(pwd)/blobs/dev.cpio
initrd-y += $(build)/$(BOARD)/heads.cpio
initrd-y += $(build)/$(BOARD)/modules.cpio
initrd-y += $(build)/$(BOARD)/tools.cpio

initrd.intermediate: $(build)/$(BOARD)/initrd.cpio.xz
$(build)/$(BOARD)/initrd.cpio.xz: $(initrd-y)
$(call do,CPIO-CLEAN,$@,\
$(pwd)/bin/cpio-clean \
$^ \
| xz \
--check=crc32 \
--lzma2=dict=1MiB \
-9 \
| dd bs=512 conv=sync > "$@" \
)
$(call do,RM,$(initrd_dir),$(RM) -rf "$(initrd_dir)")
@sha256sum "$(@:$(pwd)/%=%)"

#
# The heads.cpio is built from the initrd directory in the
# Heads tree.
#
$(build)/$(BOARD)/heads.cpio: FORCE
$(call do-cpio,$@,$(pwd)/initrd)


initrd.intermediate: initrd-$(BOARD).cpio
#
# The tools initrd is made from all of the things that we've
# created during the submodule build.
#
$(build)/$(BOARD)/tools.cpio: \
$(initrd_bins) \
$(initrd_libs) \

$(call do,INSTALL,$(CONFIG), \
mkdir -p "$(initrd_dir)/etc" ; \
cp "$(CONFIG)" "$(initrd_dir)/etc/config" \
)
$(call do-cpio,$@,$(initrd_dir))
@$(RM) -rf "$(initrd_dir)"


#
Expand All @@ -375,26 +422,10 @@ initrd.intermediate: initrd-$(BOARD).cpio
# and the extra padding is to ensure that it can be concatenated to
# other cpio files.
#
coreboot.intermediate: $(build)/$(coreboot_dir)/initrd-$(BOARD).cpio.xz
$(build)/$(coreboot_dir)/initrd-$(BOARD).cpio.xz: initrd-$(BOARD).cpio.xz

%.xz: %
$(call do,COMPRESS,$<,\
xz \
--check=crc32 \
--lzma2=dict=1MiB \
-9 \
< "$<" \
| dd bs=512 conv=sync > "$@" \
)
@sha256sum "$@"

# hack for the coreboot to find the linux kernel
$(build)/$(coreboot_dir)/bzImage: $(build)/$(linux_dir)/arch/x86/boot/bzImage
$(call do,COPY,$@,cp "$^" "$@")
@sha256sum "$@"
coreboot.intermediate: $(build)/$(BOARD)/initrd.cpio.xz
coreboot.intermediate: $(build)/$(BOARD)/bzImage
#$(build)/$(coreboot_dir)/initrd-$(BOARD).cpio.xz: initrd-$(BOARD).cpio.xz

coreboot.intermediate: $(build)/$(coreboot_dir)/bzImage


# Each board output has its own fixup required to turn the coreboot.rom
Expand Down
35 changes: 35 additions & 0 deletions boards/qemu-linuxboot.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Configuration for emulating LinuxBoot+Heads with qemu
#
BOARD=qemu-linuxboot

CONFIG_LINUXBOOT=y
linuxboot-board := qemu

#CONFIG_CRYPTSETUP=y
#CONFIG_FLASHROM=y
#CONFIG_GPG=y
CONFIG_KEXEC=y
CONFIG_UTIL_LINUX=y
#CONFIG_LVM2=y
#CONFIG_MBEDTLS=y
CONFIG_PCIUTILS=y
#CONFIG_POPT=y
#CONFIG_QRENCODE=y
#CONFIG_TPMTOTP=y
#CONFIG_XEN=y
CONFIG_DROPBEAR=y

CONFIG_LINUX_USB=y
#CONFIG_LINUX_IGB=y
#CONFIG_LINUX_MEGARAID=y
#CONFIG_LINUX_E1000E=y
CONFIG_LINUX_SCSI_GDTH=y
CONFIG_LINUX_ATA=y
CONFIG_LINUX_AHCI=y

CONFIG_BOOTSCRIPT=/bin/generic-init

CONFIG_BOOT_REQ_HASH=n
CONFIG_BOOT_REQ_ROLLBACK=n
CONFIG_BOOT_DEV="/dev/sda1"
CONFIG_USB_BOOT_DEV="/dev/sdb1"
3 changes: 3 additions & 0 deletions config/r630.config → boards/r630.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# and it is NERF, not coreboot.
BOARD=r630

CONFIG_LINUXBOOT=y
CONFIG_LINUXBOOT_ROM=blobs/r630-1.3.6.rom

#CONFIG_CRYPTSETUP=y
CONFIG_FLASHROM=y
#CONFIG_GPG=y
Expand Down
3 changes: 3 additions & 0 deletions config/s2600wf.config → boards/s2600wf.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#
BOARD=s2600wf

CONFIG_LINUXBOOT=y
CONFIG_LINUXBOOT_ROM=blobs/s2600wf.rom

#CONFIG_CRYPTSETUP=y
#CONFIG_FLASHROM=y
CONFIG_GPG=y
Expand Down
5 changes: 3 additions & 2 deletions config/winterfell.config → boards/winterfell.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# and it is NERF, not coreboot.
BOARD=winterfell

CONFIG_LINUXBOOT=y
CONFIG_LINUXBOOT_ROM=blobs/winterfell.rom

#CONFIG_CRYPTSETUP=y
CONFIG_FLASHROM=y
#CONFIG_GPG=y
Expand All @@ -17,8 +20,6 @@ CONFIG_TPMTOTP=y
CONFIG_DROPBEAR=y

CONFIG_LINUX_USB=y
CONFIG_LINUX_IGB=y
CONFIG_LINUX_MEGARAID=y
CONFIG_LINUX_MLX4=y

CONFIG_BOOTSCRIPT=/bin/generic-init
Expand Down
File renamed without changes.
Loading

0 comments on commit cf8509e

Please sign in to comment.