summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile18
-rw-r--r--cpio_list.txt14
-rw-r--r--init7
-rwxr-xr-xmake61
-rw-r--r--modules8
6 files changed, 43 insertions, 67 deletions
diff --git a/.gitignore b/.gitignore
index d915069..71478b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,4 @@
/initramfs.d
/initramfs.img
/load-random-seed
-/modules.sh
+/modules.dep
diff --git a/Makefile b/Makefile
index b82a41e..0efb2cf 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
+MAKEFLAGS += -r
CFLAGS += -Wall -Wextra
+KERNVER ?= $(shell uname -r)
all: initramfs.img
-initramfs.img: gen_init_cpio load-random-seed dropbear_ed25519_host_key modules.sh
- ./make
+initramfs.img: gen_init_cpio load-random-seed dropbear_ed25519_host_key modules.dep
+ KERNVER=$(KERNVER) COMPRESSOR="zstd -19 -c -T0" ./make
%: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@
@@ -11,9 +13,11 @@ initramfs.img: gen_init_cpio load-random-seed dropbear_ed25519_host_key modules.
dropbear_ed25519_host_key:
dropbearkey -t ed25519 -f $@
-modules.sh: modules
- printf '%s\n' '#!/bin/sh' 'set -e' > $@
- xargs -a $< -L1 -r modprobe --show-depends >> $@
+modules.dep.ver: FORCE
+ if ! [ -f $@ ] || [ "$$(cat $@)" != "$(KERNVER)" ]; then echo $(KERNVER) > $@; fi
+
+modules.dep: modules /lib/modules/$(KERNVER)/modules.dep modules.dep.ver
+ awk '!/^#/ { print $1 }' modules | xargs modinfo -F filename -k $(KERNVER) | sed -e 's:^/lib/modules/$(KERNVER)/:^:' | grep -f - /lib/modules/$(KERNVER)/modules.dep > $@
install: initramfs.img
rm -f /boot/initramfs.img.old /boot/initramfs.img.new
@@ -22,9 +26,9 @@ install: initramfs.img
mv /boot/initramfs.img.new /boot/initramfs.img
clean:
- rm -f initramfs.img initramfs.d gen_init_cpio load-random-seed
+ rm -f initramfs.img initramfs.d gen_init_cpio load-random-seed modules.dep
-include initramfs.d
.PHONY: all install clean
-MAKEFLAGS += -r # slightly faster
+FORCE:
diff --git a/cpio_list.txt b/cpio_list.txt
index ca93071..d4dc126 100644
--- a/cpio_list.txt
+++ b/cpio_list.txt
@@ -15,12 +15,20 @@ dir /run/cryptsetup 0755 0 0
nod /dev/console 0600 0 0 c 5 1
# symlinks
-slink /bin/sh busybox 0755 0 0
-slink /etc/mtab /proc/self/mounts 0755 0 0
+slink /bin/sh busybox 0777 0 0
+slink /etc/mtab /proc/self/mounts 0777 0 0
+# kernel.modprobe
+slink /sbin/modprobe ../bin/busybox 0777 0 0
+# required to mount /proc for busybox self-exec /proc/self/exe
+slink /sbin/mount ../bin/busybox 0777 0 0
+# required to exec switch_root after umount /proc
+slink /sbin/switch_root ../bin/busybox 0777 0 0
+
+# config files
+file /etc/modules ./modules 0644 0 0
# executables
file /bin/busybox /bin/busybox 0755 0 0
-file /etc/modules.sh ./modules.sh 0755 0 0
file /init ./init 0755 0 0
# firmware
diff --git a/init b/init
index b1a78f3..3b58e88 100644
--- a/init
+++ b/init
@@ -11,7 +11,12 @@ mkdir -p /dev/pts
# /dev/pts for dropbear
mount -t devpts devpts /dev/pts
-/etc/modules.sh || exit
+while read -r line; do
+ case "$line" in
+ '#'*) ;;
+ *) modprobe $line || exit
+ esac
+done < /etc/modules
mount -t efivarfs efivarfs /efivars
load-random-seed /efivars/LoaderRandomSeed-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
diff --git a/make b/make
index 9ce479c..461043f 100755
--- a/make
+++ b/make
@@ -1,9 +1,5 @@
#!/bin/sh
-#[ -n "$compressor" ] || compressor="lz4 --best --favor-decSpeed -l"
-[ -n "$compressor" ] || compressor="zstd -19 -c -T0"
-#[ -n "$compressor" ] || compressor="xz -c --check=crc32 --x86 --lzma2=preset=9e"
-
toppid=$$
die() {
fmt=$1
@@ -21,77 +17,32 @@ gen_cmd() {
# ignore builtins
[ "$cmd" != "$cmdp" ] || return
printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp"
- ldd "$cmdp" | grep / | while read line; do
- tmp=${line% *}
- lib=/${tmp#*/}
- # don't bother with ld.so.conf
- printf 'file /lib64/%s %s 0755 0 0\n' "${lib##*/}" "$lib"
- done
+ ldd "$cmdp" | awk '/\// { if ($1~/^\//) file=$1; else file=$3; print "file " file " " file " 0755 0 0" }'
}
# generate the main file list
gen_cpio_list() {
sed -e '/^#/d' cpio_list.txt
- while read insmod mod args; do
- if [ "$insmod" = insmod ]; then
- printf 'file %s %s 0644 0 0\n' "$mod" "$mod"
- fi
- done < modules.sh
+ tr ' ' '\n' < modules.dep | sed -e "s/://;s:.*:file /lib/modules/$KERNVER/& /lib/modules/$KERNVER/& 0644 0 0:"
gen_cmd e2fsck
gen_cmd dropbear
- # cryptsetup argon2 uses pthread_cancel, glibc dlopens libgcc_s.so.1
- # ldd will find the correct libgcc_s.so.1 based on ld.so.conf
- export LD_PRELOAD=libgcc_s.so.1
gen_cmd cryptsetup
- # LD_PRELOAD unset at end of subshell
+ ldconfig -p | awk '$1 == "libgcc_s.so.1" { print "file " $4 " " $4 " 0755 0 0" }'
}
# filter the list and insert parent directory entries
gen_dir_ents() {
- while read type target args; do
- # re-print the original entry
- printf '%s %s %s\n' "$type" "$target" "$args"
- # print the necessary directory entries. duplicates will be
- # filtered by sort -u later
- while [ "${target%/*}" != '' ]; do
- target=${target%/*}
- printf 'dir %s 0755 0 0\n' "$target"
- done
- done
+ awk '{print; while (sub("/[^/]*$", "", $2) && $2) print "dir " $2 " 0755 0 0"; }'
}
# filter the list and generate the make dependency file
gen_depfile() {
deps='cpio_list.txt make'
- while read type target source args; do
- # re-print the original entry
- printf '%s %s %s %s\n' "$type" "$target" "$source" "$args"
- # accumulate the dependencies in a list to avoid make bugs.
- # there will be no duplicates since the list was previously sorted
- if [ "$type" != file ]; then
- continue
- fi
- case "$source" in
- /dev/*) continue
- esac
- deps="$deps $source"
- # avoid "No rule to make target" when deps disappear
- echo "$source:" >&3
- done
- echo "initramfs.img: $deps" >&3
+ awk -v d=/dev/fd/3 '$1 == "file" {print; deps=deps " " $3; print $3 ":" > d; } END { print "initramfs.img:" deps > d }'
}
if ! [ -e cpio_list.txt ] || ! [ -e gen_init_cpio ]; then
cd "${0%/*}"
fi
-trap 'test -L initramfs.img || test -f initramfs.img && rm -f initramfs.img; exit 1' HUP INT QUIT TERM EXIT
-
-gen_cpio_list | \
-gen_dir_ents | \
-sort -u | \
-gen_depfile 3>initramfs.d | \
-./gen_init_cpio -t 0 - | \
-$compressor > initramfs.img
-
-trap '' EXIT
+gen_cpio_list | gen_dir_ents | sort -u | gen_depfile 3>initramfs.d | ./gen_init_cpio -t 0 - | $COMPRESSOR > initramfs.img
diff --git a/modules b/modules
index e69de29..118d388 100644
--- a/modules
+++ b/modules
@@ -0,0 +1,8 @@
+aesni-intel
+atkbd
+cbc
+crc32c-intel
+dm-crypt
+ext4
+i8042
+i915