2021-04-19 21:00:37

by H. Peter Anvin

[permalink] [raw]
Subject: [PATCH 0/3] x86 disk image and modules initramfs generation

From: "H. Peter Anvin" (Intel) <[email protected]>

When compiling on a different machine than the runtime target,
including but not limited to simulators, it is rather handy to be able
to produce a bootable image. The scripts for that in x86 are
relatively old, and assume a BIOS system.

This adds a build target to generate a hdimage which can be booted
either from BIOS or EFI, and modernizes the genimage.sh script
including adding the ability to add an arbitrary number of initramfs
files (limited only by the length of the command line.)

Possibly more controversial, at least from a Kbuild design perspective
(as usual I'm the guy who wants to do something with Kbuild which it
seems it was never really designed to do), is add the ability to
create an initramfs image which includes all the built modules. Some
distributions cannot be easily booted without modules in initramfs,
and this creates an image which can be added to initramfs to provide
the kernel modules, as finalized by "make modules_install".

The final patch put these two together, and allows the modules
initramfs to be included in the x86 boot image.

Makefile | 17 ++-
arch/x86/Makefile | 8 +-
arch/x86/boot/.gitignore | 1 +
arch/x86/boot/Makefile | 55 +++++----
arch/x86/boot/genimage.sh | 284 +++++++++++++++++++++++++++++++------------
arch/x86/boot/mtools.conf.in | 3 +
usr/.gitignore | 3 +
usr/Kconfig | 31 ++---
usr/Makefile | 39 +++++-
9 files changed, 318 insertions(+), 123 deletions(-)


2021-04-19 22:26:09

by H. Peter Anvin

[permalink] [raw]
Subject: [PATCH 3/3] x86/boot: Add option to add modules.img to {fd,hd,iso}image

From: "H. Peter Anvin" (Intel) <[email protected]>

Make it easy to generate a disk image which includes the all-modules
initramfs image.

Signed-off-by: H. Peter Anvin (Intel) <[email protected]>
---
arch/x86/Makefile | 3 ++-
arch/x86/boot/Makefile | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 943f26a32834..74f4e66568d7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -309,7 +309,8 @@ define archhelp
echo ' isoimage - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
echo ' bzdisk/fdimage*/hdimage/isoimage also accept:'
echo ' FDARGS="..." arguments for the booted kernel'
- echo ' FDINITRD=file initrd for the booted kernel'
+ echo ' FDINITRD=file initrd for the booted kernel'
+ echo ' FDMODS=1 to include all modules as an initrd'
echo ''
echo ' kvm_guest.config - Enable Kconfig items for running this kernel as a KVM guest'
echo ' xen.config - Enable Kconfig items for running this kernel as a Xen guest'
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index dfbc26a8e924..601ade7adc70 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -119,9 +119,20 @@ $(obj)/compressed/vmlinux: FORCE
FDARGS =
# Set this if you want one or more initrds included in the image
FDINITRD =
+# Set this to 1 if you want usr/modules.img included in the image
+FDMODS =

imgdeps = $(obj)/bzImage $(obj)/mtools.conf $(src)/genimage.sh

+ifneq ($(FDMODS),)
+imgdeps += $(objtree)/usr/modules.img
+FDINITRD += $(objtree)/usr/modules.img
+
+$(objtree)/usr/modules.img:
+ $(Q)$(MAKE) -f $(srctree)/Makefile usr/modules.img
+KBUILD_MODULES := 1
+endif
+
$(obj)/mtools.conf: $(src)/mtools.conf.in
sed -e 's|@OBJ@|$(obj)|g' < $< > $@

--
2.30.2