@@ -11,6 +11,7 @@ include modules/kexec
1111include modules/tpmtotp
1212include modules/mbedtls
1313include modules/busybox
14+ include modules/linux
1415
1516all : $(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
6266endef
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
0 commit comments