compress kernels with minigzip
cover compress kernels with minigzip
This patch is for building kernels on x86-based Android devices. The binary patches created by its OTA system work much better if the deflate() algorithm inside zlib is used, rather than the older version inside gzip.
This patch was committed against the master branch of Linus' tree.
Andrew Boie (1):
x86: boot: support minigzip bzImage compression
arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 +++ arch/x86/boot/compressed/misc.c | 2 +- init/Kconfig | 18 +++++++++++++++++- scripts/Makefile.lib | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/1 x86: boot: support minigzip bzImage compression
Android OTA system computes very efficient diffs of compressed files if the deflate() algorithm it has access to is the same version as used to create the original file. Here we add support for compressing the kernel with 'minigzip' which uses the deflate() inside zlib. This is much better than using 'gzip' as that tool has a very old version of deflate() inside the gzip codebase instead of linking against zlib.
--- arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 +++ arch/x86/boot/compressed/misc.c | 2 +- init/Kconfig | 18 +++++++++++++++++- scripts/Makefile.lib | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-)
arch/x86/Kconfig +1 -0
@@ -62,6 +62,7 @@ config X86 select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_DMA_API_DEBUG select HAVE_KERNEL_GZIP + select HAVE_KERNEL_MINIGZIP select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_LZMA select HAVE_KERNEL_XZ
arch/x86/boot/compressed/Makefile +3 -0
@@ -56,6 +56,8 @@ vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE $(call if_changed,gzip) +$(obj)/vmlinux.bin.mgz: $(vmlinux.bin.all-y) FORCE + $(call if_changed,minigzip) $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE $(call if_changed,bzip2) $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
@@ -68,6 +70,7 @@ $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE $(call if_changed,lz4) suffix-$(CONFIG_KERNEL_GZIP) := gz +suffix-$(CONFIG_KERNEL_MINIGZIP):= mgz suffix-$(CONFIG_KERNEL_BZIP2) := bz2 suffix-$(CONFIG_KERNEL_LZMA) := lzma suffix-$(CONFIG_KERNEL_XZ) := xz
arch/x86/boot/compressed/misc.c +1 -1
@@ -125,7 +125,7 @@ static char *vidmem;static int vidport;static int lines, cols; -#ifdef CONFIG_KERNEL_GZIP +#if defined(CONFIG_KERNEL_GZIP ) || defined(CONFIG_KERNEL_MINIGZIP )#include "../../../../lib/decompress_inflate.c" #endif
init/Kconfig +17 -1
@@ -100,6 +100,9 @@ config LOCALVERSION_AUTO config HAVE_KERNEL_GZIP bool +config HAVE_KERNEL_MINIGZIP + bool + config HAVE_KERNEL_BZIP2 bool
@@ -118,7 +121,7 @@ config HAVE_KERNEL_LZ4 choice prompt "Kernel compression mode" default KERNEL_GZIP - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_MINIGZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 help The linux kernel is a kind of self-extracting executable. Several compression algorithms are available, which differ
@@ -144,6 +147,19 @@ config KERNEL_GZIP The old and tried gzip compression. It provides a good balance between compression ratio and decompression speed. +config KERNEL_MINIGZIP + bool "Minigzip" + depends on HAVE_KERNEL_MINIGZIP + help + Use minigzip to compress the bzImage. This is very similar to gzip + but uses the zlib library to compress, rather than the very old version + of zlib inside the gzip codebase. This is used for Android kernels + so that the same version of the deflate() algorithm is used when + building the kernel and constructing diffs with OTA applypatch, which + uncompresses sections of files that it detects are gzipped before computing + the diffs. If the versions of deflate() are out of alignment the binary + diffs tend to be very large. + config KERNEL_BZIP2 bool "Bzip2" depends on HAVE_KERNEL_BZIP2
scripts/Makefile.lib +7 -0
@@ -240,6 +240,13 @@ quiet_cmd_gzip = GZIP $@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ (rm -f $@ ; false) +# Minigzip +# --------------------------------------------------------------------------- + +quiet_cmd_minigzip = MINGZIP $@ +cmd_minigzip = (cat $(filter-out FORCE,$^) | minigzip -c -9 > $@) || \ + (rm -f $@ ; false) + # DTC # ---------------------------------------------------------------------------
Signature · 1 line
1.8.3.2
H. Peter Anvin
reviewerRe: [PATCH 1/1] x86: boot: support minigzip bzImage compression
Wouldn't it be better to fix gzip than hacking around this in the kernel?
Quoted 137 lines · Andrew Boie
Android OTA system computes very efficient diffs of compressed files if the
deflate()algorithm it has access to is the same version as used to create the original file. Here we add support for compressing the kernel with 'minigzip' which uses thedeflate()inside zlib. This is much better than using 'gzip' as that tool has a very old version ofdeflate()inside the gzip codebase instead of linking against
zlib.Signed-off-by Andrew Boie <[email protected]>---
arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 +++ arch/x86/boot/compressed/misc.c | 2 +- init/Kconfig | 18 +++++++++++++++++- scripts/Makefile.lib | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-)arch/x86/Kconfig +1
-0@@ -62,6 +62,7 @@ config X86 select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_DMA_API_DEBUG select HAVE_KERNEL_GZIP + select HAVE_KERNEL_MINIGZIP select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_LZMA select HAVE_KERNEL_XZarch/x86/boot/compressed/Makefile +0
-0@@ -56,6 +56,8 @@ vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) +=$(obj)/vmlinux.relocs
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
$(call if_changed,gzip)+$(obj)/vmlinux.bin.mgz: $(vmlinux.bin.all-y) FORCE
arch/x86/boot/compressed/Makefile +1
-0+ $(call if_changed,minigzip)$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
$(call if_changed,bzip2)$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
arch/x86/boot/compressed/Makefile +0
-0@@ -68,6 +70,7 @@ $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE $(call if_changed,lz4)suffix-$(CONFIG_KERNEL_GZIP) := gz
+suffix-$(CONFIG_KERNEL_MINIGZIP):= mgz
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
suffix-$(CONFIG_KERNEL_LZMA) := lzma
suffix-$(CONFIG_KERNEL_XZ) := xzarch/x86/boot/compressed/misc.c +1
-1@@ -125,7 +125,7 @@ static char *vidmem;static int vidport;static int lines, cols; -#ifdef CONFIG_KERNEL_GZIP +#if defined(CONFIG_KERNEL_GZIP ) || defined(CONFIG_KERNEL_MINIGZIP )#include "../../../../lib/decompress_inflate.c" #endif init/Kconfig +0
-0@@ -100,6 +100,9 @@ config LOCALVERSION_AUTOconfig
HAVE_KERNEL_GZIP
boolinit/Kconfig +3
-0+config HAVE_KERNEL_MINIGZIP + bool +config
HAVE_KERNEL_BZIP2
boolinit/Kconfig +0
-0@@ -118,7 +121,7 @@ config HAVE_KERNEL_LZ4choice
prompt "Kernel compression mode"
defaultKERNEL_GZIPinit/Kconfig +0
-1- depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA||
HAVE_KERNEL_XZ||HAVE_KERNEL_LZO||HAVE_KERNEL_LZ4init/Kconfig +1
-0+ depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_MINIGZIP ||
HAVE_KERNEL_BZIP2||HAVE_KERNEL_LZMA||HAVE_KERNEL_XZ||HAVE_KERNEL_LZO||HAVE_KERNEL_LZ4
help
The linux kernel is a kind of self-extracting executable. Several compression algorithms are available, which differinit/Kconfig +6
-0@@ -144,6 +147,19 @@ config KERNEL_GZIP The old and tried gzip compression. It provides a good balance between compression ratio and decompression speed. +config KERNEL_MINIGZIP + bool "Minigzip" + depends on HAVE_KERNEL_MINIGZIP + help + Use minigzip to compress the bzImage. This is very similar to gzip + but uses the zlib library to compress, rather than the very oldversion
init/Kconfig +3
-0+ of zlib inside the gzip codebase. This is used for Android kernels + so that the same version of the deflate() algorithm is used when + building the kernel and constructing diffs with OTA applypatch,which
init/Kconfig +1
-0+ uncompresses sections of files that it detects are gzipped beforecomputing
init/Kconfig +1
-0+ the diffs. If the versions of deflate() are out of alignment thebinary
init/Kconfig +2
-0+ diffs tend to be very large. +config
KERNEL_BZIP2
bool "Bzip2"
depends onHAVE_KERNEL_BZIP2scripts/Makefile.lib +7
-2@@ -240,6 +240,13 @@ quiet_cmd_gzip = GZIP $@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ (rm -f $@ ; false) +# Minigzip +# --------------------------------------------------------------------------- + +quiet_cmd_minigzip = MINGZIP $@ +cmd_minigzip = (cat $(filter-out FORCE,$^) | minigzip -c -9 > $@) || \ + (rm -f $@ ; false) + # DTC # ---------------------------------------------------------------------------
Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
Re: [PATCH 1/1] x86: boot: support minigzip bzImage compression
Quoted 2 lines · H. Peter Anvin
Wouldn't it be better to fix gzip than hacking around this in the kernel?
Or just change the build system to have /bin/gzip point to minigzip if so desired. I have done the same to replace it with pigz. Debian/Ubuntu provides the update-alternatives command for that purpose. If that is not available, just hard-link it.
In general, I don't think it would be a good idea to add tool variant dependencies like this one to the kernel configuration.
Guenter
Quoted 139 lines
Quoted 137 lines · Andrew Boie
Android OTA system computes very efficient diffs of compressed files if the
deflate()algorithm it has access to is the same version as used to create the original file. Here we add support for compressing the kernel with 'minigzip' which uses thedeflate()inside zlib. This is much better than using 'gzip' as that tool has a very old version ofdeflate()inside the gzip codebase instead of linking against
zlib.Signed-off-by Andrew Boie <[email protected]>---
arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 +++ arch/x86/boot/compressed/misc.c | 2 +- init/Kconfig | 18 +++++++++++++++++- scripts/Makefile.lib | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-)arch/x86/Kconfig +1
-0@@ -62,6 +62,7 @@ config X86 select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_DMA_API_DEBUG select HAVE_KERNEL_GZIP + select HAVE_KERNEL_MINIGZIP select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_LZMA select HAVE_KERNEL_XZarch/x86/boot/compressed/Makefile +0
-0@@ -56,6 +56,8 @@ vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) +=$(obj)/vmlinux.relocs
$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
$(call if_changed,gzip)+$(obj)/vmlinux.bin.mgz: $(vmlinux.bin.all-y) FORCE
arch/x86/boot/compressed/Makefile +1
-0+ $(call if_changed,minigzip)$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
$(call if_changed,bzip2)$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
arch/x86/boot/compressed/Makefile +0
-0@@ -68,6 +70,7 @@ $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE $(call if_changed,lz4)suffix-$(CONFIG_KERNEL_GZIP) := gz
+suffix-$(CONFIG_KERNEL_MINIGZIP):= mgz
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
suffix-$(CONFIG_KERNEL_LZMA) := lzma
suffix-$(CONFIG_KERNEL_XZ) := xzarch/x86/boot/compressed/misc.c +1
-1@@ -125,7 +125,7 @@ static char *vidmem;static int vidport;static int lines, cols; -#ifdef CONFIG_KERNEL_GZIP +#if defined(CONFIG_KERNEL_GZIP ) || defined(CONFIG_KERNEL_MINIGZIP )#include "../../../../lib/decompress_inflate.c" #endif init/Kconfig +0
-0@@ -100,6 +100,9 @@ config LOCALVERSION_AUTOconfig
HAVE_KERNEL_GZIP
boolinit/Kconfig +3
-0+config HAVE_KERNEL_MINIGZIP + bool +config
HAVE_KERNEL_BZIP2
boolinit/Kconfig +0
-0@@ -118,7 +121,7 @@ config HAVE_KERNEL_LZ4choice
prompt "Kernel compression mode"
defaultKERNEL_GZIPinit/Kconfig +0
-1- depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA||
HAVE_KERNEL_XZ||HAVE_KERNEL_LZO||HAVE_KERNEL_LZ4init/Kconfig +1
-0+ depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_MINIGZIP ||
HAVE_KERNEL_BZIP2||HAVE_KERNEL_LZMA||HAVE_KERNEL_XZ||HAVE_KERNEL_LZO||HAVE_KERNEL_LZ4
help
The linux kernel is a kind of self-extracting executable. Several compression algorithms are available, which differinit/Kconfig +6
-0@@ -144,6 +147,19 @@ config KERNEL_GZIP The old and tried gzip compression. It provides a good balance between compression ratio and decompression speed. +config KERNEL_MINIGZIP + bool "Minigzip" + depends on HAVE_KERNEL_MINIGZIP + help + Use minigzip to compress the bzImage. This is very similar to gzip + but uses the zlib library to compress, rather than the very oldversion
init/Kconfig +3
-0+ of zlib inside the gzip codebase. This is used for Android kernels + so that the same version of the deflate() algorithm is used when + building the kernel and constructing diffs with OTA applypatch,which
init/Kconfig +1
-0+ uncompresses sections of files that it detects are gzipped beforecomputing
init/Kconfig +1
-0+ the diffs. If the versions of deflate() are out of alignment thebinary
init/Kconfig +2
-0+ diffs tend to be very large. +config
KERNEL_BZIP2
bool "Bzip2"
depends onHAVE_KERNEL_BZIP2scripts/Makefile.lib +7
-2@@ -240,6 +240,13 @@ quiet_cmd_gzip = GZIP $@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ (rm -f $@ ; false) +# Minigzip +# --------------------------------------------------------------------------- + +quiet_cmd_minigzip = MINGZIP $@ +cmd_minigzip = (cat $(filter-out FORCE,$^) | minigzip -c -9 > $@) || \ + (rm -f $@ ; false) + # DTC # ---------------------------------------------------------------------------
Re: [PATCH 1/1] x86: boot: support minigzip bzImage compression
Quoted 5 lines · Guenter Roeck
Quoted 2 lines · H. Peter Anvin
Wouldn't it be better to fix gzip than hacking around this in the kernel?
Or just change the build system to have
/bin/gzippoint to minigzip if so desired. I have done the same to replace it with pigz.
Yes. And if the Makefiles must be patched, then I'd suggest adding a $(GZIP) variable to the main Makefile and using that:
make GZIP=pigz bzImage
make GZIP=minigzip bzImage
Michal
RE: [PATCH 1/1] x86: boot: support minigzip bzImage compression
In reply to Guenter RoeckQuoted 5 lines
From: Guenter Roeck [[email protected]]
Or just change the build system to have/bin/gzippoint to minigzip if so desired. I have done the same to replace it with pigz. Debian/Ubuntu provides the update-alternatives command for that purpose. If that is not available, just hard-link it.
Android minigzip and gzip unfortunately don't have the same command line syntax. Before I wrote this patch I had a horrible hack in place involving a shell script named "gzip" that called minigzip internally.
Andrew
Re: [PATCH 1/1] x86: boot: support minigzip bzImage compression
Quoted 8 lines · Andrew P
Quoted 5 lines
From: Guenter Roeck [[email protected]]
Or just change the build system to have/bin/gzippoint to minigzip if so desired. I have done the same to replace it with pigz. Debian/Ubuntu provides the update-alternatives command for that purpose. If that is not available, just hard-link it.Android minigzip and gzip unfortunately don't have the same command line syntax. Before I wrote this patch I had a horrible hack in place involving a shell script named "gzip" that called minigzip internally.
Why is that a horrible hack ? I think it is better than clogging kernel makefiles with that kind of tools detail. Actually, you have (at least) three other options: fix/update gzip, update minigzip to match the gzip cli, or use a script to map one to the other.
Guenter