Skip to content

Commit 7ce7e98

Browse files
committed
kbuild: rename cmd_{bzip2,lzma,lzo,lz4,xzkern,zstd22}
GZIP-compressed files end with 4 byte data that represents the size of the original input. The decompressors (the self-extracting kernel) exploit it to know the vmlinux size beforehand. To mimic the GZIP's trailer, Kbuild provides cmd_{bzip2,lzma,lzo,lz4,xzkern,zstd22}. Unfortunately these macros are used everywhere despite the appended size data is only useful for the decompressors. There is no guarantee that such hand-crafted trailers are safely ignored. In fact, the kernel refuses compressed initramdfs with the garbage data. That is why usr/Makefile overrides size_append to make it no-op. To limit the use of such broken compressed files, this commit renames the existing macros as follows: cmd_bzip2 --> cmd_bzip2_with_size cmd_lzma --> cmd_lzma_with_size cmd_lzo --> cmd_lzo_with_size cmd_lz4 --> cmd_lz4_with_size cmd_xzkern --> cmd_xzkern_with_size cmd_zstd22 --> cmd_zstd22_with_size To keep the decompressors working, I updated the following Makefiles accordingly: arch/arm/boot/compressed/Makefile arch/h8300/boot/compressed/Makefile arch/mips/boot/compressed/Makefile arch/parisc/boot/compressed/Makefile arch/s390/boot/compressed/Makefile arch/sh/boot/compressed/Makefile arch/x86/boot/compressed/Makefile I reused the current macro names for the normal usecases; they produce the compressed data in the proper format. I did not touch the following: arch/arc/boot/Makefile arch/arm64/boot/Makefile arch/csky/boot/Makefile arch/mips/boot/Makefile arch/riscv/boot/Makefile arch/sh/boot/Makefile kernel/Makefile This means those Makefiles will stop appending the size data. I dropped the 'override size_append' hack from usr/Makefile. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <n.schier@avm.de>
1 parent 64d8aaa commit 7ce7e98

File tree

9 files changed

+58
-43
lines changed

9 files changed

+58
-43
lines changed

arch/arm/boot/compressed/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ CPPFLAGS_vmlinux.lds += -DTEXT_OFFSET="$(TEXT_OFFSET)"
7777
CPPFLAGS_vmlinux.lds += -DMALLOC_SIZE="$(MALLOC_SIZE)"
7878

7979
compress-$(CONFIG_KERNEL_GZIP) = gzip
80-
compress-$(CONFIG_KERNEL_LZO) = lzo
81-
compress-$(CONFIG_KERNEL_LZMA) = lzma
82-
compress-$(CONFIG_KERNEL_XZ) = xzkern
83-
compress-$(CONFIG_KERNEL_LZ4) = lz4
80+
compress-$(CONFIG_KERNEL_LZO) = lzo_with_size
81+
compress-$(CONFIG_KERNEL_LZMA) = lzma_with_size
82+
compress-$(CONFIG_KERNEL_XZ) = xzkern_with_size
83+
compress-$(CONFIG_KERNEL_LZ4) = lz4_with_size
8484

8585
libfdt_objs := fdt_rw.o fdt_ro.o fdt_wip.o fdt.o
8686

arch/h8300/boot/compressed/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ $(obj)/vmlinux.bin: vmlinux FORCE
3030

3131
suffix-$(CONFIG_KERNEL_GZIP) := gzip
3232
suffix-$(CONFIG_KERNEL_LZO) := lzo
33+
compress-$(CONFIG_KERNEL_GZIP) := gzip
34+
compress-$(CONFIG_KERNEL_LZO) := lzo_with_size
3335

3436
$(obj)/vmlinux.bin.$(suffix-y): $(obj)/vmlinux.bin FORCE
35-
$(call if_changed,$(suffix-y))
37+
$(call if_changed,$(compress-y))
3638

3739
LDFLAGS_piggy.o := -r --format binary --oformat elf32-h8300-linux -T
3840
OBJCOPYFLAGS := -O binary

arch/mips/boot/compressed/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ $(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE
6464
$(call if_changed,objcopy)
6565

6666
tool_$(CONFIG_KERNEL_GZIP) = gzip
67-
tool_$(CONFIG_KERNEL_BZIP2) = bzip2
68-
tool_$(CONFIG_KERNEL_LZ4) = lz4
69-
tool_$(CONFIG_KERNEL_LZMA) = lzma
70-
tool_$(CONFIG_KERNEL_LZO) = lzo
71-
tool_$(CONFIG_KERNEL_XZ) = xzkern
72-
tool_$(CONFIG_KERNEL_ZSTD) = zstd22
67+
tool_$(CONFIG_KERNEL_BZIP2) = bzip2_with_size
68+
tool_$(CONFIG_KERNEL_LZ4) = lz4_with_size
69+
tool_$(CONFIG_KERNEL_LZMA) = lzma_with_size
70+
tool_$(CONFIG_KERNEL_LZO) = lzo_with_size
71+
tool_$(CONFIG_KERNEL_XZ) = xzkern_with_size
72+
tool_$(CONFIG_KERNEL_ZSTD) = zstd22_with_size
7373

7474
targets += vmlinux.bin.z
7575

arch/parisc/boot/compressed/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ suffix-$(CONFIG_KERNEL_XZ) := xz
7070
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
7171
$(call if_changed,gzip)
7272
$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
73-
$(call if_changed,bzip2)
73+
$(call if_changed,bzip2_with_size)
7474
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
75-
$(call if_changed,lz4)
75+
$(call if_changed,lz4_with_size)
7676
$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
77-
$(call if_changed,lzma)
77+
$(call if_changed,lzma_with_size)
7878
$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
79-
$(call if_changed,lzo)
79+
$(call if_changed,lzo_with_size)
8080
$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
81-
$(call if_changed,xzkern)
81+
$(call if_changed,xzkern_with_size)
8282

8383
LDFLAGS_piggy.o := -r --format binary --oformat $(LD_BFD) -T
8484
$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix-y) FORCE

arch/s390/boot/compressed/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ suffix-$(CONFIG_KERNEL_ZSTD) := .zst
7171
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
7272
$(call if_changed,gzip)
7373
$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
74-
$(call if_changed,bzip2)
74+
$(call if_changed,bzip2_with_size)
7575
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
76-
$(call if_changed,lz4)
76+
$(call if_changed,lz4_with_size)
7777
$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
78-
$(call if_changed,lzma)
78+
$(call if_changed,lzma_with_size)
7979
$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
80-
$(call if_changed,lzo)
80+
$(call if_changed,lzo_with_size)
8181
$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
82-
$(call if_changed,xzkern)
82+
$(call if_changed,xzkern_with_size)
8383
$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
84-
$(call if_changed,zstd22)
84+
$(call if_changed,zstd22_with_size)
8585

8686
OBJCOPYFLAGS_piggy.o := -I binary -O elf64-s390 -B s390:64-bit --rename-section .data=.vmlinux.bin.compressed
8787
$(obj)/piggy.o: $(obj)/vmlinux.bin$(suffix-y) FORCE

arch/sh/boot/compressed/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ vmlinux.bin.all-y := $(obj)/vmlinux.bin
5252
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
5353
$(call if_changed,gzip)
5454
$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
55-
$(call if_changed,bzip2)
55+
$(call if_changed,bzip2_with_size)
5656
$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
57-
$(call if_changed,lzma)
57+
$(call if_changed,lzma_with_size)
5858
$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
59-
$(call if_changed,xzkern)
59+
$(call if_changed,xzkern_with_size)
6060
$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
61-
$(call if_changed,lzo)
61+
$(call if_changed,lzo_with_size)
6262

6363
OBJCOPYFLAGS += -R .empty_zero_page
6464

arch/x86/boot/compressed/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
123123
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
124124
$(call if_changed,gzip)
125125
$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
126-
$(call if_changed,bzip2)
126+
$(call if_changed,bzip2_with_size)
127127
$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
128-
$(call if_changed,lzma)
128+
$(call if_changed,lzma_with_size)
129129
$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
130-
$(call if_changed,xzkern)
130+
$(call if_changed,xzkern_with_size)
131131
$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
132-
$(call if_changed,lzo)
132+
$(call if_changed,lzo_with_size)
133133
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
134-
$(call if_changed,lz4)
134+
$(call if_changed,lz4_with_size)
135135
$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
136-
$(call if_changed,zstd22)
136+
$(call if_changed,zstd22_with_size)
137137

138138
suffix-$(CONFIG_KERNEL_GZIP) := gz
139139
suffix-$(CONFIG_KERNEL_BZIP2) := bz2

scripts/Makefile.lib

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,19 +395,31 @@ printf "%08x\n" $$dec_size | \
395395
)
396396

397397
quiet_cmd_bzip2 = BZIP2 $@
398-
cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
398+
cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
399+
400+
quiet_cmd_bzip2_with_size = BZIP2 $@
401+
cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
399402

400403
# Lzma
401404
# ---------------------------------------------------------------------------
402405

403406
quiet_cmd_lzma = LZMA $@
404-
cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
407+
cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
408+
409+
quiet_cmd_lzma_with_size = LZMA $@
410+
cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
405411

406412
quiet_cmd_lzo = LZO $@
407-
cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
413+
cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
414+
415+
quiet_cmd_lzo_with_size = LZO $@
416+
cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
408417

409418
quiet_cmd_lz4 = LZ4 $@
410-
cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
419+
cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@
420+
421+
quiet_cmd_lz4_with_size = LZ4 $@
422+
cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
411423
$(size_append); } > $@
412424

413425
# U-Boot mkimage
@@ -450,7 +462,10 @@ quiet_cmd_uimage = UIMAGE $@
450462
# big dictionary would increase the memory usage too much in the multi-call
451463
# decompression mode. A BCJ filter isn't used either.
452464
quiet_cmd_xzkern = XZKERN $@
453-
cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
465+
cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
466+
467+
quiet_cmd_xzkern_with_size = XZKERN $@
468+
cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
454469
$(size_append); } > $@
455470

456471
quiet_cmd_xzmisc = XZMISC $@
@@ -476,7 +491,10 @@ quiet_cmd_zstd = ZSTD $@
476491
cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
477492

478493
quiet_cmd_zstd22 = ZSTD22 $@
479-
cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
494+
cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
495+
496+
quiet_cmd_zstd22_with_size = ZSTD22 $@
497+
cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
480498

481499
# ASM offsets
482500
# ---------------------------------------------------------------------------

usr/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
# kbuild file for usr/ - including initramfs image
44
#
55

6-
# cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the
7-
# size at the end of the compressed file, which unfortunately does not work
8-
# with unpack_to_rootfs(). Make size_append no-op.
9-
override size_append := :
10-
116
compress-y := shipped
127
compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip
138
compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2

0 commit comments

Comments
 (0)