.gitignore | 5 +++++ Makefile | 2 +- scripts/Makefile.package | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-)
From: Sascha Hauer <s.hauer@pengutronix.de>
Add a new package target to build a cpio archive containing the kernel
modules. This is particularly useful to supplement an existing initramfs
with the kernel modules so that the root filesystem can be started with
all needed kernel modules without modifying it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Co-developed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
.gitignore | 5 +++++
Makefile | 2 +-
scripts/Makefile.package | 17 +++++++++++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 86a1ba0d90353962183b47c0c657ec877e5b2f9f..764d115400d90f0904b8f60ea8851a7860c16411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -96,6 +96,11 @@ modules.order
#
/tar-install/
+#
+# modules directory (make cpio-modules-pkg)
+#
+/modules-install/
+
#
# pacman files (make pacman-pkg)
#
diff --git a/Makefile b/Makefile
index fb4389aa5d5f1776f7bb5988102ed54f92491de7..19c7900d02ed5eee06f00820c138591b42e895e1 100644
--- a/Makefile
+++ b/Makefile
@@ -1583,7 +1583,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \
# Directories & files removed with 'make mrproper'
MRPROPER_FILES += include/config include/generated \
arch/$(SRCARCH)/include/generated .objdiff \
- debian snap tar-install PKGBUILD pacman \
+ debian snap tar-install modules-install PKGBUILD pacman \
.config .config.old .version \
Module.symvers \
certs/signing_key.pem \
diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -189,6 +189,22 @@ tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
@:
+modules-install: FORCE
+ $(Q)$(MAKE) -f $(srctree)/Makefile
+ $(Q)rm -rf $@
+ $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@ modules_install
+
+quiet_cmd_cpio = CPIO $@
+ cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@
+
+modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install
+ $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio
+ $(call cmd,cpio)
+
+PHONY += cpio-modules-pkg
+cpio-modules-pkg: modules-$(KERNELRELEASE)-$(ARCH).cpio
+ @:
+
# perf-tar*-src-pkg - generate a source tarball with perf source
# ---------------------------------------------------------------------------
@@ -245,6 +261,7 @@ help:
@echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
@echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
@echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
+ @echo ' cpio-modules-pkg - Build the kernel modules as cpio archive'
@echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
@echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
@echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
---
base-commit: e9a6fb0bcdd7609be6969112f3fbfcce3b1d4a7c
change-id: 20251115-cpio-modules-pkg-70d85a69892b
Best regards,
--
Ahmad Fatoum <a.fatoum@pengutronix.de>
On Sat, Nov 15, 2025 at 03:21:51PM +0100, Ahmad Fatoum wrote: > From: Sascha Hauer <s.hauer@pengutronix.de> > > Add a new package target to build a cpio archive containing the kernel > modules. This is particularly useful to supplement an existing initramfs > with the kernel modules so that the root filesystem can be started with > all needed kernel modules without modifying it. > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > Co-developed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > .gitignore | 5 +++++ > Makefile | 2 +- > scripts/Makefile.package | 17 +++++++++++++++++ > 3 files changed, 23 insertions(+), 1 deletion(-) > > diff --git a/.gitignore b/.gitignore > index 86a1ba0d90353962183b47c0c657ec877e5b2f9f..764d115400d90f0904b8f60ea8851a7860c16411 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -96,6 +96,11 @@ modules.order > # > /tar-install/ > > +# > +# modules directory (make cpio-modules-pkg) > +# > +/modules-install/ > + > # > # pacman files (make pacman-pkg) > # > diff --git a/Makefile b/Makefile > index fb4389aa5d5f1776f7bb5988102ed54f92491de7..19c7900d02ed5eee06f00820c138591b42e895e1 100644 > --- a/Makefile > +++ b/Makefile > @@ -1583,7 +1583,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \ > # Directories & files removed with 'make mrproper' > MRPROPER_FILES += include/config include/generated \ > arch/$(SRCARCH)/include/generated .objdiff \ > - debian snap tar-install PKGBUILD pacman \ > + debian snap tar-install modules-install PKGBUILD pacman \ > .config .config.old .version \ > Module.symvers \ > certs/signing_key.pem \ > diff --git a/scripts/Makefile.package b/scripts/Makefile.package > index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644 > --- a/scripts/Makefile.package > +++ b/scripts/Makefile.package > @@ -189,6 +189,22 @@ tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar > tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE > @: The other package targets have a separator and documentation comment. > > +modules-install: FORCE > + $(Q)$(MAKE) -f $(srctree)/Makefile > + $(Q)rm -rf $@ We have the filename prefix ".tmp_" for temporary files and directories. These will be automatically ignored by git and cleaned up by "make clean". > + $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@ modules_install > + > +quiet_cmd_cpio = CPIO $@ > + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ Use $(CONFIG_SHELL). Using '-o' instead of redirecting stdout to the output file should enable the usage of the recent copy_file_range() optimizations in gen_init_cpio. > + > +modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install > + $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio Drop the explicit '-f'; $(build) overwrites it. Is the cpio-data= intended to make sure the line 'hostprogs := gen_init_cpio' is executed? I don't think this works as usr/Makefile will overwrite 'cpio-data' in any case. But it should be fine to make hostprogs definition unconditional. > + $(call cmd,cpio) > + > +PHONY += cpio-modules-pkg > +cpio-modules-pkg: modules-$(KERNELRELEASE)-$(ARCH).cpio > + @: > + > # perf-tar*-src-pkg - generate a source tarball with perf source > # --------------------------------------------------------------------------- > > @@ -245,6 +261,7 @@ help: > @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' > @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' > @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' > + @echo ' cpio-modules-pkg - Build the kernel modules as cpio archive' > @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' > @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' > @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' > > --- > base-commit: e9a6fb0bcdd7609be6969112f3fbfcce3b1d4a7c > change-id: 20251115-cpio-modules-pkg-70d85a69892b > > Best regards, > -- > Ahmad Fatoum <a.fatoum@pengutronix.de> >
Hello Thomas, On 11/20/25 8:32 AM, Thomas Weißschuh wrote: >> diff --git a/scripts/Makefile.package b/scripts/Makefile.package >> index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644 >> --- a/scripts/Makefile.package >> +++ b/scripts/Makefile.package >> @@ -189,6 +189,22 @@ tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar >> tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE >> @: > > The other package targets have a separator and documentation comment. Ack. >> +modules-install: FORCE >> + $(Q)$(MAKE) -f $(srctree)/Makefile >> + $(Q)rm -rf $@ > > We have the filename prefix ".tmp_" for temporary files and directories. > These will be automatically ignored by git and cleaned up by "make clean". The commit originally followed what the tar target did, but it seems doing it like perf is the better template. Will adapt. >> +quiet_cmd_cpio = CPIO $@ >> + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ > > Use $(CONFIG_SHELL). Can do. Is this to allow users to override CONFIG_SHELL from outside? If so, why not go one step further and remove shebangs from scripts altogether to enforce that they are called with a $(VARIABLE) that can be overridden? > Using '-o' instead of redirecting stdout to the output file should enable the > usage of the recent copy_file_range() optimizations in gen_init_cpio. Will give it a try, thanks. >> +modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install >> + $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio > > Drop the explicit '-f'; $(build) overwrites it. Indeed, will drop. > Is the cpio-data= intended to make sure the line 'hostprogs := gen_init_cpio' > is executed? I don't think this works as usr/Makefile will overwrite 'cpio-data' > in any case. But it should be fine to make hostprogs definition unconditional. Will add a commit making hostprogs := gen_init_cpio unconditional. The current approach worked though, because specifying the variable on the command line overrides cpio-data := assignments even if there are multiple. Thanks, Ahmad -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
On Tue, Nov 25, 2025 at 01:07:20PM +0100, Ahmad Fatoum wrote: > On 11/20/25 8:32 AM, Thomas Weißschuh wrote: > >> diff --git a/scripts/Makefile.package b/scripts/Makefile.package > >> index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644 > >> --- a/scripts/Makefile.package > >> +++ b/scripts/Makefile.package (...) > >> +quiet_cmd_cpio = CPIO $@ > >> + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ > > > > Use $(CONFIG_SHELL). > > Can do. Is this to allow users to override CONFIG_SHELL from outside? I think so. Some distributions do weird things. > If so, why not go one step further and remove shebangs from scripts > altogether to enforce that they are called with a $(VARIABLE) that can > be overridden? The shebang is also useful to enable syntax highlighting in editors, tell linters which shell dialect (POSIX/bash) is expected and to run the script without kbuild. I would just leave it as is. (...) > > Is the cpio-data= intended to make sure the line 'hostprogs := gen_init_cpio' > > is executed? I don't think this works as usr/Makefile will overwrite 'cpio-data' > > in any case. But it should be fine to make hostprogs definition unconditional. > > Will add a commit making hostprogs := gen_init_cpio unconditional. > The current approach worked though, because specifying the variable on > the command line overrides cpio-data := assignments even if there are > multiple. Indeed. Good to know, thanks! Thomas
Hi Ahmad, On Sat, Nov 15, 2025 at 03:21:51PM +0100, Ahmad Fatoum wrote: > From: Sascha Hauer <s.hauer@pengutronix.de> > > Add a new package target to build a cpio archive containing the kernel > modules. This is particularly useful to supplement an existing initramfs > with the kernel modules so that the root filesystem can be started with > all needed kernel modules without modifying it. Yeah, I would say this is pretty useful, I have already used it while triaging another issue. > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > Co-developed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > .gitignore | 5 +++++ > Makefile | 2 +- > scripts/Makefile.package | 17 +++++++++++++++++ > 3 files changed, 23 insertions(+), 1 deletion(-) > > diff --git a/.gitignore b/.gitignore > index 86a1ba0d90353962183b47c0c657ec877e5b2f9f..764d115400d90f0904b8f60ea8851a7860c16411 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -96,6 +96,11 @@ modules.order > # > /tar-install/ > > +# > +# modules directory (make cpio-modules-pkg) > +# > +/modules-install/ > + > # > # pacman files (make pacman-pkg) > # > diff --git a/Makefile b/Makefile > index fb4389aa5d5f1776f7bb5988102ed54f92491de7..19c7900d02ed5eee06f00820c138591b42e895e1 100644 > --- a/Makefile > +++ b/Makefile > @@ -1583,7 +1583,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \ > # Directories & files removed with 'make mrproper' > MRPROPER_FILES += include/config include/generated \ > arch/$(SRCARCH)/include/generated .objdiff \ > - debian snap tar-install PKGBUILD pacman \ > + debian snap tar-install modules-install PKGBUILD pacman \ > .config .config.old .version \ > Module.symvers \ > certs/signing_key.pem \ > diff --git a/scripts/Makefile.package b/scripts/Makefile.package > index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644 > --- a/scripts/Makefile.package > +++ b/scripts/Makefile.package > @@ -189,6 +189,22 @@ tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar > tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE > @: > > +modules-install: FORCE > + $(Q)$(MAKE) -f $(srctree)/Makefile > + $(Q)rm -rf $@ > + $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@ modules_install > + > +quiet_cmd_cpio = CPIO $@ > + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ > + > +modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install > + $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio This seems like a bit of a hack to generate gen_init_cpio this way but I am not sure it is worth moving usr/gen_init_cpio.c and usr/gen_initramfs.sh elsewhere (scripts?) to make it a most accessible hostprog right now... Nicolas, do you have any opinions on this? > + $(call cmd,cpio) > + > +PHONY += cpio-modules-pkg > +cpio-modules-pkg: modules-$(KERNELRELEASE)-$(ARCH).cpio I think it would make a little more sense (and match the style of the perf package targets as well) to name this target modules-cpio-pkg. > + @: > + > # perf-tar*-src-pkg - generate a source tarball with perf source > # --------------------------------------------------------------------------- > > @@ -245,6 +261,7 @@ help: > @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' > @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' > @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' > + @echo ' cpio-modules-pkg - Build the kernel modules as cpio archive' > @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' > @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' > @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' > > --- > base-commit: e9a6fb0bcdd7609be6969112f3fbfcce3b1d4a7c > change-id: 20251115-cpio-modules-pkg-70d85a69892b > > Best regards, > -- > Ahmad Fatoum <a.fatoum@pengutronix.de> >
On Wed, Nov 19, 2025 at 11:39:36PM -0700, Nathan Chancellor wrote: ... > > diff --git a/scripts/Makefile.package b/scripts/Makefile.package > > index 74bcb9e7f7a4516473481468a0fcf700c3bead33..20eec9e2dec4dda3fa0ef64a15b80dccdcb55f90 100644 > > --- a/scripts/Makefile.package > > +++ b/scripts/Makefile.package > > @@ -189,6 +189,22 @@ tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar > > tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE > > @: > > > > +modules-install: FORCE > > + $(Q)$(MAKE) -f $(srctree)/Makefile > > + $(Q)rm -rf $@ > > + $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@ modules_install > > + > > +quiet_cmd_cpio = CPIO $@ > > + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ > > + > > +modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install > > + $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio > > This seems like a bit of a hack to generate gen_init_cpio this way but I > am not sure it is worth moving usr/gen_init_cpio.c and > usr/gen_initramfs.sh elsewhere (scripts?) to make it a most accessible > hostprog right now... Nicolas, do you have any opinions on this? Yes, it feels hacky to me, too. After digging into this a bit, I am in favor of moving at least gen_init* and friends to scripts/. I can prepare a patch in a few days. Kind regards, Nicolas
Hi Nathan, On 11/20/25 7:39 AM, Nathan Chancellor wrote: > On Sat, Nov 15, 2025 at 03:21:51PM +0100, Ahmad Fatoum wrote: >> From: Sascha Hauer <s.hauer@pengutronix.de> >> +modules-install: FORCE >> + $(Q)$(MAKE) -f $(srctree)/Makefile >> + $(Q)rm -rf $@ >> + $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@ modules_install >> + >> +quiet_cmd_cpio = CPIO $@ >> + cmd_cpio = $(srctree)/usr/gen_initramfs.sh $< > $@ >> + >> +modules-$(KERNELRELEASE)-$(ARCH).cpio: modules-install >> + $(Q)$(MAKE) -f $(srctree)/Makefile $(build)=usr cpio-data= usr/gen_init_cpio > > This seems like a bit of a hack to generate gen_init_cpio this way but I > am not sure it is worth moving usr/gen_init_cpio.c and > usr/gen_initramfs.sh elsewhere (scripts?) to make it a most accessible > hostprog right now... Nicolas, do you have any opinions on this? After incorporating Thomas' feedback, this is simplified to: $(Q)$(MAKE) $(build)=usr usr/gen_init_cpio which looks much better. >> + $(call cmd,cpio) >> + >> +PHONY += cpio-modules-pkg >> +cpio-modules-pkg: modules-$(KERNELRELEASE)-$(ARCH).cpio > > I think it would make a little more sense (and match the style of the > perf package targets as well) to name this target modules-cpio-pkg. It currently matches the style of the tar packages, which start with tar-, but I can follow the perf- order. Makes more sense if it's extended to support compressed cpios in future too. Cheers, Ahmad > >> + @: >> + >> # perf-tar*-src-pkg - generate a source tarball with perf source >> # --------------------------------------------------------------------------- >> >> @@ -245,6 +261,7 @@ help: >> @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' >> @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' >> @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' >> + @echo ' cpio-modules-pkg - Build the kernel modules as cpio archive' >> @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' >> @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' >> @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' >> >> --- >> base-commit: e9a6fb0bcdd7609be6969112f3fbfcce3b1d4a7c >> change-id: 20251115-cpio-modules-pkg-70d85a69892b >> >> Best regards, >> -- >> Ahmad Fatoum <a.fatoum@pengutronix.de> >> > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
On Sat, 15 Nov 2025 at 07:31, Ahmad Fatoum <a.fatoum@pengutronix.de> wrote: > > From: Sascha Hauer <s.hauer@pengutronix.de> > > Add a new package target to build a cpio archive containing the kernel > modules. This is particularly useful to supplement an existing initramfs > with the kernel modules so that the root filesystem can be started with > all needed kernel modules without modifying it. > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > Co-developed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > .gitignore | 5 +++++ > Makefile | 2 +- > scripts/Makefile.package | 17 +++++++++++++++++ > 3 files changed, 23 insertions(+), 1 deletion(-) > Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
© 2016 - 2026 Red Hat, Inc.