Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 2/2] x86: Add support for uncompressed kernel images

88 views
Skip to first unread message

Christian Ruppert

unread,
Nov 14, 2013, 3:40:02 AM11/14/13
to
Signed-off-by: Christian Ruppert <christia...@abilis.com>
---
arch/x86/Kconfig | 1 +
arch/x86/boot/compressed/Makefile | 14 ++++++------
arch/x86/boot/compressed/misc.c | 4 ++++
lib/decompress_copy.c | 47 +++++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 7 deletions(-)
create mode 100644 lib/decompress_copy.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f67e839..2a32df9 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -61,6 +61,7 @@ config X86
select USER_STACKTRACE_SUPPORT
select HAVE_REGS_AND_STACK_ACCESS_API
select HAVE_DMA_API_DEBUG
+ select HAVE_KERNEL_UNCOMPRESSED
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_BZIP2
select HAVE_KERNEL_LZMA
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index dcd90df..f65e444 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -67,16 +67,16 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lz4)

-suffix-$(CONFIG_KERNEL_GZIP) := gz
-suffix-$(CONFIG_KERNEL_BZIP2) := bz2
-suffix-$(CONFIG_KERNEL_LZMA) := lzma
-suffix-$(CONFIG_KERNEL_XZ) := xz
-suffix-$(CONFIG_KERNEL_LZO) := lzo
-suffix-$(CONFIG_KERNEL_LZ4) := lz4
+suffix-$(CONFIG_KERNEL_GZIP) := .gz
+suffix-$(CONFIG_KERNEL_BZIP2) := .bz2
+suffix-$(CONFIG_KERNEL_LZMA) := .lzma
+suffix-$(CONFIG_KERNEL_XZ) := .xz
+suffix-$(CONFIG_KERNEL_LZO) := .lzo
+suffix-$(CONFIG_KERNEL_LZ4) := .lz4

quiet_cmd_mkpiggy = MKPIGGY $@
cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )

targets += piggy.S
-$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
+$(obj)/piggy.S: $(obj)/vmlinux.bin$(suffix-y) $(obj)/mkpiggy FORCE
$(call if_changed,mkpiggy)
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 434f077..c210314 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -149,6 +149,10 @@ static int lines, cols;
#include "../../../../lib/decompress_unlz4.c"
#endif

+#ifdef CONFIG_KERNEL_UNCOMPRESSED
+#include "../../../../lib/decompress_copy.c"
+#endif
+
static void scroll(void)
{
int i;
diff --git a/lib/decompress_copy.c b/lib/decompress_copy.c
new file mode 100644
index 0000000..8a41090
--- /dev/null
+++ b/lib/decompress_copy.c
@@ -0,0 +1,47 @@
+#include <linux/decompress/mm.h>
+
+#define NOZIP_BUFSZ (16 * 1024)
+STATIC int INIT nozip(unsigned char *buf, int len,
+ int(*fill)(void*, unsigned int),
+ int(*flush)(void*, unsigned int),
+ unsigned char *outbuf,
+ int *pos,
+ void(*error)(char *x))
+{
+ char *b;
+
+ if (buf)
+ b = buf;
+ else
+ b = malloc(NOZIP_BUFSZ);
+
+ if (!b) {
+ error("Out of memory while allocating buffer");
+ return -1;
+ }
+
+ if (flush) {
+ if (!len)
+ len = fill(b, NOZIP_BUFSZ);
+
+ len = flush(b, len);
+ } else {
+ if (!len)
+ len = fill(outbuf, NOZIP_BUFSZ);
+ else {
+ int i;
+ for (i = 0; i < len; i++)
+ outbuf[i] = b[i];
+ }
+ }
+
+ if (pos)
+ *pos = len;
+
+ if (!buf)
+ free(b);
+
+ return 0;
+}
+
+#define decompress nozip
--
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Christian Ruppert

unread,
Nov 14, 2013, 3:40:03 AM11/14/13
to
Some ARC users say they can boot faster with without kernel compression.
This probably depends on things like the FLASH chip they use etc.

Until now, kernel compression can only be disabled by removing "select
HAVE_<compression>" lines from the architecture Kconfig. So add the
Kconfig logic to permit disabling of kernel compression.

Signed-off-by: Christian Ruppert <christia...@abilis.com>
---
arch/arc/Kconfig | 2 ++
init/Kconfig | 12 +++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 91dbb27..3991f03 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -21,6 +21,8 @@ config ARC
select HAVE_ARCH_KGDB
select HAVE_ARCH_TRACEHOOK
select HAVE_IOREMAP_PROT
+ select HAVE_KERNEL_UNCOMPRESSED
+ select HAVE_KERNEL_GZIP
select HAVE_KPROBES
select HAVE_KRETPROBES
select HAVE_MEMBLOCK
diff --git a/init/Kconfig b/init/Kconfig
index 3ecd8a1..b1a6f92 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -97,6 +97,9 @@ config LOCALVERSION_AUTO

which is done within the script "scripts/setlocalversion".)

+config HAVE_KERNEL_UNCOMPRESSED
+ bool
+
config HAVE_KERNEL_GZIP
bool

@@ -118,7 +121,6 @@ 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
help
The linux kernel is a kind of self-extracting executable.
Several compression algorithms are available, which differ
@@ -137,6 +139,14 @@ choice

If in doubt, select 'gzip'

+config KERNEL_UNCOMPRESSED
+ bool "No compression"
+ depends on HAVE_KERNEL_UNCOMPRESSED || ! ( HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 )
+ help
+ No compression at all. The kernel is huge but the compression and
+ decompression times are zero.
+ This is usually not what you want.
+
config KERNEL_GZIP
bool "Gzip"
depends on HAVE_KERNEL_GZIP

Vineet Gupta

unread,
Nov 14, 2013, 5:30:02 AM11/14/13
to
+CC Sam for Kconfig wisdom

On 11/14/2013 02:08 PM, Christian Ruppert wrote:
> Some ARC users say they can boot faster with without kernel compression.
> This probably depends on things like the FLASH chip they use etc.
>
> Until now, kernel compression can only be disabled by removing "select
> HAVE_<compression>" lines from the architecture Kconfig. So add the
> Kconfig logic to permit disabling of kernel compression.
>
> Signed-off-by: Christian Ruppert <christia...@abilis.com>
> ---
> arch/arc/Kconfig | 2 ++
> init/Kconfig | 12 +++++++++++-
> 2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
> index 91dbb27..3991f03 100644
> --- a/arch/arc/Kconfig
> +++ b/arch/arc/Kconfig
> @@ -21,6 +21,8 @@ config ARC
> select HAVE_ARCH_KGDB
> select HAVE_ARCH_TRACEHOOK
> select HAVE_IOREMAP_PROT
> + select HAVE_KERNEL_UNCOMPRESSED
> + select HAVE_KERNEL_GZIP

Fine.

> select HAVE_KPROBES
> select HAVE_KRETPROBES
> select HAVE_MEMBLOCK
> diff --git a/init/Kconfig b/init/Kconfig
> index 3ecd8a1..b1a6f92 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -97,6 +97,9 @@ config LOCALVERSION_AUTO
>
> which is done within the script "scripts/setlocalversion".)
>
> +config HAVE_KERNEL_UNCOMPRESSED
> + bool
> +

This is good to avoid perturbing other arches.

> config HAVE_KERNEL_GZIP
> bool
>
> @@ -118,7 +121,6 @@ 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
> help
> The linux kernel is a kind of self-extracting executable.
> Several compression algorithms are available, which differ
> @@ -137,6 +139,14 @@ choice
>
> If in doubt, select 'gzip'
>
> +config KERNEL_UNCOMPRESSED
> + bool "No compression"
> + depends on HAVE_KERNEL_UNCOMPRESSED || ! ( HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 )
> + help
> + No compression at all. The kernel is huge but the compression and
> + decompression times are zero.
> + This is usually not what you want.
> +
> config KERNEL_GZIP
> bool "Gzip"
> depends on HAVE_KERNEL_GZIP
>

How about doing this part slightly differently (simpler IMO).
We add uncompressed as just another category rather than being a special case.

Indicative diff against current mainline code

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_BZIP2 || HAVE_KERNEL_LZMA ||
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 || HAVE_KERNEL_UNCOMPRESSED


+config KERNEL_UNCOMPRESSED
+ bool "No compression"
+ depends on HAVE_KERNEL_UNCOMPRESSED
+

-Vineet

H. Peter Anvin

unread,
Nov 14, 2013, 12:40:02 PM11/14/13
to
So it sounds like we're starting from the beginning - I presume that
means the patch currently in the kernel should be reverted first?

-hpa

H. Peter Anvin

unread,
Nov 14, 2013, 12:50:02 PM11/14/13
to
Clever way of doing memcpy(). I know some other compression
implementations open-code memmove(), but using it for the entire data
set in the most common case is atrocious. If we need to get a default
implementation of memmove() we should just do that.

-hpa

Christian Ruppert

unread,
Nov 15, 2013, 4:40:02 AM11/15/13
to
On Thu, Nov 14, 2013 at 09:31:44AM -0800, H. Peter Anvin wrote:
> So it sounds like we're starting from the beginning - I presume that
> means the patch currently in the kernel should be reverted first?

Ack

Christian Ruppert

unread,
Nov 15, 2013, 5:00:02 AM11/15/13
to
Actually, the x86 architecture already contains a basic implementation
of memcpy in its self-decompressor. Correct me if I'm wrong but I guess
memmove is not required since I don't expect the output of a generic
decompression function to overlap with its input.

We can simply use that function if we agree that
. either nozip is x86 specific
. or every architecture using this code must bring along its own memcpy
implementation in its self-decompressor.

Do you think that would be OK?

Greetings,
Christian

H. Peter Anvin

unread,
Nov 15, 2013, 5:10:02 AM11/15/13
to
On 11/15/2013 01:49 AM, Christian Ruppert wrote:
>
> Actually, the x86 architecture already contains a basic implementation
> of memcpy in its self-decompressor. Correct me if I'm wrong but I guess
> memmove is not required since I don't expect the output of a generic
> decompression function to overlap with its input.
>
> We can simply use that function if we agree that
> . either nozip is x86 specific
> . or every architecture using this code must bring along its own memcpy
> implementation in its self-decompressor.
>
> Do you think that would be OK?
>

I think all of them have memcpy().

-hpa

Christian Ruppert

unread,
Nov 15, 2013, 12:00:02 PM11/15/13
to
Good Idea. I fixed this and sent the updated patch directly in reply to
H. Peter's revert patch to avoid too much patch ping-pong:
http://www.spinics.net/lists/kernel/msg1636397.html

Greetings,
Christian

Vineet Gupta

unread,
Nov 16, 2013, 4:50:02 AM11/16/13
to
I didn't see that patch in my mailbox. It needs an ACK from me anyways.

-Vineet
0 new messages