[PATCH 2/2] riscv: boot: emit standard LZ4 frame for Image.lz4

From: Ping Li

Date: Tue Nov 24 2026 - 01:57:11 EST


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 (magic 0x184C2102) that
only the kernel's own decompressor understands, so U-Boot's 'booti'
compressed-kernel path (boot/image.c image_decomp ->
lib/lz4_wrapper.c ulz4fn), which only accepts the standard LZ4 frame
(magic 0x184D2204), rejects 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 LZ4 frame through a local rule, leaving the shared
cmd_lz4 untouched for the in-kernel users (the lz4-compressed
initramfs and the self-extracting images of other architectures).

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

diff --git a/arch/riscv/boot/Makefile b/arch/riscv/boot/Makefile
index b80a077a8e8f..0e7607d7e39f 100644
--- a/arch/riscv/boot/Makefile
+++ b/arch/riscv/boot/Makefile
@@ -33,8 +33,15 @@ $(obj)/loader: $(obj)/loader.o $(obj)/Image $(obj)/loader.lds FORCE
$(obj)/Image.bz2: $(obj)/Image FORCE
$(call if_changed,bzip2)

+# The shared cmd_lz4 passes -l, producing the legacy LZ4 format that
+# matches the kernel's own decompressor. Image.lz4 is decompressed by
+# the bootloader though, and U-Boot only supports the standard LZ4 frame
+# format, so use a local rule that omits -l.
+quiet_cmd_lz4_std = LZ4 $@
+ cmd_lz4_std = cat $(real-prereqs) | $(LZ4) -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