2 +++ b/include/linux/decompress/unlzo.h
4 +#ifndef DECOMPRESS_UNLZO_H
5 +#define DECOMPRESS_UNLZO_H
7 +int unlzo(unsigned char *inbuf, int len,
8 + int(*fill)(void*, unsigned int),
9 + int(*flush)(void*, unsigned int),
10 + unsigned char *output,
12 + void(*error)(char *x));
16 @@ -115,10 +115,13 @@ config HAVE_KERNEL_BZIP2
17 config HAVE_KERNEL_LZMA
20 +config HAVE_KERNEL_LZO
24 prompt "Kernel compression mode"
26 - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA
27 + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_LZO
29 The linux kernel is a kind of self-extracting executable.
30 Several compression algorithms are available, which differ
31 @@ -141,9 +144,8 @@ config KERNEL_GZIP
33 depends on HAVE_KERNEL_GZIP
35 - The old and tried gzip compression. Its compression ratio is
36 - the poorest among the 3 choices; however its speed (both
37 - compression and decompression) is the fastest.
38 + The old and tried gzip compression. It provides a good balance
39 + between compression ratio and decompression speed.
43 @@ -164,6 +166,14 @@ config KERNEL_LZMA
44 two. Compression is slowest. The kernel size is about 33%
45 smaller with LZMA in comparison to gzip.
49 + depends on HAVE_KERNEL_LZO
51 + Its compression ratio is the poorest among the 4. The kernel
52 + size is about about 10% bigger than gzip; however its speed
53 + (both compression and decompression) is the fastest.
59 +++ b/lib/decompress_unlzo.c
62 + * LZO decompressor for the Linux kernel. Code borrowed from the lzo
63 + * implementation by Markus Franz Xaver Johannes Oberhumer.
65 + * Linux kernel adaptation:
66 + * Copyright (C) 2009
67 + * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
70 + * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
71 + * All Rights Reserved.
73 + * lzop and the LZO library are free software; you can redistribute them
74 + * and/or modify them under the terms of the GNU General Public License as
75 + * published by the Free Software Foundation; either version 2 of
76 + * the License, or (at your option) any later version.
78 + * This program is distributed in the hope that it will be useful,
79 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
80 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81 + * GNU General Public License for more details.
83 + * You should have received a copy of the GNU General Public License
84 + * along with this program; see the file COPYING.
85 + * If not, write to the Free Software Foundation, Inc.,
86 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
88 + * Markus F.X.J. Oberhumer
89 + * <markus@oberhumer.com>
90 + * http://www.oberhumer.com/opensource/lzop/
94 +#include "lzo/lzo1x_decompress.c"
96 +#include <linux/slab.h>
97 +#include <linux/decompress/unlzo.h>
100 +#include <linux/types.h>
101 +#include <linux/lzo.h>
102 +#include <linux/decompress/mm.h>
104 +#include <linux/compiler.h>
105 +#include <asm/unaligned.h>
107 +static const unsigned char lzop_magic[] =
108 + { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
110 +#define LZO_BLOCK_SIZE (256*1024l)
111 +#define HEADER_HAS_FILTER 0x00000800L
113 +STATIC inline int INIT parse_header(u8 *input, u8 *skip)
120 + /* read magic: 9 first bits */
121 + for (l = 0; l < 9; l++) {
122 + if (*parse++ != lzop_magic[l])
125 + /* get version (2bytes), skip library version (2),
126 + * 'need to be extracted' version (2) and
128 + version = get_unaligned_be16(parse);
130 + if (version >= 0x0940)
132 + if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
133 + parse += 8; /* flags + filter info */
135 + parse += 4; /* flags */
137 + /* skip mode and mtime_low */
139 + if (version >= 0x0940)
140 + parse += 4; /* skip mtime_high */
143 + /* don't care about the file name, and skip checksum */
146 + *skip = parse - input;
150 +STATIC inline int INIT unlzo(u8 *input, int in_len,
151 + int (*fill) (void *, unsigned int),
152 + int (*flush) (void *, unsigned int),
153 + u8 *output, int *posp,
154 + void (*error_fn) (char *x))
156 + u8 skip = 0, r = 0;
157 + u32 src_len, dst_len;
159 + u8 *in_buf, *in_buf_save, *out_buf;
160 + int obytes_processed = 0;
162 + set_error_fn(error_fn);
167 + error("NULL output pointer and no flush function provided");
170 + out_buf = malloc(LZO_BLOCK_SIZE);
172 + error("Could not allocate output buffer");
177 + if (input && fill) {
178 + error("Both input pointer and fill function provided, don't know what to do");
182 + else if (!fill || !posp) {
183 + error("NULL input pointer and missing position pointer or fill function");
186 + in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
188 + error("Could not allocate input buffer");
192 + in_buf_save = in_buf;
198 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
200 + if (!parse_header(input, &skip)) {
201 + error("invalid header");
210 + /* read uncompressed block size */
211 + dst_len = get_unaligned_be32(in_buf);
214 + /* exit if last block */
215 + if (dst_len == 0) {
221 + if (dst_len > LZO_BLOCK_SIZE) {
222 + error("dest len longer than block size");
226 + /* read compressed block size, and skip block checksum info */
227 + src_len = get_unaligned_be32(in_buf);
230 + if (src_len <= 0 || src_len > dst_len) {
231 + error("file corrupted");
237 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
239 + if (r != LZO_E_OK || dst_len != tmp) {
240 + error("Compressed data violation");
244 + obytes_processed += dst_len;
246 + flush(out_buf, dst_len);
248 + out_buf += dst_len;
250 + *posp += src_len + 12;
252 + in_buf = in_buf_save;
253 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
265 + return obytes_processed;
268 +#define decompress unlzo
269 --- a/lib/lzo/lzo1x_decompress.c
270 +++ b/lib/lzo/lzo1x_decompress.c
272 * Richard Purdie <rpurdie@openedhand.com>
276 #include <linux/module.h>
277 #include <linux/kernel.h>
278 -#include <linux/lzo.h>
279 -#include <asm/byteorder.h>
282 #include <asm/unaligned.h>
283 +#include <linux/lzo.h>
286 #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
287 @@ -244,9 +246,10 @@ lookbehind_overrun:
289 return LZO_E_LOOKBEHIND_OVERRUN;
293 EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
295 MODULE_LICENSE("GPL");
296 MODULE_DESCRIPTION("LZO1X Decompressor");
299 --- a/scripts/Makefile.lib
300 +++ b/scripts/Makefile.lib
301 @@ -230,3 +230,8 @@ quiet_cmd_lzma = LZMA $@
302 cmd_lzma = (cat $(filter-out FORCE,$^) | \
303 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
306 +quiet_cmd_lzo = LZO $@
307 +cmd_lzo = (cat $(filter-out FORCE,$^) | \
308 + lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \