rev |
line source |
pascal@215
|
1 --- linux-2.6.24.2/arch/x86/boot/compressed/Makefile_32
|
pascal@215
|
2 +++ linux-2.6.24.2/arch/x86/boot/compressed/Makefile_32
|
pascal@215
|
3 @@ -4,7 +4,7 @@
|
pascal@215
|
4 # create a compressed vmlinux image from the original vmlinux
|
pascal@215
|
5 #
|
pascal@215
|
6
|
pascal@215
|
7 -targets := vmlinux vmlinux.bin vmlinux.bin.gz head_32.o misc_32.o piggy.o \
|
pascal@215
|
8 +targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head_32.o misc_32.o piggy.o \
|
pascal@215
|
9 vmlinux.bin.all vmlinux.relocs
|
pascal@215
|
10 EXTRA_AFLAGS := -traditional
|
pascal@215
|
11
|
pascal@215
|
12 @@ -44,7 +44,27 @@ $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bi
|
pascal@215
|
13 $(call if_changed,gzip)
|
pascal@215
|
14 endif
|
pascal@215
|
15
|
pascal@215
|
16 +ifdef CONFIG_RELOCATABLE
|
pascal@215
|
17 +$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin.all FORCE
|
pascal@215
|
18 + $(call if_changed,bzip2)
|
pascal@215
|
19 +else
|
pascal@215
|
20 +$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
|
pascal@215
|
21 + $(call if_changed,bzip2)
|
pascal@215
|
22 +endif
|
pascal@215
|
23 +
|
pascal@215
|
24 +ifdef CONFIG_RELOCATABLE
|
pascal@215
|
25 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
|
pascal@215
|
26 + $(call if_changed,lzma)
|
pascal@215
|
27 +else
|
pascal@215
|
28 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
|
pascal@215
|
29 + $(call if_changed,lzma)
|
pascal@215
|
30 +endif
|
pascal@215
|
31 +
|
pascal@215
|
32 LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
|
pascal@215
|
33
|
pascal@215
|
34 -$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.gz FORCE
|
pascal@215
|
35 +suffix_$(CONFIG_KERNEL_GZIP) = gz
|
pascal@215
|
36 +suffix_$(CONFIG_KERNEL_BZIP2) = bz2
|
pascal@215
|
37 +suffix_$(CONFIG_KERNEL_LZMA) = lzma
|
pascal@215
|
38 +
|
pascal@215
|
39 +$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
|
pascal@215
|
40 $(call if_changed,ld)
|
pascal@215
|
41 --- linux-2.6.24.2/arch/x86/boot/compressed/Makefile_64
|
pascal@215
|
42 +++ linux-2.6.24.2/arch/x86/boot/compressed/Makefile_64
|
pascal@215
|
43 @@ -4,7 +4,7 @@
|
pascal@215
|
44 # create a compressed vmlinux image from the original vmlinux
|
pascal@215
|
45 #
|
pascal@215
|
46
|
pascal@215
|
47 -targets := vmlinux vmlinux.bin vmlinux.bin.gz head_64.o misc_64.o piggy.o
|
pascal@215
|
48 +targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head_64.o misc_64.o piggy.o
|
pascal@215
|
49
|
pascal@215
|
50 KBUILD_CFLAGS := -m64 -D__KERNEL__ $(LINUXINCLUDE) -O2 \
|
pascal@215
|
51 -fno-strict-aliasing -fPIC -mcmodel=small \
|
pascal@215
|
52 --- linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
|
pascal@215
|
53 +++ linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
|
pascal@215
|
54 @@ -121,9 +121,12 @@ typedef unsigned long ulg;
|
pascal@215
|
55 * always be larger than our output buffer.
|
pascal@215
|
56 */
|
pascal@215
|
57
|
pascal@215
|
58 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
59 static uch *inbuf; /* input buffer */
|
pascal@215
|
60 +#endif
|
pascal@215
|
61 static uch *window; /* Sliding window buffer, (and final output buffer) */
|
pascal@215
|
62
|
pascal@215
|
63 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
64 static unsigned insize; /* valid bytes in inbuf */
|
pascal@215
|
65 static unsigned inptr; /* index of next byte to be processed in inbuf */
|
pascal@215
|
66 static unsigned outcnt; /* bytes in output buffer */
|
pascal@215
|
67 @@ -158,9 +161,14 @@ static unsigned outcnt; /* bytes in out
|
pascal@215
|
68
|
pascal@215
|
69 static int fill_inbuf(void);
|
pascal@215
|
70 static void flush_window(void);
|
pascal@215
|
71 +#endif
|
pascal@215
|
72 +
|
pascal@215
|
73 static void error(char *m);
|
pascal@215
|
74 +
|
pascal@215
|
75 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
76 static void gzip_mark(void **);
|
pascal@215
|
77 static void gzip_release(void **);
|
pascal@215
|
78 +#endif
|
pascal@215
|
79
|
pascal@215
|
80 /*
|
pascal@215
|
81 * This is set up by the setup-routine at boot-time
|
pascal@215
|
82 @@ -181,7 +189,9 @@ static long bytes_out = 0;
|
pascal@215
|
83 static void *malloc(int size);
|
pascal@215
|
84 static void free(void *where);
|
pascal@215
|
85
|
pascal@215
|
86 +#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
|
pascal@215
|
87 static void *memset(void *s, int c, unsigned n);
|
pascal@215
|
88 +#endif
|
pascal@215
|
89 static void *memcpy(void *dest, const void *src, unsigned n);
|
pascal@215
|
90
|
pascal@215
|
91 static void putstr(const char *);
|
pascal@215
|
92 @@ -189,7 +199,11 @@ static void putstr(const char *);
|
pascal@215
|
93 static unsigned long free_mem_ptr;
|
pascal@215
|
94 static unsigned long free_mem_end_ptr;
|
pascal@215
|
95
|
pascal@215
|
96 +#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
|
pascal@215
|
97 +#define HEAP_SIZE 0x400000
|
pascal@215
|
98 +#else
|
pascal@215
|
99 #define HEAP_SIZE 0x4000
|
pascal@215
|
100 +#endif
|
pascal@215
|
101
|
pascal@215
|
102 static char *vidmem = (char *)0xb8000;
|
pascal@215
|
103 static int vidport;
|
pascal@215
|
104 @@ -199,7 +213,29 @@ static int lines, cols;
|
pascal@215
|
105 void *xquad_portio;
|
pascal@215
|
106 #endif
|
pascal@215
|
107
|
pascal@215
|
108 +#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
|
pascal@215
|
109 +
|
pascal@215
|
110 +#define large_malloc malloc
|
pascal@215
|
111 +#define large_free free
|
pascal@215
|
112 +
|
pascal@215
|
113 +#ifdef current
|
pascal@215
|
114 +#undef current
|
pascal@215
|
115 +#endif
|
pascal@215
|
116 +
|
pascal@215
|
117 +#define INCLUDED
|
pascal@215
|
118 +#endif
|
pascal@215
|
119 +
|
pascal@215
|
120 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
121 #include "../../../../lib/inflate.c"
|
pascal@215
|
122 +#endif
|
pascal@215
|
123 +
|
pascal@215
|
124 +#ifdef CONFIG_KERNEL_BZIP2
|
pascal@215
|
125 +#include "../../../../lib/decompress_bunzip2.c"
|
pascal@215
|
126 +#endif
|
pascal@215
|
127 +
|
pascal@215
|
128 +#ifdef CONFIG_KERNEL_LZMA
|
pascal@215
|
129 +#include "../../../../lib/decompress_unlzma.c"
|
pascal@215
|
130 +#endif
|
pascal@215
|
131
|
pascal@215
|
132 static void *malloc(int size)
|
pascal@215
|
133 {
|
pascal@215
|
134 @@ -223,6 +259,7 @@ static void free(void *where)
|
pascal@215
|
135 { /* Don't care */
|
pascal@215
|
136 }
|
pascal@215
|
137
|
pascal@215
|
138 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
139 static void gzip_mark(void **ptr)
|
pascal@215
|
140 {
|
pascal@215
|
141 *ptr = (void *) free_mem_ptr;
|
pascal@215
|
142 @@ -232,6 +269,7 @@ static void gzip_release(void **ptr)
|
pascal@215
|
143 {
|
pascal@215
|
144 free_mem_ptr = (unsigned long) *ptr;
|
pascal@215
|
145 }
|
pascal@215
|
146 +#endif
|
pascal@215
|
147
|
pascal@215
|
148 static void scroll(void)
|
pascal@215
|
149 {
|
pascal@215
|
150 @@ -282,6 +320,7 @@ static void putstr(const char *s)
|
pascal@215
|
151 outb_p(0xff & (pos >> 1), vidport+1);
|
pascal@215
|
152 }
|
pascal@215
|
153
|
pascal@215
|
154 +#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
|
pascal@215
|
155 static void* memset(void* s, int c, unsigned n)
|
pascal@215
|
156 {
|
pascal@215
|
157 int i;
|
pascal@215
|
158 @@ -290,6 +329,7 @@ static void* memset(void* s, int c, unsi
|
pascal@215
|
159 for (i=0;i<n;i++) ss[i] = c;
|
pascal@215
|
160 return s;
|
pascal@215
|
161 }
|
pascal@215
|
162 +#endif
|
pascal@215
|
163
|
pascal@215
|
164 static void* memcpy(void* dest, const void* src, unsigned n)
|
pascal@215
|
165 {
|
pascal@215
|
166 @@ -300,6 +340,26 @@ static void* memcpy(void* dest, const vo
|
pascal@215
|
167 return dest;
|
pascal@215
|
168 }
|
pascal@215
|
169
|
pascal@215
|
170 +#ifndef CONFIG_KERNEL_GZIP
|
pascal@215
|
171 +/* ===========================================================================
|
pascal@215
|
172 + * Write the output window window[0..outcnt-1] and update bytes_out.
|
pascal@215
|
173 + * (Used for the decompressed data only.)
|
pascal@215
|
174 + */
|
pascal@215
|
175 +static int compr_flush(char *data, unsigned int len)
|
pascal@215
|
176 +{
|
pascal@215
|
177 + unsigned n;
|
pascal@215
|
178 + uch *out;
|
pascal@215
|
179 +
|
pascal@215
|
180 + out = window;
|
pascal@215
|
181 + for (n = 0; n < len; n++) {
|
pascal@215
|
182 + *out++ = *data++;
|
pascal@215
|
183 + }
|
pascal@215
|
184 + bytes_out += (ulg)len;
|
pascal@215
|
185 + window += (ulg)len;
|
pascal@215
|
186 + return len;
|
pascal@215
|
187 +}
|
pascal@215
|
188 +
|
pascal@215
|
189 +#else
|
pascal@215
|
190 /* ===========================================================================
|
pascal@215
|
191 * Fill the input buffer. This is called only when the buffer is empty
|
pascal@215
|
192 * and at least one byte is really needed.
|
pascal@215
|
193 @@ -332,6 +392,7 @@ static void flush_window(void)
|
pascal@215
|
194 bytes_out += (ulg)outcnt;
|
pascal@215
|
195 outcnt = 0;
|
pascal@215
|
196 }
|
pascal@215
|
197 +#endif
|
pascal@215
|
198
|
pascal@215
|
199 static void error(char *x)
|
pascal@215
|
200 {
|
pascal@215
|
201 @@ -361,9 +422,11 @@ asmlinkage void decompress_kernel(void *
|
pascal@215
|
202 window = output; /* Output buffer (Normally at 1M) */
|
pascal@215
|
203 free_mem_ptr = end; /* Heap */
|
pascal@215
|
204 free_mem_end_ptr = end + HEAP_SIZE;
|
pascal@215
|
205 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
206 inbuf = input_data; /* Input buffer */
|
pascal@215
|
207 insize = input_len;
|
pascal@215
|
208 inptr = 0;
|
pascal@215
|
209 +#endif
|
pascal@215
|
210
|
pascal@215
|
211 if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1))
|
pascal@215
|
212 error("Destination address not CONFIG_PHYSICAL_ALIGN aligned");
|
pascal@215
|
213 @@ -374,9 +437,21 @@ asmlinkage void decompress_kernel(void *
|
pascal@215
|
214 error("Wrong destination address");
|
pascal@215
|
215 #endif
|
pascal@215
|
216
|
pascal@215
|
217 +#ifdef CONFIG_KERNEL_BZIP2
|
pascal@215
|
218 + putstr("Bunzipping Linux... ");
|
pascal@215
|
219 + bunzip2(input_data, input_len-4, NULL, compr_flush, NULL);
|
pascal@215
|
220 +#endif
|
pascal@215
|
221 +
|
pascal@215
|
222 +#ifdef CONFIG_KERNEL_LZMA
|
pascal@215
|
223 + putstr("Unlzmaing Linux... ");
|
pascal@215
|
224 + unlzma(input_data, input_len-4, NULL, compr_flush, NULL);
|
pascal@215
|
225 +#endif
|
pascal@215
|
226 +
|
pascal@215
|
227 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
228 makecrc();
|
pascal@215
|
229 putstr("Uncompressing Linux... ");
|
pascal@215
|
230 gunzip();
|
pascal@215
|
231 +#endif
|
pascal@215
|
232 putstr("Ok, booting the kernel.\n");
|
pascal@215
|
233 return;
|
pascal@215
|
234 }
|
pascal@215
|
235 --- linux-2.6.24.2/arch/x86/boot/compressed/misc_64.c
|
pascal@215
|
236 +++ linux-2.6.24.2/arch/x86/boot/compressed/misc_64.c
|
pascal@215
|
237 @@ -121,9 +121,12 @@ typedef unsigned long ulg;
|
pascal@215
|
238 * always be larger than our output buffer.
|
pascal@215
|
239 */
|
pascal@215
|
240
|
pascal@215
|
241 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
242 static uch *inbuf; /* input buffer */
|
pascal@215
|
243 +#endif
|
pascal@215
|
244 static uch *window; /* Sliding window buffer, (and final output buffer) */
|
pascal@215
|
245
|
pascal@215
|
246 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
247 static unsigned insize; /* valid bytes in inbuf */
|
pascal@215
|
248 static unsigned inptr; /* index of next byte to be processed in inbuf */
|
pascal@215
|
249 static unsigned outcnt; /* bytes in output buffer */
|
pascal@215
|
250 @@ -158,9 +161,14 @@ static unsigned outcnt; /* bytes in out
|
pascal@215
|
251
|
pascal@215
|
252 static int fill_inbuf(void);
|
pascal@215
|
253 static void flush_window(void);
|
pascal@215
|
254 +#endif
|
pascal@215
|
255 +
|
pascal@215
|
256 static void error(char *m);
|
pascal@215
|
257 +
|
pascal@215
|
258 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
259 static void gzip_mark(void **);
|
pascal@215
|
260 static void gzip_release(void **);
|
pascal@215
|
261 +#endif
|
pascal@215
|
262
|
pascal@215
|
263 /*
|
pascal@215
|
264 * This is set up by the setup-routine at boot-time
|
pascal@215
|
265 @@ -173,15 +181,19 @@ static unsigned char *real_mode; /* Poin
|
pascal@215
|
266 #endif
|
pascal@215
|
267 #define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))
|
pascal@215
|
268
|
pascal@215
|
269 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
270 extern unsigned char input_data[];
|
pascal@215
|
271 extern int input_len;
|
pascal@215
|
272 +#endif
|
pascal@215
|
273
|
pascal@215
|
274 static long bytes_out = 0;
|
pascal@215
|
275
|
pascal@215
|
276 static void *malloc(int size);
|
pascal@215
|
277 static void free(void *where);
|
pascal@215
|
278
|
pascal@215
|
279 +#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
|
pascal@215
|
280 static void *memset(void *s, int c, unsigned n);
|
pascal@215
|
281 +#endif
|
pascal@215
|
282 static void *memcpy(void *dest, const void *src, unsigned n);
|
pascal@215
|
283
|
pascal@215
|
284 static void putstr(const char *);
|
pascal@215
|
285 @@ -189,13 +201,39 @@ static void putstr(const char *);
|
pascal@215
|
286 static long free_mem_ptr;
|
pascal@215
|
287 static long free_mem_end_ptr;
|
pascal@215
|
288
|
pascal@215
|
289 +#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
|
pascal@215
|
290 +#define HEAP_SIZE 0x400000
|
pascal@215
|
291 +#else
|
pascal@215
|
292 #define HEAP_SIZE 0x7000
|
pascal@215
|
293 +#endif
|
pascal@215
|
294
|
pascal@215
|
295 static char *vidmem = (char *)0xb8000;
|
pascal@215
|
296 static int vidport;
|
pascal@215
|
297 static int lines, cols;
|
pascal@215
|
298
|
pascal@215
|
299 +#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA)
|
pascal@215
|
300 +
|
pascal@215
|
301 +#define large_malloc malloc
|
pascal@215
|
302 +#define large_free free
|
pascal@215
|
303 +
|
pascal@215
|
304 +#ifdef current
|
pascal@215
|
305 +#undef current
|
pascal@215
|
306 +#endif
|
pascal@215
|
307 +
|
pascal@215
|
308 +#define INCLUDED
|
pascal@215
|
309 +#endif
|
pascal@215
|
310 +
|
pascal@215
|
311 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
312 #include "../../../../lib/inflate.c"
|
pascal@215
|
313 +#endif
|
pascal@215
|
314 +
|
pascal@215
|
315 +#ifdef CONFIG_KERNEL_BZIP2
|
pascal@215
|
316 +#include "../../../../lib/decompress_bunzip2.c"
|
pascal@215
|
317 +#endif
|
pascal@215
|
318 +
|
pascal@215
|
319 +#ifdef CONFIG_KERNEL_LZMA
|
pascal@215
|
320 +#include "../../../../lib/decompress_unlzma.c"
|
pascal@215
|
321 +#endif
|
pascal@215
|
322
|
pascal@215
|
323 static void *malloc(int size)
|
pascal@215
|
324 {
|
pascal@215
|
325 @@ -219,6 +257,7 @@ static void free(void *where)
|
pascal@215
|
326 { /* Don't care */
|
pascal@215
|
327 }
|
pascal@215
|
328
|
pascal@215
|
329 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
330 static void gzip_mark(void **ptr)
|
pascal@215
|
331 {
|
pascal@215
|
332 *ptr = (void *) free_mem_ptr;
|
pascal@215
|
333 @@ -228,6 +267,7 @@ static void gzip_release(void **ptr)
|
pascal@215
|
334 {
|
pascal@215
|
335 free_mem_ptr = (long) *ptr;
|
pascal@215
|
336 }
|
pascal@215
|
337 +#endif
|
pascal@215
|
338
|
pascal@215
|
339 static void scroll(void)
|
pascal@215
|
340 {
|
pascal@215
|
341 @@ -275,6 +315,7 @@ static void putstr(const char *s)
|
pascal@215
|
342 outb_p(0xff & (pos >> 1), vidport+1);
|
pascal@215
|
343 }
|
pascal@215
|
344
|
pascal@215
|
345 +#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2)
|
pascal@215
|
346 static void* memset(void* s, int c, unsigned n)
|
pascal@215
|
347 {
|
pascal@215
|
348 int i;
|
pascal@215
|
349 @@ -283,6 +324,7 @@ static void* memset(void* s, int c, unsi
|
pascal@215
|
350 for (i=0;i<n;i++) ss[i] = c;
|
pascal@215
|
351 return s;
|
pascal@215
|
352 }
|
pascal@215
|
353 +#endif
|
pascal@215
|
354
|
pascal@215
|
355 static void* memcpy(void* dest, const void* src, unsigned n)
|
pascal@215
|
356 {
|
pascal@215
|
357 @@ -293,6 +335,26 @@ static void* memcpy(void* dest, const vo
|
pascal@215
|
358 return dest;
|
pascal@215
|
359 }
|
pascal@215
|
360
|
pascal@215
|
361 +#ifndef CONFIG_KERNEL_GZIP
|
pascal@215
|
362 +/* ===========================================================================
|
pascal@215
|
363 + * Write the output window window[0..outcnt-1] and update bytes_out.
|
pascal@215
|
364 + * (Used for the decompressed data only.)
|
pascal@215
|
365 + */
|
pascal@215
|
366 +static int compr_flush(char *data, unsigned int len)
|
pascal@215
|
367 +{
|
pascal@215
|
368 + unsigned n;
|
pascal@215
|
369 + uch *out;
|
pascal@215
|
370 +
|
pascal@215
|
371 + out = window;
|
pascal@215
|
372 + for (n = 0; n < len; n++) {
|
pascal@215
|
373 + *out++ = *data++;
|
pascal@215
|
374 + }
|
pascal@215
|
375 + bytes_out += (ulg)len;
|
pascal@215
|
376 + window += (ulg)len;
|
pascal@215
|
377 + return len;
|
pascal@215
|
378 +}
|
pascal@215
|
379 +
|
pascal@215
|
380 +#else
|
pascal@215
|
381 /* ===========================================================================
|
pascal@215
|
382 * Fill the input buffer. This is called only when the buffer is empty
|
pascal@215
|
383 * and at least one byte is really needed.
|
pascal@215
|
384 @@ -325,6 +387,7 @@ static void flush_window(void)
|
pascal@215
|
385 bytes_out += (ulg)outcnt;
|
pascal@215
|
386 outcnt = 0;
|
pascal@215
|
387 }
|
pascal@215
|
388 +#endif
|
pascal@215
|
389
|
pascal@215
|
390 static void error(char *x)
|
pascal@215
|
391 {
|
pascal@215
|
392 @@ -363,9 +426,21 @@ asmlinkage void decompress_kernel(void *
|
pascal@215
|
393 if ((ulg)output >= 0xffffffffffUL)
|
pascal@215
|
394 error("Destination address too large");
|
pascal@215
|
395
|
pascal@215
|
396 +#ifdef CONFIG_KERNEL_BZIP2
|
pascal@215
|
397 + putstr(".\nBunzipping Linux...");
|
pascal@215
|
398 + bunzip2(input_data, input_len-4, NULL, compr_flush, NULL);
|
pascal@215
|
399 +#endif
|
pascal@215
|
400 +
|
pascal@215
|
401 +#ifdef CONFIG_KERNEL_LZMA
|
pascal@215
|
402 + putstr(".\nUnlzmaing Linux...");
|
pascal@215
|
403 + unlzma(input_data, input_len-4, NULL, compr_flush, NULL);
|
pascal@215
|
404 +#endif
|
pascal@215
|
405 +
|
pascal@215
|
406 +#ifdef CONFIG_KERNEL_GZIP
|
pascal@215
|
407 makecrc();
|
pascal@215
|
408 putstr(".\nDecompressing Linux...");
|
pascal@215
|
409 gunzip();
|
pascal@215
|
410 +#endif
|
pascal@215
|
411 putstr("done.\nBooting the kernel.\n");
|
pascal@215
|
412 return;
|
pascal@215
|
413 }
|
pascal@215
|
414 --- linux-2.6.24.2/drivers/block/Kconfig
|
pascal@215
|
415 +++ linux-2.6.24.2/drivers/block/Kconfig
|
pascal@215
|
416 @@ -356,6 +356,30 @@ config BLK_DEV_RAM_BLOCKSIZE
|
pascal@215
|
417 setups function - apparently needed by the rd_load_image routine
|
pascal@215
|
418 that supposes the filesystem in the image uses a 1024 blocksize.
|
pascal@215
|
419
|
pascal@215
|
420 +config RD_BZIP2
|
pascal@215
|
421 + bool "Initial ramdisk compressed using bzip2"
|
pascal@215
|
422 + default n
|
pascal@215
|
423 + depends on BLK_DEV_INITRD=y
|
pascal@215
|
424 + help
|
pascal@215
|
425 + Support loading of a bzip2 encoded initial ramdisk or cpio buffer
|
pascal@215
|
426 + If unsure, say N.
|
pascal@215
|
427 +
|
pascal@215
|
428 +config RD_LZMA
|
pascal@215
|
429 + bool "Initial ramdisk compressed using lzma"
|
pascal@215
|
430 + default n
|
pascal@215
|
431 + depends on BLK_DEV_INITRD=y
|
pascal@215
|
432 + help
|
pascal@215
|
433 + Support loading of a lzma encoded initial ramdisk or cpio buffer
|
pascal@215
|
434 + If unsure, say N.
|
pascal@215
|
435 +
|
pascal@215
|
436 +config RD_GZIP
|
pascal@215
|
437 + bool "Initial ramdisk compressed using gzip"
|
pascal@215
|
438 + default y
|
pascal@215
|
439 + depends on BLK_DEV_INITRD=y
|
pascal@215
|
440 + help
|
pascal@215
|
441 + Support loading of a gzip encoded initial ramdisk or cpio buffer.
|
pascal@215
|
442 + If unsure, say Y.
|
pascal@215
|
443 +
|
pascal@215
|
444 config CDROM_PKTCDVD
|
pascal@215
|
445 tristate "Packet writing on CD/DVD media"
|
pascal@215
|
446 depends on !UML
|
pascal@215
|
447 --- linux-2.6.24.2/include/linux/decompress_bunzip2.h
|
pascal@215
|
448 +++ linux-2.6.24.2/include/linux/decompress_bunzip2.h
|
pascal@215
|
449 @@ -0,0 +1,16 @@
|
pascal@215
|
450 +#ifndef DECOMPRESS_BUNZIP2_H
|
pascal@215
|
451 +#define DECOMPRESS_BUNZIP2_H
|
pascal@215
|
452 +
|
pascal@215
|
453 +/* Other housekeeping constants */
|
pascal@215
|
454 +#define BZIP2_IOBUF_SIZE 4096
|
pascal@215
|
455 +
|
pascal@215
|
456 +#ifndef STATIC
|
pascal@215
|
457 +#define STATIC /**/
|
pascal@215
|
458 +#endif
|
pascal@215
|
459 +
|
pascal@215
|
460 +STATIC int bunzip2(char *inbuf, int len,
|
pascal@215
|
461 + int(*fill)(void*,unsigned int),
|
pascal@215
|
462 + int(*writebb)(char*,unsigned int),
|
pascal@215
|
463 + int *pos);
|
pascal@215
|
464 +
|
pascal@215
|
465 +#endif
|
pascal@215
|
466 --- linux-2.6.24.2/include/linux/decompress_generic.h
|
pascal@215
|
467 +++ linux-2.6.24.2/include/linux/decompress_generic.h
|
pascal@215
|
468 @@ -0,0 +1,28 @@
|
pascal@215
|
469 +#ifndef DECOMPRESS_GENERIC_H
|
pascal@215
|
470 +#define DECOMPRESS_GENERIC_H
|
pascal@215
|
471 +
|
pascal@215
|
472 +/* Minimal chunksize to be read.
|
pascal@215
|
473 + * Bzip2 prefers at least 4096
|
pascal@215
|
474 + * Lzma prefers 0x10000 */
|
pascal@215
|
475 +#define COMPR_IOBUF_SIZE 4096
|
pascal@215
|
476 +
|
pascal@215
|
477 +typedef int (*uncompress_fn) (char *inbuf, int len,
|
pascal@215
|
478 + int(*fill)(char*,unsigned int),
|
pascal@215
|
479 + int(*writebb)(char*,unsigned int),
|
pascal@215
|
480 + int *posp);
|
pascal@215
|
481 +
|
pascal@215
|
482 +/* inbuf - input buffer
|
pascal@215
|
483 + * len - len of pre-read data in inbuf
|
pascal@215
|
484 + * fill - function to fill inbuf if empty
|
pascal@215
|
485 + * writebb - function to write out outbug
|
pascal@215
|
486 + * posp - if non-null, input position (number of bytes read) will be
|
pascal@215
|
487 + * returned here
|
pascal@215
|
488 + *
|
pascal@215
|
489 + * If len != 0, the inbuf is initialized (with as much data), and fill
|
pascal@215
|
490 + * should not be called
|
pascal@215
|
491 + * If len = 0, the inbuf is allocated, but empty. Its size is IOBUF_SIZE
|
pascal@215
|
492 + * fill should be called (repeatedly...) to read data, at most IOBUF_SIZE
|
pascal@215
|
493 + */
|
pascal@215
|
494 +
|
pascal@215
|
495 +
|
pascal@215
|
496 +#endif
|
pascal@215
|
497 --- linux-2.6.24.2/include/linux/decompress_unlzma.h
|
pascal@215
|
498 +++ linux-2.6.24.2/include/linux/decompress_unlzma.h
|
pascal@215
|
499 @@ -0,0 +1,15 @@
|
pascal@215
|
500 +#ifndef DECOMPRESS_UNLZMA_H
|
pascal@215
|
501 +#define DECOMPRESS_UNLZMA_H
|
pascal@215
|
502 +
|
pascal@215
|
503 +#define LZMA_IOBUF_SIZE 0x10000
|
pascal@215
|
504 +
|
pascal@215
|
505 +#ifndef STATIC
|
pascal@215
|
506 +#define STATIC /**/
|
pascal@215
|
507 +#endif
|
pascal@215
|
508 +
|
pascal@215
|
509 +STATIC int unlzma(char *inbuf, int len,
|
pascal@215
|
510 + int(*fill)(void*,unsigned int),
|
pascal@215
|
511 + int(*writebb)(char*,unsigned int),
|
pascal@215
|
512 + int *pos);
|
pascal@215
|
513 +
|
pascal@215
|
514 +#endif
|
pascal@215
|
515 --- linux-2.6.24.2/init/do_mounts_rd.c
|
pascal@215
|
516 +++ linux-2.6.24.2/init/do_mounts_rd.c
|
pascal@215
|
517 @@ -8,6 +8,16 @@
|
pascal@215
|
518 #include <linux/initrd.h>
|
pascal@215
|
519 #include <linux/string.h>
|
pascal@215
|
520
|
pascal@215
|
521 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
522 +#include <linux/decompress_bunzip2.h>
|
pascal@215
|
523 +#undef STATIC
|
pascal@215
|
524 +#endif
|
pascal@215
|
525 +
|
pascal@215
|
526 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
527 +#include <linux/decompress_unlzma.h>
|
pascal@215
|
528 +#undef STATIC
|
pascal@215
|
529 +#endif
|
pascal@215
|
530 +
|
pascal@215
|
531 #include "do_mounts.h"
|
pascal@215
|
532
|
pascal@215
|
533 #define BUILD_CRAMDISK
|
pascal@215
|
534 @@ -30,7 +40,15 @@ static int __init ramdisk_start_setup(ch
|
pascal@215
|
535 }
|
pascal@215
|
536 __setup("ramdisk_start=", ramdisk_start_setup);
|
pascal@215
|
537
|
pascal@215
|
538 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
539 static int __init crd_load(int in_fd, int out_fd);
|
pascal@215
|
540 +#endif
|
pascal@215
|
541 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
542 +static int __init crd_load_bzip2(int in_fd, int out_fd);
|
pascal@215
|
543 +#endif
|
pascal@215
|
544 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
545 +static int __init crd_load_lzma(int in_fd, int out_fd);
|
pascal@215
|
546 +#endif
|
pascal@215
|
547
|
pascal@215
|
548 /*
|
pascal@215
|
549 * This routine tries to find a RAM disk image to load, and returns the
|
pascal@215
|
550 @@ -46,7 +64,7 @@ static int __init crd_load(int in_fd, in
|
pascal@215
|
551 * gzip
|
pascal@215
|
552 */
|
pascal@215
|
553 static int __init
|
pascal@215
|
554 -identify_ramdisk_image(int fd, int start_block)
|
pascal@215
|
555 +identify_ramdisk_image(int fd, int start_block, int *ztype)
|
pascal@215
|
556 {
|
pascal@215
|
557 const int size = 512;
|
pascal@215
|
558 struct minix_super_block *minixsb;
|
pascal@215
|
559 @@ -72,6 +90,7 @@ identify_ramdisk_image(int fd, int start
|
pascal@215
|
560 sys_lseek(fd, start_block * BLOCK_SIZE, 0);
|
pascal@215
|
561 sys_read(fd, buf, size);
|
pascal@215
|
562
|
pascal@215
|
563 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
564 /*
|
pascal@215
|
565 * If it matches the gzip magic numbers, return -1
|
pascal@215
|
566 */
|
pascal@215
|
567 @@ -79,9 +98,40 @@ identify_ramdisk_image(int fd, int start
|
pascal@215
|
568 printk(KERN_NOTICE
|
pascal@215
|
569 "RAMDISK: Compressed image found at block %d\n",
|
pascal@215
|
570 start_block);
|
pascal@215
|
571 + *ztype = 0;
|
pascal@215
|
572 + nblocks = 0;
|
pascal@215
|
573 + goto done;
|
pascal@215
|
574 + }
|
pascal@215
|
575 +#endif
|
pascal@215
|
576 +
|
pascal@215
|
577 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
578 + /*
|
pascal@215
|
579 + * If it matches the bzip magic numbers, return -1
|
pascal@215
|
580 + */
|
pascal@215
|
581 + if (buf[0] == 0x42 && (buf[1] == 0x5a)) {
|
pascal@215
|
582 + printk(KERN_NOTICE
|
pascal@215
|
583 + "RAMDISK: Bzipped image found at block %d\n",
|
pascal@215
|
584 + start_block);
|
pascal@215
|
585 + *ztype = 1;
|
pascal@215
|
586 + nblocks = 0;
|
pascal@215
|
587 + goto done;
|
pascal@215
|
588 + }
|
pascal@215
|
589 +#endif
|
pascal@215
|
590 +
|
pascal@215
|
591 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
592 + /*
|
pascal@215
|
593 + * If it matches the bzip magic numbers, return -1
|
pascal@215
|
594 + */
|
pascal@215
|
595 + if (buf[0] == 0x5d && (buf[1] == 0x00)) {
|
pascal@215
|
596 + printk(KERN_NOTICE
|
pascal@215
|
597 + "RAMDISK: Lzma image found at block %d\n",
|
pascal@215
|
598 + start_block);
|
pascal@215
|
599 + *ztype = 2;
|
pascal@215
|
600 nblocks = 0;
|
pascal@215
|
601 goto done;
|
pascal@215
|
602 }
|
pascal@215
|
603 +#endif
|
pascal@215
|
604 +
|
pascal@215
|
605
|
pascal@215
|
606 /* romfs is at block zero too */
|
pascal@215
|
607 if (romfsb->word0 == ROMSB_WORD0 &&
|
pascal@215
|
608 @@ -145,6 +195,7 @@ int __init rd_load_image(char *from)
|
pascal@215
|
609 int nblocks, i, disk;
|
pascal@215
|
610 char *buf = NULL;
|
pascal@215
|
611 unsigned short rotate = 0;
|
pascal@215
|
612 + int ztype=-1;
|
pascal@215
|
613 #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES)
|
pascal@215
|
614 char rotator[4] = { '|' , '/' , '-' , '\\' };
|
pascal@215
|
615 #endif
|
pascal@215
|
616 @@ -157,14 +208,38 @@ int __init rd_load_image(char *from)
|
pascal@215
|
617 if (in_fd < 0)
|
pascal@215
|
618 goto noclose_input;
|
pascal@215
|
619
|
pascal@215
|
620 - nblocks = identify_ramdisk_image(in_fd, rd_image_start);
|
pascal@215
|
621 + nblocks = identify_ramdisk_image(in_fd, rd_image_start, &ztype);
|
pascal@215
|
622 if (nblocks < 0)
|
pascal@215
|
623 goto done;
|
pascal@215
|
624
|
pascal@215
|
625 if (nblocks == 0) {
|
pascal@215
|
626 #ifdef BUILD_CRAMDISK
|
pascal@215
|
627 - if (crd_load(in_fd, out_fd) == 0)
|
pascal@215
|
628 - goto successful_load;
|
pascal@215
|
629 + switch(ztype) {
|
pascal@215
|
630 +
|
pascal@215
|
631 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
632 + case 0:
|
pascal@215
|
633 + if (crd_load(in_fd, out_fd) == 0)
|
pascal@215
|
634 + goto successful_load;
|
pascal@215
|
635 + break;
|
pascal@215
|
636 +#endif
|
pascal@215
|
637 +
|
pascal@215
|
638 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
639 + case 1:
|
pascal@215
|
640 + if (crd_load_bzip2(in_fd, out_fd) == 0)
|
pascal@215
|
641 + goto successful_load;
|
pascal@215
|
642 + break;
|
pascal@215
|
643 +#endif
|
pascal@215
|
644 +
|
pascal@215
|
645 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
646 + case 2:
|
pascal@215
|
647 + if (crd_load_lzma(in_fd, out_fd) == 0)
|
pascal@215
|
648 + goto successful_load;
|
pascal@215
|
649 + break;
|
pascal@215
|
650 +#endif
|
pascal@215
|
651 +
|
pascal@215
|
652 + default:
|
pascal@215
|
653 + break;
|
pascal@215
|
654 + }
|
pascal@215
|
655 #else
|
pascal@215
|
656 printk(KERN_NOTICE
|
pascal@215
|
657 "RAMDISK: Kernel does not support compressed "
|
pascal@215
|
658 @@ -269,6 +344,7 @@ int __init rd_load_disk(int n)
|
pascal@215
|
659
|
pascal@215
|
660 #ifdef BUILD_CRAMDISK
|
pascal@215
|
661
|
pascal@215
|
662 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
663 /*
|
pascal@215
|
664 * gzip declarations
|
pascal@215
|
665 */
|
pascal@215
|
666 @@ -296,8 +372,11 @@ static unsigned outcnt; /* bytes in out
|
pascal@215
|
667 static int exit_code;
|
pascal@215
|
668 static int unzip_error;
|
pascal@215
|
669 static long bytes_out;
|
pascal@215
|
670 +#endif
|
pascal@215
|
671 +
|
pascal@215
|
672 static int crd_infd, crd_outfd;
|
pascal@215
|
673
|
pascal@215
|
674 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
675 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
|
pascal@215
|
676
|
pascal@215
|
677 /* Diagnostic functions (stubbed out) */
|
pascal@215
|
678 @@ -359,7 +438,22 @@ static int __init fill_inbuf(void)
|
pascal@215
|
679
|
pascal@215
|
680 return inbuf[0];
|
pascal@215
|
681 }
|
pascal@215
|
682 +#endif
|
pascal@215
|
683 +
|
pascal@215
|
684 +#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA)
|
pascal@215
|
685 +static int __init compr_fill(void *buf, unsigned int len)
|
pascal@215
|
686 +{
|
pascal@215
|
687 + int r = sys_read(crd_infd, buf, len);
|
pascal@215
|
688 + if(r < 0) {
|
pascal@215
|
689 + printk(KERN_ERR "RAMDISK: error while reading compressed data");
|
pascal@215
|
690 + } else if(r == 0) {
|
pascal@215
|
691 + printk(KERN_ERR "RAMDISK: EOF while reading compressed data");
|
pascal@215
|
692 + }
|
pascal@215
|
693 + return r;
|
pascal@215
|
694 +}
|
pascal@215
|
695 +#endif
|
pascal@215
|
696
|
pascal@215
|
697 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
698 /* ===========================================================================
|
pascal@215
|
699 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
|
pascal@215
|
700 * (Used for the decompressed data only.)
|
pascal@215
|
701 @@ -385,7 +479,24 @@ static void __init flush_window(void)
|
pascal@215
|
702 bytes_out += (ulg)outcnt;
|
pascal@215
|
703 outcnt = 0;
|
pascal@215
|
704 }
|
pascal@215
|
705 +#endif
|
pascal@215
|
706 +
|
pascal@215
|
707 +#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA)
|
pascal@215
|
708 +static int __init compr_flush(void *window, unsigned int outcnt) {
|
pascal@215
|
709 + static int progressDots=0;
|
pascal@215
|
710 + int written = sys_write(crd_outfd, window, outcnt);
|
pascal@215
|
711 + if (written != outcnt) {
|
pascal@215
|
712 + printk(KERN_ERR "RAMDISK: incomplete write (%d != %d)\n",
|
pascal@215
|
713 + written, outcnt);
|
pascal@215
|
714 + }
|
pascal@215
|
715 + progressDots = (progressDots+1)%10;
|
pascal@215
|
716 + if(!progressDots)
|
pascal@215
|
717 + printk(".");
|
pascal@215
|
718 + return outcnt;
|
pascal@215
|
719 +}
|
pascal@215
|
720 +#endif
|
pascal@215
|
721
|
pascal@215
|
722 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
723 static void __init error(char *x)
|
pascal@215
|
724 {
|
pascal@215
|
725 printk(KERN_ERR "%s\n", x);
|
pascal@215
|
726 @@ -425,5 +536,43 @@ static int __init crd_load(int in_fd, in
|
pascal@215
|
727 kfree(window);
|
pascal@215
|
728 return result;
|
pascal@215
|
729 }
|
pascal@215
|
730 +#endif
|
pascal@215
|
731 +
|
pascal@215
|
732 +#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA)
|
pascal@215
|
733 +static int __init crd_load_compr(int in_fd, int out_fd, int size,
|
pascal@215
|
734 + int (*deco)(char *,int,
|
pascal@215
|
735 + int(*fill)(void*,unsigned int),
|
pascal@215
|
736 + int(*flush)(void*,unsigned int),
|
pascal@215
|
737 + int *))
|
pascal@215
|
738 +{
|
pascal@215
|
739 + int result;
|
pascal@215
|
740 + char *inbuf = kmalloc(size, GFP_KERNEL);
|
pascal@215
|
741 + crd_infd = in_fd;
|
pascal@215
|
742 + crd_outfd = out_fd;
|
pascal@215
|
743 + if (inbuf == 0) {
|
pascal@215
|
744 + printk(KERN_ERR "RAMDISK: Couldn't allocate decompression buffer\n");
|
pascal@215
|
745 + return -1;
|
pascal@215
|
746 + }
|
pascal@215
|
747 + result=deco(inbuf, 0, compr_fill, compr_flush, NULL);
|
pascal@215
|
748 + kfree(inbuf);
|
pascal@215
|
749 + printk("\n");
|
pascal@215
|
750 + return result;
|
pascal@215
|
751 +}
|
pascal@215
|
752 +#endif
|
pascal@215
|
753 +
|
pascal@215
|
754 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
755 +static int __init crd_load_bzip2(int in_fd, int out_fd)
|
pascal@215
|
756 +{
|
pascal@215
|
757 + return crd_load_compr(in_fd, out_fd, BZIP2_IOBUF_SIZE, bunzip2);
|
pascal@215
|
758 +}
|
pascal@215
|
759 +#endif
|
pascal@215
|
760 +
|
pascal@215
|
761 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
762 +static int __init crd_load_lzma(int in_fd, int out_fd)
|
pascal@215
|
763 +{
|
pascal@215
|
764 + return crd_load_compr(in_fd, out_fd, LZMA_IOBUF_SIZE, unlzma);
|
pascal@215
|
765 +}
|
pascal@215
|
766 +
|
pascal@215
|
767 +#endif
|
pascal@215
|
768
|
pascal@215
|
769 #endif /* BUILD_CRAMDISK */
|
pascal@215
|
770 --- linux-2.6.24.2/init/initramfs.c
|
pascal@215
|
771 +++ linux-2.6.24.2/init/initramfs.c
|
pascal@215
|
772 @@ -7,6 +7,15 @@
|
pascal@215
|
773 #include <linux/string.h>
|
pascal@215
|
774 #include <linux/syscalls.h>
|
pascal@215
|
775
|
pascal@215
|
776 +/* We need to enable RD_GZIP unconditionnally, as the built-in
|
pascal@215
|
777 + * initramfs is gzip-compressed, alas!
|
pascal@215
|
778 + * We can only wonder why, though, as the whole kernel (which contains
|
pascal@215
|
779 + * built-in initramfs) is gzip (or bzip) compressed anyways afterwards...
|
pascal@215
|
780 + */
|
pascal@215
|
781 +#ifndef CONFIG_RD_GZIP
|
pascal@215
|
782 +#define CONFIG_RD_GZIP
|
pascal@215
|
783 +#endif
|
pascal@215
|
784 +
|
pascal@215
|
785 static __initdata char *message;
|
pascal@215
|
786 static void __init error(char *x)
|
pascal@215
|
787 {
|
pascal@215
|
788 @@ -347,11 +356,13 @@ static int __init write_buffer(char *buf
|
pascal@215
|
789 return len - count;
|
pascal@215
|
790 }
|
pascal@215
|
791
|
pascal@215
|
792 -static void __init flush_buffer(char *buf, unsigned len)
|
pascal@215
|
793 +
|
pascal@215
|
794 +static int __init flush_buffer(char *buf, unsigned len)
|
pascal@215
|
795 {
|
pascal@215
|
796 int written;
|
pascal@215
|
797 + int origLen = len;
|
pascal@215
|
798 if (message)
|
pascal@215
|
799 - return;
|
pascal@215
|
800 + return -1;
|
pascal@215
|
801 while ((written = write_buffer(buf, len)) < len && !message) {
|
pascal@215
|
802 char c = buf[written];
|
pascal@215
|
803 if (c == '0') {
|
pascal@215
|
804 @@ -365,8 +376,24 @@ static void __init flush_buffer(char *bu
|
pascal@215
|
805 } else
|
pascal@215
|
806 error("junk in compressed archive");
|
pascal@215
|
807 }
|
pascal@215
|
808 + return origLen;
|
pascal@215
|
809 }
|
pascal@215
|
810
|
pascal@215
|
811 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
812 +#include <linux/decompress_bunzip2.h>
|
pascal@215
|
813 +#undef STATIC
|
pascal@215
|
814 +
|
pascal@215
|
815 +#endif
|
pascal@215
|
816 +
|
pascal@215
|
817 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
818 +#include <linux/decompress_unlzma.h>
|
pascal@215
|
819 +#undef STATIC
|
pascal@215
|
820 +
|
pascal@215
|
821 +#endif
|
pascal@215
|
822 +
|
pascal@215
|
823 +static unsigned inptr; /* index of next byte to be processed in inbuf */
|
pascal@215
|
824 +
|
pascal@215
|
825 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
826 /*
|
pascal@215
|
827 * gzip declarations
|
pascal@215
|
828 */
|
pascal@215
|
829 @@ -388,7 +415,6 @@ static uch *inbuf;
|
pascal@215
|
830 static uch *window;
|
pascal@215
|
831
|
pascal@215
|
832 static unsigned insize; /* valid bytes in inbuf */
|
pascal@215
|
833 -static unsigned inptr; /* index of next byte to be processed in inbuf */
|
pascal@215
|
834 static unsigned outcnt; /* bytes in output buffer */
|
pascal@215
|
835 static long bytes_out;
|
pascal@215
|
836
|
pascal@215
|
837 @@ -440,6 +466,7 @@ static void __init flush_window(void)
|
pascal@215
|
838 bytes_out += (ulg)outcnt;
|
pascal@215
|
839 outcnt = 0;
|
pascal@215
|
840 }
|
pascal@215
|
841 +#endif
|
pascal@215
|
842
|
pascal@215
|
843 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
|
pascal@215
|
844 {
|
pascal@215
|
845 @@ -448,9 +475,11 @@ static char * __init unpack_to_rootfs(ch
|
pascal@215
|
846 header_buf = malloc(110);
|
pascal@215
|
847 symlink_buf = malloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1);
|
pascal@215
|
848 name_buf = malloc(N_ALIGN(PATH_MAX));
|
pascal@215
|
849 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
850 window = malloc(WSIZE);
|
pascal@215
|
851 if (!window || !header_buf || !symlink_buf || !name_buf)
|
pascal@215
|
852 panic("can't allocate buffers");
|
pascal@215
|
853 +#endif
|
pascal@215
|
854 state = Start;
|
pascal@215
|
855 this_header = 0;
|
pascal@215
|
856 message = NULL;
|
pascal@215
|
857 @@ -470,6 +499,7 @@ static char * __init unpack_to_rootfs(ch
|
pascal@215
|
858 continue;
|
pascal@215
|
859 }
|
pascal@215
|
860 this_header = 0;
|
pascal@215
|
861 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
862 insize = len;
|
pascal@215
|
863 inbuf = buf;
|
pascal@215
|
864 inptr = 0;
|
pascal@215
|
865 @@ -477,14 +507,38 @@ static char * __init unpack_to_rootfs(ch
|
pascal@215
|
866 bytes_out = 0;
|
pascal@215
|
867 crc = (ulg)0xffffffffL; /* shift register contents */
|
pascal@215
|
868 makecrc();
|
pascal@215
|
869 - gunzip();
|
pascal@215
|
870 + if(!gunzip() && message == NULL)
|
pascal@215
|
871 + goto ok;
|
pascal@215
|
872 +#endif
|
pascal@215
|
873 +
|
pascal@215
|
874 +#ifdef CONFIG_RD_BZIP2
|
pascal@215
|
875 + message = NULL; /* Zero out message, or else cpio will
|
pascal@215
|
876 + think an error has already occured */
|
pascal@215
|
877 + if(!bunzip2(buf, len, NULL, flush_buffer, &inptr) < 0 &&
|
pascal@215
|
878 + message == NULL) {
|
pascal@215
|
879 + goto ok;
|
pascal@215
|
880 + }
|
pascal@215
|
881 +#endif
|
pascal@215
|
882 +
|
pascal@215
|
883 +#ifdef CONFIG_RD_LZMA
|
pascal@215
|
884 + message = NULL; /* Zero out message, or else cpio will
|
pascal@215
|
885 + think an error has already occured */
|
pascal@215
|
886 + if(!unlzma(buf, len, NULL, flush_buffer, &inptr) < 0 &&
|
pascal@215
|
887 + message == NULL) {
|
pascal@215
|
888 + goto ok;
|
pascal@215
|
889 + }
|
pascal@215
|
890 +#endif
|
pascal@215
|
891 + ok:
|
pascal@215
|
892 +
|
pascal@215
|
893 if (state != Reset)
|
pascal@215
|
894 - error("junk in gzipped archive");
|
pascal@215
|
895 + error("junk in compressed archive");
|
pascal@215
|
896 this_header = saved_offset + inptr;
|
pascal@215
|
897 buf += inptr;
|
pascal@215
|
898 len -= inptr;
|
pascal@215
|
899 }
|
pascal@215
|
900 +#ifdef CONFIG_RD_GZIP
|
pascal@215
|
901 free(window);
|
pascal@215
|
902 +#endif
|
pascal@215
|
903 free(name_buf);
|
pascal@215
|
904 free(symlink_buf);
|
pascal@215
|
905 free(header_buf);
|
pascal@215
|
906 --- linux-2.6.24.2/init/Kconfig
|
pascal@215
|
907 +++ linux-2.6.24.2/init/Kconfig
|
pascal@215
|
908 @@ -92,6 +92,56 @@ config LOCALVERSION_AUTO
|
pascal@215
|
909
|
pascal@215
|
910 which is done within the script "scripts/setlocalversion".)
|
pascal@215
|
911
|
pascal@215
|
912 +choice
|
pascal@215
|
913 + prompt "Kernel compression mode"
|
pascal@215
|
914 + default KERNEL_GZIP
|
pascal@215
|
915 + help
|
pascal@215
|
916 + The linux kernel is a kind of self-extracting executable.
|
pascal@215
|
917 + Several compression algorithms are available, which differ
|
pascal@215
|
918 + in efficiency, compression and decompression speed.
|
pascal@215
|
919 + Compression speed is only relevant when building a kernel.
|
pascal@215
|
920 + Decompression speed is relevant at each boot.
|
pascal@215
|
921 +
|
pascal@215
|
922 + If you have any problems with bzip2 or lzma compressed
|
pascal@215
|
923 + kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
|
pascal@215
|
924 + version of this functionality (bzip2 only), for 2.4, was
|
pascal@215
|
925 + supplied by Christian Ludwig)
|
pascal@215
|
926 +
|
pascal@215
|
927 + High compression options are mostly useful for users, who
|
pascal@215
|
928 + are low on disk space (embedded systems), but for whom ram
|
pascal@215
|
929 + size matters less.
|
pascal@215
|
930 +
|
pascal@215
|
931 + If in doubt, select 'gzip'
|
pascal@215
|
932 +
|
pascal@215
|
933 +config KERNEL_GZIP
|
pascal@215
|
934 + bool "Gzip"
|
pascal@215
|
935 + help
|
pascal@215
|
936 + The old and tries gzip compression. Its compression ratio is
|
pascal@215
|
937 + the poorest among the 3 choices; however its speed (both
|
pascal@215
|
938 + compression and decompression) is the fastest.
|
pascal@215
|
939 +
|
pascal@215
|
940 +config KERNEL_BZIP2
|
pascal@215
|
941 + bool "Bzip2"
|
pascal@215
|
942 + help
|
pascal@215
|
943 + Its compression ratio and speed is intermediate.
|
pascal@215
|
944 + Decompression speed is slowest among the 3.
|
pascal@215
|
945 + The kernel size is about 10 per cent smaller with bzip2,
|
pascal@215
|
946 + in comparison to gzip.
|
pascal@215
|
947 + Bzip2 uses a large amount of memory. For modern kernels
|
pascal@215
|
948 + you will need at least 8MB RAM or more for booting.
|
pascal@215
|
949 +
|
pascal@215
|
950 +config KERNEL_LZMA
|
pascal@215
|
951 + bool "LZMA"
|
pascal@215
|
952 + help
|
pascal@215
|
953 + The most recent compression algorithm.
|
pascal@215
|
954 + Its ratio is best, decompression speed is between the other
|
pascal@215
|
955 + 2. Compression is slowest.
|
pascal@215
|
956 + The kernel size is about 33 per cent smaller with lzma,
|
pascal@215
|
957 + in comparison to gzip.
|
pascal@215
|
958 +
|
pascal@215
|
959 +endchoice
|
pascal@215
|
960 +
|
pascal@215
|
961 +
|
pascal@215
|
962 config SWAP
|
pascal@215
|
963 bool "Support for paging of anonymous memory (swap)"
|
pascal@215
|
964 depends on MMU && BLOCK
|
pascal@215
|
965 --- linux-2.6.24.2/lib/decompress_bunzip2.c
|
pascal@215
|
966 +++ linux-2.6.24.2/lib/decompress_bunzip2.c
|
pascal@215
|
967 @@ -0,0 +1,645 @@
|
pascal@215
|
968 +/* vi: set sw=4 ts=4: */
|
pascal@215
|
969 +/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
|
pascal@215
|
970 +
|
pascal@215
|
971 + Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
|
pascal@215
|
972 + which also acknowledges contributions by Mike Burrows, David Wheeler,
|
pascal@215
|
973 + Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
|
pascal@215
|
974 + Robert Sedgewick, and Jon L. Bentley.
|
pascal@215
|
975 +
|
pascal@215
|
976 + This code is licensed under the LGPLv2:
|
pascal@215
|
977 + LGPL (http://www.gnu.org/copyleft/lgpl.html
|
pascal@215
|
978 +*/
|
pascal@215
|
979 +
|
pascal@215
|
980 +/*
|
pascal@215
|
981 + Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org).
|
pascal@215
|
982 +
|
pascal@215
|
983 + More efficient reading of Huffman codes, a streamlined read_bunzip()
|
pascal@215
|
984 + function, and various other tweaks. In (limited) tests, approximately
|
pascal@215
|
985 + 20% faster than bzcat on x86 and about 10% faster on arm.
|
pascal@215
|
986 +
|
pascal@215
|
987 + Note that about 2/3 of the time is spent in read_unzip() reversing
|
pascal@215
|
988 + the Burrows-Wheeler transformation. Much of that time is delay
|
pascal@215
|
989 + resulting from cache misses.
|
pascal@215
|
990 +
|
pascal@215
|
991 + I would ask that anyone benefiting from this work, especially those
|
pascal@215
|
992 + using it in commercial products, consider making a donation to my local
|
pascal@215
|
993 + non-profit hospice organization in the name of the woman I loved, who
|
pascal@215
|
994 + passed away Feb. 12, 2003.
|
pascal@215
|
995 +
|
pascal@215
|
996 + In memory of Toni W. Hagan
|
pascal@215
|
997 +
|
pascal@215
|
998 + Hospice of Acadiana, Inc.
|
pascal@215
|
999 + 2600 Johnston St., Suite 200
|
pascal@215
|
1000 + Lafayette, LA 70503-3240
|
pascal@215
|
1001 +
|
pascal@215
|
1002 + Phone (337) 232-1234 or 1-800-738-2226
|
pascal@215
|
1003 + Fax (337) 232-1297
|
pascal@215
|
1004 +
|
pascal@215
|
1005 + http://www.hospiceacadiana.com/
|
pascal@215
|
1006 +
|
pascal@215
|
1007 + Manuel
|
pascal@215
|
1008 + */
|
pascal@215
|
1009 +
|
pascal@215
|
1010 +/*
|
pascal@215
|
1011 + Made it fit for running in Linux Kernel by Alain Knaff (alain@knaff.lu)
|
pascal@215
|
1012 +*/
|
pascal@215
|
1013 +
|
pascal@215
|
1014 +
|
pascal@215
|
1015 +#ifndef STATIC
|
pascal@215
|
1016 +
|
pascal@215
|
1017 +#include <linux/kernel.h>
|
pascal@215
|
1018 +#include <linux/fs.h>
|
pascal@215
|
1019 +#include <linux/string.h>
|
pascal@215
|
1020 +
|
pascal@215
|
1021 +#ifdef TEST
|
pascal@215
|
1022 +#include "test.h"
|
pascal@215
|
1023 +#else
|
pascal@215
|
1024 +#include <linux/vmalloc.h>
|
pascal@215
|
1025 +#endif
|
pascal@215
|
1026 +
|
pascal@215
|
1027 +static void __init *large_malloc(size_t size)
|
pascal@215
|
1028 +{
|
pascal@215
|
1029 + return vmalloc(size);
|
pascal@215
|
1030 +}
|
pascal@215
|
1031 +
|
pascal@215
|
1032 +static void __init large_free(void *where)
|
pascal@215
|
1033 +{
|
pascal@215
|
1034 + vfree(where);
|
pascal@215
|
1035 +}
|
pascal@215
|
1036 +
|
pascal@215
|
1037 +#ifndef TEST
|
pascal@215
|
1038 +static void __init *malloc(size_t size)
|
pascal@215
|
1039 +{
|
pascal@215
|
1040 + return kmalloc(size, GFP_KERNEL);
|
pascal@215
|
1041 +}
|
pascal@215
|
1042 +
|
pascal@215
|
1043 +static void __init free(void *where)
|
pascal@215
|
1044 +{
|
pascal@215
|
1045 + kfree(where);
|
pascal@215
|
1046 +}
|
pascal@215
|
1047 +
|
pascal@215
|
1048 +static void __init error(char *x)
|
pascal@215
|
1049 +{
|
pascal@215
|
1050 + printk(KERN_ERR "%s\n", x);
|
pascal@215
|
1051 +}
|
pascal@215
|
1052 +#endif
|
pascal@215
|
1053 +
|
pascal@215
|
1054 +#define STATIC /**/
|
pascal@215
|
1055 +
|
pascal@215
|
1056 +#endif
|
pascal@215
|
1057 +
|
pascal@215
|
1058 +#include <linux/decompress_bunzip2.h>
|
pascal@215
|
1059 +
|
pascal@215
|
1060 +
|
pascal@215
|
1061 +/* Constants for Huffman coding */
|
pascal@215
|
1062 +#define MAX_GROUPS 6
|
pascal@215
|
1063 +#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
pascal@215
|
1064 +#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
pascal@215
|
1065 +#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
pascal@215
|
1066 +#define SYMBOL_RUNA 0
|
pascal@215
|
1067 +#define SYMBOL_RUNB 1
|
pascal@215
|
1068 +
|
pascal@215
|
1069 +/* Status return values */
|
pascal@215
|
1070 +#define RETVAL_OK 0
|
pascal@215
|
1071 +#define RETVAL_LAST_BLOCK (-1)
|
pascal@215
|
1072 +#define RETVAL_NOT_BZIP_DATA (-2)
|
pascal@215
|
1073 +#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
pascal@215
|
1074 +#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
pascal@215
|
1075 +#define RETVAL_DATA_ERROR (-5)
|
pascal@215
|
1076 +#define RETVAL_OUT_OF_MEMORY (-6)
|
pascal@215
|
1077 +#define RETVAL_OBSOLETE_INPUT (-7)
|
pascal@215
|
1078 +
|
pascal@215
|
1079 +
|
pascal@215
|
1080 +/* This is what we know about each Huffman coding group */
|
pascal@215
|
1081 +struct group_data {
|
pascal@215
|
1082 + /* We have an extra slot at the end of limit[] for a sentinal value. */
|
pascal@215
|
1083 + int limit[MAX_HUFCODE_BITS+1],base[MAX_HUFCODE_BITS],permute[MAX_SYMBOLS];
|
pascal@215
|
1084 + int minLen, maxLen;
|
pascal@215
|
1085 +};
|
pascal@215
|
1086 +
|
pascal@215
|
1087 +/* Structure holding all the housekeeping data, including IO buffers and
|
pascal@215
|
1088 + memory that persists between calls to bunzip */
|
pascal@215
|
1089 +typedef struct {
|
pascal@215
|
1090 + /* State for interrupting output loop */
|
pascal@215
|
1091 + int writeCopies,writePos,writeRunCountdown,writeCount,writeCurrent;
|
pascal@215
|
1092 + /* I/O tracking data (file handles, buffers, positions, etc.) */
|
pascal@215
|
1093 + int (*fill)(void*,unsigned int);
|
pascal@215
|
1094 + int inbufCount,inbufPos /*,outbufPos*/;
|
pascal@215
|
1095 + unsigned char *inbuf /*,*outbuf*/;
|
pascal@215
|
1096 + unsigned int inbufBitCount, inbufBits;
|
pascal@215
|
1097 + /* The CRC values stored in the block header and calculated from the data */
|
pascal@215
|
1098 + unsigned int crc32Table[256],headerCRC, totalCRC, writeCRC;
|
pascal@215
|
1099 + /* Intermediate buffer and its size (in bytes) */
|
pascal@215
|
1100 + unsigned int *dbuf, dbufSize;
|
pascal@215
|
1101 + /* These things are a bit too big to go on the stack */
|
pascal@215
|
1102 + unsigned char selectors[32768]; /* nSelectors=15 bits */
|
pascal@215
|
1103 + struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
pascal@215
|
1104 + int io_error; /* non-zero if we have IO error */
|
pascal@215
|
1105 +} bunzip_data;
|
pascal@215
|
1106 +
|
pascal@215
|
1107 +
|
pascal@215
|
1108 +/* Return the next nnn bits of input. All reads from the compressed input
|
pascal@215
|
1109 + are done through this function. All reads are big endian */
|
pascal@215
|
1110 +static unsigned int get_bits(bunzip_data *bd, char bits_wanted)
|
pascal@215
|
1111 +{
|
pascal@215
|
1112 + unsigned int bits=0;
|
pascal@215
|
1113 +
|
pascal@215
|
1114 + /* If we need to get more data from the byte buffer, do so. (Loop getting
|
pascal@215
|
1115 + one byte at a time to enforce endianness and avoid unaligned access.) */
|
pascal@215
|
1116 + while (bd->inbufBitCount<bits_wanted) {
|
pascal@215
|
1117 + /* If we need to read more data from file into byte buffer, do so */
|
pascal@215
|
1118 + if(bd->inbufPos==bd->inbufCount) {
|
pascal@215
|
1119 + if(bd->io_error)
|
pascal@215
|
1120 + return 0;
|
pascal@215
|
1121 + if((bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE)) <= 0) {
|
pascal@215
|
1122 + bd->io_error=RETVAL_UNEXPECTED_INPUT_EOF;
|
pascal@215
|
1123 + return 0;
|
pascal@215
|
1124 + }
|
pascal@215
|
1125 + bd->inbufPos=0;
|
pascal@215
|
1126 + }
|
pascal@215
|
1127 + /* Avoid 32-bit overflow (dump bit buffer to top of output) */
|
pascal@215
|
1128 + if(bd->inbufBitCount>=24) {
|
pascal@215
|
1129 + bits=bd->inbufBits&((1<<bd->inbufBitCount)-1);
|
pascal@215
|
1130 + bits_wanted-=bd->inbufBitCount;
|
pascal@215
|
1131 + bits<<=bits_wanted;
|
pascal@215
|
1132 + bd->inbufBitCount=0;
|
pascal@215
|
1133 + }
|
pascal@215
|
1134 + /* Grab next 8 bits of input from buffer. */
|
pascal@215
|
1135 + bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++];
|
pascal@215
|
1136 + bd->inbufBitCount+=8;
|
pascal@215
|
1137 + }
|
pascal@215
|
1138 + /* Calculate result */
|
pascal@215
|
1139 + bd->inbufBitCount-=bits_wanted;
|
pascal@215
|
1140 + bits|=(bd->inbufBits>>bd->inbufBitCount)&((1<<bits_wanted)-1);
|
pascal@215
|
1141 +
|
pascal@215
|
1142 + return bits;
|
pascal@215
|
1143 +}
|
pascal@215
|
1144 +
|
pascal@215
|
1145 +/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
|
pascal@215
|
1146 +
|
pascal@215
|
1147 +static int get_next_block(bunzip_data *bd)
|
pascal@215
|
1148 +{
|
pascal@215
|
1149 + struct group_data *hufGroup=NULL;
|
pascal@215
|
1150 + int *base=NULL;
|
pascal@215
|
1151 + int *limit=NULL;
|
pascal@215
|
1152 + int dbufCount,nextSym,dbufSize,groupCount,selector,
|
pascal@215
|
1153 + i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256];
|
pascal@215
|
1154 + unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
|
pascal@215
|
1155 + unsigned int *dbuf,origPtr;
|
pascal@215
|
1156 +
|
pascal@215
|
1157 + dbuf=bd->dbuf;
|
pascal@215
|
1158 + dbufSize=bd->dbufSize;
|
pascal@215
|
1159 + selectors=bd->selectors;
|
pascal@215
|
1160 +
|
pascal@215
|
1161 + /* Read in header signature and CRC, then validate signature.
|
pascal@215
|
1162 + (last block signature means CRC is for whole file, return now) */
|
pascal@215
|
1163 + i = get_bits(bd,24);
|
pascal@215
|
1164 + j = get_bits(bd,24);
|
pascal@215
|
1165 + bd->headerCRC=get_bits(bd,32);
|
pascal@215
|
1166 + if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
|
pascal@215
|
1167 + if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
|
pascal@215
|
1168 + /* We can add support for blockRandomised if anybody complains. There was
|
pascal@215
|
1169 + some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
pascal@215
|
1170 + it didn't actually work. */
|
pascal@215
|
1171 + if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
|
pascal@215
|
1172 + if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
|
pascal@215
|
1173 + /* mapping table: if some byte values are never used (encoding things
|
pascal@215
|
1174 + like ascii text), the compression code removes the gaps to have fewer
|
pascal@215
|
1175 + symbols to deal with, and writes a sparse bitfield indicating which
|
pascal@215
|
1176 + values were present. We make a translation table to convert the symbols
|
pascal@215
|
1177 + back to the corresponding bytes. */
|
pascal@215
|
1178 + t=get_bits(bd, 16);
|
pascal@215
|
1179 + symTotal=0;
|
pascal@215
|
1180 + for (i=0;i<16;i++) {
|
pascal@215
|
1181 + if(t&(1<<(15-i))) {
|
pascal@215
|
1182 + k=get_bits(bd,16);
|
pascal@215
|
1183 + for(j=0;j<16;j++)
|
pascal@215
|
1184 + if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j;
|
pascal@215
|
1185 + }
|
pascal@215
|
1186 + }
|
pascal@215
|
1187 + /* How many different Huffman coding groups does this block use? */
|
pascal@215
|
1188 + groupCount=get_bits(bd,3);
|
pascal@215
|
1189 + if (groupCount<2 || groupCount>MAX_GROUPS) return RETVAL_DATA_ERROR;
|
pascal@215
|
1190 + /* nSelectors: Every GROUP_SIZE many symbols we select a new Huffman coding
|
pascal@215
|
1191 + group. Read in the group selector list, which is stored as MTF encoded
|
pascal@215
|
1192 + bit runs. (MTF=Move To Front, as each value is used it's moved to the
|
pascal@215
|
1193 + start of the list.) */
|
pascal@215
|
1194 + if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR;
|
pascal@215
|
1195 + for(i=0; i<groupCount; i++) mtfSymbol[i] = i;
|
pascal@215
|
1196 + for(i=0; i<nSelectors; i++) {
|
pascal@215
|
1197 + /* Get next value */
|
pascal@215
|
1198 + for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
|
pascal@215
|
1199 + /* Decode MTF to get the next selector */
|
pascal@215
|
1200 + uc = mtfSymbol[j];
|
pascal@215
|
1201 + for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
pascal@215
|
1202 + mtfSymbol[0]=selectors[i]=uc;
|
pascal@215
|
1203 + }
|
pascal@215
|
1204 + /* Read the Huffman coding tables for each group, which code for symTotal
|
pascal@215
|
1205 + literal symbols, plus two run symbols (RUNA, RUNB) */
|
pascal@215
|
1206 + symCount=symTotal+2;
|
pascal@215
|
1207 + for (j=0; j<groupCount; j++) {
|
pascal@215
|
1208 + unsigned char length[MAX_SYMBOLS],temp[MAX_HUFCODE_BITS+1];
|
pascal@215
|
1209 + int minLen, maxLen, pp;
|
pascal@215
|
1210 + /* Read Huffman code lengths for each symbol. They're stored in
|
pascal@215
|
1211 + a way similar to mtf; record a starting value for the first symbol,
|
pascal@215
|
1212 + and an offset from the previous value for everys symbol after that.
|
pascal@215
|
1213 + (Subtracting 1 before the loop and then adding it back at the end is
|
pascal@215
|
1214 + an optimization that makes the test inside the loop simpler: symbol
|
pascal@215
|
1215 + length 0 becomes negative, so an unsigned inequality catches it.) */
|
pascal@215
|
1216 + t=get_bits(bd, 5)-1;
|
pascal@215
|
1217 + for (i = 0; i < symCount; i++) {
|
pascal@215
|
1218 + for(;;) {
|
pascal@215
|
1219 + if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
|
pascal@215
|
1220 + return RETVAL_DATA_ERROR;
|
pascal@215
|
1221 + /* If first bit is 0, stop. Else second bit indicates whether
|
pascal@215
|
1222 + to increment or decrement the value. Optimization: grab 2
|
pascal@215
|
1223 + bits and unget the second if the first was 0. */
|
pascal@215
|
1224 + k = get_bits(bd,2);
|
pascal@215
|
1225 + if (k < 2) {
|
pascal@215
|
1226 + bd->inbufBitCount++;
|
pascal@215
|
1227 + break;
|
pascal@215
|
1228 + }
|
pascal@215
|
1229 + /* Add one if second bit 1, else subtract 1. Avoids if/else */
|
pascal@215
|
1230 + t+=(((k+1)&2)-1);
|
pascal@215
|
1231 + }
|
pascal@215
|
1232 + /* Correct for the initial -1, to get the final symbol length */
|
pascal@215
|
1233 + length[i]=t+1;
|
pascal@215
|
1234 + }
|
pascal@215
|
1235 + /* Find largest and smallest lengths in this group */
|
pascal@215
|
1236 + minLen=maxLen=length[0];
|
pascal@215
|
1237 + for(i = 1; i < symCount; i++) {
|
pascal@215
|
1238 + if(length[i] > maxLen) maxLen = length[i];
|
pascal@215
|
1239 + else if(length[i] < minLen) minLen = length[i];
|
pascal@215
|
1240 + }
|
pascal@215
|
1241 + /* Calculate permute[], base[], and limit[] tables from length[].
|
pascal@215
|
1242 + *
|
pascal@215
|
1243 + * permute[] is the lookup table for converting Huffman coded symbols
|
pascal@215
|
1244 + * into decoded symbols. base[] is the amount to subtract from the
|
pascal@215
|
1245 + * value of a Huffman symbol of a given length when using permute[].
|
pascal@215
|
1246 + *
|
pascal@215
|
1247 + * limit[] indicates the largest numerical value a symbol with a given
|
pascal@215
|
1248 + * number of bits can have. This is how the Huffman codes can vary in
|
pascal@215
|
1249 + * length: each code with a value>limit[length] needs another bit.
|
pascal@215
|
1250 + */
|
pascal@215
|
1251 + hufGroup=bd->groups+j;
|
pascal@215
|
1252 + hufGroup->minLen = minLen;
|
pascal@215
|
1253 + hufGroup->maxLen = maxLen;
|
pascal@215
|
1254 + /* Note that minLen can't be smaller than 1, so we adjust the base
|
pascal@215
|
1255 + and limit array pointers so we're not always wasting the first
|
pascal@215
|
1256 + entry. We do this again when using them (during symbol decoding).*/
|
pascal@215
|
1257 + base=hufGroup->base-1;
|
pascal@215
|
1258 + limit=hufGroup->limit-1;
|
pascal@215
|
1259 + /* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
|
pascal@215
|
1260 + pp=0;
|
pascal@215
|
1261 + for(i=minLen;i<=maxLen;i++) {
|
pascal@215
|
1262 + temp[i]=limit[i]=0;
|
pascal@215
|
1263 + for(t=0;t<symCount;t++)
|
pascal@215
|
1264 + if(length[t]==i) hufGroup->permute[pp++] = t;
|
pascal@215
|
1265 + }
|
pascal@215
|
1266 + /* Count symbols coded for at each bit length */
|
pascal@215
|
1267 + for (i=0;i<symCount;i++) temp[length[i]]++;
|
pascal@215
|
1268 + /* Calculate limit[] (the largest symbol-coding value at each bit
|
pascal@215
|
1269 + * length, which is (previous limit<<1)+symbols at this level), and
|
pascal@215
|
1270 + * base[] (number of symbols to ignore at each bit length, which is
|
pascal@215
|
1271 + * limit minus the cumulative count of symbols coded for already). */
|
pascal@215
|
1272 + pp=t=0;
|
pascal@215
|
1273 + for (i=minLen; i<maxLen; i++) {
|
pascal@215
|
1274 + pp+=temp[i];
|
pascal@215
|
1275 + /* We read the largest possible symbol size and then unget bits
|
pascal@215
|
1276 + after determining how many we need, and those extra bits could
|
pascal@215
|
1277 + be set to anything. (They're noise from future symbols.) At
|
pascal@215
|
1278 + each level we're really only interested in the first few bits,
|
pascal@215
|
1279 + so here we set all the trailing to-be-ignored bits to 1 so they
|
pascal@215
|
1280 + don't affect the value>limit[length] comparison. */
|
pascal@215
|
1281 + limit[i]= (pp << (maxLen - i)) - 1;
|
pascal@215
|
1282 + pp<<=1;
|
pascal@215
|
1283 + base[i+1]=pp-(t+=temp[i]);
|
pascal@215
|
1284 + }
|
pascal@215
|
1285 + limit[maxLen+1] = INT_MAX; /* Sentinal value for reading next sym. */
|
pascal@215
|
1286 + limit[maxLen]=pp+temp[maxLen]-1;
|
pascal@215
|
1287 + base[minLen]=0;
|
pascal@215
|
1288 + }
|
pascal@215
|
1289 + /* We've finished reading and digesting the block header. Now read this
|
pascal@215
|
1290 + block's Huffman coded symbols from the file and undo the Huffman coding
|
pascal@215
|
1291 + and run length encoding, saving the result into dbuf[dbufCount++]=uc */
|
pascal@215
|
1292 +
|
pascal@215
|
1293 + /* Initialize symbol occurrence counters and symbol Move To Front table */
|
pascal@215
|
1294 + for(i=0;i<256;i++) {
|
pascal@215
|
1295 + byteCount[i] = 0;
|
pascal@215
|
1296 + mtfSymbol[i]=(unsigned char)i;
|
pascal@215
|
1297 + }
|
pascal@215
|
1298 + /* Loop through compressed symbols. */
|
pascal@215
|
1299 + runPos=dbufCount=symCount=selector=0;
|
pascal@215
|
1300 + for(;;) {
|
pascal@215
|
1301 + /* Determine which Huffman coding group to use. */
|
pascal@215
|
1302 + if(!(symCount--)) {
|
pascal@215
|
1303 + symCount=GROUP_SIZE-1;
|
pascal@215
|
1304 + if(selector>=nSelectors) return RETVAL_DATA_ERROR;
|
pascal@215
|
1305 + hufGroup=bd->groups+selectors[selector++];
|
pascal@215
|
1306 + base=hufGroup->base-1;
|
pascal@215
|
1307 + limit=hufGroup->limit-1;
|
pascal@215
|
1308 + }
|
pascal@215
|
1309 + /* Read next Huffman-coded symbol. */
|
pascal@215
|
1310 + /* Note: It is far cheaper to read maxLen bits and back up than it is
|
pascal@215
|
1311 + to read minLen bits and then an additional bit at a time, testing
|
pascal@215
|
1312 + as we go. Because there is a trailing last block (with file CRC),
|
pascal@215
|
1313 + there is no danger of the overread causing an unexpected EOF for a
|
pascal@215
|
1314 + valid compressed file. As a further optimization, we do the read
|
pascal@215
|
1315 + inline (falling back to a call to get_bits if the buffer runs
|
pascal@215
|
1316 + dry). The following (up to got_huff_bits:) is equivalent to
|
pascal@215
|
1317 + j=get_bits(bd,hufGroup->maxLen);
|
pascal@215
|
1318 + */
|
pascal@215
|
1319 + while (bd->inbufBitCount<hufGroup->maxLen) {
|
pascal@215
|
1320 + if(bd->inbufPos==bd->inbufCount) {
|
pascal@215
|
1321 + j = get_bits(bd,hufGroup->maxLen);
|
pascal@215
|
1322 + goto got_huff_bits;
|
pascal@215
|
1323 + }
|
pascal@215
|
1324 + bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++];
|
pascal@215
|
1325 + bd->inbufBitCount+=8;
|
pascal@215
|
1326 + };
|
pascal@215
|
1327 + bd->inbufBitCount-=hufGroup->maxLen;
|
pascal@215
|
1328 + j = (bd->inbufBits>>bd->inbufBitCount)&((1<<hufGroup->maxLen)-1);
|
pascal@215
|
1329 +got_huff_bits:
|
pascal@215
|
1330 + /* Figure how how many bits are in next symbol and unget extras */
|
pascal@215
|
1331 + i=hufGroup->minLen;
|
pascal@215
|
1332 + while(j>limit[i]) ++i;
|
pascal@215
|
1333 + bd->inbufBitCount += (hufGroup->maxLen - i);
|
pascal@215
|
1334 + /* Huffman decode value to get nextSym (with bounds checking) */
|
pascal@215
|
1335 + if ((i > hufGroup->maxLen)
|
pascal@215
|
1336 + || (((unsigned)(j=(j>>(hufGroup->maxLen-i))-base[i]))
|
pascal@215
|
1337 + >= MAX_SYMBOLS))
|
pascal@215
|
1338 + return RETVAL_DATA_ERROR;
|
pascal@215
|
1339 + nextSym = hufGroup->permute[j];
|
pascal@215
|
1340 + /* We have now decoded the symbol, which indicates either a new literal
|
pascal@215
|
1341 + byte, or a repeated run of the most recent literal byte. First,
|
pascal@215
|
1342 + check if nextSym indicates a repeated run, and if so loop collecting
|
pascal@215
|
1343 + how many times to repeat the last literal. */
|
pascal@215
|
1344 + if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
|
pascal@215
|
1345 + /* If this is the start of a new run, zero out counter */
|
pascal@215
|
1346 + if(!runPos) {
|
pascal@215
|
1347 + runPos = 1;
|
pascal@215
|
1348 + t = 0;
|
pascal@215
|
1349 + }
|
pascal@215
|
1350 + /* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at
|
pascal@215
|
1351 + each bit position, add 1 or 2 instead. For example,
|
pascal@215
|
1352 + 1011 is 1<<0 + 1<<1 + 2<<2. 1010 is 2<<0 + 2<<1 + 1<<2.
|
pascal@215
|
1353 + You can make any bit pattern that way using 1 less symbol than
|
pascal@215
|
1354 + the basic or 0/1 method (except all bits 0, which would use no
|
pascal@215
|
1355 + symbols, but a run of length 0 doesn't mean anything in this
|
pascal@215
|
1356 + context). Thus space is saved. */
|
pascal@215
|
1357 + t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
|
pascal@215
|
1358 + runPos <<= 1;
|
pascal@215
|
1359 + continue;
|
pascal@215
|
1360 + }
|
pascal@215
|
1361 + /* When we hit the first non-run symbol after a run, we now know
|
pascal@215
|
1362 + how many times to repeat the last literal, so append that many
|
pascal@215
|
1363 + copies to our buffer of decoded symbols (dbuf) now. (The last
|
pascal@215
|
1364 + literal used is the one at the head of the mtfSymbol array.) */
|
pascal@215
|
1365 + if(runPos) {
|
pascal@215
|
1366 + runPos=0;
|
pascal@215
|
1367 + if(dbufCount+t>=dbufSize) return RETVAL_DATA_ERROR;
|
pascal@215
|
1368 +
|
pascal@215
|
1369 + uc = symToByte[mtfSymbol[0]];
|
pascal@215
|
1370 + byteCount[uc] += t;
|
pascal@215
|
1371 + while(t--) dbuf[dbufCount++]=uc;
|
pascal@215
|
1372 + }
|
pascal@215
|
1373 + /* Is this the terminating symbol? */
|
pascal@215
|
1374 + if(nextSym>symTotal) break;
|
pascal@215
|
1375 + /* At this point, nextSym indicates a new literal character. Subtract
|
pascal@215
|
1376 + one to get the position in the MTF array at which this literal is
|
pascal@215
|
1377 + currently to be found. (Note that the result can't be -1 or 0,
|
pascal@215
|
1378 + because 0 and 1 are RUNA and RUNB. But another instance of the
|
pascal@215
|
1379 + first symbol in the mtf array, position 0, would have been handled
|
pascal@215
|
1380 + as part of a run above. Therefore 1 unused mtf position minus
|
pascal@215
|
1381 + 2 non-literal nextSym values equals -1.) */
|
pascal@215
|
1382 + if(dbufCount>=dbufSize) return RETVAL_DATA_ERROR;
|
pascal@215
|
1383 + i = nextSym - 1;
|
pascal@215
|
1384 + uc = mtfSymbol[i];
|
pascal@215
|
1385 + /* Adjust the MTF array. Since we typically expect to move only a
|
pascal@215
|
1386 + * small number of symbols, and are bound by 256 in any case, using
|
pascal@215
|
1387 + * memmove here would typically be bigger and slower due to function
|
pascal@215
|
1388 + * call overhead and other assorted setup costs. */
|
pascal@215
|
1389 + do {
|
pascal@215
|
1390 + mtfSymbol[i] = mtfSymbol[i-1];
|
pascal@215
|
1391 + } while (--i);
|
pascal@215
|
1392 + mtfSymbol[0] = uc;
|
pascal@215
|
1393 + uc=symToByte[uc];
|
pascal@215
|
1394 + /* We have our literal byte. Save it into dbuf. */
|
pascal@215
|
1395 + byteCount[uc]++;
|
pascal@215
|
1396 + dbuf[dbufCount++] = (unsigned int)uc;
|
pascal@215
|
1397 + }
|
pascal@215
|
1398 + /* At this point, we've read all the Huffman-coded symbols (and repeated
|
pascal@215
|
1399 + runs) for this block from the input stream, and decoded them into the
|
pascal@215
|
1400 + intermediate buffer. There are dbufCount many decoded bytes in dbuf[].
|
pascal@215
|
1401 + Now undo the Burrows-Wheeler transform on dbuf.
|
pascal@215
|
1402 + See http://dogma.net/markn/articles/bwt/bwt.htm
|
pascal@215
|
1403 + */
|
pascal@215
|
1404 + /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
|
pascal@215
|
1405 + j=0;
|
pascal@215
|
1406 + for(i=0;i<256;i++) {
|
pascal@215
|
1407 + k=j+byteCount[i];
|
pascal@215
|
1408 + byteCount[i] = j;
|
pascal@215
|
1409 + j=k;
|
pascal@215
|
1410 + }
|
pascal@215
|
1411 + /* Figure out what order dbuf would be in if we sorted it. */
|
pascal@215
|
1412 + for (i=0;i<dbufCount;i++) {
|
pascal@215
|
1413 + uc=(unsigned char)(dbuf[i] & 0xff);
|
pascal@215
|
1414 + dbuf[byteCount[uc]] |= (i << 8);
|
pascal@215
|
1415 + byteCount[uc]++;
|
pascal@215
|
1416 + }
|
pascal@215
|
1417 + /* Decode first byte by hand to initialize "previous" byte. Note that it
|
pascal@215
|
1418 + doesn't get output, and if the first three characters are identical
|
pascal@215
|
1419 + it doesn't qualify as a run (hence writeRunCountdown=5). */
|
pascal@215
|
1420 + if(dbufCount) {
|
pascal@215
|
1421 + if(origPtr>=dbufCount) return RETVAL_DATA_ERROR;
|
pascal@215
|
1422 + bd->writePos=dbuf[origPtr];
|
pascal@215
|
1423 + bd->writeCurrent=(unsigned char)(bd->writePos&0xff);
|
pascal@215
|
1424 + bd->writePos>>=8;
|
pascal@215
|
1425 + bd->writeRunCountdown=5;
|
pascal@215
|
1426 + }
|
pascal@215
|
1427 + bd->writeCount=dbufCount;
|
pascal@215
|
1428 +
|
pascal@215
|
1429 + return RETVAL_OK;
|
pascal@215
|
1430 +}
|
pascal@215
|
1431 +
|
pascal@215
|
1432 +/* Undo burrows-wheeler transform on intermediate buffer to produce output.
|
pascal@215
|
1433 + If start_bunzip was initialized with out_fd=-1, then up to len bytes of
|
pascal@215
|
1434 + data are written to outbuf. Return value is number of bytes written or
|
pascal@215
|
1435 + error (all errors are negative numbers). If out_fd!=-1, outbuf and len
|
pascal@215
|
1436 + are ignored, data is written to out_fd and return is RETVAL_OK or error.
|
pascal@215
|
1437 +*/
|
pascal@215
|
1438 +
|
pascal@215
|
1439 +static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
pascal@215
|
1440 +{
|
pascal@215
|
1441 + const unsigned int *dbuf;
|
pascal@215
|
1442 + int pos,xcurrent,previous,gotcount;
|
pascal@215
|
1443 +
|
pascal@215
|
1444 + /* If last read was short due to end of file, return last block now */
|
pascal@215
|
1445 + if(bd->writeCount<0) return bd->writeCount;
|
pascal@215
|
1446 +
|
pascal@215
|
1447 + gotcount = 0;
|
pascal@215
|
1448 + dbuf=bd->dbuf;
|
pascal@215
|
1449 + pos=bd->writePos;
|
pascal@215
|
1450 + xcurrent=bd->writeCurrent;
|
pascal@215
|
1451 +
|
pascal@215
|
1452 + /* We will always have pending decoded data to write into the output
|
pascal@215
|
1453 + buffer unless this is the very first call (in which case we haven't
|
pascal@215
|
1454 + Huffman-decoded a block into the intermediate buffer yet). */
|
pascal@215
|
1455 +
|
pascal@215
|
1456 + if (bd->writeCopies) {
|
pascal@215
|
1457 + /* Inside the loop, writeCopies means extra copies (beyond 1) */
|
pascal@215
|
1458 + --bd->writeCopies;
|
pascal@215
|
1459 + /* Loop outputting bytes */
|
pascal@215
|
1460 + for(;;) {
|
pascal@215
|
1461 + /* If the output buffer is full, snapshot state and return */
|
pascal@215
|
1462 + if(gotcount >= len) {
|
pascal@215
|
1463 + bd->writePos=pos;
|
pascal@215
|
1464 + bd->writeCurrent=xcurrent;
|
pascal@215
|
1465 + bd->writeCopies++;
|
pascal@215
|
1466 + return len;
|
pascal@215
|
1467 + }
|
pascal@215
|
1468 + /* Write next byte into output buffer, updating CRC */
|
pascal@215
|
1469 + outbuf[gotcount++] = xcurrent;
|
pascal@215
|
1470 + bd->writeCRC=(((bd->writeCRC)<<8)
|
pascal@215
|
1471 + ^bd->crc32Table[((bd->writeCRC)>>24)^xcurrent]);
|
pascal@215
|
1472 + /* Loop now if we're outputting multiple copies of this byte */
|
pascal@215
|
1473 + if (bd->writeCopies) {
|
pascal@215
|
1474 + --bd->writeCopies;
|
pascal@215
|
1475 + continue;
|
pascal@215
|
1476 + }
|
pascal@215
|
1477 +decode_next_byte:
|
pascal@215
|
1478 + if (!bd->writeCount--) break;
|
pascal@215
|
1479 + /* Follow sequence vector to undo Burrows-Wheeler transform */
|
pascal@215
|
1480 + previous=xcurrent;
|
pascal@215
|
1481 + pos=dbuf[pos];
|
pascal@215
|
1482 + xcurrent=pos&0xff;
|
pascal@215
|
1483 + pos>>=8;
|
pascal@215
|
1484 + /* After 3 consecutive copies of the same byte, the 4th is a repeat
|
pascal@215
|
1485 + count. We count down from 4 instead
|
pascal@215
|
1486 + * of counting up because testing for non-zero is faster */
|
pascal@215
|
1487 + if(--bd->writeRunCountdown) {
|
pascal@215
|
1488 + if(xcurrent!=previous) bd->writeRunCountdown=4;
|
pascal@215
|
1489 + } else {
|
pascal@215
|
1490 + /* We have a repeated run, this byte indicates the count */
|
pascal@215
|
1491 + bd->writeCopies=xcurrent;
|
pascal@215
|
1492 + xcurrent=previous;
|
pascal@215
|
1493 + bd->writeRunCountdown=5;
|
pascal@215
|
1494 + /* Sometimes there are just 3 bytes (run length 0) */
|
pascal@215
|
1495 + if(!bd->writeCopies) goto decode_next_byte;
|
pascal@215
|
1496 + /* Subtract the 1 copy we'd output anyway to get extras */
|
pascal@215
|
1497 + --bd->writeCopies;
|
pascal@215
|
1498 + }
|
pascal@215
|
1499 + }
|
pascal@215
|
1500 + /* Decompression of this block completed successfully */
|
pascal@215
|
1501 + bd->writeCRC=~bd->writeCRC;
|
pascal@215
|
1502 + bd->totalCRC=((bd->totalCRC<<1) | (bd->totalCRC>>31)) ^ bd->writeCRC;
|
pascal@215
|
1503 + /* If this block had a CRC error, force file level CRC error. */
|
pascal@215
|
1504 + if(bd->writeCRC!=bd->headerCRC) {
|
pascal@215
|
1505 + bd->totalCRC=bd->headerCRC+1;
|
pascal@215
|
1506 + return RETVAL_LAST_BLOCK;
|
pascal@215
|
1507 + }
|
pascal@215
|
1508 + }
|
pascal@215
|
1509 +
|
pascal@215
|
1510 + /* Refill the intermediate buffer by Huffman-decoding next block of input */
|
pascal@215
|
1511 + /* (previous is just a convenient unused temp variable here) */
|
pascal@215
|
1512 + previous=get_next_block(bd);
|
pascal@215
|
1513 + if(previous) {
|
pascal@215
|
1514 + bd->writeCount=previous;
|
pascal@215
|
1515 + return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount;
|
pascal@215
|
1516 + }
|
pascal@215
|
1517 + bd->writeCRC=0xffffffffUL;
|
pascal@215
|
1518 + pos=bd->writePos;
|
pascal@215
|
1519 + xcurrent=bd->writeCurrent;
|
pascal@215
|
1520 + goto decode_next_byte;
|
pascal@215
|
1521 +}
|
pascal@215
|
1522 +
|
pascal@215
|
1523 +static int nofill(void *buf,unsigned int len) {
|
pascal@215
|
1524 + return -1;
|
pascal@215
|
1525 +}
|
pascal@215
|
1526 +
|
pascal@215
|
1527 +/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
|
pascal@215
|
1528 + a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
|
pascal@215
|
1529 + ignored, and data is read from file handle into temporary buffer. */
|
pascal@215
|
1530 +static int start_bunzip(bunzip_data **bdp, void *inbuf, int len,
|
pascal@215
|
1531 + int (*fill)(void*,unsigned int))
|
pascal@215
|
1532 +{
|
pascal@215
|
1533 + bunzip_data *bd;
|
pascal@215
|
1534 + unsigned int i,j,c;
|
pascal@215
|
1535 + const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16)
|
pascal@215
|
1536 + +(((unsigned int)'h')<<8)+(unsigned int)'0';
|
pascal@215
|
1537 +
|
pascal@215
|
1538 + /* Figure out how much data to allocate */
|
pascal@215
|
1539 + i=sizeof(bunzip_data);
|
pascal@215
|
1540 +
|
pascal@215
|
1541 + /* Allocate bunzip_data. Most fields initialize to zero. */
|
pascal@215
|
1542 + bd=*bdp=malloc(i);
|
pascal@215
|
1543 + memset(bd,0,sizeof(bunzip_data));
|
pascal@215
|
1544 + /* Setup input buffer */
|
pascal@215
|
1545 + bd->inbuf=inbuf;
|
pascal@215
|
1546 + bd->inbufCount=len;
|
pascal@215
|
1547 + if(fill != NULL)
|
pascal@215
|
1548 + bd->fill=fill;
|
pascal@215
|
1549 + else
|
pascal@215
|
1550 + bd->fill=nofill;
|
pascal@215
|
1551 +
|
pascal@215
|
1552 + /* Init the CRC32 table (big endian) */
|
pascal@215
|
1553 + for(i=0;i<256;i++) {
|
pascal@215
|
1554 + c=i<<24;
|
pascal@215
|
1555 + for(j=8;j;j--)
|
pascal@215
|
1556 + c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
|
pascal@215
|
1557 + bd->crc32Table[i]=c;
|
pascal@215
|
1558 + }
|
pascal@215
|
1559 +
|
pascal@215
|
1560 + /* Ensure that file starts with "BZh['1'-'9']." */
|
pascal@215
|
1561 + i = get_bits(bd,32);
|
pascal@215
|
1562 + if (((unsigned int)(i-BZh0-1)) >= 9) return RETVAL_NOT_BZIP_DATA;
|
pascal@215
|
1563 +
|
pascal@215
|
1564 + /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
|
pascal@215
|
1565 + uncompressed data. Allocate intermediate buffer for block. */
|
pascal@215
|
1566 + bd->dbufSize=100000*(i-BZh0);
|
pascal@215
|
1567 +
|
pascal@215
|
1568 + bd->dbuf=large_malloc(bd->dbufSize * sizeof(int));
|
pascal@215
|
1569 + return RETVAL_OK;
|
pascal@215
|
1570 +}
|
pascal@215
|
1571 +
|
pascal@215
|
1572 +/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data,
|
pascal@215
|
1573 + not end of file.) */
|
pascal@215
|
1574 +STATIC int bunzip2(char *inbuf, int len,
|
pascal@215
|
1575 + int(*fill)(void*,unsigned int),
|
pascal@215
|
1576 + int(*writebb)(char*,unsigned int),
|
pascal@215
|
1577 + int *pos)
|
pascal@215
|
1578 +{
|
pascal@215
|
1579 + char *outbuf;
|
pascal@215
|
1580 + bunzip_data *bd;
|
pascal@215
|
1581 + int i;
|
pascal@215
|
1582 +
|
pascal@215
|
1583 + outbuf=malloc(BZIP2_IOBUF_SIZE);
|
pascal@215
|
1584 + if(!(i=start_bunzip(&bd,inbuf,len,fill))) {
|
pascal@215
|
1585 + for(;;) {
|
pascal@215
|
1586 + if((i=read_bunzip(bd,outbuf,BZIP2_IOBUF_SIZE)) <= 0) break;
|
pascal@215
|
1587 + if(i!=writebb(outbuf,i)) {
|
pascal@215
|
1588 + i=RETVAL_UNEXPECTED_OUTPUT_EOF;
|
pascal@215
|
1589 + break;
|
pascal@215
|
1590 + }
|
pascal@215
|
1591 + }
|
pascal@215
|
1592 + }
|
pascal@215
|
1593 + /* Check CRC and release memory */
|
pascal@215
|
1594 + if(i==RETVAL_LAST_BLOCK) {
|
pascal@215
|
1595 + if (bd->headerCRC!=bd->totalCRC) {
|
pascal@215
|
1596 + error("Data integrity error when decompressing.");
|
pascal@215
|
1597 + } else {
|
pascal@215
|
1598 + i=RETVAL_OK;
|
pascal@215
|
1599 + }
|
pascal@215
|
1600 + }
|
pascal@215
|
1601 + else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
pascal@215
|
1602 + error("Compressed file ends unexpectedly");
|
pascal@215
|
1603 + }
|
pascal@215
|
1604 + if(bd->dbuf) large_free(bd->dbuf);
|
pascal@215
|
1605 + if(pos)
|
pascal@215
|
1606 + *pos = bd->inbufPos;
|
pascal@215
|
1607 + free(bd);
|
pascal@215
|
1608 + free(outbuf);
|
pascal@215
|
1609 +
|
pascal@215
|
1610 + return i;
|
pascal@215
|
1611 +}
|
pascal@215
|
1612 +
|
pascal@215
|
1613 --- linux-2.6.24.2/lib/decompress_unlzma.c
|
pascal@215
|
1614 +++ linux-2.6.24.2/lib/decompress_unlzma.c
|
pascal@215
|
1615 @@ -0,0 +1,605 @@
|
pascal@215
|
1616 +/* Lzma decompressor for Linux kernel. Shamelessly snarfed
|
pascal@215
|
1617 + * from busybox 1.1.1
|
pascal@215
|
1618 + *
|
pascal@215
|
1619 + * Linux kernel adaptation
|
pascal@215
|
1620 + * Copyright (C) 2006 Alain <alain@knaff.lu>
|
pascal@215
|
1621 + *
|
pascal@215
|
1622 + * Based on small lzma deflate implementation/Small range coder
|
pascal@215
|
1623 + * implementation for lzma.
|
pascal@215
|
1624 + * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
pascal@215
|
1625 + *
|
pascal@215
|
1626 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
|
pascal@215
|
1627 + * Copyright (C) 1999-2005 Igor Pavlov
|
pascal@215
|
1628 + *
|
pascal@215
|
1629 + * Copyrights of the parts, see headers below.
|
pascal@215
|
1630 + *
|
pascal@215
|
1631 + *
|
pascal@215
|
1632 + * This program is free software; you can redistribute it and/or
|
pascal@215
|
1633 + * modify it under the terms of the GNU Lesser General Public
|
pascal@215
|
1634 + * License as published by the Free Software Foundation; either
|
pascal@215
|
1635 + * version 2.1 of the License, or (at your option) any later version.
|
pascal@215
|
1636 + *
|
pascal@215
|
1637 + * This program is distributed in the hope that it will be useful,
|
pascal@215
|
1638 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
pascal@215
|
1639 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
pascal@215
|
1640 + * Lesser General Public License for more details.
|
pascal@215
|
1641 + *
|
pascal@215
|
1642 + * You should have received a copy of the GNU Lesser General Public
|
pascal@215
|
1643 + * License along with this library; if not, write to the Free Software
|
pascal@215
|
1644 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
pascal@215
|
1645 + */
|
pascal@215
|
1646 +
|
pascal@215
|
1647 +#ifndef STATIC
|
pascal@215
|
1648 +
|
pascal@215
|
1649 +#include <linux/kernel.h>
|
pascal@215
|
1650 +#include <linux/fs.h>
|
pascal@215
|
1651 +#include <linux/string.h>
|
pascal@215
|
1652 +
|
pascal@215
|
1653 +#ifdef TEST
|
pascal@215
|
1654 +#include "test.h"
|
pascal@215
|
1655 +#else
|
pascal@215
|
1656 +#include <linux/vmalloc.h>
|
pascal@215
|
1657 +#endif
|
pascal@215
|
1658 +
|
pascal@215
|
1659 +static void __init *large_malloc(size_t size)
|
pascal@215
|
1660 +{
|
pascal@215
|
1661 + return vmalloc(size);
|
pascal@215
|
1662 +}
|
pascal@215
|
1663 +
|
pascal@215
|
1664 +static void __init large_free(void *where)
|
pascal@215
|
1665 +{
|
pascal@215
|
1666 + vfree(where);
|
pascal@215
|
1667 +}
|
pascal@215
|
1668 +
|
pascal@215
|
1669 +#ifndef TEST
|
pascal@215
|
1670 +static void __init *malloc(size_t size)
|
pascal@215
|
1671 +{
|
pascal@215
|
1672 + return kmalloc(size, GFP_KERNEL);
|
pascal@215
|
1673 +}
|
pascal@215
|
1674 +
|
pascal@215
|
1675 +static void __init free(void *where)
|
pascal@215
|
1676 +{
|
pascal@215
|
1677 + kfree(where);
|
pascal@215
|
1678 +}
|
pascal@215
|
1679 +
|
pascal@215
|
1680 +static void __init error(char *x)
|
pascal@215
|
1681 +{
|
pascal@215
|
1682 + printk(KERN_ERR "%s\n", x);
|
pascal@215
|
1683 +}
|
pascal@215
|
1684 +
|
pascal@215
|
1685 +#endif
|
pascal@215
|
1686 +
|
pascal@215
|
1687 +#define STATIC /**/
|
pascal@215
|
1688 +
|
pascal@215
|
1689 +#endif
|
pascal@215
|
1690 +
|
pascal@215
|
1691 +#include <linux/decompress_unlzma.h>
|
pascal@215
|
1692 +
|
pascal@215
|
1693 +#define MIN(a,b) (((a)<(b))?(a):(b))
|
pascal@215
|
1694 +
|
pascal@215
|
1695 +static long long read_int(unsigned char *ptr, int size)
|
pascal@215
|
1696 +{
|
pascal@215
|
1697 + int i;
|
pascal@215
|
1698 + long long ret=0;
|
pascal@215
|
1699 +
|
pascal@215
|
1700 + for(i=0; i<size; i++) {
|
pascal@215
|
1701 + ret = (ret << 8) | ptr[size-i-1];
|
pascal@215
|
1702 + }
|
pascal@215
|
1703 + return ret;
|
pascal@215
|
1704 +}
|
pascal@215
|
1705 +
|
pascal@215
|
1706 +#define ENDIAN_CONVERT(x) x=(typeof(x))read_int((unsigned char*)&x,sizeof(x))
|
pascal@215
|
1707 +
|
pascal@215
|
1708 +
|
pascal@215
|
1709 +/* Small range coder implementation for lzma.
|
pascal@215
|
1710 + * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
pascal@215
|
1711 + *
|
pascal@215
|
1712 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
|
pascal@215
|
1713 + * Copyright (c) 1999-2005 Igor Pavlov
|
pascal@215
|
1714 + */
|
pascal@215
|
1715 +
|
pascal@215
|
1716 +#ifndef always_inline
|
pascal@215
|
1717 +# if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >0)
|
pascal@215
|
1718 +# define always_inline __attribute__((always_inline)) inline
|
pascal@215
|
1719 +# else
|
pascal@215
|
1720 +# define always_inline inline
|
pascal@215
|
1721 +# endif
|
pascal@215
|
1722 +#endif
|
pascal@215
|
1723 +
|
pascal@215
|
1724 +#ifdef CONFIG_FEATURE_LZMA_FAST
|
pascal@215
|
1725 +# define speed_inline always_inline
|
pascal@215
|
1726 +#else
|
pascal@215
|
1727 +# define speed_inline
|
pascal@215
|
1728 +#endif
|
pascal@215
|
1729 +
|
pascal@215
|
1730 +
|
pascal@215
|
1731 +typedef struct {
|
pascal@215
|
1732 + int (*fill)(void*,unsigned int);
|
pascal@215
|
1733 + uint8_t *ptr;
|
pascal@215
|
1734 + uint8_t *buffer;
|
pascal@215
|
1735 + uint8_t *buffer_end;
|
pascal@215
|
1736 + int buffer_size;
|
pascal@215
|
1737 + uint32_t code;
|
pascal@215
|
1738 + uint32_t range;
|
pascal@215
|
1739 + uint32_t bound;
|
pascal@215
|
1740 +} rc_t;
|
pascal@215
|
1741 +
|
pascal@215
|
1742 +
|
pascal@215
|
1743 +#define RC_TOP_BITS 24
|
pascal@215
|
1744 +#define RC_MOVE_BITS 5
|
pascal@215
|
1745 +#define RC_MODEL_TOTAL_BITS 11
|
pascal@215
|
1746 +
|
pascal@215
|
1747 +
|
pascal@215
|
1748 +/* Called twice: once at startup and once in rc_normalize() */
|
pascal@215
|
1749 +static void rc_read(rc_t * rc)
|
pascal@215
|
1750 +{
|
pascal@215
|
1751 + rc->buffer_size = rc->fill((char*)rc->buffer, LZMA_IOBUF_SIZE);
|
pascal@215
|
1752 + if (rc->buffer_size <= 0)
|
pascal@215
|
1753 + error("unexpected EOF");
|
pascal@215
|
1754 + rc->ptr = rc->buffer;
|
pascal@215
|
1755 + rc->buffer_end = rc->buffer + rc->buffer_size;
|
pascal@215
|
1756 +}
|
pascal@215
|
1757 +
|
pascal@215
|
1758 +/* Called once */
|
pascal@215
|
1759 +static always_inline void rc_init(rc_t * rc, int (*fill)(void*,unsigned int),
|
pascal@215
|
1760 + char *buffer, int buffer_size)
|
pascal@215
|
1761 +{
|
pascal@215
|
1762 + rc->fill = fill;
|
pascal@215
|
1763 + rc->buffer = (uint8_t *)buffer;
|
pascal@215
|
1764 + rc->buffer_size = buffer_size;
|
pascal@215
|
1765 + rc->buffer_end = rc->buffer + rc->buffer_size;
|
pascal@215
|
1766 + rc->ptr = rc->buffer;
|
pascal@215
|
1767 +
|
pascal@215
|
1768 + rc->code = 0;
|
pascal@215
|
1769 + rc->range = 0xFFFFFFFF;
|
pascal@215
|
1770 +}
|
pascal@215
|
1771 +
|
pascal@215
|
1772 +static always_inline void rc_init_code(rc_t * rc)
|
pascal@215
|
1773 +{
|
pascal@215
|
1774 + int i;
|
pascal@215
|
1775 +
|
pascal@215
|
1776 + for (i = 0; i < 5; i++) {
|
pascal@215
|
1777 + if (rc->ptr >= rc->buffer_end)
|
pascal@215
|
1778 + rc_read(rc);
|
pascal@215
|
1779 + rc->code = (rc->code << 8) | *rc->ptr++;
|
pascal@215
|
1780 + }
|
pascal@215
|
1781 +}
|
pascal@215
|
1782 +
|
pascal@215
|
1783 +
|
pascal@215
|
1784 +/* Called once. TODO: bb_maybe_free() */
|
pascal@215
|
1785 +static always_inline void rc_free(rc_t * rc)
|
pascal@215
|
1786 +{
|
pascal@215
|
1787 + free(rc->buffer);
|
pascal@215
|
1788 +}
|
pascal@215
|
1789 +
|
pascal@215
|
1790 +/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
|
pascal@215
|
1791 +static void rc_do_normalize(rc_t * rc)
|
pascal@215
|
1792 +{
|
pascal@215
|
1793 + if (rc->ptr >= rc->buffer_end)
|
pascal@215
|
1794 + rc_read(rc);
|
pascal@215
|
1795 + rc->range <<= 8;
|
pascal@215
|
1796 + rc->code = (rc->code << 8) | *rc->ptr++;
|
pascal@215
|
1797 +}
|
pascal@215
|
1798 +static always_inline void rc_normalize(rc_t * rc)
|
pascal@215
|
1799 +{
|
pascal@215
|
1800 + if (rc->range < (1 << RC_TOP_BITS)) {
|
pascal@215
|
1801 + rc_do_normalize(rc);
|
pascal@215
|
1802 + }
|
pascal@215
|
1803 +}
|
pascal@215
|
1804 +
|
pascal@215
|
1805 +/* Called 9 times */
|
pascal@215
|
1806 +/* Why rc_is_bit_0_helper exists?
|
pascal@215
|
1807 + * Because we want to always expose (rc->code < rc->bound) to optimizer
|
pascal@215
|
1808 + */
|
pascal@215
|
1809 +static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p)
|
pascal@215
|
1810 +{
|
pascal@215
|
1811 + rc_normalize(rc);
|
pascal@215
|
1812 + rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
|
pascal@215
|
1813 + return rc->bound;
|
pascal@215
|
1814 +}
|
pascal@215
|
1815 +static always_inline int rc_is_bit_0(rc_t * rc, uint16_t * p)
|
pascal@215
|
1816 +{
|
pascal@215
|
1817 + uint32_t t = rc_is_bit_0_helper(rc, p);
|
pascal@215
|
1818 + return rc->code < t;
|
pascal@215
|
1819 +}
|
pascal@215
|
1820 +
|
pascal@215
|
1821 +/* Called ~10 times, but very small, thus inlined */
|
pascal@215
|
1822 +static speed_inline void rc_update_bit_0(rc_t * rc, uint16_t * p)
|
pascal@215
|
1823 +{
|
pascal@215
|
1824 + rc->range = rc->bound;
|
pascal@215
|
1825 + *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
|
pascal@215
|
1826 +}
|
pascal@215
|
1827 +static speed_inline void rc_update_bit_1(rc_t * rc, uint16_t * p)
|
pascal@215
|
1828 +{
|
pascal@215
|
1829 + rc->range -= rc->bound;
|
pascal@215
|
1830 + rc->code -= rc->bound;
|
pascal@215
|
1831 + *p -= *p >> RC_MOVE_BITS;
|
pascal@215
|
1832 +}
|
pascal@215
|
1833 +
|
pascal@215
|
1834 +/* Called 4 times in unlzma loop */
|
pascal@215
|
1835 +static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol)
|
pascal@215
|
1836 +{
|
pascal@215
|
1837 + if (rc_is_bit_0(rc, p)) {
|
pascal@215
|
1838 + rc_update_bit_0(rc, p);
|
pascal@215
|
1839 + *symbol *= 2;
|
pascal@215
|
1840 + return 0;
|
pascal@215
|
1841 + } else {
|
pascal@215
|
1842 + rc_update_bit_1(rc, p);
|
pascal@215
|
1843 + *symbol = *symbol * 2 + 1;
|
pascal@215
|
1844 + return 1;
|
pascal@215
|
1845 + }
|
pascal@215
|
1846 +}
|
pascal@215
|
1847 +
|
pascal@215
|
1848 +/* Called once */
|
pascal@215
|
1849 +static always_inline int rc_direct_bit(rc_t * rc)
|
pascal@215
|
1850 +{
|
pascal@215
|
1851 + rc_normalize(rc);
|
pascal@215
|
1852 + rc->range >>= 1;
|
pascal@215
|
1853 + if (rc->code >= rc->range) {
|
pascal@215
|
1854 + rc->code -= rc->range;
|
pascal@215
|
1855 + return 1;
|
pascal@215
|
1856 + }
|
pascal@215
|
1857 + return 0;
|
pascal@215
|
1858 +}
|
pascal@215
|
1859 +
|
pascal@215
|
1860 +/* Called twice */
|
pascal@215
|
1861 +static speed_inline void
|
pascal@215
|
1862 +rc_bit_tree_decode(rc_t * rc, uint16_t * p, int num_levels, int *symbol)
|
pascal@215
|
1863 +{
|
pascal@215
|
1864 + int i = num_levels;
|
pascal@215
|
1865 +
|
pascal@215
|
1866 + *symbol = 1;
|
pascal@215
|
1867 + while (i--)
|
pascal@215
|
1868 + rc_get_bit(rc, p + *symbol, symbol);
|
pascal@215
|
1869 + *symbol -= 1 << num_levels;
|
pascal@215
|
1870 +}
|
pascal@215
|
1871 +
|
pascal@215
|
1872 +
|
pascal@215
|
1873 +/*
|
pascal@215
|
1874 + * Small lzma deflate implementation.
|
pascal@215
|
1875 + * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
pascal@215
|
1876 + *
|
pascal@215
|
1877 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
|
pascal@215
|
1878 + * Copyright (C) 1999-2005 Igor Pavlov
|
pascal@215
|
1879 + */
|
pascal@215
|
1880 +
|
pascal@215
|
1881 +
|
pascal@215
|
1882 +typedef struct {
|
pascal@215
|
1883 + uint8_t pos;
|
pascal@215
|
1884 + uint32_t dict_size;
|
pascal@215
|
1885 + uint64_t dst_size;
|
pascal@215
|
1886 +} __attribute__ ((packed)) lzma_header_t;
|
pascal@215
|
1887 +
|
pascal@215
|
1888 +
|
pascal@215
|
1889 +#define LZMA_BASE_SIZE 1846
|
pascal@215
|
1890 +#define LZMA_LIT_SIZE 768
|
pascal@215
|
1891 +
|
pascal@215
|
1892 +#define LZMA_NUM_POS_BITS_MAX 4
|
pascal@215
|
1893 +
|
pascal@215
|
1894 +#define LZMA_LEN_NUM_LOW_BITS 3
|
pascal@215
|
1895 +#define LZMA_LEN_NUM_MID_BITS 3
|
pascal@215
|
1896 +#define LZMA_LEN_NUM_HIGH_BITS 8
|
pascal@215
|
1897 +
|
pascal@215
|
1898 +#define LZMA_LEN_CHOICE 0
|
pascal@215
|
1899 +#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
|
pascal@215
|
1900 +#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
|
pascal@215
|
1901 +#define LZMA_LEN_MID (LZMA_LEN_LOW \
|
pascal@215
|
1902 + + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
|
pascal@215
|
1903 +#define LZMA_LEN_HIGH (LZMA_LEN_MID \
|
pascal@215
|
1904 + +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
|
pascal@215
|
1905 +#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
|
pascal@215
|
1906 +
|
pascal@215
|
1907 +#define LZMA_NUM_STATES 12
|
pascal@215
|
1908 +#define LZMA_NUM_LIT_STATES 7
|
pascal@215
|
1909 +
|
pascal@215
|
1910 +#define LZMA_START_POS_MODEL_INDEX 4
|
pascal@215
|
1911 +#define LZMA_END_POS_MODEL_INDEX 14
|
pascal@215
|
1912 +#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
|
pascal@215
|
1913 +
|
pascal@215
|
1914 +#define LZMA_NUM_POS_SLOT_BITS 6
|
pascal@215
|
1915 +#define LZMA_NUM_LEN_TO_POS_STATES 4
|
pascal@215
|
1916 +
|
pascal@215
|
1917 +#define LZMA_NUM_ALIGN_BITS 4
|
pascal@215
|
1918 +
|
pascal@215
|
1919 +#define LZMA_MATCH_MIN_LEN 2
|
pascal@215
|
1920 +
|
pascal@215
|
1921 +#define LZMA_IS_MATCH 0
|
pascal@215
|
1922 +#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX))
|
pascal@215
|
1923 +#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
|
pascal@215
|
1924 +#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
|
pascal@215
|
1925 +#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
|
pascal@215
|
1926 +#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
|
pascal@215
|
1927 +#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
|
pascal@215
|
1928 + + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
|
pascal@215
|
1929 +#define LZMA_SPEC_POS (LZMA_POS_SLOT \
|
pascal@215
|
1930 + +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
|
pascal@215
|
1931 +#define LZMA_ALIGN (LZMA_SPEC_POS \
|
pascal@215
|
1932 + + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
|
pascal@215
|
1933 +#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
|
pascal@215
|
1934 +#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
pascal@215
|
1935 +#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
pascal@215
|
1936 +
|
pascal@215
|
1937 +
|
pascal@215
|
1938 +STATIC int unlzma(char *inbuf, int in_len,
|
pascal@215
|
1939 + int(*fill)(void*,unsigned int),
|
pascal@215
|
1940 + int(*writebb)(char*,unsigned int),
|
pascal@215
|
1941 + int *posp)
|
pascal@215
|
1942 +{
|
pascal@215
|
1943 + lzma_header_t header;
|
pascal@215
|
1944 + int lc, pb, lp;
|
pascal@215
|
1945 + uint32_t pos_state_mask;
|
pascal@215
|
1946 + uint32_t literal_pos_mask;
|
pascal@215
|
1947 + uint32_t pos;
|
pascal@215
|
1948 + uint16_t *p;
|
pascal@215
|
1949 + uint16_t *prob;
|
pascal@215
|
1950 + uint16_t *prob_lit;
|
pascal@215
|
1951 + int num_bits;
|
pascal@215
|
1952 + int num_probs;
|
pascal@215
|
1953 + rc_t rc;
|
pascal@215
|
1954 + int i, mi;
|
pascal@215
|
1955 + uint8_t *buffer;
|
pascal@215
|
1956 + uint8_t previous_byte = 0;
|
pascal@215
|
1957 + size_t buffer_pos = 0, global_pos = 0;
|
pascal@215
|
1958 + int len = 0;
|
pascal@215
|
1959 + int state = 0;
|
pascal@215
|
1960 + int bufsize;
|
pascal@215
|
1961 + uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
pascal@215
|
1962 +
|
pascal@215
|
1963 + rc_init(&rc, fill, inbuf, in_len);
|
pascal@215
|
1964 +
|
pascal@215
|
1965 + for (i = 0; i < sizeof(header); i++) {
|
pascal@215
|
1966 + if (rc.ptr >= rc.buffer_end)
|
pascal@215
|
1967 + rc_read(&rc);
|
pascal@215
|
1968 + ((unsigned char *)&header)[i] = *rc.ptr++;
|
pascal@215
|
1969 + }
|
pascal@215
|
1970 +
|
pascal@215
|
1971 + if (header.pos >= (9 * 5 * 5))
|
pascal@215
|
1972 + error("bad header");
|
pascal@215
|
1973 +
|
pascal@215
|
1974 + mi = header.pos / 9;
|
pascal@215
|
1975 + lc = header.pos % 9;
|
pascal@215
|
1976 + pb = mi / 5;
|
pascal@215
|
1977 + lp = mi % 5;
|
pascal@215
|
1978 + pos_state_mask = (1 << pb) - 1;
|
pascal@215
|
1979 + literal_pos_mask = (1 << lp) - 1;
|
pascal@215
|
1980 +
|
pascal@215
|
1981 + ENDIAN_CONVERT(header.dict_size);
|
pascal@215
|
1982 + ENDIAN_CONVERT(header.dst_size);
|
pascal@215
|
1983 +
|
pascal@215
|
1984 + if (header.dict_size == 0)
|
pascal@215
|
1985 + header.dict_size = 1;
|
pascal@215
|
1986 +
|
pascal@215
|
1987 + bufsize = MIN(header.dst_size, header.dict_size);
|
pascal@215
|
1988 + buffer = large_malloc(bufsize);
|
pascal@215
|
1989 + if(buffer == NULL)
|
pascal@215
|
1990 + return -1;
|
pascal@215
|
1991 +
|
pascal@215
|
1992 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
pascal@215
|
1993 + p = large_malloc(num_probs * sizeof(*p));
|
pascal@215
|
1994 + num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
|
pascal@215
|
1995 + for (i = 0; i < num_probs; i++)
|
pascal@215
|
1996 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
pascal@215
|
1997 +
|
pascal@215
|
1998 + rc_init_code(&rc);
|
pascal@215
|
1999 +
|
pascal@215
|
2000 + while (global_pos + buffer_pos < header.dst_size) {
|
pascal@215
|
2001 + int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
pascal@215
|
2002 +
|
pascal@215
|
2003 + prob =
|
pascal@215
|
2004 + p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
pascal@215
|
2005 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2006 + mi = 1;
|
pascal@215
|
2007 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2008 + prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE
|
pascal@215
|
2009 + * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
pascal@215
|
2010 + + (previous_byte >> (8 - lc)))));
|
pascal@215
|
2011 +
|
pascal@215
|
2012 + if (state >= LZMA_NUM_LIT_STATES) {
|
pascal@215
|
2013 + int match_byte;
|
pascal@215
|
2014 +
|
pascal@215
|
2015 + pos = buffer_pos - rep0;
|
pascal@215
|
2016 + while (pos >= header.dict_size)
|
pascal@215
|
2017 + pos += header.dict_size;
|
pascal@215
|
2018 + if(pos >= bufsize) {
|
pascal@215
|
2019 + goto fail;
|
pascal@215
|
2020 + }
|
pascal@215
|
2021 + match_byte = buffer[pos];
|
pascal@215
|
2022 + do {
|
pascal@215
|
2023 + int bit;
|
pascal@215
|
2024 +
|
pascal@215
|
2025 + match_byte <<= 1;
|
pascal@215
|
2026 + bit = match_byte & 0x100;
|
pascal@215
|
2027 + prob_lit = prob + 0x100 + bit + mi;
|
pascal@215
|
2028 + if (rc_get_bit(&rc, prob_lit, &mi)) {
|
pascal@215
|
2029 + if (!bit)
|
pascal@215
|
2030 + break;
|
pascal@215
|
2031 + } else {
|
pascal@215
|
2032 + if (bit)
|
pascal@215
|
2033 + break;
|
pascal@215
|
2034 + }
|
pascal@215
|
2035 + } while (mi < 0x100);
|
pascal@215
|
2036 + }
|
pascal@215
|
2037 + while (mi < 0x100) {
|
pascal@215
|
2038 + prob_lit = prob + mi;
|
pascal@215
|
2039 + rc_get_bit(&rc, prob_lit, &mi);
|
pascal@215
|
2040 + }
|
pascal@215
|
2041 + previous_byte = (uint8_t) mi;
|
pascal@215
|
2042 +
|
pascal@215
|
2043 + buffer[buffer_pos++] = previous_byte;
|
pascal@215
|
2044 + if (buffer_pos == header.dict_size) {
|
pascal@215
|
2045 + buffer_pos = 0;
|
pascal@215
|
2046 + global_pos += header.dict_size;
|
pascal@215
|
2047 + writebb((char*)buffer, header.dict_size);
|
pascal@215
|
2048 + }
|
pascal@215
|
2049 + if (state < 4)
|
pascal@215
|
2050 + state = 0;
|
pascal@215
|
2051 + else if (state < 10)
|
pascal@215
|
2052 + state -= 3;
|
pascal@215
|
2053 + else
|
pascal@215
|
2054 + state -= 6;
|
pascal@215
|
2055 + } else {
|
pascal@215
|
2056 + int offset;
|
pascal@215
|
2057 + uint16_t *prob_len;
|
pascal@215
|
2058 +
|
pascal@215
|
2059 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2060 + prob = p + LZMA_IS_REP + state;
|
pascal@215
|
2061 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2062 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2063 + rep3 = rep2;
|
pascal@215
|
2064 + rep2 = rep1;
|
pascal@215
|
2065 + rep1 = rep0;
|
pascal@215
|
2066 + state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
|
pascal@215
|
2067 + prob = p + LZMA_LEN_CODER;
|
pascal@215
|
2068 + } else {
|
pascal@215
|
2069 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2070 + prob = p + LZMA_IS_REP_G0 + state;
|
pascal@215
|
2071 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2072 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2073 + prob = (p + LZMA_IS_REP_0_LONG
|
pascal@215
|
2074 + + (state << LZMA_NUM_POS_BITS_MAX) + pos_state);
|
pascal@215
|
2075 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2076 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2077 +
|
pascal@215
|
2078 + state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
pascal@215
|
2079 + pos = buffer_pos - rep0;
|
pascal@215
|
2080 + while (pos >= header.dict_size)
|
pascal@215
|
2081 + pos += header.dict_size;
|
pascal@215
|
2082 + if(pos >= bufsize) {
|
pascal@215
|
2083 + goto fail;
|
pascal@215
|
2084 + }
|
pascal@215
|
2085 + previous_byte = buffer[pos];
|
pascal@215
|
2086 + buffer[buffer_pos++] = previous_byte;
|
pascal@215
|
2087 + if (buffer_pos == header.dict_size) {
|
pascal@215
|
2088 + buffer_pos = 0;
|
pascal@215
|
2089 + global_pos += header.dict_size;
|
pascal@215
|
2090 + writebb((char*)buffer, header.dict_size);
|
pascal@215
|
2091 + }
|
pascal@215
|
2092 + continue;
|
pascal@215
|
2093 + } else {
|
pascal@215
|
2094 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2095 + }
|
pascal@215
|
2096 + } else {
|
pascal@215
|
2097 + uint32_t distance;
|
pascal@215
|
2098 +
|
pascal@215
|
2099 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2100 + prob = p + LZMA_IS_REP_G1 + state;
|
pascal@215
|
2101 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2102 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2103 + distance = rep1;
|
pascal@215
|
2104 + } else {
|
pascal@215
|
2105 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2106 + prob = p + LZMA_IS_REP_G2 + state;
|
pascal@215
|
2107 + if (rc_is_bit_0(&rc, prob)) {
|
pascal@215
|
2108 + rc_update_bit_0(&rc, prob);
|
pascal@215
|
2109 + distance = rep2;
|
pascal@215
|
2110 + } else {
|
pascal@215
|
2111 + rc_update_bit_1(&rc, prob);
|
pascal@215
|
2112 + distance = rep3;
|
pascal@215
|
2113 + rep3 = rep2;
|
pascal@215
|
2114 + }
|
pascal@215
|
2115 + rep2 = rep1;
|
pascal@215
|
2116 + }
|
pascal@215
|
2117 + rep1 = rep0;
|
pascal@215
|
2118 + rep0 = distance;
|
pascal@215
|
2119 + }
|
pascal@215
|
2120 + state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
|
pascal@215
|
2121 + prob = p + LZMA_REP_LEN_CODER;
|
pascal@215
|
2122 + }
|
pascal@215
|
2123 +
|
pascal@215
|
2124 + prob_len = prob + LZMA_LEN_CHOICE;
|
pascal@215
|
2125 + if (rc_is_bit_0(&rc, prob_len)) {
|
pascal@215
|
2126 + rc_update_bit_0(&rc, prob_len);
|
pascal@215
|
2127 + prob_len = (prob + LZMA_LEN_LOW
|
pascal@215
|
2128 + + (pos_state << LZMA_LEN_NUM_LOW_BITS));
|
pascal@215
|
2129 + offset = 0;
|
pascal@215
|
2130 + num_bits = LZMA_LEN_NUM_LOW_BITS;
|
pascal@215
|
2131 + } else {
|
pascal@215
|
2132 + rc_update_bit_1(&rc, prob_len);
|
pascal@215
|
2133 + prob_len = prob + LZMA_LEN_CHOICE_2;
|
pascal@215
|
2134 + if (rc_is_bit_0(&rc, prob_len)) {
|
pascal@215
|
2135 + rc_update_bit_0(&rc, prob_len);
|
pascal@215
|
2136 + prob_len = (prob + LZMA_LEN_MID
|
pascal@215
|
2137 + + (pos_state << LZMA_LEN_NUM_MID_BITS));
|
pascal@215
|
2138 + offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
pascal@215
|
2139 + num_bits = LZMA_LEN_NUM_MID_BITS;
|
pascal@215
|
2140 + } else {
|
pascal@215
|
2141 + rc_update_bit_1(&rc, prob_len);
|
pascal@215
|
2142 + prob_len = prob + LZMA_LEN_HIGH;
|
pascal@215
|
2143 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
pascal@215
|
2144 + + (1 << LZMA_LEN_NUM_MID_BITS));
|
pascal@215
|
2145 + num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
pascal@215
|
2146 + }
|
pascal@215
|
2147 + }
|
pascal@215
|
2148 + rc_bit_tree_decode(&rc, prob_len, num_bits, &len);
|
pascal@215
|
2149 + len += offset;
|
pascal@215
|
2150 +
|
pascal@215
|
2151 + if (state < 4) {
|
pascal@215
|
2152 + int pos_slot;
|
pascal@215
|
2153 +
|
pascal@215
|
2154 + state += LZMA_NUM_LIT_STATES;
|
pascal@215
|
2155 + prob =
|
pascal@215
|
2156 + p + LZMA_POS_SLOT +
|
pascal@215
|
2157 + ((len <
|
pascal@215
|
2158 + LZMA_NUM_LEN_TO_POS_STATES ? len :
|
pascal@215
|
2159 + LZMA_NUM_LEN_TO_POS_STATES - 1)
|
pascal@215
|
2160 + << LZMA_NUM_POS_SLOT_BITS);
|
pascal@215
|
2161 + rc_bit_tree_decode(&rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
pascal@215
|
2162 + &pos_slot);
|
pascal@215
|
2163 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
pascal@215
|
2164 + num_bits = (pos_slot >> 1) - 1;
|
pascal@215
|
2165 + rep0 = 2 | (pos_slot & 1);
|
pascal@215
|
2166 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
|
pascal@215
|
2167 + rep0 <<= num_bits;
|
pascal@215
|
2168 + prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
|
pascal@215
|
2169 + } else {
|
pascal@215
|
2170 + num_bits -= LZMA_NUM_ALIGN_BITS;
|
pascal@215
|
2171 + while (num_bits--)
|
pascal@215
|
2172 + rep0 = (rep0 << 1) | rc_direct_bit(&rc);
|
pascal@215
|
2173 + prob = p + LZMA_ALIGN;
|
pascal@215
|
2174 + rep0 <<= LZMA_NUM_ALIGN_BITS;
|
pascal@215
|
2175 + num_bits = LZMA_NUM_ALIGN_BITS;
|
pascal@215
|
2176 + }
|
pascal@215
|
2177 + i = 1;
|
pascal@215
|
2178 + mi = 1;
|
pascal@215
|
2179 + while (num_bits--) {
|
pascal@215
|
2180 + if (rc_get_bit(&rc, prob + mi, &mi))
|
pascal@215
|
2181 + rep0 |= i;
|
pascal@215
|
2182 + i <<= 1;
|
pascal@215
|
2183 + }
|
pascal@215
|
2184 + } else
|
pascal@215
|
2185 + rep0 = pos_slot;
|
pascal@215
|
2186 + if (++rep0 == 0)
|
pascal@215
|
2187 + break;
|
pascal@215
|
2188 + }
|
pascal@215
|
2189 +
|
pascal@215
|
2190 + len += LZMA_MATCH_MIN_LEN;
|
pascal@215
|
2191 +
|
pascal@215
|
2192 + do {
|
pascal@215
|
2193 + pos = buffer_pos - rep0;
|
pascal@215
|
2194 + while (pos >= header.dict_size)
|
pascal@215
|
2195 + pos += header.dict_size;
|
pascal@215
|
2196 + if(pos >= bufsize) {
|
pascal@215
|
2197 + goto fail;
|
pascal@215
|
2198 + }
|
pascal@215
|
2199 + previous_byte = buffer[pos];
|
pascal@215
|
2200 + buffer[buffer_pos++] = previous_byte;
|
pascal@215
|
2201 + if (buffer_pos == header.dict_size) {
|
pascal@215
|
2202 + buffer_pos = 0;
|
pascal@215
|
2203 + global_pos += header.dict_size;
|
pascal@215
|
2204 + writebb((char*)buffer, header.dict_size);
|
pascal@215
|
2205 + }
|
pascal@215
|
2206 + len--;
|
pascal@215
|
2207 + } while (len != 0 && buffer_pos < header.dst_size);
|
pascal@215
|
2208 + }
|
pascal@215
|
2209 + }
|
pascal@215
|
2210 +
|
pascal@215
|
2211 + writebb((char*)buffer, buffer_pos);
|
pascal@215
|
2212 + if(posp) {
|
pascal@215
|
2213 + *posp = rc.ptr-rc.buffer;
|
pascal@215
|
2214 + }
|
pascal@215
|
2215 + large_free(buffer);
|
pascal@215
|
2216 + return 0;
|
pascal@215
|
2217 + fail:
|
pascal@215
|
2218 + large_free(buffer);
|
pascal@215
|
2219 + return -1;
|
pascal@215
|
2220 +}
|
pascal@215
|
2221 --- linux-2.6.24.2/lib/Makefile
|
pascal@215
|
2222 +++ linux-2.6.24.2/lib/Makefile
|
pascal@215
|
2223 @@ -50,6 +50,10 @@ obj-$(CONFIG_CRC7) += crc7.o
|
pascal@215
|
2224 obj-$(CONFIG_LIBCRC32C) += libcrc32c.o
|
pascal@215
|
2225 obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o
|
pascal@215
|
2226
|
pascal@215
|
2227 +obj-$(CONFIG_RD_BZIP2) += decompress_bunzip2.o
|
pascal@215
|
2228 +obj-$(CONFIG_RD_LZMA) += decompress_unlzma.o
|
pascal@215
|
2229 +
|
pascal@215
|
2230 +
|
pascal@215
|
2231 obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/
|
pascal@215
|
2232 obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
|
pascal@215
|
2233 obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
|
pascal@215
|
2234 --- linux-2.6.24.2/scripts/Makefile.lib
|
pascal@215
|
2235 +++ linux-2.6.24.2/scripts/Makefile.lib
|
pascal@215
|
2236 @@ -166,4 +166,17 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS)
|
pascal@215
|
2237 quiet_cmd_gzip = GZIP $@
|
pascal@215
|
2238 cmd_gzip = gzip -f -9 < $< > $@
|
pascal@215
|
2239
|
pascal@215
|
2240 +# Append size
|
pascal@215
|
2241 +size_append=perl -e 'print(pack("i",(stat($$ARGV[0]))[7]));'
|
pascal@215
|
2242
|
pascal@215
|
2243 +# Bzip2
|
pascal@215
|
2244 +# ---------------------------------------------------------------------------
|
pascal@215
|
2245 +
|
pascal@215
|
2246 +quiet_cmd_bzip2 = BZIP2 $@
|
pascal@215
|
2247 +cmd_bzip2 = (bzip2 -9 < $< ; $(size_append) $<) > $@
|
pascal@215
|
2248 +
|
pascal@215
|
2249 +# Lzma
|
pascal@215
|
2250 +# ---------------------------------------------------------------------------
|
pascal@215
|
2251 +
|
pascal@215
|
2252 +quiet_cmd_lzma = LZMA $@
|
pascal@215
|
2253 +cmd_lzma = (lzma e $< -so ; $(size_append) $<) >$@
|