1 diff --git a/include/linux/decompress/unlzo.h b/include/linux/decompress/unlzo.h
5 +++ b/include/linux/decompress/unlzo.h
7 +#ifndef DECOMPRESS_UNLZO_H
8 +#define DECOMPRESS_UNLZO_H
10 +int unlzo(unsigned char *inbuf, int len,
11 + int(*fill)(void*, unsigned int),
12 + int(*flush)(void*, unsigned int),
13 + unsigned char *output,
15 + void(*error)(char *x));
17 diff --git a/init/Kconfig b/init/Kconfig
18 index f515864..eb65318 100644
21 @@ -115,10 +115,13 @@ config HAVE_KERNEL_BZIP2
22 config HAVE_KERNEL_LZMA
25 +config HAVE_KERNEL_LZO
29 prompt "Kernel compression mode"
31 - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA
32 + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_LZO
34 The linux kernel is a kind of self-extracting executable.
35 Several compression algorithms are available, which differ
36 @@ -141,9 +144,8 @@ config KERNEL_GZIP
38 depends on HAVE_KERNEL_GZIP
40 - The old and tried gzip compression. Its compression ratio is
41 - the poorest among the 3 choices; however its speed (both
42 - compression and decompression) is the fastest.
43 + The old and tried gzip compression. It provides a good balance
44 + between compression ratio and decompression speed.
48 @@ -164,6 +166,14 @@ config KERNEL_LZMA
49 two. Compression is slowest. The kernel size is about 33%
50 smaller with LZMA in comparison to gzip.
54 + depends on HAVE_KERNEL_LZO
56 + Its compression ratio is the poorest among the 4. The kernel
57 + size is about about 10% bigger than gzip; however its speed
58 + (both compression and decompression) is the fastest.
63 diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
65 index 0000000..2bb736f
67 +++ b/lib/decompress_unlzo.c
70 + * LZO decompressor for the Linux kernel. Code borrowed from the lzo
71 + * implementation by Markus Franz Xaver Johannes Oberhumer.
73 + * Linux kernel adaptation:
74 + * Copyright (C) 2009
75 + * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
78 + * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
79 + * All Rights Reserved.
81 + * lzop and the LZO library are free software; you can redistribute them
82 + * and/or modify them under the terms of the GNU General Public License as
83 + * published by the Free Software Foundation; either version 2 of
84 + * the License, or (at your option) any later version.
86 + * This program is distributed in the hope that it will be useful,
87 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 + * GNU General Public License for more details.
91 + * You should have received a copy of the GNU General Public License
92 + * along with this program; see the file COPYING.
93 + * If not, write to the Free Software Foundation, Inc.,
94 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
96 + * Markus F.X.J. Oberhumer
97 + * <markus@oberhumer.com>
98 + * http://www.oberhumer.com/opensource/lzop/
102 +#include "lzo/lzo1x_decompress.c"
104 +#include <linux/slab.h>
105 +#include <linux/decompress/unlzo.h>
108 +#include <linux/types.h>
109 +#include <linux/lzo.h>
110 +#include <linux/decompress/mm.h>
112 +#include <linux/compiler.h>
113 +#include <asm/unaligned.h>
115 +static const unsigned char lzop_magic[] =
116 + { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
118 +#define LZO_BLOCK_SIZE (256*1024l)
119 +#define HEADER_HAS_FILTER 0x00000800L
121 +STATIC inline int INIT parse_header(u8 *input, u8 *skip)
128 + /* read magic: 9 first bits */
129 + for (l = 0; l < 9; l++) {
130 + if (*parse++ != lzop_magic[l])
133 + /* get version (2bytes), skip library version (2),
134 + * 'need to be extracted' version (2) and
136 + version = get_unaligned_be16(parse);
138 + if (version >= 0x0940)
140 + if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
141 + parse += 8; /* flags + filter info */
143 + parse += 4; /* flags */
145 + /* skip mode and mtime_low */
147 + if (version >= 0x0940)
148 + parse += 4; /* skip mtime_high */
151 + /* don't care about the file name, and skip checksum */
154 + *skip = parse - input;
158 +STATIC inline int INIT unlzo(u8 *input, int in_len,
159 + int (*fill) (void *, unsigned int),
160 + int (*flush) (void *, unsigned int),
161 + u8 *output, int *posp,
162 + void (*error_fn) (char *x))
164 + u8 skip = 0, r = 0;
165 + u32 src_len, dst_len;
167 + u8 *in_buf, *in_buf_save, *out_buf;
168 + int obytes_processed = 0;
170 + set_error_fn(error_fn);
175 + error("NULL output pointer and no flush function provided");
178 + out_buf = malloc(LZO_BLOCK_SIZE);
180 + error("Could not allocate output buffer");
185 + if (input && fill) {
186 + error("Both input pointer and fill function provided, don't know what to do");
190 + else if (!fill || !posp) {
191 + error("NULL input pointer and missing position pointer or fill function");
194 + in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
196 + error("Could not allocate input buffer");
200 + in_buf_save = in_buf;
206 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
208 + if (!parse_header(input, &skip)) {
209 + error("invalid header");
218 + /* read uncompressed block size */
219 + dst_len = get_unaligned_be32(in_buf);
222 + /* exit if last block */
223 + if (dst_len == 0) {
229 + if (dst_len > LZO_BLOCK_SIZE) {
230 + error("dest len longer than block size");
234 + /* read compressed block size, and skip block checksum info */
235 + src_len = get_unaligned_be32(in_buf);
238 + if (src_len <= 0 || src_len > dst_len) {
239 + error("file corrupted");
245 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
247 + if (r != LZO_E_OK || dst_len != tmp) {
248 + error("Compressed data violation");
252 + obytes_processed += dst_len;
254 + flush(out_buf, dst_len);
256 + out_buf += dst_len;
258 + *posp += src_len + 12;
260 + in_buf = in_buf_save;
261 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
273 + return obytes_processed;
276 +#define decompress unlzo
277 diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c
278 index 5dc6b29..f2fd098 100644
279 --- a/lib/lzo/lzo1x_decompress.c
280 +++ b/lib/lzo/lzo1x_decompress.c
282 * Richard Purdie <rpurdie@openedhand.com>
286 #include <linux/module.h>
287 #include <linux/kernel.h>
288 -#include <linux/lzo.h>
289 -#include <asm/byteorder.h>
292 #include <asm/unaligned.h>
293 +#include <linux/lzo.h>
296 #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
297 @@ -244,9 +246,10 @@ lookbehind_overrun:
299 return LZO_E_LOOKBEHIND_OVERRUN;
303 EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
305 MODULE_LICENSE("GPL");
306 MODULE_DESCRIPTION("LZO1X Decompressor");
309 diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
310 index ffdafb2..39c3483 100644
311 --- a/scripts/Makefile.lib
312 +++ b/scripts/Makefile.lib
313 @@ -230,3 +230,8 @@ quiet_cmd_lzma = LZMA $@
314 cmd_lzma = (cat $(filter-out FORCE,$^) | \
315 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
318 +quiet_cmd_lzo = LZO $@
319 +cmd_lzo = (cat $(filter-out FORCE,$^) | \
320 + lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \