alpha: self-extracting compressed kernel images
Subsystems (2)
Matt Turner
maintainerv2 cover alpha: self-extracting compressed kernel images
Alpha is the last architecture whose boot loader decompresses the kernel
itself: aboot carries its own inflate code, so vmlinux.gz has always been plain gzip, and adding a compression format meant writing a decompressor for aboot as well as for the kernel.
Build a self-extracting image instead, a small ELF stub with the compressed vmlinux linked in, which aboot loads and enters like any other kernel. The compression format then becomes an ordinary kernel Kconfig choice, and all seven formats become available: xz gives the smallest image, 5547496 bytes against 7677280 for the equivalent gzip one. The build now emits arch/alpha/boot/vmlinuz, since the image is no longer gzip data.
The SRM netboot path (bootpz.c) has its own boot protocol and keeps using gzip.
---
Changes in v2:
- Build private copies of the arch/alpha/lib/ memory and division
routines for the stub instead of linking lib.a, whose objects carry
UBSAN/gcov instrumentation and the kernel's -mcpu=. Fixes stub link
failures with UBSAN or GCOV_PROFILE_ALL. (Magnus)
- Build the stub with an explicit -mcpu=ev4.
- Collect trailers.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Matt Turner (3):
xz: add arch-specific tuning for alpha
alpha: add self-extracting compressed kernel boot stub
alpha: support the remaining kernel compression formats
arch/alpha/Kconfig | 7 ++ arch/alpha/Makefile | 6 +- arch/alpha/boot/.gitignore | 2 + arch/alpha/boot/Makefile | 16 ++- arch/alpha/boot/compressed/.gitignore | 3 + arch/alpha/boot/compressed/Makefile | 89 +++++++++++++ arch/alpha/boot/compressed/head.S | 36 ++++++ arch/alpha/boot/compressed/misc.c | 209 +++++++++++++++++++++++++++++++ arch/alpha/boot/compressed/trampoline.S | 46 +++++++ arch/alpha/boot/compressed/vmlinux.lds.S | 83 ++++++++++++ arch/alpha/boot/compressed/vmlinux.scr | 10 ++ scripts/xz_wrap.sh | 5 + 12 files changed, 504 insertions(+), 8 deletions(-)
---
base-commit: 4407825b2f96b0e48a4bd08ab196b50a30eb3aef
change-id: 20260912-alpha-kernel-compression-2043f806fb75
Best regards,
Signature · 1 line
Matt Turner <[email protected]>
Matt Turner
maintainerPATCH v2 1/3 xz: add arch-specific tuning for alpha
Alpha has fixed-length, 4-byte-aligned instructions and no XZ BCJ filter, so it wants the same LZMA2 settings as the other 4-byte-aligned targets. Without an entry it hits the default case, which warns
scripts/xz_wrap.sh: Arch-specific tuning is missing for 'alpha'
and conservatively assumes 2-byte alignment. Alpha gains HAVE_KERNEL_XZ later in this series; the correct alignment also shrinks a UP1500 kernel's XZ image from 6469320 to 6448840 bytes.
--- scripts/xz_wrap.sh | 5 +++++ 1 file changed, 5 insertions(+)
scripts/xz_wrap.sh +5 -0
@@ -10,6 +10,7 @@ # XZ-compressed kernel isn't currently supported on every listed arch. # # Arch Align Notes +# alpha 4 # arm 2/4 ARM and ARM-Thumb2 # arm64 4 # csky 2
@@ -44,6 +45,10 @@ BCJ= # Set the BCJ filter if one is available. # It must match the #ifdef usage in lib/decompress_unxz.c. case $SRCARCH in + alpha) + ALIGN=4 + ;; + arm) if is_enabled CONFIG_THUMB2_KERNEL; then ALIGN=2
Signature · 1 line
2.55.0
Matt Turner
maintainerPATCH v2 2/3 alpha: add self-extracting compressed kernel boot stub
In reply to Matt TurnerAlpha only ever supported gzip for the kernel image, and did so in a way out of step with every other architecture: aboot, the disk boot loader, decompresses vmlinux.gz itself with its own bundled inflate code, so adding a compression format meant writing a new decompressor inside aboot as well as in the kernel.
Build a proper self-extracting arch/alpha/boot/compressed/vmlinux instead, modeled on parisc: a small ELF stub with the real, compressed vmlinux linked in, which decompresses the kernel, relocates it into place and jumps to its entry point. aboot needs no changes.
The stub has no sanitizer or coverage runtime and must run on any Alpha, so it builds private copies of the arch/alpha/lib/ memory and division routines it needs instead of linking lib.a, whose objects carry the kernel's instrumentation and -mcpu=.
The build now emits arch/alpha/boot/vmlinuz rather than vmlinux.gz, which was never a name aboot cared about and would be a lie for an ELF
stub: the bootpz path in the same directory still produces real gzip data as vmlinux.nh.gz. Existing aboot.conf files name the image as it was installed in /boot, so only the command that copies it out of the build tree changes.
Unlike parisc and mips, the stub is linked at START_ADDR rather than at a separate low address; see compressed/vmlinux.lds.S. It has no console output, since bringing up the HWRPB console callbacks needs more than the CRB dispatch the kernel proper does much later, so error() just halts.
The legacy SRM netboot path (bootpz.c) is left alone: it has its own boot protocol (PALcode reinitialization, self-populated ZERO_PGE, build-time-computed image sizes) that does not fit this design without a separate rewrite, and keeps using plain gzip via vmlinux.nh.gz.
--- arch/alpha/Kconfig | 1 + arch/alpha/Makefile | 6 +- arch/alpha/boot/.gitignore | 2 + arch/alpha/boot/Makefile | 16 ++- arch/alpha/boot/compressed/.gitignore | 3 + arch/alpha/boot/compressed/Makefile | 62 +++++++++++ arch/alpha/boot/compressed/head.S | 36 +++++++ arch/alpha/boot/compressed/misc.c | 178 +++++++++++++++++++++++++++++++ arch/alpha/boot/compressed/trampoline.S | 46 ++++++++ arch/alpha/boot/compressed/vmlinux.lds.S | 83 ++++++++++++++ arch/alpha/boot/compressed/vmlinux.scr | 10 ++ 11 files changed, 435 insertions(+), 8 deletions(-)
arch/alpha/Kconfig +1 -0
@@ -30,6 +30,7 @@ config ALPHA select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_KMEMLEAK select HAVE_GUP_FAST + select HAVE_KERNEL_GZIP select HAVE_PAGE_SIZE_8KB select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
arch/alpha/Makefile +3 -3
@@ -47,9 +47,9 @@ export LIBS_Y boot := arch/alpha/boot #Default target when executing make with no arguments -all boot: $(boot)/vmlinux.gz +all boot: $(boot)/vmlinuz -$(boot)/vmlinux.gz: vmlinux +$(boot)/vmlinuz: vmlinux $(Q)$(MAKE) $(build)=$(boot) $@ bootimage bootpfile bootpzfile: vmlinux
@@ -59,7 +59,7 @@ archheaders: $(Q)$(MAKE) $(build)=arch/alpha/kernel/syscalls all define archhelp - echo '* boot - Compressed kernel image (arch/alpha/boot/vmlinux.gz)' + echo '* boot - Compressed kernel image (arch/alpha/boot/vmlinuz)' echo ' bootimage - SRM bootable image (arch/alpha/boot/bootimage)' echo ' bootpfile - BOOTP bootable image (arch/alpha/boot/bootpfile)' echo ' bootpzfile - compressed kernel BOOTP image (arch/alpha/boot/bootpzfile)'
arch/alpha/boot/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +vmlinuz
arch/alpha/boot/Makefile +11 -5
@@ -9,9 +9,10 @@ # hostprogs := tools/mkbb tools/objstrip -targets := vmlinux.gz vmlinux \ +targets := vmlinuz vmlinux \ vmlinux.nh tools/lxboot tools/bootlx tools/bootph \ - tools/bootpzh bootloader bootpheader bootpzheader + tools/bootpzh bootloader bootpheader bootpzheader +subdir- := compressed OBJSTRIP := $(obj)/tools/objstrip KBUILD_HOSTCFLAGS := -Wall -I$(objtree)/usr/include
@@ -38,9 +39,14 @@ ifdef INITRD cat $(INITRD) >> $@ endif -# Compressed kernel image -$(obj)/vmlinux.gz: $(obj)/vmlinux FORCE - $(call if_changed,gzip) +# Self-extracting compressed kernel image: a small ELF stub (see +# compressed/) with the real vmlinux linked in compressed, which aboot +# loads and enters like a plain vmlinux. +$(obj)/compressed/vmlinux: vmlinux FORCE + $(Q)$(MAKE) $(build)=$(obj)/compressed $@ + +$(obj)/vmlinuz: $(obj)/compressed/vmlinux FORCE + $(call if_changed,copy) @echo ' Kernel $@ is ready' $(obj)/main.o: $(obj)/ksize.h
arch/alpha/boot/compressed/.gitignore new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +vmlinux +vmlinux.lds
arch/alpha/boot/compressed/Makefile new file +62 -0
62 lines not on this page · raw message
arch/alpha/boot/compressed/head.S new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Entry point for the self-extracting compressed kernel stub. aboot + * jumps here with the OSF/1 parameter page (ZERO_PGE) already populated + * and $30 set to INIT_STACK, exactly as it would for an uncompressed + * vmlinux. + */ + +#include <linux/init.h> +#include <asm/pal.h> + + .set noreorder + +__HEAD + .globl __start + .ent __start +__start: + br $29,1f +1: ldgp $29,0($29) + + /* + * Clear our own bss. The decompressors keep state there, and + * nothing guarantees that aboot zeroed the part of our PT_LOAD + * segment that has no file backing. + */ + lda $1,_bss + lda $2,_ebss +2: cmpult $1,$2,$3 + beq $3,3f + stq $31,0($1) + addq $1,8,$1 + br $31,2b + +3: jsr $26,decompress_and_boot + call_pal PAL_halt + .end __start
arch/alpha/boot/compressed/misc.c new file +178 -0
178 lines not on this page · raw message
arch/alpha/boot/compressed/trampoline.S new file +46 -0
46 lines not on this page · raw message
arch/alpha/boot/compressed/vmlinux.lds.S new file +83 -0
83 lines not on this page · raw message
arch/alpha/boot/compressed/vmlinux.scr new file +10 -0
@@ -0,0 +1,10 @@ +SECTIONS +{ + .rodata.compressed : { + input_len = .; + LONG(input_data_end - input_data) input_data = .; + *(.data) + output_len = . - 4; /* can be at unaligned address */ + input_data_end = .; + } +}
Signature · 1 line
2.55.0
Matt Turner
maintainerPATCH v2 3/3 alpha: support the remaining kernel compression formats
In reply to Matt TurnerNothing about the boot stub is specific to gzip, so wire up bzip2, lz4, lzma, lzo, xz and zstd as well: select the matching HAVE_KERNEL_* symbol, add a suffix-y entry and a compression rule for the piggy-backed image, and include the decompressor into the stub's misc.c.
Only gzip's trailer already carries the uncompressed size, so the other formats use the _with_size variants; output_len, which vmlinux.scr takes from the last 4 bytes of the payload, then works for all of them. The stub passes it to __decompress(), which zstd requires.
--- arch/alpha/Kconfig | 6 ++++++ arch/alpha/boot/compressed/Makefile | 31 +++++++++++++++++++++++++++++-- arch/alpha/boot/compressed/misc.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-)
arch/alpha/Kconfig +6 -0
@@ -30,7 +30,13 @@ config ALPHA select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_KMEMLEAK select HAVE_GUP_FAST + select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP + select HAVE_KERNEL_LZ4 + select HAVE_KERNEL_LZMA + select HAVE_KERNEL_LZO + select HAVE_KERNEL_XZ + select HAVE_KERNEL_ZSTD select HAVE_PAGE_SIZE_8KB select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
arch/alpha/boot/compressed/Makefile +29 -2
@@ -7,7 +7,10 @@ OBJECTS := head.o misc.o trampoline.o piggy.o OBJECTS += memcpy.o memmove.o memset.o OBJECTS += __divqu.o __remqu.o __divlu.o __remlu.o -targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz +targets := vmlinux.lds vmlinux vmlinux.bin +targets += vmlinux.bin.bz2 vmlinux.bin.gz vmlinux.bin.lz4 +targets += vmlinux.bin.lzma vmlinux.bin.lzo vmlinux.bin.xz +targets += vmlinux.bin.zst targets += $(OBJECTS) # The stub runs before the kernel has identified the CPU it booted on, so
@@ -44,18 +47,42 @@ AFLAGS___remlu.o := -DREM -DINTSIZE $(addprefix $(obj)/,__divqu.o __remqu.o __divlu.o __remlu.o): $(srctree)/arch/alpha/lib/divide.S FORCE $(call if_changed_dep,as_o_S) +# zstd's decompressor uses __builtin_ctzll()/__builtin_clzll(). Those are +# inline code only with the CIX extension, which the base instruction set +# the stub is built for does not have, so they become calls to libgcc's +# __ctzdi2/__clzdi2. +LIBGCC := $(shell $(CC) -print-libgcc-file-name) + LDFLAGS_vmlinux := -X --orphan-handling=warn -T -$(obj)/vmlinux: $(obj)/vmlinux.lds $(addprefix $(obj)/, $(OBJECTS)) FORCE +$(obj)/vmlinux: $(obj)/vmlinux.lds $(addprefix $(obj)/, $(OBJECTS)) $(LIBGCC) FORCE $(call if_changed,ld) OBJCOPYFLAGS_vmlinux.bin := -R .comment -R .note -S $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) +suffix-$(CONFIG_KERNEL_BZIP2) := bz2 suffix-$(CONFIG_KERNEL_GZIP) := gz +suffix-$(CONFIG_KERNEL_LZ4) := lz4 +suffix-$(CONFIG_KERNEL_LZMA) := lzma +suffix-$(CONFIG_KERNEL_LZO) := lzo +suffix-$(CONFIG_KERNEL_XZ) := xz +suffix-$(CONFIG_KERNEL_ZSTD) := zst +$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE + $(call if_changed,bzip2_with_size) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE $(call if_changed,gzip) +$(obj)/vmlinux.bin.lz4: $(obj)/vmlinux.bin FORCE + $(call if_changed,lz4_with_size) +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE + $(call if_changed,lzma_with_size) +$(obj)/vmlinux.bin.lzo: $(obj)/vmlinux.bin FORCE + $(call if_changed,lzo_with_size) +$(obj)/vmlinux.bin.xz: $(obj)/vmlinux.bin FORCE + $(call if_changed,xzkern_with_size) +$(obj)/vmlinux.bin.zst: $(obj)/vmlinux.bin FORCE + $(call if_changed,zstd22_with_size) LDFLAGS_piggy.o := -r --format binary --oformat elf64-alpha -T $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix-y) FORCE
arch/alpha/boot/compressed/misc.c +31 -0
@@ -23,6 +23,13 @@#define STATIC static#define memzero (s, n) memset((s), 0, (n)) +/* +* decompress_unxz.c supplies its own memmove() unless the identifier is +* already a macro. We link our own build of arch/alpha/lib/memmove.S, +* which is better, so take that instead. +*/ +#define memmove memmove +extern char input_data[];extern int input_len;/* output_len is inserted by the linker, possibly at an unaligned address */
@@ -42,10 +49,34 @@ void __noreturn error(char *m)__halt (); } +#ifdef CONFIG_KERNEL_BZIP2 +#include "../../../../lib/decompress_bunzip2.c" +#endif +#ifdef CONFIG_KERNEL_GZIP #include "../../../../lib/decompress_inflate.c" #endif +#ifdef CONFIG_KERNEL_LZ4 +#include "../../../../lib/decompress_unlz4.c" +#endif + +#ifdef CONFIG_KERNEL_LZMA +#include "../../../../lib/decompress_unlzma.c" +#endif + +#ifdef CONFIG_KERNEL_LZO +#include "../../../../lib/decompress_unlzo.c" +#endif + +#ifdef CONFIG_KERNEL_XZ +#include "../../../../lib/decompress_unxz.c" +#endif + +#ifdef CONFIG_KERNEL_ZSTD +#include "../../../../lib/decompress_unzstd.c" +#endif +/* Scratch heap for the decompressors, larger than any of them needs. */ #define STUB_HEAP_SIZE (4 * 1024 * 1024)
Signature · 1 line
2.55.0