[PATCH v2 1/2] arm64: boot: emit standard LZ4 frame for Image.lz4

From: Ping Li

Date: Wed Nov 25 2026 - 22:03:06 EST


The shared cmd_lz4 rule passes -l to the lz4 tool, producing the
legacy LZ4 format (magic 0x184C2102). That is the format understood
by the kernel's own decompressor, lib/decompress_unlz4, whose users
are the self-extracting images of other architectures (all of which
compress their payloads with the *_with_size variants) and the
lz4-compressed initramfs. An arm64 boot image is not consumed by
the kernel itself though: it is decompressed by the bootloader.

U-Boot, which supports booting compressed arm64 kernels with 'booti'
(boot/image.c image_decomp -> lib/lz4_wrapper.c ulz4fn), only accepts
the standard LZ4 frame (magic 0x184D2204) and returns
-EPROTONOSUPPORT for anything else. Its host tooling (binman)
likewise emits standard frames. As a result, an arm64 Image.lz4
built today cannot be decompressed by U-Boot at all.

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@xxxxxxxxx>
---
arch/arm64/boot/Makefile | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/Makefile b/arch/arm64/boot/Makefile
index d42d07667822..eb28967469b4 100644
--- a/arch/arm64/boot/Makefile
+++ b/arch/arm64/boot/Makefile
@@ -28,8 +28,20 @@ $(obj)/Image.bz2: $(obj)/Image FORCE
$(obj)/Image.gz: $(obj)/Image FORCE
+$(call if_changed,gzip)

+# 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