Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
To: buildroot@buildroot.org
Cc: Corentin Labbe <clabbe@baylibre.com>,
	Arnout Vandecappelle <arnout@rnout.be>
Subject: [Buildroot] [PATCH v2] linux: Use the choosen rootfs compression type when rootfs is builtin
Date: Mon, 23 Nov 2026 18:47:25 +0100	[thread overview]
Message-ID: <20261123174725.2554738-1-angelo.compagnucci@gmail.com> (raw)
In-Reply-To: <20231106123705.311899-1-clabbe@baylibre.com>

From: Corentin Labbe <clabbe@baylibre.com>

I have built a buildroot with:
BR2_TARGET_ROOTFS_CPIO_XZ=y
BR2_TARGET_ROOTFS_INITRAMFS=y
With this buildroot produces an images/rootfs.cpio.xz but the kernel still use gzip (CONFIG_INITRAMFS_COMPRESSION_GZIP)
as compression for a plain rootfs.cpio

Setting CONFIG_INITRAMFS_COMPRESSION_XZ in a linux.fragment does not
work as it seems the fragment is setup before buildroot set
CONFIG_INITRAMFS_SOURCE which reset the CONFIG_INITRAMFS_COMPRESSION
choice.

So buildroot have to change CONFIG_INITRAMFS_COMPRESSION after setup
CONFIG_INITRAMFS_SOURCE.

Without cpio compression, the kernel keeps its own default, as before.
So the defconfigs with a built-in initramfs, which use no cpio
compression and often boot an uncompressed kernel image, don't change.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Co-authored-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Tested-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
Changes v1 -> v2:
  - keep the kernel default when the cpio image is not compressed,
    instead of CONFIG_INITRAMFS_COMPRESSION_NONE: the 20 defconfigs
    with a built-in initramfs use no cpio compression, and most of them
    boot an uncompressed kernel (vmlinux, linux.bin, XIP), so their
    images would grow [Arnout Vandecappelle]
  - only enable the chosen option, don't disable the others
    [Arnout Vandecappelle]
  - also enable the CONFIG_RD_* option the choice depends on
  - add bzip2
  - rebase on master

Supersedes v1: https://patchwork.buildroot.org/project/buildroot/patch/20231106123705.311899-1-clabbe@baylibre.com/

 linux/linux.mk | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/linux/linux.mk b/linux/linux.mk
index 49325a3a07..72624fff59 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -420,7 +420,26 @@ define LINUX_KCONFIG_FIXUP_CMDS_ROOTFS_CPIO
 	$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio")
 	$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0)
 	$(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0)
+	$(LINUX_KCONFIG_FIXUP_CMDS_INITRAMFS_COMPRESSION)
 endef
+
+# Compress the built-in initramfs like the cpio image. Setting
+# CONFIG_INITRAMFS_SOURCE above resets this choice, so a kernel
+# configuration fragment can't set it. Without cpio compression, the
+# kernel keeps its own default.
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_BZIP2) = BZIP2
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_GZIP) = GZIP
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_LZ4) = LZ4
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_LZMA) = LZMA
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_LZO) = LZO
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_XZ) = XZ
+LINUX_INITRAMFS_COMPRESSION_$(BR2_TARGET_ROOTFS_CPIO_ZSTD) = ZSTD
+ifneq ($(LINUX_INITRAMFS_COMPRESSION_y),)
+define LINUX_KCONFIG_FIXUP_CMDS_INITRAMFS_COMPRESSION
+	$(call KCONFIG_ENABLE_OPT,CONFIG_RD_$(LINUX_INITRAMFS_COMPRESSION_y))
+	$(call KCONFIG_ENABLE_OPT,CONFIG_INITRAMFS_COMPRESSION_$(LINUX_INITRAMFS_COMPRESSION_y))
+endef
+endif
 endif
 
 # Since kernel >= 6.15.y, x86 and x86_64 kernels requires a toolchain
-- 
2.53.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

      parent reply	other threads:[~2026-11-23 17:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 12:37 [Buildroot] [PATCH 1/1] linux: Use the choosen rootfs compression type when rootfs is builtin Corentin Labbe
2023-11-27 11:42 ` Corentin LABBE
2026-10-11 13:11 ` Arnout Vandecappelle via buildroot
2026-11-23 17:47 ` Angelo Compagnucci [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123174725.2554738-1-angelo.compagnucci@gmail.com \
    --to=angelo.compagnucci@gmail.com \
    --cc=arnout@rnout.be \
    --cc=buildroot@buildroot.org \
    --cc=clabbe@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox