[PATCH] arm: Add support for ZSTD compressed kernel

Norbert Lange
2020-08-05T23:06:48Z

* Add support for zstd compressed kernel
* Define __DISABLE_EXPORTS in Makefile
* Bump the heap size for zstd.

This replicates the steps taken for x86 support.

Only if ZSTD is selected, heap size for kernel decompression is
increased, this should guarantee no changes in code / sideeffects for
other compressors.

The patch is so far only tested with Qemu, and some 64MB size limit
exists (might be Qemu specific), but this seems not caused by
this patch (upstream 5.8 and GZIP exhibits similar problems).

Signed-off-by: Norbert Lange <nolange79@gmail.com>
---
arch/arm/Kconfig | 1 +
arch/arm/boot/compressed/Makefile | 2 ++
arch/arm/boot/compressed/decompress.c | 4 ++++
arch/arm/boot/compressed/head.S | 4 ++++
4 files changed, 11 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 2ac74904a3ce..3e853cdc688d 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -93,6 +93,7 @@ config ARM
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_LZO
select HAVE_KERNEL_XZ
+ select HAVE_KERNEL_ZSTD
select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M
select HAVE_KRETPROBES if HAVE_KPROBES
select HAVE_MOD_ARCH_SPECIFIC
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 00602a6fba04..61229e93ea4a 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -75,6 +75,7 @@ compress-$(CONFIG_KERNEL_LZO) = lzo
compress-$(CONFIG_KERNEL_LZMA) = lzma
compress-$(CONFIG_KERNEL_XZ) = xzkern
compress-$(CONFIG_KERNEL_LZ4) = lz4
+compress-$(CONFIG_KERNEL_ZSTD) = zstd22

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

@@ -102,6 +103,7 @@ targets := vmlinux vmlinux.lds piggy_data piggy.o \
clean-files += piggy_data lib1funcs.S ashldi3.S bswapsdi2.S hyp-stub.S

KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
+KBUILD_CFLAGS += -D__DISABLE_EXPORTS

ifeq ($(CONFIG_FUNCTION_TRACER),y)
ORIG_CFLAGS := $(KBUILD_CFLAGS)
diff --git a/arch/arm/boot/compressed/decompress.c b/arch/arm/boot/compressed/decompress.c
index aa075d8372ea..04f77491975a 100644
--- a/arch/arm/boot/compressed/decompress.c
+++ b/arch/arm/boot/compressed/decompress.c
@@ -56,6 +56,10 @@ extern char * strchrnul(const char *, int);
#include "../../../../lib/decompress_unlz4.c"
#endif

+#ifdef CONFIG_KERNEL_ZSTD
+#include "../../../../lib/decompress_unzstd.c"
+#endif
+
int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
{
return __decompress(input, len, NULL, NULL, output, 0, NULL, error);
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 434a16982e34..1af01bfe6638 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -614,7 +614,11 @@ not_relocated: mov r0, #0
*/
mov r0, r4
mov r1, sp @ malloc space above stack
+#if defined(CONFIG_KERNEL_ZSTD)
+ add r2, sp, #0x30000 @ Context needs ~160K
+#else
add r2, sp, #0x10000 @ 64k max
+#endif
mov r3, r7
bl decompress_kernel

--
2.27.0