Add support for custom initramfs contents
PATCH v2 1/1 Add support for custom initramfs contents
This adds an option to build an initramfs image with different content than the rootfs within a single defconig. The intended use case is to provide a minimal early userland for systems that cannot mount their root file system directly from the kernel (e.g. because that rootfs resides in an image file on a FAT formatted SD card, which has to be mounted first before the rootfs can be set up).
The rationale for implementing this as an option for initramfs instead of using two different configurations is ease of use: One configuration is easier to maintain and builds faster than two.
--- fs/initramfs/Config.in | 34 +++++++++++++++++++++++++++++++++- fs/initramfs/initramfs.mk | 18 +++++++++++++++++- linux/linux.mk | 8 ++++---- 3 files changed, 54 insertions(+), 6 deletions(-)
fs/initramfs/Config.in +33 -1
@@ -1,6 +1,22 @@ config BR2_TARGET_ROOTFS_INITRAMFS bool "initial RAM filesystem linked into linux kernel" depends on BR2_LINUX_KERNEL + help + Integrate an initramfs inside the kernel image. + This integration will take place automatically. + + The initramfs contents can either be the full root filesystem + generated by buildroot, or an image built from a custom list + of files specified via the BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + config option. + +choice + prompt "initial RAM filesystem contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS + +config BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS + bool "rootfs.cpio" + depends on BR2_TARGET_ROOTFS_INITRAMFS select BR2_TARGET_ROOTFS_CPIO help Integrate the root filesystem generated by Buildroot as an
@@ -13,10 +29,26 @@ config BR2_TARGET_ROOTFS_INITRAMFS is used, regardless of how buildroot's cpio archive is configured. - Note that enabling initramfs together with another filesystem + Note that enabling this option together with another filesystem formats doesn't make sense: you would end up having two identical root filesystems, one embedded inside the kernel image, and one separately. +config BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM + bool "custom initramfs contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS + help + Use the contents of BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + as the linux kernel configuration variable CONFIG_INITRAMFS_SOURCE + +endchoice + +config BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + string "custom initramfs contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM + help + Custom value to use as CONFIG_INITRAMFS_SOURCE linux kernel configuration + variable. See Documentation/filesystems/ramfs-rootfs-initramfs.txt in the + linux kernel sources for details. comment "initramfs needs a Linux kernel to be built" depends on !BR2_LINUX_KERNEL
fs/initramfs/initramfs.mk +17 -1
@@ -4,6 +4,12 @@ # ################################################################################ +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS),y) +ROOTFS_INITRAMFS_DEPENDENCIES += rootfs-cpio +endif + +ROOTFS_INITRAMFS_DEPENDENCIES += $(BINARIES_DIR)/initramfs.cpio + # The generic fs infrastructure isn't very useful here. # # The initramfs image does not actually build an image; its only purpose is:
@@ -19,13 +25,23 @@ # advertise that our dependency is on the rootfs-cpio rule, which is # cleaner in the dependency graph. -rootfs-initramfs: linux-rebuild-with-initramfs +rootfs-initramfs: $(ROOTFS_INITRAMFS_DEPENDENCIES) linux-rebuild-with-initramfs rootfs-initramfs-show-depends: @echo rootfs-cpio .PHONY: rootfs-initramfs rootfs-initramfs-show-depends +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS),y) +$(BINARIES_DIR)/initramfs.cpio: rootfs-cpio + ln -sf rootfs.cpio $(BINARIES_DIR)/initramfs.cpio +endif + +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM),y) +$(BINARIES_DIR)/initramfs.cpio: target-finalize $(call qstrip,$(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS)) + $(LINUX_DIR)/usr/gen_init_cpio $(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS) > $(BINARIES_DIR)/initramfs.cpio +endif + ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS),y) TARGETS_ROOTFS += rootfs-initramfs endif
linux/linux.mk +4 -4
@@ -300,8 +300,8 @@ define LINUX_KCONFIG_FIXUP_CMDS # replaced later by the real cpio archive, and the kernel will be # rebuilt using the linux-rebuild-with-initramfs target. $(if $(BR2_TARGET_ROOTFS_INITRAMFS), - touch $(BINARIES_DIR)/rootfs.cpio - $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config) + touch $(BINARIES_DIR)/initramfs.cpio + $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/initramfs.cpio",$(@D)/.config) $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config) $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config)) $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),,
@@ -528,11 +528,11 @@ endif # BR_BUILDING $(eval $(kconfig-package)) # Support for rebuilding the kernel after the cpio archive has -# been generated. +# been generated in $(BINARIES_DIR)/initramfs.cpio. .PHONY: linux-rebuild-with-initramfs linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_target_installed linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_images_installed -linux-rebuild-with-initramfs: rootfs-cpio +linux-rebuild-with-initramfs: $(BINARIES_DIR)/initramfs.cpio linux-rebuild-with-initramfs: @$(call MESSAGE,"Rebuilding kernel with initramfs") # Build the kernel.
Signature · 1 line
2.18.0
PATCH v2 1/1 Add support for custom initramfs contents
Richard, All,
On 2018-08-25 21:51 +0200, Richard Kunze spake thusly:
Quoted 10 lines
This adds an option to build an initramfs image with different content than the rootfs within a single defconig. The intended use case is to provide a minimal early userland for systems that cannot mount their root file system directly from the kernel (e.g. because that rootfs resides in an image file on a FAT formatted SD card, which has to be mounted first before the rootfs can be set up).
The rationale for implementing this as an option for initramfs instead of using two different configurations is ease of use: One configuration is easier to maintain and builds faster than two.
We discussed this change during the developpers meeting, and we all concluded that we did not want this, as I explaiend in my previous review.
Regards,
Yann E. MORIN.
Quoted 141 lines
Signed-off-by Richard Kunze <[email protected]>--- fs/initramfs/Config.in | 34 +++++++++++++++++++++++++++++++++- fs/initramfs/initramfs.mk | 18 +++++++++++++++++- linux/linux.mk | 8 ++++---- 3 files changed, 54 insertions(+), 6 deletions(-)fs/initramfs/Config.in +33
-1@@ -1,6 +1,22 @@ config BR2_TARGET_ROOTFS_INITRAMFS bool "initial RAM filesystem linked into linux kernel" depends on BR2_LINUX_KERNEL + help + Integrate an initramfs inside the kernel image. + This integration will take place automatically. + + The initramfs contents can either be the full root filesystem + generated by buildroot, or an image built from a custom list + of files specified via the BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + config option. + +choice + prompt "initial RAM filesystem contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS + +config BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS + bool "rootfs.cpio" + depends on BR2_TARGET_ROOTFS_INITRAMFS select BR2_TARGET_ROOTFS_CPIO help Integrate the root filesystem generated by Buildroot as an@@ -13,10 +29,26 @@ config BR2_TARGET_ROOTFS_INITRAMFS is used, regardless of how buildroot's cpio archive is configured. - Note that enabling initramfs together with another filesystem + Note that enabling this option together with another filesystem formats doesn't make sense: you would end up having two identical root filesystems, one embedded inside the kernel image, and one separately. +config BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM + bool "custom initramfs contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS + help + Use the contents of BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + as the linux kernel configuration variable CONFIG_INITRAMFS_SOURCE + +endchoice + +config BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS + string "custom initramfs contents" + depends on BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM + help + Custom value to use as CONFIG_INITRAMFS_SOURCE linux kernel configuration + variable. See Documentation/filesystems/ramfs-rootfs-initramfs.txt in the + linux kernel sources for details. comment "initramfs needs a Linux kernel to be built" depends on !BR2_LINUX_KERNELfs/initramfs/initramfs.mk +17
-1@@ -4,6 +4,12 @@ # ################################################################################ +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS),y) +ROOTFS_INITRAMFS_DEPENDENCIES += rootfs-cpio +endif + +ROOTFS_INITRAMFS_DEPENDENCIES += $(BINARIES_DIR)/initramfs.cpio + # The generic fs infrastructure isn't very useful here. # # The initramfs image does not actually build an image; its only purpose is:@@ -19,13 +25,23 @@ # advertise that our dependency is on the rootfs-cpio rule, which is # cleaner in the dependency graph. -rootfs-initramfs: linux-rebuild-with-initramfs +rootfs-initramfs: $(ROOTFS_INITRAMFS_DEPENDENCIES) linux-rebuild-with-initramfs rootfs-initramfs-show-depends: @echo rootfs-cpio .PHONY: rootfs-initramfs rootfs-initramfs-show-depends +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_ROOTFS),y) +$(BINARIES_DIR)/initramfs.cpio: rootfs-cpio + ln -sf rootfs.cpio $(BINARIES_DIR)/initramfs.cpio +endif + +ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM),y) +$(BINARIES_DIR)/initramfs.cpio: target-finalize $(call qstrip,$(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS)) + $(LINUX_DIR)/usr/gen_init_cpio $(BR2_TARGET_ROOTFS_INITRAMFS_CUSTOM_CONTENTS) > $(BINARIES_DIR)/initramfs.cpio +endif + ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS),y) TARGETS_ROOTFS += rootfs-initramfs endiflinux/linux.mk +4
-4@@ -300,8 +300,8 @@ define LINUX_KCONFIG_FIXUP_CMDS # replaced later by the real cpio archive, and the kernel will be # rebuilt using the linux-rebuild-with-initramfs target. $(if $(BR2_TARGET_ROOTFS_INITRAMFS), - touch $(BINARIES_DIR)/rootfs.cpio - $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config) + touch $(BINARIES_DIR)/initramfs.cpio + $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/initramfs.cpio",$(@D)/.config) $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config) $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config)) $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),,@@ -528,11 +528,11 @@ endif # BR_BUILDING $(eval $(kconfig-package)) # Support for rebuilding the kernel after the cpio archive has -# been generated. +# been generated in $(BINARIES_DIR)/initramfs.cpio. .PHONY: linux-rebuild-with-initramfs linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_target_installed linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_images_installed -linux-rebuild-with-initramfs: rootfs-cpio +linux-rebuild-with-initramfs: $(BINARIES_DIR)/initramfs.cpio linux-rebuild-with-initramfs: @$(call MESSAGE,"Rebuilding kernel with initramfs") # Build the kernel.Signature · 7 lines
2.18.0 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'