riscv: make image compression configurable
authorEmil Renner Berthing <emil.renner.berthing@canonical.com>
Sat, 4 May 2024 19:34:38 +0000 (21:34 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 22 May 2024 23:12:44 +0000 (16:12 -0700)
Previously the build process would always set KBUILD_IMAGE to the
uncompressed Image file (unless XIP_KERNEL or EFI_ZBOOT was enabled) and
unconditionally compress it into Image.gz. However there are already
build targets for Image.bz2, Image.lz4, Image.lzma, Image.lzo and
Image.zstd, so let's make use of those, make the compression method
configurable and set KBUILD_IMAGE accordingly so that targets like
'make install' and 'make bindeb-pkg' will use the chosen image.

Tested-by: Björn Töpel <bjorn@rivosinc.com>
Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Reviewed-by: Masahiro Yamada <masahiroy@kernel.org>
Link: https://lore.kernel.org/r/20240504193446.196886-2-emil.renner.berthing@canonical.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/Kconfig
arch/riscv/Makefile
arch/riscv/boot/install.sh

index 0bdcc383644d9936f44959d1dcea5d3b8165a67b..dc846689230a6d677b4766437be02d384a1116c5 100644 (file)
@@ -140,6 +140,13 @@ config RISCV
        select HAVE_GCC_PLUGINS
        select HAVE_GENERIC_VDSO if MMU && 64BIT
        select HAVE_IRQ_TIME_ACCOUNTING
+       select HAVE_KERNEL_BZIP2 if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_GZIP if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_LZ4 if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_LZMA if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_LZO if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_UNCOMPRESSED if !XIP_KERNEL && !EFI_ZBOOT
+       select HAVE_KERNEL_ZSTD if !XIP_KERNEL && !EFI_ZBOOT
        select HAVE_KPROBES if !XIP_KERNEL
        select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
        select HAVE_KRETPROBES if !XIP_KERNEL
index c537764ee3c90c9e6ef47ddf3920fd6577621ad5..6ebf505ddd32620abadaa4d67f6e4ef412bc97fb 100644 (file)
@@ -151,6 +151,21 @@ endif
 endif
 endif
 
+boot                                   := arch/riscv/boot
+boot-image-y                           := Image
+boot-image-$(CONFIG_KERNEL_BZIP2)      := Image.bz2
+boot-image-$(CONFIG_KERNEL_GZIP)       := Image.gz
+boot-image-$(CONFIG_KERNEL_LZ4)                := Image.lz4
+boot-image-$(CONFIG_KERNEL_LZMA)       := Image.lzma
+boot-image-$(CONFIG_KERNEL_LZO)                := Image.lzo
+boot-image-$(CONFIG_KERNEL_ZSTD)       := Image.zst
+ifdef CONFIG_RISCV_M_MODE
+boot-image-$(CONFIG_ARCH_CANAAN)       := loader.bin
+endif
+boot-image-$(CONFIG_EFI_ZBOOT)         := vmlinuz.efi
+boot-image-$(CONFIG_XIP_KERNEL)                := xipImage
+KBUILD_IMAGE                           := $(boot)/$(boot-image-y)
+
 libs-y += arch/riscv/lib/
 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
 
@@ -168,21 +183,19 @@ endif
 vdso-install-y                 += arch/riscv/kernel/vdso/vdso.so.dbg
 vdso-install-$(CONFIG_COMPAT)  += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
 
-BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
+BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader loader.bin xipImage vmlinuz.efi
 
 all:   $(notdir $(KBUILD_IMAGE))
 
 loader.bin: loader
-Image.gz loader vmlinuz.efi: Image
+Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader xipImage vmlinuz.efi: Image
+
 $(BOOT_TARGETS): vmlinux
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
        @$(kecho) '  Kernel: $(boot)/$@ is ready'
 
-Image.%: Image
-       $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
-
-install: KBUILD_IMAGE := $(boot)/Image
-zinstall: KBUILD_IMAGE := $(boot)/Image.gz
+# the install target always installs KBUILD_IMAGE (which may be compressed)
+# but keep the zinstall target for compatibility with older releases
 install zinstall:
        $(call cmd,install)
 
index 4c63f3f0643d6a904836e0f5561cd1c041404bc7..a8df7591513aa04c44c0fb9b4acb9feca6d727e7 100755 (executable)
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
-if [ "$(basename $2)" = "Image.gz" ]; then
+case "${2##*/}" in
 # Compressed install
+Image.*|vmlinuz.efi)
   echo "Installing compressed kernel"
   base=vmlinuz
-else
+  ;;
 # Normal install
+*)
   echo "Installing normal kernel"
   base=vmlinux
-fi
+  ;;
+esac
 
 if [ -f $4/$base-$1 ]; then
   mv $4/$base-$1 $4/$base-$1.old