1 diff -purN linux-2.6.27.6/arch/arm/boot/compressed/Makefile linux-2.6.27.6udpcast/arch/arm/boot/compressed/Makefile
2 --- linux-2.6.27.6/arch/arm/boot/compressed/Makefile 2008-11-13 18:56:21.000000000 +0100
3 +++ linux-2.6.27.6udpcast/arch/arm/boot/compressed/Makefile 2008-11-16 23:02:55.000000000 +0100
4 @@ -67,8 +67,15 @@ endif
6 SEDFLAGS = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
8 -targets := vmlinux vmlinux.lds piggy.gz piggy.o font.o font.c \
9 - head.o misc.o $(OBJS)
10 +suffix_$(CONFIG_KERNEL_GZIP) = gz
11 +suffix_$(CONFIG_KERNEL_BZIP2) = bz2
12 +suffix_$(CONFIG_KERNEL_LZMA) = lzma
14 +targets := vmlinux vmlinux.lds \
15 + piggy.gz piggy.gz.o \
16 + piggy.bz2 piggy.bz2.o \
17 + piggy.lzma piggy.lzma.o \
18 + font.o font.c head.o misc.o $(OBJS)
20 ifeq ($(CONFIG_FTRACE),y)
21 ORIG_CFLAGS := $(KBUILD_CFLAGS)
22 @@ -95,7 +102,7 @@ LDFLAGS_vmlinux += -p --no-undefined -X
23 # would otherwise mess up our GOT table
24 CFLAGS_misc.o := -Dstatic=
26 -$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \
27 +$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
28 $(addprefix $(obj)/, $(OBJS)) FORCE
31 @@ -103,7 +110,17 @@ $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj
32 $(obj)/piggy.gz: $(obj)/../Image FORCE
33 $(call if_changed,gzip)
35 -$(obj)/piggy.o: $(obj)/piggy.gz FORCE
36 +$(obj)/piggy.bz2: $(obj)/../Image FORCE
37 + $(call if_changed,bzip2)
39 +$(obj)/piggy.lzma: $(obj)/../Image FORCE
40 + $(call if_changed,lzma)
42 +$(obj)/piggy.gz.o: $(obj)/piggy.gz FORCE
44 +$(obj)/piggy.bz2.o: $(obj)/piggy.bz2 FORCE
46 +$(obj)/piggy.lzma.o: $(obj)/piggy.lzma FORCE
48 CFLAGS_font.o := -Dstatic=
50 diff -purN linux-2.6.27.6/arch/arm/boot/compressed/misc.c linux-2.6.27.6udpcast/arch/arm/boot/compressed/misc.c
51 --- linux-2.6.27.6/arch/arm/boot/compressed/misc.c 2008-11-13 18:56:21.000000000 +0100
52 +++ linux-2.6.27.6udpcast/arch/arm/boot/compressed/misc.c 2008-11-16 23:02:55.000000000 +0100
53 @@ -169,116 +169,34 @@ static inline __ptr_t memcpy(__ptr_t __d
57 -#define OF(args) args
60 -typedef unsigned char uch;
61 -typedef unsigned short ush;
62 typedef unsigned long ulg;
64 -#define WSIZE 0x8000 /* Window size must be at least 32k, */
65 - /* and a power of two */
67 -static uch *inbuf; /* input buffer */
68 -static uch window[WSIZE]; /* Sliding window buffer */
70 -static unsigned insize; /* valid bytes in inbuf */
71 -static unsigned inptr; /* index of next byte to be processed in inbuf */
72 -static unsigned outcnt; /* bytes in output buffer */
75 -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
76 -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
77 -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
78 -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
79 -#define COMMENT 0x10 /* bit 4 set: file comment present */
80 -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
81 -#define RESERVED 0xC0 /* bit 6,7: reserved */
83 -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
85 -/* Diagnostic functions */
87 -# define Assert(cond,msg) {if(!(cond)) error(msg);}
88 -# define Trace(x) fprintf x
89 -# define Tracev(x) {if (verbose) fprintf x ;}
90 -# define Tracevv(x) {if (verbose>1) fprintf x ;}
91 -# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
92 -# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
94 -# define Assert(cond,msg)
99 -# define Tracecv(c,x)
102 -static int fill_inbuf(void);
103 -static void flush_window(void);
104 -static void error(char *m);
106 extern char input_data[];
107 extern char input_data_end[];
109 -static uch *output_data;
110 -static ulg output_ptr;
111 -static ulg bytes_out;
113 static void error(char *m);
115 -static void putstr(const char *);
118 static ulg free_mem_ptr;
119 static ulg free_mem_end_ptr;
121 -#ifdef STANDALONE_DEBUG
122 -#define NO_INFLATE_MALLOC
125 #define ARCH_HAS_DECOMP_WDOG
128 +#ifdef CONFIG_KERNEL_GZIP
129 #include "../../../../lib/inflate.c"
132 -/* ===========================================================================
133 - * Fill the input buffer. This is called only when the buffer is empty
134 - * and at least one byte is really needed.
136 -int fill_inbuf(void)
139 - error("ran out of input data");
140 +#ifdef CONFIG_KERNEL_BZIP2
141 +#include "../../../../lib/decompress_bunzip2.c"
144 - inbuf = input_data;
145 - insize = &input_data_end[0] - &input_data[0];
146 +#ifdef CONFIG_KERNEL_LZMA
147 +#include "../../../../lib/decompress_unlzma.c"
154 -/* ===========================================================================
155 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
156 - * (Used for the decompressed data only.)
158 -void flush_window(void)
165 - out = &output_data[output_ptr];
166 - for (n = 0; n < outcnt; n++) {
167 - ch = *out++ = *in++;
168 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
171 - bytes_out += (ulg)outcnt;
172 - output_ptr += (ulg)outcnt;
178 #define arch_error(x)
179 @@ -301,16 +219,24 @@ ulg
180 decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
183 - output_data = (uch *)output_start; /* Points to kernel start */
184 - free_mem_ptr = free_mem_ptr_p;
185 - free_mem_end_ptr = free_mem_ptr_end_p;
188 + size_t input_len = input_data_end - input_data;
191 __machine_arch_type = arch_id;
196 - putstr("Uncompressing Linux...");
198 + ptr = (ulg *) (((long)input_data_end) - 4);
199 + output_ptr = output_start + *ptr;
201 + free_mem_ptr = output_ptr;
202 + free_mem_end_ptr = output_ptr + 0x4000000;
204 + putstr("Decompressing Linux...");
205 + decompress(input_data, input_len,
206 + NULL, NULL, (unsigned char *) output_start, &pos, error);
207 putstr(" done, booting the kernel.\n");
210 @@ -320,11 +246,8 @@ char output_buffer[1500*1024];
214 - output_data = output_buffer;
217 putstr("Uncompressing Linux...");
219 + decompress(input_data, input_len, NULL, output_buffer, NULL);
223 diff -purN linux-2.6.27.6/arch/x86/boot/compressed/Makefile linux-2.6.27.6udpcast/arch/x86/boot/compressed/Makefile
224 --- linux-2.6.27.6/arch/x86/boot/compressed/Makefile 2008-11-13 18:56:21.000000000 +0100
225 +++ linux-2.6.27.6udpcast/arch/x86/boot/compressed/Makefile 2008-11-16 23:42:51.000000000 +0100
227 # create a compressed vmlinux image from the original vmlinux
230 -targets := vmlinux vmlinux.bin vmlinux.bin.gz head_$(BITS).o misc.o piggy.o
231 +targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head_$(BITS).o misc.o piggy.o
233 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
234 KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
235 @@ -46,9 +46,17 @@ $(obj)/vmlinux.bin.all: $(vmlinux.bin.al
236 ifdef CONFIG_RELOCATABLE
237 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
238 $(call if_changed,gzip)
239 +$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin.all FORCE
240 + $(call if_changed,bzip2)
241 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
242 + $(call if_changed,lzma)
244 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
245 $(call if_changed,gzip)
246 +$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
247 + $(call if_changed,bzip2)
248 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
249 + $(call if_changed,lzma)
251 LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
253 @@ -59,6 +67,9 @@ $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bi
254 LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T
257 +suffix_$(CONFIG_KERNEL_GZIP) = gz
258 +suffix_$(CONFIG_KERNEL_BZIP2) = bz2
259 +suffix_$(CONFIG_KERNEL_LZMA) = lzma
261 -$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
262 +$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
263 $(call if_changed,ld)
264 diff -purN linux-2.6.27.6/arch/x86/boot/compressed/misc.c linux-2.6.27.6udpcast/arch/x86/boot/compressed/misc.c
265 --- linux-2.6.27.6/arch/x86/boot/compressed/misc.c 2008-11-13 18:56:21.000000000 +0100
266 +++ linux-2.6.27.6udpcast/arch/x86/boot/compressed/misc.c 2008-11-16 23:02:55.000000000 +0100
267 @@ -116,71 +116,13 @@
272 -#define OF(args) args
273 #define STATIC static
277 #define memzero(s, n) memset((s), 0, (n))
279 -typedef unsigned char uch;
280 -typedef unsigned short ush;
281 -typedef unsigned long ulg;
284 - * Window size must be at least 32k, and a power of two.
285 - * We don't actually have a window just a huge output buffer,
286 - * so we report a 2G window size, as that should always be
287 - * larger than our output buffer:
289 -#define WSIZE 0x80000000
292 -static unsigned char *inbuf;
294 -/* Sliding window buffer (and final output buffer): */
295 -static unsigned char *window;
297 -/* Valid bytes in inbuf: */
298 -static unsigned insize;
300 -/* Index of next byte to be processed in inbuf: */
301 -static unsigned inptr;
303 -/* Bytes in output buffer: */
304 -static unsigned outcnt;
306 -/* gzip flag byte */
307 -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
308 -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gz file */
309 -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
310 -#define ORIG_NAM 0x08 /* bit 3 set: original file name present */
311 -#define COMMENT 0x10 /* bit 4 set: file comment present */
312 -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
313 -#define RESERVED 0xC0 /* bit 6, 7: reserved */
315 -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
317 -/* Diagnostic functions */
319 -# define Assert(cond, msg) do { if (!(cond)) error(msg); } while (0)
320 -# define Trace(x) do { fprintf x; } while (0)
321 -# define Tracev(x) do { if (verbose) fprintf x ; } while (0)
322 -# define Tracevv(x) do { if (verbose > 1) fprintf x ; } while (0)
323 -# define Tracec(c, x) do { if (verbose && (c)) fprintf x ; } while (0)
324 -# define Tracecv(c, x) do { if (verbose > 1 && (c)) fprintf x ; } while (0)
326 -# define Assert(cond, msg)
330 -# define Tracec(c, x)
331 -# define Tracecv(c, x)
334 -static int fill_inbuf(void);
335 -static void flush_window(void);
336 static void error(char *m);
339 @@ -189,11 +131,6 @@ static void error(char *m);
340 static struct boot_params *real_mode; /* Pointer to real-mode data */
343 -extern unsigned char input_data[];
344 -extern int input_len;
346 -static long bytes_out;
348 static void *memset(void *s, int c, unsigned n);
349 static void *memcpy(void *dest, const void *src, unsigned n);
351 @@ -213,7 +150,19 @@ static char *vidmem;
353 static int lines, cols;
357 +#ifdef CONFIG_KERNEL_GZIP
358 #include "../../../../lib/inflate.c"
361 +#ifdef CONFIG_KERNEL_BZIP2
362 +#include "../../../../lib/decompress_bunzip2.c"
365 +#ifdef CONFIG_KERNEL_LZMA
366 +#include "../../../../lib/decompress_unlzma.c"
369 static void scroll(void)
371 @@ -291,38 +240,6 @@ static void *memcpy(void *dest, const vo
375 -/* ===========================================================================
376 - * Fill the input buffer. This is called only when the buffer is empty
377 - * and at least one byte is really needed.
379 -static int fill_inbuf(void)
381 - error("ran out of input data");
385 -/* ===========================================================================
386 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
387 - * (Used for the decompressed data only.)
389 -static void flush_window(void)
391 - /* With my window equal to my output buffer
392 - * I only need to compute the crc here.
394 - unsigned long c = crc; /* temporary variable */
396 - unsigned char *in, ch;
399 - for (n = 0; n < outcnt; n++) {
401 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
404 - bytes_out += (unsigned long)outcnt;
408 static void error(char *x)
410 @@ -405,12 +322,8 @@ asmlinkage void decompress_kernel(void *
411 lines = real_mode->screen_info.orig_video_lines;
412 cols = real_mode->screen_info.orig_video_cols;
414 - window = output; /* Output buffer (Normally at 1M) */
415 free_mem_ptr = heap; /* Heap */
416 free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
417 - inbuf = input_data; /* Input buffer */
418 - insize = input_len;
422 if ((unsigned long)output & (__KERNEL_ALIGN - 1))
423 @@ -428,10 +341,9 @@ asmlinkage void decompress_kernel(void *
429 putstr("\nDecompressing Linux... ");
431 + decompress(input_data, input_len, NULL, NULL, output, NULL, error);
434 putstr("done.\nBooting the kernel.\n");
435 diff -purN linux-2.6.27.6/drivers/block/Kconfig linux-2.6.27.6udpcast/drivers/block/Kconfig
436 --- linux-2.6.27.6/drivers/block/Kconfig 2008-11-13 18:56:21.000000000 +0100
437 +++ linux-2.6.27.6udpcast/drivers/block/Kconfig 2008-11-16 23:02:55.000000000 +0100
438 @@ -357,6 +357,30 @@ config BLK_DEV_XIP
439 will prevent RAM block device backing store memory from being
440 allocated from highmem (only a problem for highmem systems).
443 + bool "Initial ramdisk compressed using bzip2"
445 + depends on BLK_DEV_INITRD=y
447 + Support loading of a bzip2 encoded initial ramdisk or cpio buffer
451 + bool "Initial ramdisk compressed using lzma"
453 + depends on BLK_DEV_INITRD=y
455 + Support loading of a lzma encoded initial ramdisk or cpio buffer
459 + bool "Initial ramdisk compressed using gzip"
461 + depends on BLK_DEV_INITRD=y
463 + Support loading of a gzip encoded initial ramdisk or cpio buffer.
467 tristate "Packet writing on CD/DVD media"
469 diff -purN linux-2.6.27.6/include/asm-x86/boot.h linux-2.6.27.6udpcast/include/asm-x86/boot.h
470 --- linux-2.6.27.6/include/asm-x86/boot.h 2008-11-13 18:56:21.000000000 +0100
471 +++ linux-2.6.27.6udpcast/include/asm-x86/boot.h 2008-11-16 23:02:55.000000000 +0100
473 + (CONFIG_PHYSICAL_ALIGN - 1)) \
474 & ~(CONFIG_PHYSICAL_ALIGN - 1))
476 +#if (defined CONFIG_KERNEL_BZIP2)
477 +#define BOOT_HEAP_SIZE 0x400000
481 #define BOOT_HEAP_SIZE 0x7000
482 -#define BOOT_STACK_SIZE 0x4000
484 #define BOOT_HEAP_SIZE 0x4000
489 +#ifdef CONFIG_X86_64
490 +#define BOOT_STACK_SIZE 0x4000
492 #define BOOT_STACK_SIZE 0x1000
495 diff -purN linux-2.6.27.6/include/linux/decompress/bunzip2.h linux-2.6.27.6udpcast/include/linux/decompress/bunzip2.h
496 --- linux-2.6.27.6/include/linux/decompress/bunzip2.h 1970-01-01 01:00:00.000000000 +0100
497 +++ linux-2.6.27.6udpcast/include/linux/decompress/bunzip2.h 2008-11-16 23:34:15.000000000 +0100
499 +#ifndef DECOMPRESS_BUNZIP2_H
500 +#define DECOMPRESS_BUNZIP2_H
502 +int bunzip2(unsigned char *inbuf, int len,
503 + int(*fill)(void*, unsigned int),
504 + int(*flush)(void*, unsigned int),
505 + unsigned char *output,
507 + void(*error)(char *x));
509 diff -purN linux-2.6.27.6/include/linux/decompress/generic.h linux-2.6.27.6udpcast/include/linux/decompress/generic.h
510 --- linux-2.6.27.6/include/linux/decompress/generic.h 1970-01-01 01:00:00.000000000 +0100
511 +++ linux-2.6.27.6udpcast/include/linux/decompress/generic.h 2008-11-16 23:34:15.000000000 +0100
513 +#ifndef DECOMPRESS_GENERIC_H
514 +#define DECOMPRESS_GENERIC_H
516 +/* Minimal chunksize to be read.
517 + *Bzip2 prefers at least 4096
518 + *Lzma prefers 0x10000 */
519 +#define COMPR_IOBUF_SIZE 4096
521 +typedef int (*decompress_fn) (unsigned char *inbuf, int len,
522 + int(*fill)(void*, unsigned int),
523 + int(*writebb)(void*, unsigned int),
524 + unsigned char *output,
526 + void(*error)(char *x));
528 +/* inbuf - input buffer
529 + *len - len of pre-read data in inbuf
530 + *fill - function to fill inbuf if empty
531 + *writebb - function to write out outbug
532 + *posp - if non-null, input position (number of bytes read) will be
535 + *If len != 0, the inbuf is initialized (with as much data), and fill
536 + *should not be called
537 + *If len = 0, the inbuf is allocated, but empty. Its size is IOBUF_SIZE
538 + *fill should be called (repeatedly...) to read data, at most IOBUF_SIZE
543 diff -purN linux-2.6.27.6/include/linux/decompress/inflate.h linux-2.6.27.6udpcast/include/linux/decompress/inflate.h
544 --- linux-2.6.27.6/include/linux/decompress/inflate.h 1970-01-01 01:00:00.000000000 +0100
545 +++ linux-2.6.27.6udpcast/include/linux/decompress/inflate.h 2008-11-16 23:34:15.000000000 +0100
550 +/* Other housekeeping constants */
551 +#define INBUFSIZ 4096
553 +int gunzip(unsigned char *inbuf, int len,
554 + int(*fill)(void*, unsigned int),
555 + int(*flush)(void*, unsigned int),
556 + unsigned char *output,
558 + void(*error_fn)(char *x));
560 diff -purN linux-2.6.27.6/include/linux/decompress/mm.h linux-2.6.27.6udpcast/include/linux/decompress/mm.h
561 --- linux-2.6.27.6/include/linux/decompress/mm.h 1970-01-01 01:00:00.000000000 +0100
562 +++ linux-2.6.27.6udpcast/include/linux/decompress/mm.h 2008-11-16 23:34:15.000000000 +0100
567 + * Memory management for pre-boot and ramdisk uncompressors
569 + * Authors: Alain Knaff <alain@knaff.lu>
573 +#ifndef DECOMPR_MM_H
574 +#define DECOMPR_MM_H
578 +/* Code active when included from pre-boot environment: */
580 +/* A trivial malloc implementation, adapted from
581 + * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
583 +static unsigned long malloc_ptr;
584 +static int malloc_count;
586 +static void *malloc(int size)
591 + error("Malloc error");
593 + malloc_ptr = free_mem_ptr;
595 + malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
597 + p = (void *)malloc_ptr;
598 + malloc_ptr += size;
600 + if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
601 + error("Out of memory");
607 +static void free(void *where)
611 + malloc_ptr = free_mem_ptr;
614 +#define large_malloc(a) malloc(a)
615 +#define large_free(a) free(a)
617 +#define set_error_fn(x)
624 +/* Code active when compiled standalone for use when loading ramdisk: */
626 +#include <linux/kernel.h>
627 +#include <linux/fs.h>
628 +#include <linux/string.h>
629 +#include <linux/vmalloc.h>
631 +/* Use defines rather than static inline in order to avoid spurious
632 + * warnings when not needed (indeed large_malloc / large_free are not
633 + * needed by inflate */
635 +#define malloc(a) kmalloc(a, GFP_KERNEL)
636 +#define free(a) kfree(a)
638 +#define large_malloc(a) vmalloc(a)
639 +#define large_free(a) vfree(a)
641 +static void(*error)(char *m);
642 +#define set_error_fn(x) error = x;
648 +#include <linux/init.h>
652 +#endif /* DECOMPR_MM_H */
653 diff -purN linux-2.6.27.6/include/linux/decompress/unlzma.h linux-2.6.27.6udpcast/include/linux/decompress/unlzma.h
654 --- linux-2.6.27.6/include/linux/decompress/unlzma.h 1970-01-01 01:00:00.000000000 +0100
655 +++ linux-2.6.27.6udpcast/include/linux/decompress/unlzma.h 2008-11-16 23:34:15.000000000 +0100
657 +#ifndef DECOMPRESS_UNLZMA_H
658 +#define DECOMPRESS_UNLZMA_H
660 +int unlzma(unsigned char *, int,
661 + int(*fill)(void*, unsigned int),
662 + int(*flush)(void*, unsigned int),
663 + unsigned char *output,
665 + void(*error)(char *x)
669 diff -purN linux-2.6.27.6/init/do_mounts_rd.c linux-2.6.27.6udpcast/init/do_mounts_rd.c
670 --- linux-2.6.27.6/init/do_mounts_rd.c 2008-11-13 18:56:21.000000000 +0100
671 +++ linux-2.6.27.6udpcast/init/do_mounts_rd.c 2008-11-16 23:02:55.000000000 +0100
674 #include "do_mounts.h"
676 +#include <linux/decompress/generic.h>
678 +#include <linux/decompress/bunzip2.h>
679 +#include <linux/decompress/unlzma.h>
680 +#include <linux/decompress/inflate.h>
682 int __initdata rd_prompt = 1;/* 1 = prompt for RAM disk, 0 = don't prompt */
684 static int __init prompt_ramdisk(char *str)
685 @@ -28,7 +34,7 @@ static int __init ramdisk_start_setup(ch
687 __setup("ramdisk_start=", ramdisk_start_setup);
689 -static int __init crd_load(int in_fd, int out_fd);
690 +static int __init crd_load(int in_fd, int out_fd, decompress_fn deco);
693 * This routine tries to find a RAM disk image to load, and returns the
694 @@ -44,7 +50,7 @@ static int __init crd_load(int in_fd, in
698 -identify_ramdisk_image(int fd, int start_block)
699 +identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
701 const int size = 512;
702 struct minix_super_block *minixsb;
703 @@ -70,6 +76,7 @@ identify_ramdisk_image(int fd, int start
704 sys_lseek(fd, start_block * BLOCK_SIZE, 0);
705 sys_read(fd, buf, size);
707 +#ifdef CONFIG_RD_GZIP
709 * If it matches the gzip magic numbers, return -1
711 @@ -77,9 +84,39 @@ identify_ramdisk_image(int fd, int start
713 "RAMDISK: Compressed image found at block %d\n",
715 + *decompressor = gunzip;
721 +#ifdef CONFIG_RD_BZIP2
723 + * If it matches the bzip2 magic numbers, return -1
725 + if (buf[0] == 0x42 && (buf[1] == 0x5a)) {
727 + "RAMDISK: Bzipped image found at block %d\n",
729 + *decompressor = bunzip2;
735 +#ifdef CONFIG_RD_LZMA
737 + * If it matches the lzma magic numbers, return -1
739 + if (buf[0] == 0x5d && (buf[1] == 0x00)) {
741 + "RAMDISK: Lzma image found at block %d\n",
743 + *decompressor = unlzma;
749 /* romfs is at block zero too */
750 if (romfsb->word0 == ROMSB_WORD0 &&
751 @@ -143,6 +180,7 @@ int __init rd_load_image(char *from)
752 int nblocks, i, disk;
754 unsigned short rotate = 0;
755 + decompress_fn decompressor = NULL;
756 #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES)
757 char rotator[4] = { '|' , '/' , '-' , '\\' };
759 @@ -155,12 +193,12 @@ int __init rd_load_image(char *from)
763 - nblocks = identify_ramdisk_image(in_fd, rd_image_start);
764 + nblocks = identify_ramdisk_image(in_fd, rd_image_start, &decompressor);
769 - if (crd_load(in_fd, out_fd) == 0)
770 + if (crd_load(in_fd, out_fd, decompressor) == 0)
771 goto successful_load;
774 @@ -259,138 +297,48 @@ int __init rd_load_disk(int n)
775 return rd_load_image("/dev/root");
779 - * gzip declarations
782 -#define OF(args) args
785 -#define memzero(s, n) memset ((s), 0, (n))
788 -typedef unsigned char uch;
789 -typedef unsigned short ush;
790 -typedef unsigned long ulg;
792 -#define INBUFSIZ 4096
793 -#define WSIZE 0x8000 /* window size--must be a power of two, and */
794 - /* at least 32K for zip's deflate method */
799 -static unsigned insize; /* valid bytes in inbuf */
800 -static unsigned inptr; /* index of next byte to be processed in inbuf */
801 -static unsigned outcnt; /* bytes in output buffer */
802 static int exit_code;
803 -static int unzip_error;
804 -static long bytes_out;
805 +static int decompress_error;
806 static int crd_infd, crd_outfd;
808 -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
810 -/* Diagnostic functions (stubbed out) */
811 -#define Assert(cond,msg)
816 -#define Tracecv(c,x)
818 -#define STATIC static
821 -static int __init fill_inbuf(void);
822 -static void __init flush_window(void);
823 -static void __init error(char *m);
825 -#define NO_INFLATE_MALLOC
827 -#include "../lib/inflate.c"
829 -/* ===========================================================================
830 - * Fill the input buffer. This is called only when the buffer is empty
831 - * and at least one byte is really needed.
832 - * Returning -1 does not guarantee that gunzip() will ever return.
834 -static int __init fill_inbuf(void)
835 +static int __init compr_fill(void *buf, unsigned int len)
837 - if (exit_code) return -1;
839 - insize = sys_read(crd_infd, inbuf, INBUFSIZ);
841 - error("RAMDISK: ran out of compressed data");
848 + int r = sys_read(crd_infd, buf, len);
850 + printk(KERN_ERR "RAMDISK: error while reading compressed data");
852 + printk(KERN_ERR "RAMDISK: EOF while reading compressed data");
856 -/* ===========================================================================
857 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
858 - * (Used for the decompressed data only.)
860 -static void __init flush_window(void)
861 +static int __init compr_flush(void *window, unsigned int outcnt)
863 - ulg c = crc; /* temporary variable */
864 - unsigned n, written;
867 - written = sys_write(crd_outfd, window, outcnt);
868 - if (written != outcnt && unzip_error == 0) {
869 - printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %ld\n",
870 - written, outcnt, bytes_out);
874 - for (n = 0; n < outcnt; n++) {
876 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
879 - bytes_out += (ulg)outcnt;
881 + int written = sys_write(crd_outfd, window, outcnt);
882 + if (written != outcnt) {
883 + if (decompress_error == 0)
885 + "RAMDISK: incomplete write (%d != %d)\n",
887 + decompress_error = 1;
893 static void __init error(char *x)
895 printk(KERN_ERR "%s\n", x);
898 + decompress_error = 1;
901 -static int __init crd_load(int in_fd, int out_fd)
902 +static int __init crd_load(int in_fd, int out_fd, decompress_fn deco)
906 - insize = 0; /* valid bytes in inbuf */
907 - inptr = 0; /* index of next byte to be processed in inbuf */
908 - outcnt = 0; /* bytes in output buffer */
911 - crc = (ulg)0xffffffffL; /* shift register contents */
915 - inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
917 - printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
920 - window = kmalloc(WSIZE, GFP_KERNEL);
922 - printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
929 + result = deco(NULL, 0, compr_fill, compr_flush, NULL, NULL, error);
930 + if (decompress_error)
936 diff -purN linux-2.6.27.6/init/initramfs.c linux-2.6.27.6udpcast/init/initramfs.c
937 --- linux-2.6.27.6/init/initramfs.c 2008-11-13 18:56:21.000000000 +0100
938 +++ linux-2.6.27.6udpcast/init/initramfs.c 2008-11-16 23:02:55.000000000 +0100
939 @@ -337,11 +337,14 @@ static int __init write_buffer(char *buf
943 -static void __init flush_buffer(char *buf, unsigned len)
945 +static int __init flush_buffer(void *bufv, unsigned len)
947 + char *buf = (char *) bufv;
953 while ((written = write_buffer(buf, len)) < len && !message) {
954 char c = buf[written];
956 @@ -355,73 +358,14 @@ static void __init flush_buffer(char *bu
958 error("junk in compressed archive");
964 - * gzip declarations
967 -#define OF(args) args
970 -#define memzero(s, n) memset ((s), 0, (n))
972 +static unsigned my_inptr; /* index of next byte to be processed in inbuf */
974 -typedef unsigned char uch;
975 -typedef unsigned short ush;
976 -typedef unsigned long ulg;
978 -#define WSIZE 0x8000 /* window size--must be a power of two, and */
979 - /* at least 32K for zip's deflate method */
984 -static unsigned insize; /* valid bytes in inbuf */
985 -static unsigned inptr; /* index of next byte to be processed in inbuf */
986 -static unsigned outcnt; /* bytes in output buffer */
987 -static long bytes_out;
989 -#define get_byte() (inptr < insize ? inbuf[inptr++] : -1)
991 -/* Diagnostic functions (stubbed out) */
992 -#define Assert(cond,msg)
997 -#define Tracecv(c,x)
999 -#define STATIC static
1000 -#define INIT __init
1002 -static void __init flush_window(void);
1003 -static void __init error(char *m);
1005 -#define NO_INFLATE_MALLOC
1007 -#include "../lib/inflate.c"
1009 -/* ===========================================================================
1010 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
1011 - * (Used for the decompressed data only.)
1013 -static void __init flush_window(void)
1015 - ulg c = crc; /* temporary variable */
1019 - flush_buffer(window, outcnt);
1021 - for (n = 0; n < outcnt; n++) {
1023 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
1026 - bytes_out += (ulg)outcnt;
1029 +#include <linux/decompress/bunzip2.h>
1030 +#include <linux/decompress/unlzma.h>
1031 +#include <linux/decompress/inflate.h>
1033 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
1035 @@ -430,9 +374,10 @@ static char * __init unpack_to_rootfs(ch
1036 header_buf = kmalloc(110, GFP_KERNEL);
1037 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
1038 name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
1039 - window = kmalloc(WSIZE, GFP_KERNEL);
1040 - if (!window || !header_buf || !symlink_buf || !name_buf)
1042 + if (!header_buf || !symlink_buf || !name_buf)
1043 panic("can't allocate buffers");
1048 @@ -452,21 +397,39 @@ static char * __init unpack_to_rootfs(ch
1055 - outcnt = 0; /* bytes in output buffer */
1057 - crc = (ulg)0xffffffffL; /* shift register contents */
1060 + if (!gunzip(buf, len, NULL, flush_buffer, NULL,
1061 + &my_inptr, error) &&
1065 +#ifdef CONFIG_RD_BZIP2
1066 + message = NULL; /* Zero out message, or else cpio will
1067 + think an error has already occured */
1068 + if (!bunzip2(buf, len, NULL, flush_buffer, NULL,
1069 + &my_inptr, error) < 0
1071 + message == NULL) {
1076 +#ifdef CONFIG_RD_LZMA
1077 + message = NULL; /* Zero out message, or else cpio will
1078 + think an error has already occured */
1079 + if (!unlzma(buf, len, NULL, flush_buffer, NULL,
1080 + &my_inptr, error) < 0
1082 + message == NULL) {
1088 - error("junk in gzipped archive");
1089 - this_header = saved_offset + inptr;
1092 + error("junk in compressed archive");
1093 + this_header = saved_offset + my_inptr;
1101 diff -purN linux-2.6.27.6/init/Kconfig linux-2.6.27.6udpcast/init/Kconfig
1102 --- linux-2.6.27.6/init/Kconfig 2008-11-13 18:56:21.000000000 +0100
1103 +++ linux-2.6.27.6udpcast/init/Kconfig 2008-11-16 23:02:55.000000000 +0100
1104 @@ -101,6 +101,56 @@ config LOCALVERSION_AUTO
1106 which is done within the script "scripts/setlocalversion".)
1109 + prompt "Kernel compression mode"
1110 + default KERNEL_GZIP
1112 + The linux kernel is a kind of self-extracting executable.
1113 + Several compression algorithms are available, which differ
1114 + in efficiency, compression and decompression speed.
1115 + Compression speed is only relevant when building a kernel.
1116 + Decompression speed is relevant at each boot.
1118 + If you have any problems with bzip2 or lzma compressed
1119 + kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
1120 + version of this functionality (bzip2 only), for 2.4, was
1121 + supplied by Christian Ludwig)
1123 + High compression options are mostly useful for users, who
1124 + are low on disk space (embedded systems), but for whom ram
1125 + size matters less.
1127 + If in doubt, select 'gzip'
1132 + The old and tried gzip compression. Its compression ratio is
1133 + the poorest among the 3 choices; however its speed (both
1134 + compression and decompression) is the fastest.
1136 +config KERNEL_BZIP2
1139 + Its compression ratio and speed is intermediate.
1140 + Decompression speed is slowest among the 3.
1141 + The kernel size is about 10 per cent smaller with bzip2,
1142 + in comparison to gzip.
1143 + Bzip2 uses a large amount of memory. For modern kernels
1144 + you will need at least 8MB RAM or more for booting.
1149 + The most recent compression algorithm.
1150 + Its ratio is best, decompression speed is between the other
1151 + 2. Compression is slowest.
1152 + The kernel size is about 33 per cent smaller with lzma,
1153 + in comparison to gzip.
1159 bool "Support for paging of anonymous memory (swap)"
1160 depends on MMU && BLOCK
1161 diff -purN linux-2.6.27.6/lib/decompress_bunzip2.c linux-2.6.27.6udpcast/lib/decompress_bunzip2.c
1162 --- linux-2.6.27.6/lib/decompress_bunzip2.c 1970-01-01 01:00:00.000000000 +0100
1163 +++ linux-2.6.27.6udpcast/lib/decompress_bunzip2.c 2008-11-16 23:40:21.000000000 +0100
1165 +/* vi: set sw = 4 ts = 4: */
1166 +/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
1168 + Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
1169 + which also acknowledges contributions by Mike Burrows, David Wheeler,
1170 + Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
1171 + Robert Sedgewick, and Jon L. Bentley.
1173 + This code is licensed under the LGPLv2:
1174 + LGPL (http://www.gnu.org/copyleft/lgpl.html
1178 + Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org).
1180 + More efficient reading of Huffman codes, a streamlined read_bunzip()
1181 + function, and various other tweaks. In (limited) tests, approximately
1182 + 20% faster than bzcat on x86 and about 10% faster on arm.
1184 + Note that about 2/3 of the time is spent in read_unzip() reversing
1185 + the Burrows-Wheeler transformation. Much of that time is delay
1186 + resulting from cache misses.
1188 + I would ask that anyone benefiting from this work, especially those
1189 + using it in commercial products, consider making a donation to my local
1190 + non-profit hospice organization in the name of the woman I loved, who
1191 + passed away Feb. 12, 2003.
1193 + In memory of Toni W. Hagan
1195 + Hospice of Acadiana, Inc.
1196 + 2600 Johnston St., Suite 200
1197 + Lafayette, LA 70503-3240
1199 + Phone (337) 232-1234 or 1-800-738-2226
1200 + Fax (337) 232-1297
1202 + http://www.hospiceacadiana.com/
1208 + Made it fit for running in Linux Kernel by Alain Knaff (alain@knaff.lu)
1213 +#include <linux/decompress/bunzip2.h>
1214 +#endif /* !STATIC */
1216 +#include <linux/decompress/mm.h>
1219 +#define INT_MAX 0x7fffffff
1222 +/* Constants for Huffman coding */
1223 +#define MAX_GROUPS 6
1224 +#define GROUP_SIZE 50 /* 64 would have been more efficient */
1225 +#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
1226 +#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
1227 +#define SYMBOL_RUNA 0
1228 +#define SYMBOL_RUNB 1
1230 +/* Status return values */
1231 +#define RETVAL_OK 0
1232 +#define RETVAL_LAST_BLOCK (-1)
1233 +#define RETVAL_NOT_BZIP_DATA (-2)
1234 +#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
1235 +#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
1236 +#define RETVAL_DATA_ERROR (-5)
1237 +#define RETVAL_OUT_OF_MEMORY (-6)
1238 +#define RETVAL_OBSOLETE_INPUT (-7)
1240 +/* Other housekeeping constants */
1241 +#define BZIP2_IOBUF_SIZE 4096
1243 +/* This is what we know about each Huffman coding group */
1244 +struct group_data {
1245 + /* We have an extra slot at the end of limit[] for a sentinal value. */
1246 + int limit[MAX_HUFCODE_BITS+1];
1247 + int base[MAX_HUFCODE_BITS];
1248 + int permute[MAX_SYMBOLS];
1249 + int minLen, maxLen;
1252 +/* Structure holding all the housekeeping data, including IO buffers and
1253 + memory that persists between calls to bunzip */
1254 +struct bunzip_data {
1255 + /* State for interrupting output loop */
1256 + int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
1257 + /* I/O tracking data (file handles, buffers, positions, etc.) */
1258 + int (*fill)(void*, unsigned int);
1259 + int inbufCount, inbufPos /*, outbufPos*/;
1260 + unsigned char *inbuf /*,*outbuf*/;
1261 + unsigned int inbufBitCount, inbufBits;
1262 + /* The CRC values stored in the block header and calculated from the
1264 + unsigned int crc32Table[256], headerCRC, totalCRC, writeCRC;
1265 + /* Intermediate buffer and its size (in bytes) */
1266 + unsigned int *dbuf, dbufSize;
1267 + /* These things are a bit too big to go on the stack */
1268 + unsigned char selectors[32768]; /* nSelectors = 15 bits */
1269 + struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
1270 + int io_error; /* non-zero if we have IO error */
1274 +/* Return the next nnn bits of input. All reads from the compressed input
1275 + are done through this function. All reads are big endian */
1276 +static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)
1278 + unsigned int bits = 0;
1280 + /* If we need to get more data from the byte buffer, do so.
1281 + (Loop getting one byte at a time to enforce endianness and avoid
1282 + unaligned access.) */
1283 + while (bd->inbufBitCount < bits_wanted) {
1284 + /* If we need to read more data from file into byte buffer, do
1286 + if (bd->inbufPos == bd->inbufCount) {
1289 + bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE);
1290 + if (bd->inbufCount <= 0) {
1291 + bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF;
1296 + /* Avoid 32-bit overflow (dump bit buffer to top of output) */
1297 + if (bd->inbufBitCount >= 24) {
1298 + bits = bd->inbufBits&((1 << bd->inbufBitCount)-1);
1299 + bits_wanted -= bd->inbufBitCount;
1300 + bits <<= bits_wanted;
1301 + bd->inbufBitCount = 0;
1303 + /* Grab next 8 bits of input from buffer. */
1304 + bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
1305 + bd->inbufBitCount += 8;
1307 + /* Calculate result */
1308 + bd->inbufBitCount -= bits_wanted;
1309 + bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1);
1314 +/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
1316 +static int INIT get_next_block(struct bunzip_data *bd)
1318 + struct group_data *hufGroup = NULL;
1320 + int *limit = NULL;
1321 + int dbufCount, nextSym, dbufSize, groupCount, selector,
1322 + i, j, k, t, runPos, symCount, symTotal, nSelectors,
1324 + unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
1325 + unsigned int *dbuf, origPtr;
1328 + dbufSize = bd->dbufSize;
1329 + selectors = bd->selectors;
1331 + /* Read in header signature and CRC, then validate signature.
1332 + (last block signature means CRC is for whole file, return now) */
1333 + i = get_bits(bd, 24);
1334 + j = get_bits(bd, 24);
1335 + bd->headerCRC = get_bits(bd, 32);
1336 + if ((i == 0x177245) && (j == 0x385090))
1337 + return RETVAL_LAST_BLOCK;
1338 + if ((i != 0x314159) || (j != 0x265359))
1339 + return RETVAL_NOT_BZIP_DATA;
1340 + /* We can add support for blockRandomised if anybody complains.
1341 + There was some code for this in busybox 1.0.0-pre3, but nobody ever
1342 + noticed that it didn't actually work. */
1343 + if (get_bits(bd, 1))
1344 + return RETVAL_OBSOLETE_INPUT;
1345 + origPtr = get_bits(bd, 24);
1346 + if (origPtr > dbufSize)
1347 + return RETVAL_DATA_ERROR;
1348 + /* mapping table: if some byte values are never used (encoding things
1349 + like ascii text), the compression code removes the gaps to have fewer
1350 + symbols to deal with, and writes a sparse bitfield indicating which
1351 + values were present. We make a translation table to convert the
1352 + symbols back to the corresponding bytes. */
1353 + t = get_bits(bd, 16);
1355 + for (i = 0; i < 16; i++) {
1356 + if (t&(1 << (15-i))) {
1357 + k = get_bits(bd, 16);
1358 + for (j = 0; j < 16; j++)
1359 + if (k&(1 << (15-j)))
1360 + symToByte[symTotal++] = (16*i)+j;
1363 + /* How many different Huffman coding groups does this block use? */
1364 + groupCount = get_bits(bd, 3);
1365 + if (groupCount < 2 || groupCount > MAX_GROUPS)
1366 + return RETVAL_DATA_ERROR;
1367 + /* nSelectors: Every GROUP_SIZE many symbols we select a new
1368 + Huffman coding group. Read in the group selector list,
1369 + which is stored as MTF encoded bit runs. (MTF = Move To
1370 + Front, as each value is used it's moved to the start of the
1372 + nSelectors = get_bits(bd, 15);
1374 + return RETVAL_DATA_ERROR;
1375 + for (i = 0; i < groupCount; i++)
1377 + for (i = 0; i < nSelectors; i++) {
1378 + /* Get next value */
1379 + for (j = 0; get_bits(bd, 1); j++)
1380 + if (j >= groupCount)
1381 + return RETVAL_DATA_ERROR;
1382 + /* Decode MTF to get the next selector */
1383 + uc = mtfSymbol[j];
1385 + mtfSymbol[j] = mtfSymbol[j-1];
1386 + mtfSymbol[0] = selectors[i] = uc;
1388 + /* Read the Huffman coding tables for each group, which code
1389 + for symTotal literal symbols, plus two run symbols (RUNA,
1391 + symCount = symTotal+2;
1392 + for (j = 0; j < groupCount; j++) {
1393 + unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
1394 + int minLen, maxLen, pp;
1395 + /* Read Huffman code lengths for each symbol. They're
1396 + stored in a way similar to mtf; record a starting
1397 + value for the first symbol, and an offset from the
1398 + previous value for everys symbol after that.
1399 + (Subtracting 1 before the loop and then adding it
1400 + back at the end is an optimization that makes the
1401 + test inside the loop simpler: symbol length 0
1402 + becomes negative, so an unsigned inequality catches
1404 + t = get_bits(bd, 5)-1;
1405 + for (i = 0; i < symCount; i++) {
1407 + if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
1408 + return RETVAL_DATA_ERROR;
1410 + /* If first bit is 0, stop. Else
1411 + second bit indicates whether to
1412 + increment or decrement the value.
1413 + Optimization: grab 2 bits and unget
1414 + the second if the first was 0. */
1416 + k = get_bits(bd, 2);
1418 + bd->inbufBitCount++;
1421 + /* Add one if second bit 1, else
1422 + * subtract 1. Avoids if/else */
1423 + t += (((k+1)&2)-1);
1425 + /* Correct for the initial -1, to get the
1426 + * final symbol length */
1429 + /* Find largest and smallest lengths in this group */
1430 + minLen = maxLen = length[0];
1432 + for (i = 1; i < symCount; i++) {
1433 + if (length[i] > maxLen)
1434 + maxLen = length[i];
1435 + else if (length[i] < minLen)
1436 + minLen = length[i];
1439 + /* Calculate permute[], base[], and limit[] tables from
1442 + * permute[] is the lookup table for converting
1443 + * Huffman coded symbols into decoded symbols. base[]
1444 + * is the amount to subtract from the value of a
1445 + * Huffman symbol of a given length when using
1448 + * limit[] indicates the largest numerical value a
1449 + * symbol with a given number of bits can have. This
1450 + * is how the Huffman codes can vary in length: each
1451 + * code with a value > limit[length] needs another
1454 + hufGroup = bd->groups+j;
1455 + hufGroup->minLen = minLen;
1456 + hufGroup->maxLen = maxLen;
1457 + /* Note that minLen can't be smaller than 1, so we
1458 + adjust the base and limit array pointers so we're
1459 + not always wasting the first entry. We do this
1460 + again when using them (during symbol decoding).*/
1461 + base = hufGroup->base-1;
1462 + limit = hufGroup->limit-1;
1463 + /* Calculate permute[]. Concurently, initialize
1464 + * temp[] and limit[]. */
1466 + for (i = minLen; i <= maxLen; i++) {
1467 + temp[i] = limit[i] = 0;
1468 + for (t = 0; t < symCount; t++)
1469 + if (length[t] == i)
1470 + hufGroup->permute[pp++] = t;
1472 + /* Count symbols coded for at each bit length */
1473 + for (i = 0; i < symCount; i++)
1474 + temp[length[i]]++;
1475 + /* Calculate limit[] (the largest symbol-coding value
1476 + *at each bit length, which is (previous limit <<
1477 + *1)+symbols at this level), and base[] (number of
1478 + *symbols to ignore at each bit length, which is limit
1479 + *minus the cumulative count of symbols coded for
1482 + for (i = minLen; i < maxLen; i++) {
1484 + /* We read the largest possible symbol size
1485 + and then unget bits after determining how
1486 + many we need, and those extra bits could be
1487 + set to anything. (They're noise from
1488 + future symbols.) At each level we're
1489 + really only interested in the first few
1490 + bits, so here we set all the trailing
1491 + to-be-ignored bits to 1 so they don't
1492 + affect the value > limit[length]
1494 + limit[i] = (pp << (maxLen - i)) - 1;
1496 + base[i+1] = pp-(t += temp[i]);
1498 + limit[maxLen+1] = INT_MAX; /* Sentinal value for
1499 + * reading next sym. */
1500 + limit[maxLen] = pp+temp[maxLen]-1;
1503 + /* We've finished reading and digesting the block header. Now
1504 + read this block's Huffman coded symbols from the file and
1505 + undo the Huffman coding and run length encoding, saving the
1506 + result into dbuf[dbufCount++] = uc */
1508 + /* Initialize symbol occurrence counters and symbol Move To
1510 + for (i = 0; i < 256; i++) {
1512 + mtfSymbol[i] = (unsigned char)i;
1514 + /* Loop through compressed symbols. */
1515 + runPos = dbufCount = symCount = selector = 0;
1517 + /* Determine which Huffman coding group to use. */
1518 + if (!(symCount--)) {
1519 + symCount = GROUP_SIZE-1;
1520 + if (selector >= nSelectors)
1521 + return RETVAL_DATA_ERROR;
1522 + hufGroup = bd->groups+selectors[selector++];
1523 + base = hufGroup->base-1;
1524 + limit = hufGroup->limit-1;
1526 + /* Read next Huffman-coded symbol. */
1527 + /* Note: It is far cheaper to read maxLen bits and
1528 + back up than it is to read minLen bits and then an
1529 + additional bit at a time, testing as we go.
1530 + Because there is a trailing last block (with file
1531 + CRC), there is no danger of the overread causing an
1532 + unexpected EOF for a valid compressed file. As a
1533 + further optimization, we do the read inline
1534 + (falling back to a call to get_bits if the buffer
1535 + runs dry). The following (up to got_huff_bits:) is
1536 + equivalent to j = get_bits(bd, hufGroup->maxLen);
1538 + while (bd->inbufBitCount < hufGroup->maxLen) {
1539 + if (bd->inbufPos == bd->inbufCount) {
1540 + j = get_bits(bd, hufGroup->maxLen);
1541 + goto got_huff_bits;
1544 + (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
1545 + bd->inbufBitCount += 8;
1547 + bd->inbufBitCount -= hufGroup->maxLen;
1548 + j = (bd->inbufBits >> bd->inbufBitCount)&
1549 + ((1 << hufGroup->maxLen)-1);
1551 + /* Figure how how many bits are in next symbol and
1553 + i = hufGroup->minLen;
1554 + while (j > limit[i])
1556 + bd->inbufBitCount += (hufGroup->maxLen - i);
1557 + /* Huffman decode value to get nextSym (with bounds checking) */
1558 + if ((i > hufGroup->maxLen)
1559 + || (((unsigned)(j = (j>>(hufGroup->maxLen-i))-base[i]))
1561 + return RETVAL_DATA_ERROR;
1562 + nextSym = hufGroup->permute[j];
1563 + /* We have now decoded the symbol, which indicates
1564 + either a new literal byte, or a repeated run of the
1565 + most recent literal byte. First, check if nextSym
1566 + indicates a repeated run, and if so loop collecting
1567 + how many times to repeat the last literal. */
1568 + if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
1569 + /* If this is the start of a new run, zero out
1575 + /* Neat trick that saves 1 symbol: instead of
1576 + or-ing 0 or 1 at each bit position, add 1
1577 + or 2 instead. For example, 1011 is 1 << 0
1578 + + 1 << 1 + 2 << 2. 1010 is 2 << 0 + 2 << 1
1579 + + 1 << 2. You can make any bit pattern
1580 + that way using 1 less symbol than the basic
1581 + or 0/1 method (except all bits 0, which
1582 + would use no symbols, but a run of length 0
1583 + doesn't mean anything in this context).
1584 + Thus space is saved. */
1585 + t += (runPos << nextSym);
1586 + /* +runPos if RUNA; +2*runPos if RUNB */
1591 + /* When we hit the first non-run symbol after a run,
1592 + we now know how many times to repeat the last
1593 + literal, so append that many copies to our buffer
1594 + of decoded symbols (dbuf) now. (The last literal
1595 + used is the one at the head of the mtfSymbol
1599 + if (dbufCount+t >= dbufSize)
1600 + return RETVAL_DATA_ERROR;
1602 + uc = symToByte[mtfSymbol[0]];
1603 + byteCount[uc] += t;
1605 + dbuf[dbufCount++] = uc;
1607 + /* Is this the terminating symbol? */
1608 + if (nextSym > symTotal)
1610 + /* At this point, nextSym indicates a new literal
1611 + character. Subtract one to get the position in the
1612 + MTF array at which this literal is currently to be
1613 + found. (Note that the result can't be -1 or 0,
1614 + because 0 and 1 are RUNA and RUNB. But another
1615 + instance of the first symbol in the mtf array,
1616 + position 0, would have been handled as part of a
1617 + run above. Therefore 1 unused mtf position minus 2
1618 + non-literal nextSym values equals -1.) */
1619 + if (dbufCount >= dbufSize)
1620 + return RETVAL_DATA_ERROR;
1622 + uc = mtfSymbol[i];
1623 + /* Adjust the MTF array. Since we typically expect to
1624 + *move only a small number of symbols, and are bound
1625 + *by 256 in any case, using memmove here would
1626 + *typically be bigger and slower due to function call
1627 + *overhead and other assorted setup costs. */
1629 + mtfSymbol[i] = mtfSymbol[i-1];
1631 + mtfSymbol[0] = uc;
1632 + uc = symToByte[uc];
1633 + /* We have our literal byte. Save it into dbuf. */
1635 + dbuf[dbufCount++] = (unsigned int)uc;
1637 + /* At this point, we've read all the Huffman-coded symbols
1638 + (and repeated runs) for this block from the input stream,
1639 + and decoded them into the intermediate buffer. There are
1640 + dbufCount many decoded bytes in dbuf[]. Now undo the
1641 + Burrows-Wheeler transform on dbuf. See
1642 + http://dogma.net/markn/articles/bwt/bwt.htm
1644 + /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
1646 + for (i = 0; i < 256; i++) {
1647 + k = j+byteCount[i];
1651 + /* Figure out what order dbuf would be in if we sorted it. */
1652 + for (i = 0; i < dbufCount; i++) {
1653 + uc = (unsigned char)(dbuf[i] & 0xff);
1654 + dbuf[byteCount[uc]] |= (i << 8);
1657 + /* Decode first byte by hand to initialize "previous" byte.
1658 + Note that it doesn't get output, and if the first three
1659 + characters are identical it doesn't qualify as a run (hence
1660 + writeRunCountdown = 5). */
1662 + if (origPtr >= dbufCount)
1663 + return RETVAL_DATA_ERROR;
1664 + bd->writePos = dbuf[origPtr];
1665 + bd->writeCurrent = (unsigned char)(bd->writePos&0xff);
1666 + bd->writePos >>= 8;
1667 + bd->writeRunCountdown = 5;
1669 + bd->writeCount = dbufCount;
1674 +/* Undo burrows-wheeler transform on intermediate buffer to produce output.
1675 + If start_bunzip was initialized with out_fd =-1, then up to len bytes of
1676 + data are written to outbuf. Return value is number of bytes written or
1677 + error (all errors are negative numbers). If out_fd!=-1, outbuf and len
1678 + are ignored, data is written to out_fd and return is RETVAL_OK or error.
1681 +static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len)
1683 + const unsigned int *dbuf;
1684 + int pos, xcurrent, previous, gotcount;
1686 + /* If last read was short due to end of file, return last block now */
1687 + if (bd->writeCount < 0)
1688 + return bd->writeCount;
1692 + pos = bd->writePos;
1693 + xcurrent = bd->writeCurrent;
1695 + /* We will always have pending decoded data to write into the output
1696 + buffer unless this is the very first call (in which case we haven't
1697 + Huffman-decoded a block into the intermediate buffer yet). */
1699 + if (bd->writeCopies) {
1700 + /* Inside the loop, writeCopies means extra copies (beyond 1) */
1701 + --bd->writeCopies;
1702 + /* Loop outputting bytes */
1704 + /* If the output buffer is full, snapshot
1705 + * state and return */
1706 + if (gotcount >= len) {
1707 + bd->writePos = pos;
1708 + bd->writeCurrent = xcurrent;
1709 + bd->writeCopies++;
1712 + /* Write next byte into output buffer, updating CRC */
1713 + outbuf[gotcount++] = xcurrent;
1714 + bd->writeCRC = (((bd->writeCRC) << 8)
1715 + ^bd->crc32Table[((bd->writeCRC) >> 24)
1717 + /* Loop now if we're outputting multiple
1718 + * copies of this byte */
1719 + if (bd->writeCopies) {
1720 + --bd->writeCopies;
1724 + if (!bd->writeCount--)
1726 + /* Follow sequence vector to undo
1727 + * Burrows-Wheeler transform */
1728 + previous = xcurrent;
1730 + xcurrent = pos&0xff;
1732 + /* After 3 consecutive copies of the same
1733 + byte, the 4th is a repeat count. We count
1734 + down from 4 instead *of counting up because
1735 + testing for non-zero is faster */
1736 + if (--bd->writeRunCountdown) {
1737 + if (xcurrent != previous)
1738 + bd->writeRunCountdown = 4;
1740 + /* We have a repeated run, this byte
1741 + * indicates the count */
1742 + bd->writeCopies = xcurrent;
1743 + xcurrent = previous;
1744 + bd->writeRunCountdown = 5;
1745 + /* Sometimes there are just 3 bytes
1746 + * (run length 0) */
1747 + if (!bd->writeCopies)
1748 + goto decode_next_byte;
1749 + /* Subtract the 1 copy we'd output
1750 + * anyway to get extras */
1751 + --bd->writeCopies;
1754 + /* Decompression of this block completed successfully */
1755 + bd->writeCRC = ~bd->writeCRC;
1756 + bd->totalCRC = ((bd->totalCRC << 1) |
1757 + (bd->totalCRC >> 31)) ^ bd->writeCRC;
1758 + /* If this block had a CRC error, force file level CRC error. */
1759 + if (bd->writeCRC != bd->headerCRC) {
1760 + bd->totalCRC = bd->headerCRC+1;
1761 + return RETVAL_LAST_BLOCK;
1765 + /* Refill the intermediate buffer by Huffman-decoding next
1766 + * block of input */
1767 + /* (previous is just a convenient unused temp variable here) */
1768 + previous = get_next_block(bd);
1770 + bd->writeCount = previous;
1771 + return (previous != RETVAL_LAST_BLOCK) ? previous : gotcount;
1773 + bd->writeCRC = 0xffffffffUL;
1774 + pos = bd->writePos;
1775 + xcurrent = bd->writeCurrent;
1776 + goto decode_next_byte;
1779 +static int INIT nofill(void *buf, unsigned int len)
1784 +/* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain
1785 + a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
1786 + ignored, and data is read from file handle into temporary buffer. */
1787 +static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
1788 + int (*fill)(void*, unsigned int))
1790 + struct bunzip_data *bd;
1791 + unsigned int i, j, c;
1792 + const unsigned int BZh0 =
1793 + (((unsigned int)'B') << 24)+(((unsigned int)'Z') << 16)
1794 + +(((unsigned int)'h') << 8)+(unsigned int)'0';
1796 + /* Figure out how much data to allocate */
1797 + i = sizeof(struct bunzip_data);
1799 + /* Allocate bunzip_data. Most fields initialize to zero. */
1800 + bd = *bdp = malloc(i);
1801 + memset(bd, 0, sizeof(struct bunzip_data));
1802 + /* Setup input buffer */
1803 + bd->inbuf = inbuf;
1804 + bd->inbufCount = len;
1808 + bd->fill = nofill;
1810 + /* Init the CRC32 table (big endian) */
1811 + for (i = 0; i < 256; i++) {
1813 + for (j = 8; j; j--)
1814 + c = c&0x80000000 ? (c << 1)^0x04c11db7 : (c << 1);
1815 + bd->crc32Table[i] = c;
1818 + /* Ensure that file starts with "BZh['1'-'9']." */
1819 + i = get_bits(bd, 32);
1820 + if (((unsigned int)(i-BZh0-1)) >= 9)
1821 + return RETVAL_NOT_BZIP_DATA;
1823 + /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
1824 + uncompressed data. Allocate intermediate buffer for block. */
1825 + bd->dbufSize = 100000*(i-BZh0);
1827 + bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
1831 +/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data,
1832 + not end of file.) */
1833 +STATIC int INIT bunzip2(unsigned char *buf, int len,
1834 + int(*fill)(void*, unsigned int),
1835 + int(*flush)(void*, unsigned int),
1836 + unsigned char *outbuf,
1838 + void(*error_fn)(char *x))
1840 + struct bunzip_data *bd;
1842 + unsigned char *inbuf;
1844 + set_error_fn(error_fn);
1846 + outbuf = malloc(BZIP2_IOBUF_SIZE);
1848 + len -= 4; /* Uncompressed size hack active in pre-boot
1851 + error("Could not allocate output bufer");
1857 + inbuf = malloc(BZIP2_IOBUF_SIZE);
1859 + error("Could not allocate input bufer");
1862 + i = start_bunzip(&bd, inbuf, len, fill);
1865 + i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE);
1871 + if (i != flush(outbuf, i)) {
1872 + i = RETVAL_UNEXPECTED_OUTPUT_EOF;
1877 + /* Check CRC and release memory */
1878 + if (i == RETVAL_LAST_BLOCK) {
1879 + if (bd->headerCRC != bd->totalCRC)
1880 + error("Data integrity error when decompressing.");
1883 + } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
1884 + error("Compressed file ends unexpectedly");
1887 + large_free(bd->dbuf);
1889 + *pos = bd->inbufPos;
1899 +#define decompress bunzip2
1900 diff -purN linux-2.6.27.6/lib/decompress_unlzma.c linux-2.6.27.6udpcast/lib/decompress_unlzma.c
1901 --- linux-2.6.27.6/lib/decompress_unlzma.c 1970-01-01 01:00:00.000000000 +0100
1902 +++ linux-2.6.27.6udpcast/lib/decompress_unlzma.c 2008-11-16 23:40:21.000000000 +0100
1904 +/* Lzma decompressor for Linux kernel. Shamelessly snarfed
1905 + *from busybox 1.1.1
1907 + *Linux kernel adaptation
1908 + *Copyright (C) 2006 Alain < alain@knaff.lu >
1910 + *Based on small lzma deflate implementation/Small range coder
1911 + *implementation for lzma.
1912 + *Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
1914 + *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
1915 + *Copyright (C) 1999-2005 Igor Pavlov
1917 + *Copyrights of the parts, see headers below.
1920 + *This program is free software; you can redistribute it and/or
1921 + *modify it under the terms of the GNU Lesser General Public
1922 + *License as published by the Free Software Foundation; either
1923 + *version 2.1 of the License, or (at your option) any later version.
1925 + *This program is distributed in the hope that it will be useful,
1926 + *but WITHOUT ANY WARRANTY; without even the implied warranty of
1927 + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1928 + *Lesser General Public License for more details.
1930 + *You should have received a copy of the GNU Lesser General Public
1931 + *License along with this library; if not, write to the Free Software
1932 + *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1936 +#include <linux/decompress/unlzma.h>
1937 +#endif /* STATIC */
1939 +#include <linux/decompress/mm.h>
1941 +#define MIN(a, b) (((a) < (b)) ? (a) : (b))
1943 +static long long INIT read_int(unsigned char *ptr, int size)
1946 + long long ret = 0;
1948 + for (i = 0; i < size; i++)
1949 + ret = (ret << 8) | ptr[size-i-1];
1953 +#define ENDIAN_CONVERT(x) \
1954 + x = (typeof(x))read_int((unsigned char *)&x, sizeof(x))
1957 +/* Small range coder implementation for lzma.
1958 + *Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
1960 + *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
1961 + *Copyright (c) 1999-2005 Igor Pavlov
1964 +#include <linux/compiler.h>
1966 +#define LZMA_IOBUF_SIZE 0x10000
1969 + int (*fill)(void*, unsigned int);
1972 + uint8_t *buffer_end;
1980 +#define RC_TOP_BITS 24
1981 +#define RC_MOVE_BITS 5
1982 +#define RC_MODEL_TOTAL_BITS 11
1985 +/* Called twice: once at startup and once in rc_normalize() */
1986 +static void INIT rc_read(struct rc *rc)
1988 + rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
1989 + if (rc->buffer_size <= 0)
1990 + error("unexpected EOF");
1991 + rc->ptr = rc->buffer;
1992 + rc->buffer_end = rc->buffer + rc->buffer_size;
1996 +static inline void INIT rc_init(struct rc *rc,
1997 + int (*fill)(void*, unsigned int),
1998 + char *buffer, int buffer_size)
2001 + rc->buffer = (uint8_t *)buffer;
2002 + rc->buffer_size = buffer_size;
2003 + rc->buffer_end = rc->buffer + rc->buffer_size;
2004 + rc->ptr = rc->buffer;
2007 + rc->range = 0xFFFFFFFF;
2010 +static inline void INIT rc_init_code(struct rc *rc)
2014 + for (i = 0; i < 5; i++) {
2015 + if (rc->ptr >= rc->buffer_end)
2017 + rc->code = (rc->code << 8) | *rc->ptr++;
2022 +/* Called once. TODO: bb_maybe_free() */
2023 +static inline void INIT rc_free(struct rc *rc)
2028 +/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
2029 +static void INIT rc_do_normalize(struct rc *rc)
2031 + if (rc->ptr >= rc->buffer_end)
2034 + rc->code = (rc->code << 8) | *rc->ptr++;
2036 +static inline void INIT rc_normalize(struct rc *rc)
2038 + if (rc->range < (1 << RC_TOP_BITS))
2039 + rc_do_normalize(rc);
2042 +/* Called 9 times */
2043 +/* Why rc_is_bit_0_helper exists?
2044 + *Because we want to always expose (rc->code < rc->bound) to optimizer
2046 +static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p)
2049 + rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
2052 +static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p)
2054 + uint32_t t = rc_is_bit_0_helper(rc, p);
2055 + return rc->code < t;
2058 +/* Called ~10 times, but very small, thus inlined */
2059 +static inline void INIT rc_update_bit_0(struct rc *rc, uint16_t *p)
2061 + rc->range = rc->bound;
2062 + *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
2064 +static inline void rc_update_bit_1(struct rc *rc, uint16_t *p)
2066 + rc->range -= rc->bound;
2067 + rc->code -= rc->bound;
2068 + *p -= *p >> RC_MOVE_BITS;
2071 +/* Called 4 times in unlzma loop */
2072 +static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
2074 + if (rc_is_bit_0(rc, p)) {
2075 + rc_update_bit_0(rc, p);
2079 + rc_update_bit_1(rc, p);
2080 + *symbol = *symbol * 2 + 1;
2086 +static inline int INIT rc_direct_bit(struct rc *rc)
2090 + if (rc->code >= rc->range) {
2091 + rc->code -= rc->range;
2098 +static inline void INIT
2099 +rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol)
2101 + int i = num_levels;
2105 + rc_get_bit(rc, p + *symbol, symbol);
2106 + *symbol -= 1 << num_levels;
2111 + * Small lzma deflate implementation.
2112 + * Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
2114 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
2115 + * Copyright (C) 1999-2005 Igor Pavlov
2119 +struct lzma_header {
2121 + uint32_t dict_size;
2122 + uint64_t dst_size;
2123 +} __attribute__ ((packed)) ;
2126 +#define LZMA_BASE_SIZE 1846
2127 +#define LZMA_LIT_SIZE 768
2129 +#define LZMA_NUM_POS_BITS_MAX 4
2131 +#define LZMA_LEN_NUM_LOW_BITS 3
2132 +#define LZMA_LEN_NUM_MID_BITS 3
2133 +#define LZMA_LEN_NUM_HIGH_BITS 8
2135 +#define LZMA_LEN_CHOICE 0
2136 +#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
2137 +#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
2138 +#define LZMA_LEN_MID (LZMA_LEN_LOW \
2139 + + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
2140 +#define LZMA_LEN_HIGH (LZMA_LEN_MID \
2141 + +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
2142 +#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
2144 +#define LZMA_NUM_STATES 12
2145 +#define LZMA_NUM_LIT_STATES 7
2147 +#define LZMA_START_POS_MODEL_INDEX 4
2148 +#define LZMA_END_POS_MODEL_INDEX 14
2149 +#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
2151 +#define LZMA_NUM_POS_SLOT_BITS 6
2152 +#define LZMA_NUM_LEN_TO_POS_STATES 4
2154 +#define LZMA_NUM_ALIGN_BITS 4
2156 +#define LZMA_MATCH_MIN_LEN 2
2158 +#define LZMA_IS_MATCH 0
2159 +#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
2160 +#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
2161 +#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
2162 +#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
2163 +#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
2164 +#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
2165 + + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
2166 +#define LZMA_SPEC_POS (LZMA_POS_SLOT \
2167 + +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
2168 +#define LZMA_ALIGN (LZMA_SPEC_POS \
2169 + + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
2170 +#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
2171 +#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
2172 +#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
2177 + uint8_t previous_byte;
2178 + size_t buffer_pos;
2180 + size_t global_pos;
2181 + int(*flush)(void*, unsigned int);
2182 + struct lzma_header *header;
2187 + uint32_t rep0, rep1, rep2, rep3;
2190 +static inline size_t INIT get_pos(struct writer *wr)
2193 + wr->global_pos + wr->buffer_pos;
2196 +static inline uint8_t INIT peek_old_byte(struct writer *wr,
2201 + while (offs > wr->header->dict_size)
2202 + offs -= wr->header->dict_size;
2203 + pos = wr->buffer_pos - offs;
2204 + return wr->buffer[pos];
2206 + uint32_t pos = wr->buffer_pos - offs;
2207 + while (pos >= wr->header->dict_size)
2208 + pos += wr->header->dict_size;
2209 + return wr->buffer[pos];
2214 +static inline void INIT write_byte(struct writer *wr, uint8_t byte)
2216 + wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
2217 + if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
2218 + wr->buffer_pos = 0;
2219 + wr->global_pos += wr->header->dict_size;
2220 + wr->flush((char *)wr->buffer, wr->header->dict_size);
2225 +static inline void INIT copy_byte(struct writer *wr, uint32_t offs)
2227 + write_byte(wr, peek_old_byte(wr, offs));
2230 +static inline void INIT copy_bytes(struct writer *wr,
2231 + uint32_t rep0, int len)
2234 + copy_byte(wr, rep0);
2236 + } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
2239 +static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
2240 + struct cstate *cst, uint16_t *p,
2241 + int pos_state, uint16_t *prob,
2242 + int lc, uint32_t literal_pos_mask) {
2244 + rc_update_bit_0(rc, prob);
2245 + prob = (p + LZMA_LITERAL +
2247 + * (((get_pos(wr) & literal_pos_mask) << lc)
2248 + + (wr->previous_byte >> (8 - lc))))
2251 + if (cst->state >= LZMA_NUM_LIT_STATES) {
2252 + int match_byte = peek_old_byte(wr, cst->rep0);
2255 + uint16_t *prob_lit;
2258 + bit = match_byte & 0x100;
2259 + prob_lit = prob + 0x100 + bit + mi;
2260 + if (rc_get_bit(rc, prob_lit, &mi)) {
2267 + } while (mi < 0x100);
2269 + while (mi < 0x100) {
2270 + uint16_t *prob_lit = prob + mi;
2271 + rc_get_bit(rc, prob_lit, &mi);
2273 + write_byte(wr, mi);
2274 + if (cst->state < 4)
2276 + else if (cst->state < 10)
2282 +static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
2283 + struct cstate *cst, uint16_t *p,
2284 + int pos_state, uint16_t *prob) {
2286 + uint16_t *prob_len;
2290 + rc_update_bit_1(rc, prob);
2291 + prob = p + LZMA_IS_REP + cst->state;
2292 + if (rc_is_bit_0(rc, prob)) {
2293 + rc_update_bit_0(rc, prob);
2294 + cst->rep3 = cst->rep2;
2295 + cst->rep2 = cst->rep1;
2296 + cst->rep1 = cst->rep0;
2297 + cst->state = cst->state < LZMA_NUM_LIT_STATES ? 0 : 3;
2298 + prob = p + LZMA_LEN_CODER;
2300 + rc_update_bit_1(rc, prob);
2301 + prob = p + LZMA_IS_REP_G0 + cst->state;
2302 + if (rc_is_bit_0(rc, prob)) {
2303 + rc_update_bit_0(rc, prob);
2304 + prob = (p + LZMA_IS_REP_0_LONG
2306 + LZMA_NUM_POS_BITS_MAX) +
2308 + if (rc_is_bit_0(rc, prob)) {
2309 + rc_update_bit_0(rc, prob);
2311 + cst->state = cst->state < LZMA_NUM_LIT_STATES ?
2313 + copy_byte(wr, cst->rep0);
2316 + rc_update_bit_1(rc, prob);
2319 + uint32_t distance;
2321 + rc_update_bit_1(rc, prob);
2322 + prob = p + LZMA_IS_REP_G1 + cst->state;
2323 + if (rc_is_bit_0(rc, prob)) {
2324 + rc_update_bit_0(rc, prob);
2325 + distance = cst->rep1;
2327 + rc_update_bit_1(rc, prob);
2328 + prob = p + LZMA_IS_REP_G2 + cst->state;
2329 + if (rc_is_bit_0(rc, prob)) {
2330 + rc_update_bit_0(rc, prob);
2331 + distance = cst->rep2;
2333 + rc_update_bit_1(rc, prob);
2334 + distance = cst->rep3;
2335 + cst->rep3 = cst->rep2;
2337 + cst->rep2 = cst->rep1;
2339 + cst->rep1 = cst->rep0;
2340 + cst->rep0 = distance;
2342 + cst->state = cst->state < LZMA_NUM_LIT_STATES ? 8 : 11;
2343 + prob = p + LZMA_REP_LEN_CODER;
2346 + prob_len = prob + LZMA_LEN_CHOICE;
2347 + if (rc_is_bit_0(rc, prob_len)) {
2348 + rc_update_bit_0(rc, prob_len);
2349 + prob_len = (prob + LZMA_LEN_LOW
2351 + LZMA_LEN_NUM_LOW_BITS));
2353 + num_bits = LZMA_LEN_NUM_LOW_BITS;
2355 + rc_update_bit_1(rc, prob_len);
2356 + prob_len = prob + LZMA_LEN_CHOICE_2;
2357 + if (rc_is_bit_0(rc, prob_len)) {
2358 + rc_update_bit_0(rc, prob_len);
2359 + prob_len = (prob + LZMA_LEN_MID
2361 + LZMA_LEN_NUM_MID_BITS));
2362 + offset = 1 << LZMA_LEN_NUM_LOW_BITS;
2363 + num_bits = LZMA_LEN_NUM_MID_BITS;
2365 + rc_update_bit_1(rc, prob_len);
2366 + prob_len = prob + LZMA_LEN_HIGH;
2367 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
2368 + + (1 << LZMA_LEN_NUM_MID_BITS));
2369 + num_bits = LZMA_LEN_NUM_HIGH_BITS;
2373 + rc_bit_tree_decode(rc, prob_len, num_bits, &len);
2376 + if (cst->state < 4) {
2379 + cst->state += LZMA_NUM_LIT_STATES;
2381 + p + LZMA_POS_SLOT +
2383 + LZMA_NUM_LEN_TO_POS_STATES ? len :
2384 + LZMA_NUM_LEN_TO_POS_STATES - 1)
2385 + << LZMA_NUM_POS_SLOT_BITS);
2386 + rc_bit_tree_decode(rc, prob,
2387 + LZMA_NUM_POS_SLOT_BITS,
2389 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
2391 + num_bits = (pos_slot >> 1) - 1;
2392 + cst->rep0 = 2 | (pos_slot & 1);
2393 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
2394 + cst->rep0 <<= num_bits;
2395 + prob = p + LZMA_SPEC_POS +
2396 + cst->rep0 - pos_slot - 1;
2398 + num_bits -= LZMA_NUM_ALIGN_BITS;
2399 + while (num_bits--)
2400 + cst->rep0 = (cst->rep0 << 1) |
2401 + rc_direct_bit(rc);
2402 + prob = p + LZMA_ALIGN;
2403 + cst->rep0 <<= LZMA_NUM_ALIGN_BITS;
2404 + num_bits = LZMA_NUM_ALIGN_BITS;
2408 + while (num_bits--) {
2409 + if (rc_get_bit(rc, prob + mi, &mi))
2414 + cst->rep0 = pos_slot;
2415 + if (++(cst->rep0) == 0)
2419 + len += LZMA_MATCH_MIN_LEN;
2421 + copy_bytes(wr, cst->rep0, len);
2426 +STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
2427 + int(*fill)(void*, unsigned int),
2428 + int(*flush)(void*, unsigned int),
2429 + unsigned char *output,
2431 + void(*error_fn)(char *x)
2434 + struct lzma_header header;
2436 + uint32_t pos_state_mask;
2437 + uint32_t literal_pos_mask;
2443 + struct cstate cst;
2444 + unsigned char *inbuf;
2447 + set_error_fn(error_fn);
2449 + in_len -= 4; /* Uncompressed size hack active in pre-boot
2454 + inbuf = malloc(LZMA_IOBUF_SIZE);
2456 + error("Could not allocate input bufer");
2461 + cst.rep0 = cst.rep1 = cst.rep2 = cst.rep3 = 1;
2463 + wr.header = &header;
2465 + wr.global_pos = 0;
2466 + wr.previous_byte = 0;
2467 + wr.buffer_pos = 0;
2469 + rc_init(&rc, fill, inbuf, in_len);
2471 + for (i = 0; i < sizeof(header); i++) {
2472 + if (rc.ptr >= rc.buffer_end)
2474 + ((unsigned char *)&header)[i] = *rc.ptr++;
2477 + if (header.pos >= (9 * 5 * 5))
2478 + error("bad header");
2492 + pos_state_mask = (1 << pb) - 1;
2493 + literal_pos_mask = (1 << lp) - 1;
2495 + ENDIAN_CONVERT(header.dict_size);
2496 + ENDIAN_CONVERT(header.dst_size);
2498 + if (header.dict_size == 0)
2499 + header.dict_size = 1;
2502 + wr.buffer = output;
2504 + wr.bufsize = MIN(header.dst_size, header.dict_size);
2505 + wr.buffer = large_malloc(wr.bufsize);
2507 + if (wr.buffer == NULL)
2510 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
2511 + p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
2514 + num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
2515 + for (i = 0; i < num_probs; i++)
2516 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
2518 + rc_init_code(&rc);
2520 + while (get_pos(&wr) < header.dst_size) {
2521 + int pos_state = get_pos(&wr) & pos_state_mask;
2522 + uint16_t *prob = p + LZMA_IS_MATCH +
2523 + (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
2524 + if (rc_is_bit_0(&rc, prob))
2525 + process_bit0(&wr, &rc, &cst, p, pos_state, prob,
2526 + lc, literal_pos_mask);
2528 + process_bit1(&wr, &rc, &cst, p, pos_state, prob);
2529 + if (cst.rep0 == 0)
2535 + *posp = rc.ptr-rc.buffer;
2537 + wr.flush(wr.buffer, wr.buffer_pos);
2542 + large_free(wr.buffer);
2550 +#define decompress unlzma
2551 diff -purN linux-2.6.27.6/lib/inflate.c linux-2.6.27.6udpcast/lib/inflate.c
2552 --- linux-2.6.27.6/lib/inflate.c 2008-11-13 18:56:21.000000000 +0100
2553 +++ linux-2.6.27.6udpcast/lib/inflate.c 2008-11-16 23:02:55.000000000 +0100
2554 @@ -109,20 +109,78 @@ static char rcsid[] = "#Id: inflate.c,v
2558 +#include <linux/decompress/inflate.h>
2559 +#endif /* ! STATIC */
2561 -#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
2562 -# include <sys/types.h>
2563 -# include <stdlib.h>
2564 +#include <linux/decompress/mm.h>
2566 +#include <linux/string.h>
2569 +static int(*flush_cb)(void*, unsigned int);
2570 +static int(*fill_cb)(void*, unsigned int);
2572 +/* Begin stuff copied from initramfs */
2574 + * gzip declarations
2577 +#define OF(args) args
2580 +#define memzero(s, n) memset((s), 0, (n))
2585 -#endif /* !STATIC */
2586 +#define INBUFSIZ 4096
2588 +#define WSIZE 0x8000 /* window size--must be a power of two, and */
2589 + /* at least 32K for zip's deflate method */
2591 +static uint8_t *inbuf;
2592 +static uint8_t *window;
2594 +static unsigned insize; /* valid bytes in inbuf */
2595 +static unsigned outcnt; /* bytes in output buffer */
2596 +static long bytes_out;
2600 +static unsigned inptr; /* index of next byte to be processed in inbuf */
2604 +/* ===========================================================================
2605 + * Fill the input buffer. This is called only when the buffer is empty
2606 + * and at least one byte is really needed.
2607 + * Returning -1 does not guarantee that gunzip() will ever return.
2609 +static int INIT fill_inbuf(void)
2611 + insize = fill_cb(inbuf, INBUFSIZ);
2612 + if (insize <= 0) {
2613 + error("RAMDISK: ran out of compressed data");
2622 +#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
2624 +/* Diagnostic functions (stubbed out) */
2625 +#define Assert(cond, msg)
2629 +#define Tracec(c, x)
2630 +#define Tracecv(c, x)
2634 +static void flush_window(void);
2635 +/* End stuff copied from initramfs */
2639 #define slide window
2641 /* Huffman code lookup table entry--this entry is four bytes for machines
2642 @@ -133,10 +191,10 @@ static char rcsid[] = "#Id: inflate.c,v
2643 an unused code. If a code with e == 99 is looked up, this implies an
2644 error in the data. */
2646 - uch e; /* number of extra bits or operation */
2647 - uch b; /* number of bits in this code or subcode */
2648 + uint8_t e; /* number of extra bits or operation */
2649 + uint8_t b; /* number of bits in this code or subcode */
2651 - ush n; /* literal, length base, or distance base */
2652 + uint16_t n; /* literal, length base, or distance base */
2653 struct huft *t; /* pointer to next level of table */
2656 @@ -144,7 +202,7 @@ struct huft {
2658 /* Function prototypes */
2659 STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned,
2660 - const ush *, const ush *, struct huft **, int *));
2661 + const uint16_t *, const uint16_t *, struct huft **, int *));
2662 STATIC int INIT huft_free OF((struct huft *));
2663 STATIC int INIT inflate_codes OF((struct huft *, struct huft *, int, int));
2664 STATIC int INIT inflate_stored OF((void));
2665 @@ -159,28 +217,28 @@ STATIC int INIT inflate OF((void));
2666 circular buffer. The index is updated simply by incrementing and then
2667 ANDing with 0x7fff (32K-1). */
2668 /* It is left to other modules to supply the 32 K area. It is assumed
2669 - to be usable as if it were declared "uch slide[32768];" or as just
2670 - "uch *slide;" and then malloc'ed in the latter case. The definition
2671 + to be usable as if it were declared "uint8_t slide[32768];" or as just
2672 + "uint8_t *slide;" and then malloc'ed in the latter case. The definition
2673 must be in unzip.h, included above. */
2674 /* unsigned wp; current position in slide */
2676 #define flush_output(w) (wp=(w),flush_window())
2678 /* Tables for deflate from PKZIP's appnote.txt. */
2679 -static const unsigned border[] = { /* Order of the bit length code lengths */
2680 +static const unsigned border[] = { /* Order of the bit length code lengths */
2681 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
2682 -static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */
2683 +static const uint16_t cplens[] = { /* Copy lengths for literal codes 257..285 */
2684 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
2685 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
2686 /* note: see note #13 above about the 258 in this list. */
2687 -static const ush cplext[] = { /* Extra bits for literal codes 257..285 */
2688 +static const uint16_t cplext[] = { /* Extra bits for literal codes 257..285 */
2689 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
2690 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
2691 -static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
2692 +static const uint16_t cpdist[] = { /* Copy offsets for distance codes 0..29 */
2693 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
2694 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
2695 8193, 12289, 16385, 24577};
2696 -static const ush cpdext[] = { /* Extra bits for distance codes */
2697 +static const uint16_t cpdext[] = { /* Extra bits for distance codes */
2698 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
2699 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
2701 @@ -217,59 +275,21 @@ static const ush cpdext[] = { /*
2705 -STATIC ulg bb; /* bit buffer */
2706 +STATIC uint32_t bb; /* bit buffer */
2707 STATIC unsigned bk; /* bits in bit buffer */
2709 -STATIC const ush mask_bits[] = {
2710 +STATIC const uint16_t mask_bits[] = {
2712 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
2713 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
2716 -#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (uch)v; })
2717 -#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
2718 +#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; \
2720 +#define NEEDBITS(n) {while (k < (n)) \
2721 + {b |= ((uint32_t)NEXTBYTE())<<k; k += 8; } }
2722 #define DUMPBITS(n) {b>>=(n);k-=(n);}
2724 -#ifndef NO_INFLATE_MALLOC
2725 -/* A trivial malloc implementation, adapted from
2726 - * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
2729 -static unsigned long malloc_ptr;
2730 -static int malloc_count;
2732 -static void *malloc(int size)
2737 - error("Malloc error");
2739 - malloc_ptr = free_mem_ptr;
2741 - malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
2743 - p = (void *)malloc_ptr;
2744 - malloc_ptr += size;
2746 - if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
2747 - error("Out of memory");
2753 -static void free(void *where)
2756 - if (!malloc_count)
2757 - malloc_ptr = free_mem_ptr;
2760 -#define malloc(a) kmalloc(a, GFP_KERNEL)
2761 -#define free(a) kfree(a)
2765 Huffman code decoding is performed using a multi-level table lookup.
2766 The fastest way to decode is to simply build a lookup table whose
2767 @@ -307,7 +327,7 @@ STATIC const int lbits = 9; /*
2768 STATIC const int dbits = 6; /* bits in base distance lookup table */
2771 -/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
2772 +/* If BMAX needs to be larger than 16, then h and x[] should be uint32_t. */
2773 #define BMAX 16 /* maximum bit length of any code (16 for explode) */
2774 #define N_MAX 288 /* maximum number of codes in any set */
2776 @@ -319,8 +339,8 @@ STATIC int INIT huft_build(
2777 unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
2778 unsigned n, /* number of codes (assumed <= N_MAX) */
2779 unsigned s, /* number of simple-valued codes (0..s-1) */
2780 - const ush *d, /* list of base values for non-simple codes */
2781 - const ush *e, /* list of extra bits for non-simple codes */
2782 + const uint16_t *d, /* list of base values for non-simple codes */
2783 + const uint16_t *e, /* list of extra bits for non-simple codes */
2784 struct huft **t, /* result: starting table */
2785 int *m /* maximum lookup bits, returns actual */
2787 @@ -500,8 +520,8 @@ DEBG1("5 ");
2790 x[h] = i; /* save pattern for backing up */
2791 - r.b = (uch)l; /* bits to dump before this table */
2792 - r.e = (uch)(16 + j); /* bits in this table */
2793 + r.b = (uint8_t)l; /* bits to dump before this table */
2794 + r.e = (uint8_t)(16 + j); /* bits in this table */
2795 r.v.t = q; /* pointer to this table */
2796 j = i >> (w - l); /* (get around Turbo C bug) */
2797 u[h-1][j] = r; /* connect to last table */
2798 @@ -511,18 +531,18 @@ DEBG1("6 ");
2801 /* set up table entry in r */
2802 - r.b = (uch)(k - w);
2803 + r.b = (uint8_t)(k - w);
2805 r.e = 99; /* out of values--invalid code */
2808 - r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
2809 - r.v.n = (ush)(*p); /* simple code is just the value */
2810 + r.e = (uint8_t)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
2811 + r.v.n = (uint16_t)(*p); /* simple code is just the value */
2812 p++; /* one compiler does not like *p++ */
2816 - r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
2817 + r.e = (uint8_t)e[*p - s]; /* non-simple--look up in lists */
2818 r.v.n = d[*p++ - s];
2821 @@ -592,11 +612,12 @@ STATIC int INIT inflate_codes(
2822 Return an error code or zero if it all goes ok. */
2824 register unsigned e; /* table entry flag/number of extra bits */
2825 - unsigned n, d; /* length and index for copy */
2827 + int d; /* source index for copy */
2828 unsigned w; /* current window position */
2829 struct huft *t; /* pointer to table entry */
2830 unsigned ml, md; /* masks for bl and bd bits */
2831 - register ulg b; /* bit buffer */
2832 + register uint32_t b; /* bit buffer */
2833 register unsigned k; /* number of bits in bit buffer */
2836 @@ -622,7 +643,7 @@ STATIC int INIT inflate_codes(
2838 if (e == 16) /* then it's a literal */
2840 - slide[w++] = (uch)t->v.n;
2841 + slide[w++] = (uint8_t)t->v.n;
2842 Tracevv((stderr, "%c", slide[w-1]));
2845 @@ -659,11 +680,25 @@ STATIC int INIT inflate_codes(
2849 - n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
2853 + /* Sliding window emulated using circular buffer:
2854 + * manage wrap-around */
2855 + e = WSIZE - ((d &= WSIZE-1) > w ? d : w);
2865 #if !defined(NOMEMCPY) && !defined(DEBUG)
2866 if (w - d >= e) /* (this test assumes unsigned comparison) */
2868 - memcpy(slide + w, slide + d, e);
2869 + memcpy(slide + w, slide + d, e);
2873 @@ -673,9 +708,8 @@ STATIC int INIT inflate_codes(
2874 slide[w++] = slide[d++];
2875 Tracevv((stderr, "%c", slide[w-1]));
2885 @@ -702,7 +736,7 @@ STATIC int INIT inflate_stored(void)
2887 unsigned n; /* number of bytes in block */
2888 unsigned w; /* current window position */
2889 - register ulg b; /* bit buffer */
2890 + register uint32_t b; /* bit buffer */
2891 register unsigned k; /* number of bits in bit buffer */
2894 @@ -732,7 +766,7 @@ DEBG("<stor");
2898 - slide[w++] = (uch)b;
2899 + slide[w++] = (uint8_t)b;
2903 @@ -838,7 +872,7 @@ STATIC int noinline INIT inflate_dynamic
2904 unsigned nl; /* number of literal/length codes */
2905 unsigned nd; /* number of distance codes */
2906 unsigned *ll; /* literal/length and distance code lengths */
2907 - register ulg b; /* bit buffer */
2908 + register uint32_t b; /* bit buffer */
2909 register unsigned k; /* number of bits in bit buffer */
2912 @@ -1033,7 +1067,7 @@ STATIC int INIT inflate_block(
2913 /* decompress an inflated block */
2915 unsigned t; /* block type */
2916 - register ulg b; /* bit buffer */
2917 + register uint32_t b; /* bit buffer */
2918 register unsigned k; /* number of bits in bit buffer */
2921 @@ -1130,8 +1164,8 @@ STATIC int INIT inflate(void)
2923 **********************************************************************/
2925 -static ulg crc_32_tab[256];
2926 -static ulg crc; /* initialized in makecrc() so it'll reside in bss */
2927 +static uint32_t crc_32_tab[256];
2928 +static uint32_t crc; /* initialized in makecrc() so it'll reside in bss */
2929 #define CRC_VALUE (crc ^ 0xffffffffUL)
2932 @@ -1172,7 +1206,7 @@ makecrc(void)
2935 /* this is initialized here so this code could reside in ROM */
2936 - crc = (ulg)0xffffffffUL; /* shift register contents */
2937 + crc = (uint32_t)0xffffffffUL; /* shift register contents */
2940 /* gzip flag byte */
2941 @@ -1184,18 +1218,89 @@ makecrc(void)
2942 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
2943 #define RESERVED 0xC0 /* bit 6,7: reserved */
2946 +/* ===========================================================================
2947 + * Write the output window window[0..outcnt-1] and update crc and bytes_out.
2948 + * (Used for the decompressed data only.)
2950 +static void INIT flush_window(void)
2952 + uint32_t c = crc; /* temporary variable */
2957 + for (n = 0; n < outcnt; n++) {
2959 + c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
2962 + bytes_out += (uint32_t)outcnt;
2963 + if (flush_cb != NULL)
2964 + flush_cb(window, outcnt); /* TODO: handle unzip_error */
2970 +static int empty_fill(void *buf, unsigned int len)
2978 * Do the uncompression!
2980 -static int INIT gunzip(void)
2981 +STATIC int INIT gunzip(
2983 + unsigned char *buf, int len,
2984 + int(*fill)(void*, unsigned int),
2985 + int(*flush)(void*, unsigned int),
2986 + unsigned char *output,
2988 + void(*error_fn)(char *x)
2996 unsigned char magic[2]; /* magic header */
2998 - ulg orig_crc = 0; /* original crc */
2999 - ulg orig_len = 0; /* original uncompressed length */
3000 + uint32_t orig_crc = 0; /* original crc */
3001 + uint32_t orig_len = 0; /* original uncompressed length */
3005 + set_error_fn(error_fn);
3007 + fill_cb = empty_fill;
3013 + window = malloc(0x8000);
3015 + panic("can't allocate buffers");
3023 + inbuf = malloc(INBUFSIZ);
3027 + outcnt = 0; /* bytes in output buffer */
3029 + crc = (uint32_t)0xffffffffL; /* shift register contents */
3032 magic[0] = NEXTBYTE();
3033 magic[1] = NEXTBYTE();
3034 method = NEXTBYTE();
3035 @@ -1212,7 +1317,7 @@ static int INIT gunzip(void)
3039 - flags = (uch)get_byte();
3040 + flags = (uint8_t)get_byte();
3041 if ((flags & ENCRYPTED) != 0) {
3042 error("Input is encrypted");
3044 @@ -1277,15 +1382,15 @@ static int INIT gunzip(void)
3045 /* crc32 (see algorithm.doc)
3046 * uncompressed input size modulo 2^32
3048 - orig_crc = (ulg) NEXTBYTE();
3049 - orig_crc |= (ulg) NEXTBYTE() << 8;
3050 - orig_crc |= (ulg) NEXTBYTE() << 16;
3051 - orig_crc |= (ulg) NEXTBYTE() << 24;
3052 + orig_crc = (uint32_t) NEXTBYTE();
3053 + orig_crc |= (uint32_t) NEXTBYTE() << 8;
3054 + orig_crc |= (uint32_t) NEXTBYTE() << 16;
3055 + orig_crc |= (uint32_t) NEXTBYTE() << 24;
3057 - orig_len = (ulg) NEXTBYTE();
3058 - orig_len |= (ulg) NEXTBYTE() << 8;
3059 - orig_len |= (ulg) NEXTBYTE() << 16;
3060 - orig_len |= (ulg) NEXTBYTE() << 24;
3061 + orig_len = (uint32_t) NEXTBYTE();
3062 + orig_len |= (uint32_t) NEXTBYTE() << 8;
3063 + orig_len |= (uint32_t) NEXTBYTE() << 16;
3064 + orig_len |= (uint32_t) NEXTBYTE() << 24;
3066 /* Validate decompression */
3067 if (orig_crc != CRC_VALUE) {
3068 @@ -1296,11 +1401,22 @@ static int INIT gunzip(void)
3069 error("length error");
3080 underrun: /* NEXTBYTE() goto's here if needed */
3086 error("out of input data");
3091 +#define decompress gunzip
3092 diff -purN linux-2.6.27.6/lib/Makefile linux-2.6.27.6udpcast/lib/Makefile
3093 --- linux-2.6.27.6/lib/Makefile 2008-11-13 18:56:21.000000000 +0100
3094 +++ linux-2.6.27.6udpcast/lib/Makefile 2008-11-16 23:07:34.000000000 +0100
3095 @@ -11,7 +11,8 @@ lib-y := ctype.o string.o vsprintf.o cmd
3096 rbtree.o radix-tree.o dump_stack.o \
3097 idr.o int_sqrt.o extable.o prio_tree.o \
3098 sha1.o irq_regs.o reciprocal_div.o argv_split.o \
3099 - proportions.o prio_heap.o ratelimit.o show_mem.o
3100 + proportions.o prio_heap.o ratelimit.o show_mem.o \
3101 + inflate.o decompress_bunzip2.o decompress_unlzma.o
3103 lib-$(CONFIG_MMU) += ioremap.o
3104 lib-$(CONFIG_SMP) += cpumask.o
3105 diff -purN linux-2.6.27.6/scripts/bin_size linux-2.6.27.6udpcast/scripts/bin_size
3106 --- linux-2.6.27.6/scripts/bin_size 1970-01-01 01:00:00.000000000 +0100
3107 +++ linux-2.6.27.6udpcast/scripts/bin_size 2008-11-16 23:43:34.000000000 +0100
3111 +if [ $# = 0 ] ; then
3112 + echo Usage: $0 file
3115 +size_dec=`stat -c "%s" $1`
3116 +size_hex_echo_string=`printf "%08x" $size_dec |
3117 + sed 's/\(..\)\(..\)\(..\)\(..\)/\\\\x\4\\\\x\3\\\\x\2\\\\x\1/g'`
3118 +/bin/echo -ne $size_hex_echo_string
3119 diff -purN linux-2.6.27.6/scripts/Makefile.lib linux-2.6.27.6udpcast/scripts/Makefile.lib
3120 --- linux-2.6.27.6/scripts/Makefile.lib 2008-11-13 18:56:21.000000000 +0100
3121 +++ linux-2.6.27.6udpcast/scripts/Makefile.lib 2008-11-16 23:02:55.000000000 +0100
3122 @@ -174,3 +174,17 @@ quiet_cmd_gzip = GZIP $@
3123 cmd_gzip = gzip -f -9 < $< > $@
3127 +# ---------------------------------------------------------------------------
3129 +# Bzip2 does not include size in file... so we have to fake that
3130 +size_append=$(CONFIG_SHELL) $(srctree)/scripts/bin_size
3132 +quiet_cmd_bzip2 = BZIP2 $@
3133 +cmd_bzip2 = (bzip2 -9 < $< ; $(size_append) $<) > $@ || (rm -f $@ ; false)
3136 +# ---------------------------------------------------------------------------
3138 +quiet_cmd_lzma = LZMA $@
3139 +cmd_lzma = (lzma e $< $@; $(size_append) $<) > $@ || (rm -f $@ ; false)