Skip to content

Commit e79dfcb

Browse files
esmilpalmer-dabbelt
authored andcommitted
riscv: make image compression configurable
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 <[email protected]> Signed-off-by: Emil Renner Berthing <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Reviewed-by: Masahiro Yamada <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 0bfbc91 commit e79dfcb

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

arch/riscv/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ config RISCV
140140
select HAVE_GCC_PLUGINS
141141
select HAVE_GENERIC_VDSO if MMU && 64BIT
142142
select HAVE_IRQ_TIME_ACCOUNTING
143+
select HAVE_KERNEL_BZIP2 if !XIP_KERNEL && !EFI_ZBOOT
144+
select HAVE_KERNEL_GZIP if !XIP_KERNEL && !EFI_ZBOOT
145+
select HAVE_KERNEL_LZ4 if !XIP_KERNEL && !EFI_ZBOOT
146+
select HAVE_KERNEL_LZMA if !XIP_KERNEL && !EFI_ZBOOT
147+
select HAVE_KERNEL_LZO if !XIP_KERNEL && !EFI_ZBOOT
148+
select HAVE_KERNEL_UNCOMPRESSED if !XIP_KERNEL && !EFI_ZBOOT
149+
select HAVE_KERNEL_ZSTD if !XIP_KERNEL && !EFI_ZBOOT
143150
select HAVE_KPROBES if !XIP_KERNEL
144151
select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
145152
select HAVE_KRETPROBES if !XIP_KERNEL

arch/riscv/Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ endif
151151
endif
152152
endif
153153

154+
boot := arch/riscv/boot
155+
boot-image-y := Image
156+
boot-image-$(CONFIG_KERNEL_BZIP2) := Image.bz2
157+
boot-image-$(CONFIG_KERNEL_GZIP) := Image.gz
158+
boot-image-$(CONFIG_KERNEL_LZ4) := Image.lz4
159+
boot-image-$(CONFIG_KERNEL_LZMA) := Image.lzma
160+
boot-image-$(CONFIG_KERNEL_LZO) := Image.lzo
161+
boot-image-$(CONFIG_KERNEL_ZSTD) := Image.zst
162+
ifdef CONFIG_RISCV_M_MODE
163+
boot-image-$(CONFIG_ARCH_CANAAN) := loader.bin
164+
endif
165+
boot-image-$(CONFIG_EFI_ZBOOT) := vmlinuz.efi
166+
boot-image-$(CONFIG_XIP_KERNEL) := xipImage
167+
KBUILD_IMAGE := $(boot)/$(boot-image-y)
168+
154169
libs-y += arch/riscv/lib/
155170
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
156171

@@ -168,21 +183,19 @@ endif
168183
vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
169184
vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
170185

171-
BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
186+
BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader loader.bin xipImage vmlinuz.efi
172187

173188
all: $(notdir $(KBUILD_IMAGE))
174189

175190
loader.bin: loader
176-
Image.gz loader vmlinuz.efi: Image
191+
Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader xipImage vmlinuz.efi: Image
192+
177193
$(BOOT_TARGETS): vmlinux
178194
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
179195
@$(kecho) ' Kernel: $(boot)/$@ is ready'
180196

181-
Image.%: Image
182-
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
183-
184-
install: KBUILD_IMAGE := $(boot)/Image
185-
zinstall: KBUILD_IMAGE := $(boot)/Image.gz
197+
# the install target always installs KBUILD_IMAGE (which may be compressed)
198+
# but keep the zinstall target for compatibility with older releases
186199
install zinstall:
187200
$(call cmd,install)
188201

arch/riscv/boot/install.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
# $3 - kernel map file
1818
# $4 - default install path (blank if root directory)
1919

20-
if [ "$(basename $2)" = "Image.gz" ]; then
20+
case "${2##*/}" in
2121
# Compressed install
22+
Image.*|vmlinuz.efi)
2223
echo "Installing compressed kernel"
2324
base=vmlinuz
24-
else
25+
;;
2526
# Normal install
27+
*)
2628
echo "Installing normal kernel"
2729
base=vmlinux
28-
fi
30+
;;
31+
esac
2932

3033
if [ -f $4/$base-$1 ]; then
3134
mv $4/$base-$1 $4/$base-$1.old

0 commit comments

Comments
 (0)