From patchwork Sat Aug 25 19:51:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Kunze X-Patchwork-Id: 962198 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=web.de Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41yTVf4424z9s4s for ; Sun, 26 Aug 2018 05:58:50 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 9BD1430236; Sat, 25 Aug 2018 19:58:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wzf7Dp8GDz7X; Sat, 25 Aug 2018 19:58:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 458E130221; Sat, 25 Aug 2018 19:58:44 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 3AB001C076D for ; Sat, 25 Aug 2018 19:58:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 37CE889838 for ; Sat, 25 Aug 2018 19:58:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b05JZ6XcrIOb for ; Sat, 25 Aug 2018 19:58:42 +0000 (UTC) X-Greylist: delayed 00:06:39 by SQLgrey-1.7.6 Received: from hemingway.tivano.net (hemingway.tivano.net [145.253.242.197]) by whitealder.osuosl.org (Postfix) with ESMTPS id 925AE89826 for ; Sat, 25 Aug 2018 19:58:41 +0000 (UTC) Received: (qmail 15251 invoked from network); 25 Aug 2018 19:51:58 -0000 Received: from unknown (HELO localhost) (127.0.0.1) by localhost with SMTP; 25 Aug 2018 19:51:58 -0000 X-Virus-Scanned: Debian amavisd-new at tivano.de Received: from unknown ([127.0.0.1]) by localhost (hemingway.tivano.net [127.0.0.1]) (amavisd-new, port 10024) with SMTP id Gc1F0PJeoZqh; Sat, 25 Aug 2018 21:51:58 +0200 (CEST) Received: from unknown (HELO doyle.lan) (kunze@178.4.224.32) by hemingway.tivano.net with ESMTPA; 25 Aug 2018 19:51:58 -0000 From: Richard Kunze To: buildroot@buildroot.org Date: Sat, 25 Aug 2018 21:51:52 +0200 Message-Id: <20180825195152.25669-1-richard.kunze@web.de> X-Mailer: git-send-email 2.18.0 Subject: [Buildroot] [PATCH v2] Add support for custom initramfs contents X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Kunze MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" 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. Signed-off-by: Richard Kunze --- fs/initramfs/Config.in | 34 +++++++++++++++++++++++++++++++++- fs/initramfs/initramfs.mk | 18 +++++++++++++++++- linux/linux.mk | 8 ++++---- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/fs/initramfs/Config.in b/fs/initramfs/Config.in index 9d5a3f92e6..9b7ac9475e 100644 --- a/fs/initramfs/Config.in +++ b/fs/initramfs/Config.in @@ -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 diff --git a/fs/initramfs/initramfs.mk b/fs/initramfs/initramfs.mk index c751093214..ef3fdc6d3d 100644 --- a/fs/initramfs/initramfs.mk +++ b/fs/initramfs/initramfs.mk @@ -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 diff --git a/linux/linux.mk b/linux/linux.mk index 675e7906a8..5f4ddbb316 100644 --- a/linux/linux.mk +++ b/linux/linux.mk @@ -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.