Skip to content

Commit

Permalink
Build initrd tools with musl-libc (issue #77).
Browse files Browse the repository at this point in the history
This adds compilations modules for musl-libc and kernel-headers.
The entire initrd (busybox, cryptsetup, gpgv, kexec, etc) can be built
with the much smaller libc and it appears to work with chroot.

Library paths are not set correctly and files are installed into
heads/install to make them accessible to other modules.  This prevents
the initrd from working without manual fixup; need to fix before
merging into master.

Build times have gone up since everything is being rebuilt more
often for some reason.
  • Loading branch information
osresearch committed Dec 29, 2016
1 parent 177dede commit 9273e25
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 8 deletions.
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ INSTALL := $(pwd)/install
# 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
heads_cc := $(INSTALL)/bin/musl-gcc

all: $(BOARD).rom

# Disable all built in rules
Expand Down Expand Up @@ -68,7 +73,8 @@ define define_module =
$(build)/$($1_dir)/.canary: $(packages)/.$1_verify
tar -xf "$(packages)/$($1_tar)" -C "$(build)"
if [ -r patches/$1-$($1_version).patch ]; then \
( cd $(build)/$($1_dir) ; patch -p1 ) < patches/$1-$($1_version).patch; \
( cd $(build)/$($1_dir) ; patch -p1 ) \
< patches/$1-$($1_version).patch; \
fi
touch "$$@"
endif
Expand Down Expand Up @@ -100,6 +106,7 @@ define define_module =
# Target for all of the outputs, which depend on their dependent modules
$1.intermediate: \
$(foreach d,$($1_depends),$(call outputs,$d)) \
$(foreach d,$($1_depends),$d.intermediate) \
$(build)/$($1_dir)/.configured
make -C "$(build)/$($1_dir)" $($1_target)

Expand Down Expand Up @@ -163,16 +170,21 @@ initrd/bin/busybox: $(build)/$(busybox_dir)/busybox
cmp --quiet "$@" "$^" || \
make \
-C $(build)/$(busybox_dir) \
CC="$(heads_cc)" \
CONFIG_PREFIX="$(pwd)/initrd" \
-j 8 \
install

# hack to build cbmem from coreboot
# this must be built *AFTER* musl
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 $@)"
$(build)/$(coreboot_dir)/util/cbmem/cbmem: \
$(build)/$(coreboot_dir)/.canary \
musl.intermediate
make -C "$(dir $@)" CC="$(heads_cc)"


# Update all of the libraries in the initrd based on the executables
Expand Down
8 changes: 7 additions & 1 deletion modules/busybox
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ busybox_tar := busybox-$(busybox_version).tar.bz2
busybox_url := https://busybox.net/downloads/$(busybox_tar)
busybox_hash := 5a0fe06885ee1b805fb459ab6aaa023fe4f2eccee4fb8c0fd9a6c17c0daca2fc

busybox_configure := make oldconfig
busybox_configure := make CC=$(heads_cc) oldconfig
busybox_config := busybox.config
busybox_output := busybox
busybox_target := \
CC="$(heads_cc)" \
CONFIG_PREFIX="$(INSTALL)" \
-j 8 \
install

busybox_depends := $(musl_dep)
3 changes: 2 additions & 1 deletion modules/cryptsetup
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modules += cryptsetup

cryptsetup_depends := libuuid popt lvm2
cryptsetup_depends := libuuid popt lvm2 $(musl_dep)

cryptsetup_version := 1.7.3
cryptsetup_dir := cryptsetup-$(cryptsetup_version)
Expand All @@ -9,6 +9,7 @@ cryptsetup_url := https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptse
cryptsetup_hash := af2b04e8475cf40b8d9ffd97a1acfa73aa787c890430afd89804fb544d6adc02

cryptsetup_configure := ./configure \
CC="$(heads_cc)" \
CFLAGS="-I$(INSTALL)/include" \
LDFLAGS="-L$(INSTALL)/lib" \
--prefix "$(INSTALL)" \
Expand Down
2 changes: 2 additions & 0 deletions modules/gpg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gpg_url := https://www.gnupg.org/ftp/gcrypt/gnupg/$(gpg_tar)
gpg_hash := 6b47a3100c857dcab3c60e6152e56a997f2c7862c1b8b2b25adf3884a1ae2276

gpg_configure := ./configure \
CC="$(heads_cc)" \
CFLAGS="-I$(INSTALL)/include" \
LDFLAGS="-L$(INSTALL)/lib" \
--prefix $(INSTALL) \
Expand All @@ -35,3 +36,4 @@ gpg_target := -j 8 install

gpg_output := g10/gpgv

gpg_depends := $(musl_dep)
18 changes: 18 additions & 0 deletions modules/kernel-headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
modules += kernel-headers

# we install kernel-headers from sabotage linux, a musl-libc based
# distribution, that works well with busybox and other tools.

kernel-headers_version := 3.12.6-5
kernel-headers_dir := kernel-headers-$(kernel-headers_version)
kernel-headers_tar := kernel-headers-$(kernel-headers_version).tar.gz
kernel-headers_url := https://github.com/sabotage-linux/kernel-headers/archive/v$(kernel-headers_version).tar.gz
kernel-headers_hash := ecf4db8781dc50a21cbc4cb17b039f96aede53f9da13435a3201373abb49b96b

kernel-headers_configure :=

kernel-headers_target := \
ARCH=x86_64 \
prefix="$(INSTALL)" \
install

7 changes: 6 additions & 1 deletion modules/kexec
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ kexec_url := https://kernel.org/pub/linux/utils/kernel/kexec/$(kexec_tar)
kexec_hash := cc7b60dad0da202004048a6179d8a53606943062dd627a2edba45a8ea3a85135

kexec_configure := ./configure \
CC="$(heads_cc)" \
CFLAGS="-I$(INSTALL)/include" \
LDFLAGS="-L$(INSTALL)/lib" \
--prefix="$(INSTALL)" \
--without-zlib \
--without-lzma \

kexec_target := -j 8 install
kexec_target := \
CC="$(heads_cc)" \
-j 8 \
install \

kexec_output := build/sbin/kexec

# if we don't need zlib, don't built it
#kexec_depends := zlib
kexec_depends := $(musl_dep)
2 changes: 2 additions & 0 deletions modules/libuuid
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ libuuid_url := http://downloads.sourceforge.net/project/libuuid/$(libuuid_tar)
libuuid_hash := 46af3275291091009ad7f1b899de3d0cea0252737550e7919d17237997db5644

libuuid_configure := ./configure \
CC="$(heads_cc)" \
--prefix $(INSTALL) \

libuuid_target := install

libuuid_libraries := .libs/libuuid.so
libuuid_depends := $(musl_dep)
3 changes: 3 additions & 0 deletions modules/lvm2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lvm2_url := http://mirrors.kernel.org/sourceware/lvm2/$(lvm2_tar)
lvm2_hash := 23a3d1cddd41b3ef51812ebf83e9fa491f502fe74130d4263be327a91914660d

lvm2_configure := ./configure \
CC="$(heads_cc)" \
--prefix $(INSTALL) \
--disable-selinux \
--disable-udev-systemd-background-jobs \
Expand All @@ -17,3 +18,5 @@ lvm2_target := -j 8 install_device-mapper
lvm2_libraries := libdm/libdevmapper.so

lvm2_output := tools/dmsetup

lvm2_depends := $(musl_dep)
9 changes: 8 additions & 1 deletion modules/mbedtls
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ mbedtls_libraries := \
library/libmbedcrypto.so.0 \

mbedtls_configure :=
mbedtls_target := SHARED=1 DESTDIR=$(INSTALL) -j 8 install
mbedtls_target := \
SHARED=1 \
DESTDIR=$(INSTALL) \
CC="$(heads_cc)" \
-j 8 \
install

mbedtls_depends := $(musl_dep)
17 changes: 17 additions & 0 deletions modules/musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
modules += musl

musl_version := 1.1.15
musl_dir := musl-$(musl_version)
musl_tar := musl-$(musl_version).tar.gz
musl_url := https://www.musl-libc.org/releases/$(musl_tar)
musl_hash := 97e447c7ee2a7f613186ec54a93054fe15469fe34d7d323080f7ef38f5ecb0fa

musl_output := $(INSTALL)/bin/musl-gcc

musl_configure := ./configure \
--prefix="$(INSTALL)" \
--syslibdir="$(INSTALL)/lib" \

musl_target := -j 8 install

musl_depends := kernel-headers
2 changes: 2 additions & 0 deletions modules/popt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ popt_url := http://rpm5.org/files/popt/$(popt_tar)
popt_hash := e728ed296fe9f069a0e005003c3d6b2dde3d9cad453422a10d6558616d304cc8

popt_configure := ./configure \
CC="$(heads_cc)" \
--prefix $(INSTALL) \

popt_target := install

popt_libraries := ./libs/libpopt.so
popt_depends := $(musl_dep)
2 changes: 2 additions & 0 deletions modules/qrencode
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ qrencode_hash := e794e26a96019013c0e3665cb06b18992668f352c5553d0a553f5d144f7f2a7
qrencode_output := .libs/libqrencode.so.$(qrencode_version)

qrencode_configure := ./configure \
CC="$(heads_cc)" \
--prefix $(INSTALL) \
--without-tools \

qrencode_target := install

qrencode_depends := $(musl_dep)
3 changes: 2 additions & 1 deletion modules/tpmtotp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modules += tpmtotp

tpmtotp_depends := mbedtls qrencode
tpmtotp_depends := mbedtls qrencode $(musl_dep)

tpmtotp_version := git
tpmtotp_repo := https://github.com/osresearch/tpmtotp
Expand All @@ -11,6 +11,7 @@ tpmtotp_dir := tpmtotp-$(tpmtotp_version)
#tpmtotp_url := https://github.com/osresearch/tpmtotp/archive/v0.0.1.tar.gz
#tpmtotp_hash := 8bf2380248fea540a96ad0ff8a4f170b8d93b6bb5fe49b958f9f1926f994823f

tpmtotp_target := CC="$(heads_cc)"

tpmtotp_output := \
totp \
Expand Down

0 comments on commit 9273e25

Please sign in to comment.