brcm47xx: revert accidentially added EARLY_PRINTK symbol from previous commit
[openwrt.git] / target / linux / generic / patches-2.6.32 / 050-lzo_compressed_kernels.patch
1 --- /dev/null
2 +++ b/include/linux/decompress/unlzo.h
3 @@ -0,0 +1,10 @@
4 +#ifndef DECOMPRESS_UNLZO_H
5 +#define DECOMPRESS_UNLZO_H
6 +
7 +int unlzo(unsigned char *inbuf, int len,
8 + int(*fill)(void*, unsigned int),
9 + int(*flush)(void*, unsigned int),
10 + unsigned char *output,
11 + int *pos,
12 + void(*error)(char *x));
13 +#endif
14 --- a/init/Kconfig
15 +++ b/init/Kconfig
16 @@ -115,10 +115,13 @@ config HAVE_KERNEL_BZIP2
17 config HAVE_KERNEL_LZMA
18 bool
19
20 +config HAVE_KERNEL_LZO
21 + bool
22 +
23 choice
24 prompt "Kernel compression mode"
25 default KERNEL_GZIP
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
28 help
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
32 bool "Gzip"
33 depends on HAVE_KERNEL_GZIP
34 help
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.
40
41 config KERNEL_BZIP2
42 bool "Bzip2"
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.
46
47 +config KERNEL_LZO
48 + bool "LZO"
49 + depends on HAVE_KERNEL_LZO
50 + help
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.
54 +
55 endchoice
56
57 config SWAP
58 --- /dev/null
59 +++ b/lib/decompress_unlzo.c
60 @@ -0,0 +1,208 @@
61 +/*
62 + * LZO decompressor for the Linux kernel. Code borrowed from the lzo
63 + * implementation by Markus Franz Xaver Johannes Oberhumer.
64 + *
65 + * Linux kernel adaptation:
66 + * Copyright (C) 2009
67 + * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
68 + *
69 + * Original code:
70 + * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
71 + * All Rights Reserved.
72 + *
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.
77 + *
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.
82 + *
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.
87 + *
88 + * Markus F.X.J. Oberhumer
89 + * <markus@oberhumer.com>
90 + * http://www.oberhumer.com/opensource/lzop/
91 + */
92 +
93 +#ifdef STATIC
94 +#include "lzo/lzo1x_decompress.c"
95 +#else
96 +#include <linux/slab.h>
97 +#include <linux/decompress/unlzo.h>
98 +#endif
99 +
100 +#include <linux/types.h>
101 +#include <linux/lzo.h>
102 +#include <linux/decompress/mm.h>
103 +
104 +#include <linux/compiler.h>
105 +#include <asm/unaligned.h>
106 +
107 +static const unsigned char lzop_magic[] =
108 + { 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
109 +
110 +#define LZO_BLOCK_SIZE (256*1024l)
111 +#define HEADER_HAS_FILTER 0x00000800L
112 +
113 +STATIC inline int INIT parse_header(u8 *input, u8 *skip)
114 +{
115 + int l;
116 + u8 *parse = input;
117 + u8 level = 0;
118 + u16 version;
119 +
120 + /* read magic: 9 first bits */
121 + for (l = 0; l < 9; l++) {
122 + if (*parse++ != lzop_magic[l])
123 + return 0;
124 + }
125 + /* get version (2bytes), skip library version (2),
126 + * 'need to be extracted' version (2) and
127 + * method (1) */
128 + version = get_unaligned_be16(parse);
129 + parse += 7;
130 + if (version >= 0x0940)
131 + level = *parse++;
132 + if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
133 + parse += 8; /* flags + filter info */
134 + else
135 + parse += 4; /* flags */
136 +
137 + /* skip mode and mtime_low */
138 + parse += 8;
139 + if (version >= 0x0940)
140 + parse += 4; /* skip mtime_high */
141 +
142 + l = *parse++;
143 + /* don't care about the file name, and skip checksum */
144 + parse += l + 4;
145 +
146 + *skip = parse - input;
147 + return 1;
148 +}
149 +
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))
155 +{
156 + u8 skip = 0, r = 0;
157 + u32 src_len, dst_len;
158 + size_t tmp;
159 + u8 *in_buf, *in_buf_save, *out_buf;
160 + int obytes_processed = 0;
161 +
162 + set_error_fn(error_fn);
163 +
164 + if (output)
165 + out_buf = output;
166 + else if (!flush) {
167 + error("NULL output pointer and no flush function provided");
168 + goto exit;
169 + } else {
170 + out_buf = malloc(LZO_BLOCK_SIZE);
171 + if (!out_buf) {
172 + error("Could not allocate output buffer");
173 + goto exit;
174 + }
175 + }
176 +
177 + if (input && fill) {
178 + error("Both input pointer and fill function provided, don't know what to do");
179 + goto exit_1;
180 + } else if (input)
181 + in_buf = input;
182 + else if (!fill || !posp) {
183 + error("NULL input pointer and missing position pointer or fill function");
184 + goto exit_1;
185 + } else {
186 + in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
187 + if (!in_buf) {
188 + error("Could not allocate input buffer");
189 + goto exit_1;
190 + }
191 + }
192 + in_buf_save = in_buf;
193 +
194 + if (posp)
195 + *posp = 0;
196 +
197 + if (fill)
198 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
199 +
200 + if (!parse_header(input, &skip)) {
201 + error("invalid header");
202 + goto exit_2;
203 + }
204 + in_buf += skip;
205 +
206 + if (posp)
207 + *posp = skip;
208 +
209 + for (;;) {
210 + /* read uncompressed block size */
211 + dst_len = get_unaligned_be32(in_buf);
212 + in_buf += 4;
213 +
214 + /* exit if last block */
215 + if (dst_len == 0) {
216 + if (posp)
217 + *posp += 4;
218 + break;
219 + }
220 +
221 + if (dst_len > LZO_BLOCK_SIZE) {
222 + error("dest len longer than block size");
223 + goto exit_2;
224 + }
225 +
226 + /* read compressed block size, and skip block checksum info */
227 + src_len = get_unaligned_be32(in_buf);
228 + in_buf += 8;
229 +
230 + if (src_len <= 0 || src_len > dst_len) {
231 + error("file corrupted");
232 + goto exit_2;
233 + }
234 +
235 + /* decompress */
236 + tmp = dst_len;
237 + r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp);
238 +
239 + if (r != LZO_E_OK || dst_len != tmp) {
240 + error("Compressed data violation");
241 + goto exit_2;
242 + }
243 +
244 + obytes_processed += dst_len;
245 + if (flush)
246 + flush(out_buf, dst_len);
247 + if (output)
248 + out_buf += dst_len;
249 + if (posp)
250 + *posp += src_len + 12;
251 + if (fill) {
252 + in_buf = in_buf_save;
253 + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE));
254 + } else
255 + in_buf += src_len;
256 + }
257 +
258 +exit_2:
259 + if (!input)
260 + free(in_buf);
261 +exit_1:
262 + if (!output)
263 + free(out_buf);
264 +exit:
265 + return obytes_processed;
266 +}
267 +
268 +#define decompress unlzo
269 --- a/lib/lzo/lzo1x_decompress.c
270 +++ b/lib/lzo/lzo1x_decompress.c
271 @@ -11,11 +11,13 @@
272 * Richard Purdie <rpurdie@openedhand.com>
273 */
274
275 +#ifndef STATIC
276 #include <linux/module.h>
277 #include <linux/kernel.h>
278 -#include <linux/lzo.h>
279 -#include <asm/byteorder.h>
280 +#endif
281 +
282 #include <asm/unaligned.h>
283 +#include <linux/lzo.h>
284 #include "lzodefs.h"
285
286 #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
287 @@ -244,9 +246,10 @@ lookbehind_overrun:
288 *out_len = op - out;
289 return LZO_E_LOOKBEHIND_OVERRUN;
290 }
291 -
292 +#ifndef STATIC
293 EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
294
295 MODULE_LICENSE("GPL");
296 MODULE_DESCRIPTION("LZO1X Decompressor");
297
298 +#endif
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,$^))) > $@ || \
304 (rm -f $@ ; false)
305 +
306 +quiet_cmd_lzo = LZO $@
307 +cmd_lzo = (cat $(filter-out FORCE,$^) | \
308 + lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
309 + (rm -f $@ ; false)
This page took 0.062407 seconds and 5 git commands to generate.