All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [RFC/PATCH] linux: add external initramfs options
@ 2014-05-26 21:01 Guido Martínez
  2014-05-28 16:47 ` Arnout Vandecappelle
  2014-06-09 13:34 ` Thomas Petazzoni
  0 siblings, 2 replies; 6+ messages in thread
From: Guido Martínez @ 2014-05-26 21:01 UTC (permalink / raw)
  To: buildroot

This patch allows building the kernel with an external initramfs. This
is useful in cases where one wants to generate the kernel and rootfs
with BR, and the kernel needs to contain an initramfs different to the
rootfs.

The path specified can be a cpio archive or a directory, just like
the kernel config. The path is specified w.r.t. BRs topdir, and made
absolute since the kernel builds in another directory.

Signed-off-by: Guido Mart?nez <guido@vanguardiasur.com.ar>
---
Hi,

I'm marking this as RFC because I don't particularly like what I wrote
to detect if the path is relative, but I found no other way.

Any comment is appreciated,
Thanks!
Guido

 linux/Config.in | 32 ++++++++++++++++++++++++++++++++
 linux/linux.mk  | 22 ++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/linux/Config.in b/linux/Config.in
index 069a7d6..1efb845 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -155,6 +155,38 @@ config BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE
 	help
 	  Path to the kernel configuration file
 
+config BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS
+	depends on !BR2_TARGET_ROOTFS_INITRAMFS
+	bool "Use an external initramfs"
+	help
+	  Append an external initramfs to the kernel image.
+
+comment "using BR initramfs, can't use an external one"
+	depends on BR2_TARGET_ROOTFS_INITRAMFS
+
+config BR2_LINUX_KERNEL_INITRAMFS_SOURCE
+	string "Appended initramfs source"
+	depends on BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS
+	help
+	  Path to use as the external initramfs in the kernel. Can be
+	  a CPIO archive or a directory.
+
+config BR2_LINUX_KERNEL_INITRAMFS_ROOT_UID
+	string "Initramfs squash UID"
+	depends on BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS
+	help
+	  If "Appended initramfs source" is a directory, select a UID
+	  to be squashed to 0 (root). This allows creating an archive
+	  with root-owned files as a user.
+
+config BR2_LINUX_KERNEL_INITRAMFS_ROOT_GID
+	string "Initramfs squash GID"
+	depends on BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS
+	help
+	  If "Appended initramfs source" is a directory, select a GID
+	  to be squashed to 0 (root). This allows creating an archive
+	  with root-owned files as a user.
+
 #
 # Binary format
 #
diff --git a/linux/linux.mk b/linux/linux.mk
index bd3f2ac..1ce5a25 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -166,9 +166,31 @@ else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
 KERNEL_SOURCE_CONFIG = $(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE)
 endif
 
+define LINUX_CONFIGURE_INITRAMFS
+	$(if $(filter-out /%,$(call qstrip,$(BR2_LINUX_KERNEL_INITRAMFS_SOURCE))),
+	$(if $(filter-out ~%,$(call qstrip,$(BR2_LINUX_KERNEL_INITRAMFS_SOURCE))),
+		$(eval BR2_LINUX_KERNEL_INITRAMFS_SOURCE="${TOPDIR}/$(call qstrip,$(BR2_LINUX_KERNEL_INITRAMFS_SOURCE))")))
+
+	$(if $(BR2_LINUX_KERNEL_INITRAMFS_SOURCE),
+		$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD,$(@D)/.config)
+		$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,\"$(BR2_LINUX_KERNEL_INITRAMFS_SOURCE)\",$(@D)/.config)
+	)
+
+	$(if $(BR2_LINUX_KERNEL_INITRAMFS_ROOT_UID),
+		$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,$(BR2_LINUX_KERNEL_INITRAMFS_ROOT_UID),$(@D)/.config)
+	)
+
+	$(if $(BR2_LINUX_KERNEL_INITRAMFS_ROOT_GID),
+		$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,$(BR2_LINUX_KERNEL_INITRAMFS_ROOT_GID),$(@D)/.config)
+	)
+endef
+
+
 define LINUX_CONFIGURE_CMDS
 	$(INSTALL) -m 0644 $(KERNEL_SOURCE_CONFIG) $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig
 	$(TARGET_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) buildroot_defconfig
+	$(if $(BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS),
+		$(call LINUX_CONFIGURE_INITRAMFS))
 	rm $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig
 	$(if $(BR2_arm)$(BR2_armeb),
 		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config))
-- 
2.0.0.rc2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Buildroot] [RFC/PATCH] linux: add external initramfs options
  2014-05-26 21:01 [Buildroot] [RFC/PATCH] linux: add external initramfs options Guido Martínez
@ 2014-05-28 16:47 ` Arnout Vandecappelle
  2014-06-04 20:45   ` Ezequiel Garcia
  2014-06-09 13:34 ` Thomas Petazzoni
  1 sibling, 1 reply; 6+ messages in thread
From: Arnout Vandecappelle @ 2014-05-28 16:47 UTC (permalink / raw)
  To: buildroot

 Hi Guido,

 Thanks for your patch. However, I don't think it is appropriate. See my
comments below.

On 26/05/14 23:01, Guido Mart?nez wrote:
> This patch allows building the kernel with an external initramfs. This
> is useful in cases where one wants to generate the kernel and rootfs
> with BR, and the kernel needs to contain an initramfs different to the
> rootfs.

 In that case, don't you typically want to copy part of the rootfs in the
initramfs? Of course, it's possible to do that with a post-build script, but if
we add a feature like this to buildroot, I think the copying part should be
included.

> 
> The path specified can be a cpio archive or a directory, just like
> the kernel config. The path is specified w.r.t. BRs topdir, and made
> absolute since the kernel builds in another directory.

 This patch does nothing more than update the kernel config. Since you can
already supply a custom kernel config, I don't think there is much added value
to moving these options to the buildroot config.

 The only feature you add is that the patch can be relative to the buildroot
directory. Not enough to be relevant, IMHO, especially since the patch adds
non-negligible complexity.

> 
> Signed-off-by: Guido Mart?nez <guido@vanguardiasur.com.ar>
> ---
> Hi,
> 
> I'm marking this as RFC because I don't particularly like what I wrote
> to detect if the path is relative, but I found no other way.

 There is a very easy way:
$(abspath $(call qstrip,$(BR2_LINUX_KERNEL_INITRAMFS_SOURCE)))

this will evaluate the path relative to the buildroot directly. It will also
expand ~ I think (but I'm not sure, possibly you need to use wildcard for that).

[snip]
>  define LINUX_CONFIGURE_CMDS
>  	$(INSTALL) -m 0644 $(KERNEL_SOURCE_CONFIG) $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig
>  	$(TARGET_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) buildroot_defconfig
> +	$(if $(BR2_LINUX_KERNEL_EXTERNAL_INITRAMFS),
> +		$(call LINUX_CONFIGURE_INITRAMFS))

 You don't need a $(call ...) here.


 Regards,
 Arnout


>  	rm $(KERNEL_ARCH_PATH)/configs/buildroot_defconfig
>  	$(if $(BR2_arm)$(BR2_armeb),
>  		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config))
> 


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Buildroot] [RFC/PATCH] linux: add external initramfs options
  2014-05-28 16:47 ` Arnout Vandecappelle
@ 2014-06-04 20:45   ` Ezequiel Garcia
  2014-06-04 22:29     ` Arnout Vandecappelle
  0 siblings, 1 reply; 6+ messages in thread
From: Ezequiel Garcia @ 2014-06-04 20:45 UTC (permalink / raw)
  To: buildroot

Hello Arnout,

On 28 May 06:47 PM, Arnout Vandecappelle wrote:
[..]
> > 
> > The path specified can be a cpio archive or a directory, just like
> > the kernel config. The path is specified w.r.t. BRs topdir, and made
> > absolute since the kernel builds in another directory.
> 
>  This patch does nothing more than update the kernel config. Since you can
> already supply a custom kernel config, I don't think there is much added value
> to moving these options to the buildroot config.
> 
>  The only feature you add is that the patch can be relative to the buildroot
> directory. Not enough to be relevant, IMHO, especially since the patch adds
> non-negligible complexity.
> 

Our software stack includes a kernel with an appended initramfs to take care
of software upgrade and find, check and switch to the "real" rootfs. Both
the initramfs and rootfs are Buildroot-based, but each of them with their
own configuration and history (in separate git repos).

Hence we came up with this solution: the initramfs would live in a different
repo, and after it's built we use this new option to append it in the kernel.

Maybe you have a better idea, and there's a cleaner way to accomplish this
with Buildroot?

Thanks for the feedback!
-- 
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Buildroot] [RFC/PATCH] linux: add external initramfs options
  2014-06-04 20:45   ` Ezequiel Garcia
@ 2014-06-04 22:29     ` Arnout Vandecappelle
  2014-06-09 14:09       ` Ezequiel Garcia
  0 siblings, 1 reply; 6+ messages in thread
From: Arnout Vandecappelle @ 2014-06-04 22:29 UTC (permalink / raw)
  To: buildroot

On 04/06/14 22:45, Ezequiel Garcia wrote:
> Hello Arnout,
> 
> On 28 May 06:47 PM, Arnout Vandecappelle wrote:
> [..]
>>>
>>> The path specified can be a cpio archive or a directory, just like
>>> the kernel config. The path is specified w.r.t. BRs topdir, and made
>>> absolute since the kernel builds in another directory.
>>
>>  This patch does nothing more than update the kernel config. Since you can
>> already supply a custom kernel config, I don't think there is much added value
>> to moving these options to the buildroot config.
>>
>>  The only feature you add is that the patch can be relative to the buildroot
>> directory. Not enough to be relevant, IMHO, especially since the patch adds
>> non-negligible complexity.
>>
> 
> Our software stack includes a kernel with an appended initramfs to take care
> of software upgrade and find, check and switch to the "real" rootfs. Both
> the initramfs and rootfs are Buildroot-based, but each of them with their
> own configuration and history (in separate git repos).
> 
> Hence we came up with this solution: the initramfs would live in a different
> repo, and after it's built we use this new option to append it in the kernel.
> 
> Maybe you have a better idea, and there's a cleaner way to accomplish this
> with Buildroot?

 Use a custom kernel config, and code the path to the external initramfs in that
custom kernel config instead of in the buildroot config. You can use
$(BASE_DIR)/../initramfs-output-dir if you want to avoid absolute paths in the
config.

 Actually, in your case the easiest solution would be to build the kernel
together with the initramfs-buildroot and use the initramfs rootfs instead of
the cpio one. In the real-rootfs-buildroot you don't need to build a kernel.

 Or am I missing something?

 Regards,
 Arnout

> 
> Thanks for the feedback!
> 


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Buildroot] [RFC/PATCH] linux: add external initramfs options
  2014-05-26 21:01 [Buildroot] [RFC/PATCH] linux: add external initramfs options Guido Martínez
  2014-05-28 16:47 ` Arnout Vandecappelle
@ 2014-06-09 13:34 ` Thomas Petazzoni
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2014-06-09 13:34 UTC (permalink / raw)
  To: buildroot

Dear Guido Mart?nez,

On Mon, 26 May 2014 18:01:37 -0300, Guido Mart?nez wrote:
> This patch allows building the kernel with an external initramfs. This
> is useful in cases where one wants to generate the kernel and rootfs
> with BR, and the kernel needs to contain an initramfs different to the
> rootfs.
> 
> The path specified can be a cpio archive or a directory, just like
> the kernel config. The path is specified w.r.t. BRs topdir, and made
> absolute since the kernel builds in another directory.
> 
> Signed-off-by: Guido Mart?nez <guido@vanguardiasur.com.ar>

Since I agree with the feedback from Arnout, I'll mark this as Rejected
in patchwork. There's no point in duplicating each and every kernel
configuration option at the Buildroot level. Just make sure to tune
your kernel configuration properly, and pass it to Buildroot as the
kernel configuration file.

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Buildroot] [RFC/PATCH] linux: add external initramfs options
  2014-06-04 22:29     ` Arnout Vandecappelle
@ 2014-06-09 14:09       ` Ezequiel Garcia
  0 siblings, 0 replies; 6+ messages in thread
From: Ezequiel Garcia @ 2014-06-09 14:09 UTC (permalink / raw)
  To: buildroot

On 05 Jun 12:29 AM, Arnout Vandecappelle wrote:
[..]
> 
>  Actually, in your case the easiest solution would be to build the kernel
> together with the initramfs-buildroot and use the initramfs rootfs instead of
> the cpio one. In the real-rootfs-buildroot you don't need to build a kernel.
> 

Right, that sounds like a better plan.

Thanks a lot for the feedback,
-- 
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-09 14:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-26 21:01 [Buildroot] [RFC/PATCH] linux: add external initramfs options Guido Martínez
2014-05-28 16:47 ` Arnout Vandecappelle
2014-06-04 20:45   ` Ezequiel Garcia
2014-06-04 22:29     ` Arnout Vandecappelle
2014-06-09 14:09       ` Ezequiel Garcia
2014-06-09 13:34 ` Thomas Petazzoni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.