Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ping Li <leeonion.muyu@gmail.com>
To: catalin.marinas@arm.com, will@kernel.org, palmer@dabbelt.com,
	pjw@kernel.org
Cc: cyan@meta.com, mark.rutland@arm.com, alex@ghiti.fr,
	emil.renner.berthing@canonical.com, masahiroy@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	u-boot@lists.denx.de, Ping Li <leeonion.muyu@gmail.com>
Subject: [PATCH v2 2/2] riscv: boot: emit standard LZ4 frame for Image.lz4
Date: Thu, 26 Nov 2026 11:02:33 +0800	[thread overview]
Message-ID: <20261126030233.2546274-3-leeonion.muyu@gmail.com> (raw)
In-Reply-To: <20261126030233.2546274-1-leeonion.muyu@gmail.com>

Like arm64, a compressed riscv boot image is decompressed by the
bootloader, not by the kernel itself.  The shared cmd_lz4 rule
passes -l, producing the legacy LZ4 format that only the kernel's
own decompressor understands, so U-Boot (boot/image.c image_decomp
-> lib/lz4_wrapper.c ulz4fn), which only accepts the standard LZ4
frame and returns -EPROTONOSUPPORT for anything else, cannot
decompress the Image.lz4 built today.

This matters in particular when CONFIG_KERNEL_LZ4 selects Image.lz4
as the default boot image via boot-image-$(CONFIG_KERNEL_LZ4) in
arch/riscv/Makefile.

Emit the standard frame through a local rule, leaving the shared
cmd_lz4 untouched for the in-kernel users.

Also pass -BI so the blocks stay independent regardless of what the
lz4 CLI defaults to in the future; deployed U-Boot decoders reject
linked blocks, and lz4 is considering linked blocks as a future
CLI default.  -BI was introduced in lz4 v1.9.0 - older lz4 versions
reject the flag but already default to independent blocks, so the
rule probes for -BI support first.  With current lz4 versions the
output is unchanged.

Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 arch/riscv/boot/Makefile | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/boot/Makefile b/arch/riscv/boot/Makefile
index b80a077a8e8f..ab2b1b77e21d 100644
--- a/arch/riscv/boot/Makefile
+++ b/arch/riscv/boot/Makefile
@@ -33,8 +33,20 @@ $(obj)/loader: $(obj)/loader.o $(obj)/Image $(obj)/loader.lds FORCE
 $(obj)/Image.bz2: $(obj)/Image FORCE
 	$(call if_changed,bzip2)
 
+# U-Boot only accepts standard LZ4 frames with independent blocks;
+# probe -BI first because lz4 < 1.9.0 rejects the flag but already
+# defaults to independent blocks.
+ifeq ($(shell $(LZ4) -BI -V >/dev/null 2>&1 && echo y),y)
+  lz4-bi-flag := -BI
+else
+  lz4-bi-flag :=
+endif
+
+quiet_cmd_lz4_std = LZ4     $@
+      cmd_lz4_std = cat $(real-prereqs) | $(LZ4) $(lz4-bi-flag) -9 - - > $@
+
 $(obj)/Image.lz4: $(obj)/Image FORCE
-	$(call if_changed,lz4)
+	$(call if_changed,lz4_std)
 
 $(obj)/Image.lzma: $(obj)/Image FORCE
 	$(call if_changed,lzma)
-- 
2.34.1



  parent reply	other threads:[~2026-11-26  3:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  6:56 [PATCH 0/2] arm64,riscv: boot: emit standard LZ4 frame for Image.lz4 Ping Li
2026-11-24  6:56 ` [PATCH 1/2] arm64: " Ping Li
2026-11-24  6:56 ` [PATCH 2/2] riscv: " Ping Li
2026-11-26  0:19 ` [PATCH 0/2] arm64,riscv: " Yann Collet
2026-11-26  3:01   ` Ping Li
2026-11-26  3:02 ` [PATCH v2 " Ping Li
2026-11-26  3:02   ` [PATCH v2 1/2] arm64: " Ping Li
2026-11-26  3:02   ` Ping Li [this message]
2026-11-26  5:13   ` [PATCH v2 0/2] arm64,riscv: " Yann Collet
2026-11-26  6:39   ` Ping Li

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=20261126030233.2546274-3-leeonion.muyu@gmail.com \
    --to=leeonion.muyu@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=catalin.marinas@arm.com \
    --cc=cyan@meta.com \
    --cc=emil.renner.berthing@canonical.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=u-boot@lists.denx.de \
    --cc=will@kernel.org \
    /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