kernel: switch to lzo compression
[qi-bootmenu-system.git] / sources / patches / kernel-arm-add-support-for-lzo-compressed-kernels.patch
blob39d24c817a43968815dbd98623db75705f5603df
1 From: Albin Tonnerre <albin.tonnerre@free-electrons.com>
3 This patch series adds generic support for creating and extracting
4 LZO-compressed kernel images, as well as support for using such images on
5 the x86 and ARM architectures, and support for creating and using
6 LZO-compressed initrd and initramfs images.
9 Russell King said:
11 : Testing on a Cortex A9 model:
12 : - lzo decompressor is 65% of the time gzip takes to decompress a kernel
13 : - lzo kernel is 9% larger than a gzip kernel
15 : which I'm happy to say confirms your figures when comparing the two.
17 : However, when comparing your new gzip code to the old gzip code:
18 : - new is 99% of the size of the old code
19 : - new takes 42% of the time to decompress than the old code
21 : What this means is that for a proper comparison, the results get even better:
22 : - lzo is 7.5% larger than the old gzip'd kernel image
23 : - lzo takes 28% of the time that the old gzip code took
25 : So the expense seems definitely worth the effort. The only reason I
26 : can think of ever using gzip would be if you needed the additional
27 : compression (eg, because you have limited flash to store the image.)
29 : I would argue that the default for ARM should therefore be LZO.
32 This patch:
34 The lzo compressor is worse than gzip at compression, but faster at
35 extraction. Here are some figures for an ARM board I'm working on:
37 Uncompressed size: 3.24Mo
38 gzip 1.61Mo 0.72s
39 lzo 1.75Mo 0.48s
41 So for a compression ratio that is still relatively close to gzip, it's
42 much faster to extract, at least in that case.
44 This part contains:
45 - Makefile routine to support lzo compression
46 - Fixes to the existing lzo compressor so that it can be used in
47 compressed kernels
48 - wrapper around the existing lzo1x_decompress, as it only extracts one
49 block at a time, while we need to extract a whole file here
50 - config dialog for kernel compression
52 Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>
53 Tested-by: Wu Zhangjin <wuzhangjin@gmail.com>
54 Cc: "H. Peter Anvin" <hpa@zytor.com>
55 Cc: Ingo Molnar <mingo@elte.hu>
56 Cc: Thomas Gleixner <tglx@linutronix.de>
57 Tested-by: Russell King <rmk@arm.linux.org.uk>
58 Cc: Ralf Baechle <ralf@linux-mips.org>
59 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
60 ---
62 include/linux/decompress/unlzo.h | 10 +
63 init/Kconfig | 18 +-
64 lib/decompress_unlzo.c | 208 +++++++++++++++++++++++++++++
65 lib/lzo/lzo1x_decompress.c | 9 -
66 scripts/Makefile.lib | 5
67 5 files changed, 243 insertions(+), 7 deletions(-)
69 diff -puN /dev/null include/linux/decompress/unlzo.h
70 --- /dev/null
71 +++ a/include/linux/decompress/unlzo.h
72 @@ -0,0 +1,10 @@
73 +#ifndef DECOMPRESS_UNLZO_H
74 +#define DECOMPRESS_UNLZO_H
76 +int unlzo(unsigned char *inbuf, int len,
77 + int(*fill)(void*, unsigned int),
78 + int(*flush)(void*, unsigned int),
79 + unsigned char *output,
80 + int *pos,
81 + void(*error)(char *x));
82 +#endif
83 diff -puN init/Kconfig~lib-add-support-for-lzo-compressed-kernels init/Kconfig
84 --- a/init/Kconfig~lib-add-support-for-lzo-compressed-kernels
85 +++ a/init/Kconfig
86 @@ -123,10 +123,13 @@ config HAVE_KERNEL_BZIP2
87 config HAVE_KERNEL_LZMA
88 bool
90 +config HAVE_KERNEL_LZO
91 + bool
93 choice
94 prompt "Kernel compression mode"
95 default KERNEL_GZIP
96 - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA
97 + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_LZO
98 help
99 The linux kernel is a kind of self-extracting executable.
100 Several compression algorithms are available, which differ
101 @@ -149,9 +152,8 @@ config KERNEL_GZIP
102 bool "Gzip"
103 depends on HAVE_KERNEL_GZIP
104 help
105 - The old and tried gzip compression. Its compression ratio is
106 - the poorest among the 3 choices; however its speed (both
107 - compression and decompression) is the fastest.
108 + The old and tried gzip compression. It provides a good balance
109 + between compression ratio and decompression speed.
111 config KERNEL_BZIP2
112 bool "Bzip2"
113 @@ -172,6 +174,14 @@ config KERNEL_LZMA
114 two. Compression is slowest. The kernel size is about 33%
115 smaller with LZMA in comparison to gzip.
117 +config KERNEL_LZO
118 + bool "LZO"
119 + depends on HAVE_KERNEL_LZO
120 + help
121 + Its compression ratio is the poorest among the 4. The kernel
122 + size is about about 10% bigger than gzip; however its speed
123 + (both compression and decompression) is the fastest.
125 endchoice
127 config SWAP
128 diff -puN /dev/null lib/decompress_unlzo.c
129 --- /dev/null
130 +++ a/lib/decompress_unlzo.c
131 @@ -0,0 +1,208 @@
133 + * LZO decompressor for the Linux kernel. Code borrowed from the lzo
134 + * implementation by Markus Franz Xaver Johannes Oberhumer.
136 + * Linux kernel adaptation:
137 + * Copyright (C) 2009
138 + * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
140 + * Original code:
141 + * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
142 + * All Rights Reserved.
144 + * lzop and the LZO library are free software; you can redistribute them
145 + * and/or modify them under the terms of the GNU General Public License as
146 + * published by the Free Software Foundation; either version 2 of
147 + * the License, or (at your option) any later version.
149 + * This program is distributed in the hope that it will be useful,
150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152 + * GNU General Public License for more details.
154 + * You should have received a copy of the GNU General Public License
155 + * along with this program; see the file COPYING.
156 + * If not, write to the Free Software Foundation, Inc.,
157 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
159 + * Markus F.X.J. Oberhumer
160 + * <markus@oberhumer.com>
161 + * http://www.oberhumer.com/opensource/lzop/
162 + */
164 +#ifdef STATIC
165 +#include "lzo/lzo1x_decompress.c"
166 +#else
167 +#include <linux/slab.h>
168 +#include <linux/decompress/unlzo.h>
169 +#endif
171 +#include <linux/types.h>
172 +#include <linux/lzo.h>
173 +#include <linux/decompress/mm.h>
175 +#include <linux/compiler.h>
176 +#include <asm/unaligned.h>
178 +static const unsigned char lzop_magic[] =
179 + { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
181 +#define LZO_BLOCK_SIZE (256*1024l)
182 +#define HEADER_HAS_FILTER 0x00000800L
184 +STATIC inline int INIT parse_header(u8 *input, u8 *skip)
186 + int l;
187 + u8 *parse = input;
188 + u8 level = 0;
189 + u16 version;
191 + /* read magic: 9 first bits */
192 + for (l = 0; l < 9; l++) {
193 + if (*parse++ != lzop_magic[l])
194 + return 0;
196 + /* get version (2bytes), skip library version (2),
197 + * 'need to be extracted' version (2) and
198 + * method (1) */
199 + version = get_unaligned_be16(parse);
200 + parse += 7;
201 + if (version >= 0x0940)
202 + level = *parse++;
203 + if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
204 + parse += 8; /* flags + filter info */
205 + else
206 + parse += 4; /* flags */
208 + /* skip mode and mtime_low */
209 + parse += 8;
210 + if (version >= 0x0940)
211 + parse += 4; /* skip mtime_high */
213 + l = *parse++;
214 + /* don't care about the file name, and skip checksum */
215 + parse += l + 4;
217 + *skip = parse - input;
218 + return 1;
221 +STATIC inline int INIT unlzo(u8 *input, int in_len,
222 + int (*fill) (void *, unsigned int),
223 + int (*flush) (void *, unsigned int),
224 + u8 *output, int *posp,
225 + void (*error_fn) (char *x))
227 + u8 skip = 0, r = 0;
228 + u32 src_len, dst_len;
229 + size_t tmp;
230 + u8 *in_buf, *in_buf_save, *out_buf;
231 + int obytes_processed = 0;
233 + set_error_fn(error_fn);
235 + if (output)
236 + out_buf = output;
237 + else if (!flush) {
238 + error("NULL output pointer and no flush function provided");
239 + goto exit;
240 + } else {
241 + out_buf = malloc(LZO_BLOCK_SIZE);
242 + if (!out_buf) {
243 + error("Could not allocate output buffer");
244 + goto exit;
248 + if (input && fill) {
249 + error("Both input pointer and fill function provided, don't know what to do");
250 + goto exit_1;
251 + } else if (input)
252 + in_buf = input;
253 + else if (!fill || !posp) {
254 + error("NULL input pointer and missing position pointer or fill function");
255 + goto exit_1;
256 + } else {
257 + in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
258 + if (!in_buf) {
259 + error("Could not allocate input buffer");
260 + goto exit_1;
263 + in_buf_save = in_buf;
265 + if (posp)
266 + *posp = 0;
268 + if (fill)
269 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
271 + if (!parse_header(input, &skip)) {
272 + error("invalid header");
273 + goto exit_2;
275 + in_buf += skip;
277 + if (posp)
278 + *posp = skip;
280 + for (;;) {
281 + /* read uncompressed block size */
282 + dst_len = get_unaligned_be32(in_buf);
283 + in_buf += 4;
285 + /* exit if last block */
286 + if (dst_len == 0) {
287 + if (posp)
288 + *posp += 4;
289 + break;
292 + if (dst_len > LZO_BLOCK_SIZE) {
293 + error("dest len longer than block size");
294 + goto exit_2;
297 + /* read compressed block size, and skip block checksum info */
298 + src_len = get_unaligned_be32(in_buf);
299 + in_buf += 8;
301 + if (src_len <= 0 || src_len > dst_len) {
302 + error("file corrupted");
303 + goto exit_2;
306 + /* decompress */
307 + tmp = dst_len;
308 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
310 + if (r != LZO_E_OK || dst_len != tmp) {
311 + error("Compressed data violation");
312 + goto exit_2;
315 + obytes_processed += dst_len;
316 + if (flush)
317 + flush(out_buf, dst_len);
318 + if (output)
319 + out_buf += dst_len;
320 + if (posp)
321 + *posp += src_len + 12;
322 + if (fill) {
323 + in_buf = in_buf_save;
324 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
325 + } else
326 + in_buf += src_len;
329 +exit_2:
330 + if (!input)
331 + free(in_buf);
332 +exit_1:
333 + if (!output)
334 + free(out_buf);
335 +exit:
336 + return obytes_processed;
339 +#define decompress unlzo
340 diff -puN lib/lzo/lzo1x_decompress.c~lib-add-support-for-lzo-compressed-kernels lib/lzo/lzo1x_decompress.c
341 --- a/lib/lzo/lzo1x_decompress.c~lib-add-support-for-lzo-compressed-kernels
342 +++ a/lib/lzo/lzo1x_decompress.c
343 @@ -11,11 +11,13 @@
344 * Richard Purdie <rpurdie@openedhand.com>
347 +#ifndef STATIC
348 #include <linux/module.h>
349 #include <linux/kernel.h>
350 -#include <linux/lzo.h>
351 -#include <asm/byteorder.h>
352 +#endif
354 #include <asm/unaligned.h>
355 +#include <linux/lzo.h>
356 #include "lzodefs.h"
358 #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
359 @@ -244,9 +246,10 @@ lookbehind_overrun:
360 *out_len = op - out;
361 return LZO_E_LOOKBEHIND_OVERRUN;
364 +#ifndef STATIC
365 EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
367 MODULE_LICENSE("GPL");
368 MODULE_DESCRIPTION("LZO1X Decompressor");
370 +#endif
371 diff -puN scripts/Makefile.lib~lib-add-support-for-lzo-compressed-kernels scripts/Makefile.lib
372 --- a/scripts/Makefile.lib~lib-add-support-for-lzo-compressed-kernels
373 +++ a/scripts/Makefile.lib
374 @@ -235,3 +235,8 @@ quiet_cmd_lzma = LZMA $@
375 cmd_lzma = (cat $(filter-out FORCE,$^) | \
376 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
377 (rm -f $@ ; false)
379 +quiet_cmd_lzo = LZO $@
380 +cmd_lzo = (cat $(filter-out FORCE,$^) | \
381 + lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
382 + (rm -f $@ ; false)
384 From: Albin Tonnerre <albin.tonnerre@free-electrons.com>
386 - changes to ach/arch/boot/Makefile to make it easier to add new
387 compression types
388 - new piggy.lzo.S necessary for lzo compression
389 - changes in arch/arm/boot/compressed/misc.c to allow the use of lzo or
390 gzip, depending on the config
391 - Kconfig support
393 Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>
394 Tested-by: Wu Zhangjin <wuzhangjin@gmail.com>
395 Cc: "H. Peter Anvin" <hpa@zytor.com>
396 Cc: Ingo Molnar <mingo@elte.hu>
397 Cc: Thomas Gleixner <tglx@linutronix.de>
398 Cc: Russell King <rmk@arm.linux.org.uk>
399 Cc: Ralf Baechle <ralf@linux-mips.org>
400 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
403 arch/arm/Kconfig | 2
404 arch/arm/boot/compressed/Makefile | 31 ++++--
405 arch/arm/boot/compressed/misc.c | 116 +++++++-----------------
406 arch/arm/boot/compressed/piggy.S | 6 -
407 arch/arm/boot/compressed/piggy.gzip.S | 6 +
408 arch/arm/boot/compressed/piggy.lzo.S | 6 +
409 6 files changed, 70 insertions(+), 97 deletions(-)
411 diff -puN arch/arm/Kconfig~arm-add-support-for-lzo-compressed-kernels arch/arm/Kconfig
412 --- a/arch/arm/Kconfig~arm-add-support-for-lzo-compressed-kernels
413 +++ a/arch/arm/Kconfig
414 @@ -18,6 +18,8 @@ config ARM
415 select HAVE_KRETPROBES if (HAVE_KPROBES)
416 select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
417 select HAVE_GENERIC_DMA_COHERENT
418 + select HAVE_KERNEL_GZIP
419 + select HAVE_KERNEL_LZO
420 help
421 The ARM series is a line of low-power-consumption RISC chip designs
422 licensed by ARM Ltd and targeted at embedded applications and
423 diff -puN arch/arm/boot/compressed/Makefile~arm-add-support-for-lzo-compressed-kernels arch/arm/boot/compressed/Makefile
424 --- a/arch/arm/boot/compressed/Makefile~arm-add-support-for-lzo-compressed-kernels
425 +++ a/arch/arm/boot/compressed/Makefile
426 @@ -63,8 +63,12 @@ endif
428 SEDFLAGS = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
430 -targets := vmlinux vmlinux.lds piggy.gz piggy.o font.o font.c \
431 - head.o misc.o $(OBJS)
432 +suffix_$(CONFIG_KERNEL_GZIP) = gzip
433 +suffix_$(CONFIG_KERNEL_LZO) = lzo
435 +targets := vmlinux vmlinux.lds \
436 + piggy.$(suffix_y) piggy.$(suffix_y).o \
437 + font.o font.c head.o misc.o $(OBJS)
439 ifeq ($(CONFIG_FUNCTION_TRACER),y)
440 ORIG_CFLAGS := $(KBUILD_CFLAGS)
441 @@ -87,22 +91,31 @@ endif
442 ifneq ($(PARAMS_PHYS),)
443 LDFLAGS_vmlinux += --defsym params_phys=$(PARAMS_PHYS)
444 endif
445 -LDFLAGS_vmlinux += -p --no-undefined -X \
446 - $(shell $(CC) $(KBUILD_CFLAGS) --print-libgcc-file-name) -T
447 +# ?
448 +LDFLAGS_vmlinux += -p
449 +# Report unresolved symbol references
450 +LDFLAGS_vmlinux += --no-undefined
451 +# Delete all temporary local symbols
452 +LDFLAGS_vmlinux += -X
453 +# Next argument is a linker script
454 +LDFLAGS_vmlinux += -T
456 +# For __aeabi_uidivmod
457 +lib1funcs = $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.o
459 # Don't allow any static data in misc.o, which
460 # would otherwise mess up our GOT table
461 CFLAGS_misc.o := -Dstatic=
463 -$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \
464 - $(addprefix $(obj)/, $(OBJS)) FORCE
465 +$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
466 + $(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE
467 $(call if_changed,ld)
470 -$(obj)/piggy.gz: $(obj)/../Image FORCE
471 - $(call if_changed,gzip)
472 +$(obj)/piggy.$(suffix_y): $(obj)/../Image FORCE
473 + $(call if_changed,$(suffix_y))
475 -$(obj)/piggy.o: $(obj)/piggy.gz FORCE
476 +$(obj)/piggy.$(suffix_y).o: $(obj)/piggy.$(suffix_y) FORCE
478 CFLAGS_font.o := -Dstatic=
480 diff -puN arch/arm/boot/compressed/misc.c~arm-add-support-for-lzo-compressed-kernels arch/arm/boot/compressed/misc.c
481 --- a/arch/arm/boot/compressed/misc.c~arm-add-support-for-lzo-compressed-kernels
482 +++ a/arch/arm/boot/compressed/misc.c
483 @@ -18,10 +18,15 @@
485 unsigned int __machine_arch_type;
487 +#define _LINUX_STRING_H_
489 #include <linux/compiler.h> /* for inline */
490 #include <linux/types.h> /* for size_t */
491 #include <linux/stddef.h> /* for NULL */
492 #include <asm/string.h>
493 +#include <linux/linkage.h>
495 +#include <asm/unaligned.h>
497 #ifdef STANDALONE_DEBUG
498 #define putstr printf
499 @@ -188,34 +193,8 @@ static inline __ptr_t memcpy(__ptr_t __d
501 * gzip delarations
503 -#define OF(args) args
504 #define STATIC static
506 -typedef unsigned char uch;
507 -typedef unsigned short ush;
508 -typedef unsigned long ulg;
510 -#define WSIZE 0x8000 /* Window size must be at least 32k, */
511 - /* and a power of two */
513 -static uch *inbuf; /* input buffer */
514 -static uch window[WSIZE]; /* Sliding window buffer */
516 -static unsigned insize; /* valid bytes in inbuf */
517 -static unsigned inptr; /* index of next byte to be processed in inbuf */
518 -static unsigned outcnt; /* bytes in output buffer */
520 -/* gzip flag byte */
521 -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
522 -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
523 -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
524 -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
525 -#define COMMENT 0x10 /* bit 4 set: file comment present */
526 -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
527 -#define RESERVED 0xC0 /* bit 6,7: reserved */
529 -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
531 /* Diagnostic functions */
532 #ifdef DEBUG
533 # define Assert(cond,msg) {if(!(cond)) error(msg);}
534 @@ -233,24 +212,20 @@ static unsigned outcnt; /* bytes in out
535 # define Tracecv(c,x)
536 #endif
538 -static int fill_inbuf(void);
539 -static void flush_window(void);
540 static void error(char *m);
542 extern char input_data[];
543 extern char input_data_end[];
545 -static uch *output_data;
546 -static ulg output_ptr;
547 -static ulg bytes_out;
548 +static unsigned char *output_data;
549 +static unsigned long output_ptr;
551 static void error(char *m);
553 static void putstr(const char *);
555 -extern int end;
556 -static ulg free_mem_ptr;
557 -static ulg free_mem_end_ptr;
558 +static unsigned long free_mem_ptr;
559 +static unsigned long free_mem_end_ptr;
561 #ifdef STANDALONE_DEBUG
562 #define NO_INFLATE_MALLOC
563 @@ -258,46 +233,13 @@ static ulg free_mem_end_ptr;
565 #define ARCH_HAS_DECOMP_WDOG
567 -#include "../../../../lib/inflate.c"
569 -/* ===========================================================================
570 - * Fill the input buffer. This is called only when the buffer is empty
571 - * and at least one byte is really needed.
572 - */
573 -int fill_inbuf(void)
575 - if (insize != 0)
576 - error("ran out of input data");
578 - inbuf = input_data;
579 - insize = &input_data_end[0] - &input_data[0];
581 - inptr = 1;
582 - return inbuf[0];
584 +#ifdef CONFIG_KERNEL_GZIP
585 +#include "../../../../lib/decompress_inflate.c"
586 +#endif
588 -/* ===========================================================================
589 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
590 - * (Used for the decompressed data only.)
591 - */
592 -void flush_window(void)
594 - ulg c = crc;
595 - unsigned n;
596 - uch *in, *out, ch;
598 - in = window;
599 - out = &output_data[output_ptr];
600 - for (n = 0; n < outcnt; n++) {
601 - ch = *out++ = *in++;
602 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
604 - crc = c;
605 - bytes_out += (ulg)outcnt;
606 - output_ptr += (ulg)outcnt;
607 - outcnt = 0;
608 - putstr(".");
610 +#ifdef CONFIG_KERNEL_LZO
611 +#include "../../../../lib/decompress_unlzo.c"
612 +#endif
614 #ifndef arch_error
615 #define arch_error(x)
616 @@ -314,22 +256,33 @@ static void error(char *x)
617 while(1); /* Halt */
620 +asmlinkage void __div0(void)
622 + error("Attempting division by 0!");
625 #ifndef STANDALONE_DEBUG
627 -ulg
628 -decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
629 - int arch_id)
630 +unsigned long
631 +decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
632 + unsigned long free_mem_ptr_end_p,
633 + int arch_id)
635 - output_data = (uch *)output_start; /* Points to kernel start */
636 + unsigned char *tmp;
638 + output_data = (unsigned char *)output_start;
639 free_mem_ptr = free_mem_ptr_p;
640 free_mem_end_ptr = free_mem_ptr_end_p;
641 __machine_arch_type = arch_id;
643 arch_decomp_setup();
645 - makecrc();
646 + tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
647 + output_ptr = get_unaligned_le32(tmp);
649 putstr("Uncompressing Linux...");
650 - gunzip();
651 + decompress(input_data, input_data_end - input_data,
652 + NULL, NULL, output_data, NULL, error);
653 putstr(" done, booting the kernel.\n");
654 return output_ptr;
656 @@ -341,11 +294,10 @@ int main()
658 output_data = output_buffer;
660 - makecrc();
661 putstr("Uncompressing Linux...");
662 - gunzip();
663 + decompress(input_data, input_data_end - input_data,
664 + NULL, NULL, output_data, NULL, error);
665 putstr("done.\n");
666 return 0;
668 #endif
670 diff -puN arch/arm/boot/compressed/piggy.S~arm-add-support-for-lzo-compressed-kernels /dev/null
671 --- a/arch/arm/boot/compressed/piggy.S
672 +++ /dev/null
673 @@ -1,6 +0,0 @@
674 - .section .piggydata,#alloc
675 - .globl input_data
676 -input_data:
677 - .incbin "arch/arm/boot/compressed/piggy.gz"
678 - .globl input_data_end
679 -input_data_end:
680 diff -puN /dev/null arch/arm/boot/compressed/piggy.gzip.S
681 --- /dev/null
682 +++ a/arch/arm/boot/compressed/piggy.gzip.S
683 @@ -0,0 +1,6 @@
684 + .section .piggydata,#alloc
685 + .globl input_data
686 +input_data:
687 + .incbin "arch/arm/boot/compressed/piggy.gzip"
688 + .globl input_data_end
689 +input_data_end:
690 diff -puN /dev/null arch/arm/boot/compressed/piggy.lzo.S
691 --- /dev/null
692 +++ a/arch/arm/boot/compressed/piggy.lzo.S
693 @@ -0,0 +1,6 @@
694 + .section .piggydata,#alloc
695 + .globl input_data
696 +input_data:
697 + .incbin "arch/arm/boot/compressed/piggy.lzo"
698 + .globl input_data_end
699 +input_data_end:
701 From: Albin Tonnerre <albin.tonnerre@free-electrons.com>
703 Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>
704 Tested-by: Wu Zhangjin <wuzhangjin@gmail.com>
705 Cc: "H. Peter Anvin" <hpa@zytor.com>
706 Cc: Ingo Molnar <mingo@elte.hu>
707 Cc: Thomas Gleixner <tglx@linutronix.de>
708 Cc: Russell King <rmk@arm.linux.org.uk>
709 Cc: Ralf Baechle <ralf@linux-mips.org>
710 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
713 lib/Kconfig | 4 ++++
714 lib/Makefile | 1 +
715 lib/decompress.c | 5 +++++
716 usr/Kconfig | 26 +++++++++++++++++++++-----
717 4 files changed, 31 insertions(+), 5 deletions(-)
719 diff -puN lib/Kconfig~add-lzo-compression-support-for-initramfs-and-old-style-initrd lib/Kconfig
720 --- a/lib/Kconfig~add-lzo-compression-support-for-initramfs-and-old-style-initrd
721 +++ a/lib/Kconfig
722 @@ -117,6 +117,10 @@ config DECOMPRESS_BZIP2
723 config DECOMPRESS_LZMA
724 tristate
726 +config DECOMPRESS_LZO
727 + select LZO_DECOMPRESS
728 + tristate
731 # Generic allocator support is selected if needed
733 diff -puN lib/Makefile~add-lzo-compression-support-for-initramfs-and-old-style-initrd lib/Makefile
734 --- a/lib/Makefile~add-lzo-compression-support-for-initramfs-and-old-style-initrd
735 +++ a/lib/Makefile
736 @@ -70,6 +70,7 @@ obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
737 lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
738 lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
739 lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
740 +lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
742 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
743 obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
744 diff -puN lib/decompress.c~add-lzo-compression-support-for-initramfs-and-old-style-initrd lib/decompress.c
745 --- a/lib/decompress.c~add-lzo-compression-support-for-initramfs-and-old-style-initrd
746 +++ a/lib/decompress.c
747 @@ -9,6 +9,7 @@
748 #include <linux/decompress/bunzip2.h>
749 #include <linux/decompress/unlzma.h>
750 #include <linux/decompress/inflate.h>
751 +#include <linux/decompress/unlzo.h>
753 #include <linux/types.h>
754 #include <linux/string.h>
755 @@ -22,6 +23,9 @@
756 #ifndef CONFIG_DECOMPRESS_LZMA
757 # define unlzma NULL
758 #endif
759 +#ifndef CONFIG_DECOMPRESS_LZO
760 +# define unlzo NULL
761 +#endif
763 static const struct compress_format {
764 unsigned char magic[2];
765 @@ -32,6 +36,7 @@ static const struct compress_format {
766 { {037, 0236}, "gzip", gunzip },
767 { {0x42, 0x5a}, "bzip2", bunzip2 },
768 { {0x5d, 0x00}, "lzma", unlzma },
769 + { {0x89, 0x4c}, "lzo", unlzo },
770 { {0, 0}, NULL, NULL }
773 diff -puN usr/Kconfig~add-lzo-compression-support-for-initramfs-and-old-style-initrd usr/Kconfig
774 --- a/usr/Kconfig~add-lzo-compression-support-for-initramfs-and-old-style-initrd
775 +++ a/usr/Kconfig
776 @@ -72,6 +72,15 @@ config RD_LZMA
777 Support loading of a LZMA encoded initial ramdisk or cpio buffer
778 If unsure, say N.
780 +config RD_LZO
781 + bool "Support initial ramdisks compressed using LZO" if EMBEDDED
782 + default !EMBEDDED
783 + depends on BLK_DEV_INITRD
784 + select DECOMPRESS_LZO
785 + help
786 + Support loading of a LZO encoded initial ramdisk or cpio buffer
787 + If unsure, say N.
789 choice
790 prompt "Built-in initramfs compression mode" if INITRAMFS_SOURCE!=""
791 help
792 @@ -108,16 +117,15 @@ config INITRAMFS_COMPRESSION_GZIP
793 bool "Gzip"
794 depends on RD_GZIP
795 help
796 - The old and tried gzip compression. Its compression ratio is
797 - the poorest among the 3 choices; however its speed (both
798 - compression and decompression) is the fastest.
799 + The old and tried gzip compression. It provides a good balance
800 + between compression ratio and decompression speed.
802 config INITRAMFS_COMPRESSION_BZIP2
803 bool "Bzip2"
804 depends on RD_BZIP2
805 help
806 Its compression ratio and speed is intermediate.
807 - Decompression speed is slowest among the three. The initramfs
808 + Decompression speed is slowest among the four. The initramfs
809 size is about 10% smaller with bzip2, in comparison to gzip.
810 Bzip2 uses a large amount of memory. For modern kernels you
811 will need at least 8MB RAM or more for booting.
812 @@ -128,7 +136,15 @@ config INITRAMFS_COMPRESSION_LZMA
813 help
814 The most recent compression algorithm.
815 Its ratio is best, decompression speed is between the other
816 - two. Compression is slowest. The initramfs size is about 33%
817 + three. Compression is slowest. The initramfs size is about 33%
818 smaller with LZMA in comparison to gzip.
820 +config INITRAMFS_COMPRESSION_LZO
821 + bool "LZO"
822 + depends on RD_LZO
823 + help
824 + Its compression ratio is the poorest among the four. The kernel
825 + size is about about 10% bigger than gzip; however its speed
826 + (both compression and decompression) is the fastest.
828 endchoice
830 From: Albin Tonnerre <albin.tonnerre@free-electrons.com>
832 Updated patch to fix the out-of-tree build issue, thanks to Martin Michlmayr
833 and Russell King
835 Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>
836 Cc: Wu Zhangjin <wuzhangjin@gmail.com>
837 Cc: "H. Peter Anvin" <hpa@zytor.com>
838 Cc: Ingo Molnar <mingo@elte.hu>
839 Cc: Thomas Gleixner <tglx@linutronix.de>
840 Cc: Russell King <rmk@arm.linux.org.uk>
841 Cc: Ralf Baechle <ralf@linux-mips.org>
842 Cc: Martin Michlmayr <tbm@cyrius.com>
843 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
846 arch/arm/boot/compressed/Makefile | 5 ++++-
847 1 file changed, 4 insertions(+), 1 deletion(-)
849 diff -puN arch/arm/boot/compressed/Makefile~arm-add-support-for-lzo-compressed-kernels-fix arch/arm/boot/compressed/Makefile
850 --- a/arch/arm/boot/compressed/Makefile~arm-add-support-for-lzo-compressed-kernels-fix
851 +++ a/arch/arm/boot/compressed/Makefile
852 @@ -101,7 +101,10 @@ LDFLAGS_vmlinux += -X
853 LDFLAGS_vmlinux += -T
855 # For __aeabi_uidivmod
856 -lib1funcs = $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.o
857 +lib1funcs = $(obj)/lib1funcs.o
859 +$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
860 + $(call cmd,shipped)
862 # Don't allow any static data in misc.o, which
863 # would otherwise mess up our GOT table
865 From: Andrew Morton <akpm@linux-foundation.org>
867 Cc: "H. Peter Anvin" <hpa@zytor.com>
868 Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
869 Cc: Ingo Molnar <mingo@elte.hu>
870 Cc: Ralf Baechle <ralf@linux-mips.org>
871 Cc: Russell King <rmk@arm.linux.org.uk>
872 Cc: Thomas Gleixner <tglx@linutronix.de>
873 Cc: Wu Zhangjin <wuzhangjin@gmail.com>
874 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
877 lib/decompress_unlzo.c | 8 ++++----
878 1 file changed, 4 insertions(+), 4 deletions(-)
880 diff -puN lib/decompress_unlzo.c~lib-add-support-for-lzo-compressed-kernels-checkpatch-fixes-cleanup lib/decompress_unlzo.c
881 --- a/lib/decompress_unlzo.c~lib-add-support-for-lzo-compressed-kernels-checkpatch-fixes-cleanup
882 +++ a/lib/decompress_unlzo.c
883 @@ -101,9 +101,9 @@ STATIC inline int INIT unlzo(u8 *input,
885 set_error_fn(error_fn);
887 - if (output)
888 + if (output) {
889 out_buf = output;
890 - else if (!flush) {
891 + } else if (!flush) {
892 error("NULL output pointer and no flush function provided");
893 goto exit;
894 } else {
895 @@ -117,9 +117,9 @@ STATIC inline int INIT unlzo(u8 *input,
896 if (input && fill) {
897 error("Both input pointer and fill function provided, don't know what to do");
898 goto exit_1;
899 - } else if (input)
900 + } else if (input) {
901 in_buf = input;
902 - else if (!fill || !posp) {
903 + } else if (!fill || !posp) {
904 error("NULL input pointer and missing position pointer or fill function");
905 goto exit_1;
906 } else {
908 From: Andrew Morton <akpm@linux-foundation.org>
910 ERROR: that open brace { should be on the previous line
911 #184: FILE: lib/decompress_unlzo.c:48:
912 +static const unsigned char lzop_magic[] =
913 + { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
915 WARNING: line over 80 characters
916 #254: FILE: lib/decompress_unlzo.c:118:
917 + error("Both input pointer and fill function provided, don't know what to do");
919 WARNING: line over 80 characters
920 #259: FILE: lib/decompress_unlzo.c:123:
921 + error("NULL input pointer and missing position pointer or fill function");
923 WARNING: line over 80 characters
924 #313: FILE: lib/decompress_unlzo.c:177:
925 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
927 total: 1 errors, 3 warnings, 291 lines checked
929 ./patches/lib-add-support-for-lzo-compressed-kernels.patch has style problems, please review. If any of these errors
930 are false positives report them to the maintainer, see
931 CHECKPATCH in MAINTAINERS.
933 Please run checkpatch prior to sending patches
935 Cc: "H. Peter Anvin" <hpa@zytor.com>
936 Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
937 Cc: Ingo Molnar <mingo@elte.hu>
938 Cc: Ralf Baechle <ralf@linux-mips.org>
939 Cc: Russell King <rmk@arm.linux.org.uk>
940 Cc: Thomas Gleixner <tglx@linutronix.de>
941 Cc: Wu Zhangjin <wuzhangjin@gmail.com>
942 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
945 lib/decompress_unlzo.c | 7 ++++---
946 1 file changed, 4 insertions(+), 3 deletions(-)
948 diff -puN lib/decompress_unlzo.c~lib-add-support-for-lzo-compressed-kernels-checkpatch-fixes lib/decompress_unlzo.c
949 --- a/lib/decompress_unlzo.c~lib-add-support-for-lzo-compressed-kernels-checkpatch-fixes
950 +++ a/lib/decompress_unlzo.c
951 @@ -44,8 +44,8 @@
952 #include <linux/compiler.h>
953 #include <asm/unaligned.h>
955 -static const unsigned char lzop_magic[] =
956 - { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
957 +static const unsigned char lzop_magic[] = {
958 + 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
960 #define LZO_BLOCK_SIZE (256*1024l)
961 #define HEADER_HAS_FILTER 0x00000800L
962 @@ -174,7 +174,8 @@ STATIC inline int INIT unlzo(u8 *input,
964 /* decompress */
965 tmp = dst_len;
966 - r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
967 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len,
968 + out_buf, &tmp);
970 if (r != LZO_E_OK || dst_len != tmp) {
971 error("Compressed data violation");