Skip to content

Commit 426cd8f

Browse files
committed
build the linux kernel after building the initrd
1 parent f7067d8 commit 426cd8f

3 files changed

Lines changed: 94 additions & 4 deletions

File tree

Makefile

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ include modules/kexec
1111
include modules/tpmtotp
1212
include modules/mbedtls
1313
include modules/busybox
14+
include modules/linux
1415

1516
all: $(modules)
1617

@@ -53,13 +54,92 @@ define define_module =
5354
cd "$(build)/$($1_dir)" ; $($1_configure)
5455
touch "$$@"
5556

56-
# Actually build the target
57-
$(call outputs,$1): $(build)/$($1_dir)/.configured $(call outputs,$($1_depends))
57+
# Build the target after any dependencies
58+
$(call outputs,$1): \
59+
$(build)/$($1_dir)/.configured \
60+
$(call outputs,$($1_depends))
5861
make -C "$(build)/$($1_dir)" $($1_target)
62+
63+
# Short hand target for the module
5964
$1: $(call outputs,$1)
6065

61-
# Update any dependencies
6266
endef
6367

6468
$(foreach _, $(modules), $(eval $(call define_module,$_)))
6569

70+
71+
#
72+
# Files that should be copied into the initrd
73+
# THis should probably be done in a more scalable manner
74+
#
75+
define initrd_bin =
76+
initrd/bin/$(notdir $1): $1
77+
cmp --quiet "$$@" "$$^" || \
78+
cp -a "$$^" "$$@"
79+
initrd_bins += initrd/bin/$(notdir $1)
80+
endef
81+
82+
$(foreach _, $(call outputs,kexec), $(eval $(call initrd_bin,$_)))
83+
$(foreach _, $(call outputs,tpmtotp), $(eval $(call initrd_bin,$_)))
84+
85+
# hack to install busybox into the initrd
86+
initrd_bins += initrd/bin/busybox
87+
88+
initrd/bin/busybox: $(build)/$(busybox_dir)/busybox
89+
cmp --quiet "$@" "$^" || \
90+
make \
91+
-C $(build)/$(busybox_dir) \
92+
CONFIG_PREFIX="$(pwd)/initrd" \
93+
install
94+
95+
96+
# Update all of the libraries in the initrd based on the executables
97+
# that were installed.
98+
initrd_libs:
99+
./populate-lib \
100+
./initrd/lib/x86-64-linux-gnu/ \
101+
initrd/bin/* \
102+
initrd/sbin/* \
103+
104+
105+
#
106+
# We also have to include some real /dev files; the minimal
107+
# set should be determined.
108+
#
109+
initrd_devs += /dev/console
110+
initrd_devs += /dev/mem
111+
initrd_devs += /dev/null
112+
initrd_devs += /dev/tty
113+
initrd_devs += /dev/tty0
114+
initrd_devs += /dev/ttyS0
115+
116+
#
117+
# initrd image creation
118+
#
119+
# The initrd is constructed from various bits and pieces
120+
# Note the touch and sort operation on the find output -- this
121+
# ensures that the files always have the same timestamp and
122+
# appear in the same order.
123+
#
124+
# This breaks on the files in /dev.
125+
#
126+
#
127+
initrd.cpio: $(initrd_bins) initrd_libs
128+
find ./initrd -type f -print0 \
129+
| xargs -0 touch -d "1970-01-01"
130+
cd ./initrd; \
131+
find . $(initrd_devs) \
132+
| sort \
133+
| cpio --quiet -H newc -o \
134+
> "../$@.tmp"
135+
if ! cmp --quiet "$@" "$@.tmp"; then \
136+
mv "$@.tmp" "$@"; \
137+
else \
138+
echo "$@: Unchanged"; \
139+
rm "$@.tmp"; \
140+
fi
141+
142+
143+
# hack for the linux kernel to depend on the initrd image
144+
# this will change once coreboot can link in the initrd separately
145+
$(call outputs,linux): initrd.cpio

config/linux.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CONFIG_ARCH_SUPPORTS_INT128=y
138138
# CONFIG_SYSFS_DEPRECATED is not set
139139
# CONFIG_RELAY is not set
140140
CONFIG_BLK_DEV_INITRD=y
141-
CONFIG_INITRAMFS_SOURCE="../initrd"
141+
CONFIG_INITRAMFS_SOURCE="../../initrd.cpio"
142142
CONFIG_INITRAMFS_ROOT_UID=0
143143
CONFIG_INITRAMFS_ROOT_GID=0
144144
# CONFIG_RD_GZIP is not set

modules/linux

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
modules += linux
2+
3+
linux_version := 4.6.4
4+
linux_dir := linux-$(linux_version)
5+
linux_tar := linux-$(linux_version).tar.xz
6+
linux_url := https://cdn.kernel.org/pub/linux/kernel/v4.x/$(linux_tar)
7+
linux_hash := 8568d41c7104e941989b14a380d167129f83db42c04e950d8d9337fe6012ff7e
8+
9+
linux_configure := make oldconfig
10+
linux_output := arch/x86/boot/bzImage

0 commit comments

Comments
 (0)