1 diff -urN linux-2.6.28.9/arch/arm/boot/compressed/Makefile linux-2.6.28.9.new/arch/arm/boot/compressed/Makefile
2 --- linux-2.6.28.9/arch/arm/boot/compressed/Makefile 2009-03-23 22:55:52.000000000 +0100
3 +++ linux-2.6.28.9.new/arch/arm/boot/compressed/Makefile 2009-04-24 14:08:08.000000000 +0200
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_FUNCTION_TRACER),y)
21 ORIG_CFLAGS := $(KBUILD_CFLAGS)
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
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 -urN linux-2.6.28.9/arch/arm/boot/compressed/misc.c linux-2.6.28.9.new/arch/arm/boot/compressed/misc.c
51 --- linux-2.6.28.9/arch/arm/boot/compressed/misc.c 2009-03-23 22:55:52.000000000 +0100
52 +++ linux-2.6.28.9.new/arch/arm/boot/compressed/misc.c 2009-04-24 14:08:08.000000000 +0200
53 @@ -169,116 +169,34 @@
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 @@
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");
214 - output_data = output_buffer;
217 putstr("Uncompressing Linux...");
219 + decompress(input_data, input_len, NULL, output_buffer, NULL);
223 diff -urN linux-2.6.28.9/arch/x86/boot/compressed/Makefile linux-2.6.28.9.new/arch/x86/boot/compressed/Makefile
224 --- linux-2.6.28.9/arch/x86/boot/compressed/Makefile 2009-03-23 22:55:52.000000000 +0100
225 +++ linux-2.6.28.9.new/arch/x86/boot/compressed/Makefile 2009-04-24 14:10:01.000000000 +0200
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
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
254 LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T
257 -$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
258 +suffix_$(CONFIG_KERNEL_GZIP) = gz
259 +suffix_$(CONFIG_KERNEL_BZIP2) = bz2
260 +suffix_$(CONFIG_KERNEL_LZMA) = lzma
262 +$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
263 $(call if_changed,ld)
264 diff -urN linux-2.6.28.9/arch/x86/boot/compressed/misc.c linux-2.6.28.9.new/arch/x86/boot/compressed/misc.c
265 --- linux-2.6.28.9/arch/x86/boot/compressed/misc.c 2009-03-23 22:55:52.000000000 +0100
266 +++ linux-2.6.28.9.new/arch/x86/boot/compressed/misc.c 2009-04-24 14:08:08.000000000 +0200
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);
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);
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)
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)
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))
429 putstr("\nDecompressing Linux... ");
431 + decompress(input_data, input_len, NULL, NULL, output, NULL, error);
434 putstr("done.\nBooting the kernel.\n");
435 diff -urN linux-2.6.28.9/arch/x86/include/asm/boot.h linux-2.6.28.9.new/arch/x86/include/asm/boot.h
436 --- linux-2.6.28.9/arch/x86/include/asm/boot.h 2009-03-23 22:55:52.000000000 +0100
437 +++ linux-2.6.28.9.new/arch/x86/include/asm/boot.h 2009-04-24 14:08:08.000000000 +0200
439 + (CONFIG_PHYSICAL_ALIGN - 1)) \
440 & ~(CONFIG_PHYSICAL_ALIGN - 1))
442 +#if (defined CONFIG_KERNEL_BZIP2)
443 +#define BOOT_HEAP_SIZE 0x400000
447 #define BOOT_HEAP_SIZE 0x7000
448 -#define BOOT_STACK_SIZE 0x4000
450 #define BOOT_HEAP_SIZE 0x4000
455 +#ifdef CONFIG_X86_64
456 +#define BOOT_STACK_SIZE 0x4000
458 #define BOOT_STACK_SIZE 0x1000
461 diff -urN linux-2.6.28.9/drivers/block/Kconfig linux-2.6.28.9.new/drivers/block/Kconfig
462 --- linux-2.6.28.9/drivers/block/Kconfig 2009-03-23 22:55:52.000000000 +0100
463 +++ linux-2.6.28.9.new/drivers/block/Kconfig 2009-04-24 14:08:08.000000000 +0200
465 will prevent RAM block device backing store memory from being
466 allocated from highmem (only a problem for highmem systems).
469 + bool "Initial ramdisk compressed using bzip2"
471 + depends on BLK_DEV_INITRD=y
473 + Support loading of a bzip2 encoded initial ramdisk or cpio buffer
477 + bool "Initial ramdisk compressed using lzma"
479 + depends on BLK_DEV_INITRD=y
481 + Support loading of a lzma encoded initial ramdisk or cpio buffer
485 + bool "Initial ramdisk compressed using gzip"
487 + depends on BLK_DEV_INITRD=y
489 + Support loading of a gzip encoded initial ramdisk or cpio buffer.
493 tristate "Packet writing on CD/DVD media"
495 diff -urN linux-2.6.28.9/include/linux/decompress/bunzip2.h linux-2.6.28.9.new/include/linux/decompress/bunzip2.h
496 --- linux-2.6.28.9/include/linux/decompress/bunzip2.h 1970-01-01 01:00:00.000000000 +0100
497 +++ linux-2.6.28.9.new/include/linux/decompress/bunzip2.h 2009-04-24 14:08:08.000000000 +0200
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 -urN linux-2.6.28.9/include/linux/decompress/generic.h linux-2.6.28.9.new/include/linux/decompress/generic.h
510 --- linux-2.6.28.9/include/linux/decompress/generic.h 1970-01-01 01:00:00.000000000 +0100
511 +++ linux-2.6.28.9.new/include/linux/decompress/generic.h 2009-04-24 14:08:08.000000000 +0200
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 -urN linux-2.6.28.9/include/linux/decompress/inflate.h linux-2.6.28.9.new/include/linux/decompress/inflate.h
544 --- linux-2.6.28.9/include/linux/decompress/inflate.h 1970-01-01 01:00:00.000000000 +0100
545 +++ linux-2.6.28.9.new/include/linux/decompress/inflate.h 2009-04-24 14:08:08.000000000 +0200
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 -urN linux-2.6.28.9/include/linux/decompress/mm.h linux-2.6.28.9.new/include/linux/decompress/mm.h
561 --- linux-2.6.28.9/include/linux/decompress/mm.h 1970-01-01 01:00:00.000000000 +0100
562 +++ linux-2.6.28.9.new/include/linux/decompress/mm.h 2009-04-24 14:08:08.000000000 +0200
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 -urN linux-2.6.28.9/include/linux/decompress/unlzma.h linux-2.6.28.9.new/include/linux/decompress/unlzma.h
654 --- linux-2.6.28.9/include/linux/decompress/unlzma.h 1970-01-01 01:00:00.000000000 +0100
655 +++ linux-2.6.28.9.new/include/linux/decompress/unlzma.h 2009-04-24 14:08:08.000000000 +0200
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 -urN linux-2.6.28.9/init/Kconfig linux-2.6.28.9.new/init/Kconfig
670 --- linux-2.6.28.9/init/Kconfig 2009-03-23 22:55:52.000000000 +0100
671 +++ linux-2.6.28.9.new/init/Kconfig 2009-04-24 14:08:08.000000000 +0200
674 which is done within the script "scripts/setlocalversion".)
677 + prompt "Kernel compression mode"
678 + default KERNEL_GZIP
680 + The linux kernel is a kind of self-extracting executable.
681 + Several compression algorithms are available, which differ
682 + in efficiency, compression and decompression speed.
683 + Compression speed is only relevant when building a kernel.
684 + Decompression speed is relevant at each boot.
686 + If you have any problems with bzip2 or lzma compressed
687 + kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
688 + version of this functionality (bzip2 only), for 2.4, was
689 + supplied by Christian Ludwig)
691 + High compression options are mostly useful for users, who
692 + are low on disk space (embedded systems), but for whom ram
695 + If in doubt, select 'gzip'
700 + The old and tried gzip compression. Its compression ratio is
701 + the poorest among the 3 choices; however its speed (both
702 + compression and decompression) is the fastest.
707 + Its compression ratio and speed is intermediate.
708 + Decompression speed is slowest among the 3.
709 + The kernel size is about 10 per cent smaller with bzip2,
710 + in comparison to gzip.
711 + Bzip2 uses a large amount of memory. For modern kernels
712 + you will need at least 8MB RAM or more for booting.
717 + The most recent compression algorithm.
718 + Its ratio is best, decompression speed is between the other
719 + 2. Compression is slowest.
720 + The kernel size is about 33 per cent smaller with lzma,
721 + in comparison to gzip.
727 bool "Support for paging of anonymous memory (swap)"
728 depends on MMU && BLOCK
729 diff -urN linux-2.6.28.9/init/do_mounts_rd.c linux-2.6.28.9.new/init/do_mounts_rd.c
730 --- linux-2.6.28.9/init/do_mounts_rd.c 2009-04-24 13:59:44.000000000 +0200
731 +++ linux-2.6.28.9.new/init/do_mounts_rd.c 2009-04-24 14:08:08.000000000 +0200
734 #include "do_mounts.h"
736 +#include <linux/decompress/generic.h>
738 +#include <linux/decompress/bunzip2.h>
739 +#include <linux/decompress/unlzma.h>
740 +#include <linux/decompress/inflate.h>
742 int __initdata rd_prompt = 1;/* 1 = prompt for RAM disk, 0 = don't prompt */
744 static int __init prompt_ramdisk(char *str)
747 __setup("ramdisk_start=", ramdisk_start_setup);
749 -static int __init crd_load(int in_fd, int out_fd);
750 +static int __init crd_load(int in_fd, int out_fd, decompress_fn deco);
753 * This routine tries to find a RAM disk image to load, and returns the
758 -identify_ramdisk_image(int fd, int start_block)
759 +identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
761 const int size = 512;
762 struct minix_super_block *minixsb;
764 sys_lseek(fd, start_block * BLOCK_SIZE, 0);
765 sys_read(fd, buf, size);
767 +#ifdef CONFIG_RD_GZIP
769 * If it matches the gzip magic numbers, return 0
773 "RAMDISK: Compressed image found at block %d\n",
775 + *decompressor = gunzip;
781 +#ifdef CONFIG_RD_BZIP2
783 + * If it matches the bzip2 magic numbers, return -1
785 + if (buf[0] == 0x42 && (buf[1] == 0x5a)) {
787 + "RAMDISK: Bzipped image found at block %d\n",
789 + *decompressor = bunzip2;
795 +#ifdef CONFIG_RD_LZMA
797 + * If it matches the lzma magic numbers, return -1
799 + if (buf[0] == 0x5d && (buf[1] == 0x00)) {
801 + "RAMDISK: Lzma image found at block %d\n",
803 + *decompressor = unlzma;
809 /* romfs is at block zero too */
810 if (romfsb->word0 == ROMSB_WORD0 &&
812 int nblocks, i, disk;
814 unsigned short rotate = 0;
815 + decompress_fn decompressor = NULL;
816 #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES)
817 char rotator[4] = { '|' , '/' , '-' , '\\' };
819 @@ -168,12 +206,12 @@
823 - nblocks = identify_ramdisk_image(in_fd, rd_image_start);
824 + nblocks = identify_ramdisk_image(in_fd, rd_image_start, &decompressor);
829 - if (crd_load(in_fd, out_fd) == 0)
830 + if (crd_load(in_fd, out_fd, decompressor) == 0)
831 goto successful_load;
834 @@ -272,138 +310,48 @@
835 return rd_load_image("/dev/root");
839 - * gzip declarations
842 -#define OF(args) args
845 -#define memzero(s, n) memset ((s), 0, (n))
848 -typedef unsigned char uch;
849 -typedef unsigned short ush;
850 -typedef unsigned long ulg;
852 -#define INBUFSIZ 4096
853 -#define WSIZE 0x8000 /* window size--must be a power of two, and */
854 - /* at least 32K for zip's deflate method */
859 -static unsigned insize; /* valid bytes in inbuf */
860 -static unsigned inptr; /* index of next byte to be processed in inbuf */
861 -static unsigned outcnt; /* bytes in output buffer */
862 static int exit_code;
863 -static int unzip_error;
864 -static long bytes_out;
865 +static int decompress_error;
866 static int crd_infd, crd_outfd;
868 -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
870 -/* Diagnostic functions (stubbed out) */
871 -#define Assert(cond,msg)
876 -#define Tracecv(c,x)
878 -#define STATIC static
881 -static int __init fill_inbuf(void);
882 -static void __init flush_window(void);
883 -static void __init error(char *m);
885 -#define NO_INFLATE_MALLOC
887 -#include "../lib/inflate.c"
889 -/* ===========================================================================
890 - * Fill the input buffer. This is called only when the buffer is empty
891 - * and at least one byte is really needed.
892 - * Returning -1 does not guarantee that gunzip() will ever return.
894 -static int __init fill_inbuf(void)
895 +static int __init compr_fill(void *buf, unsigned int len)
897 - if (exit_code) return -1;
899 - insize = sys_read(crd_infd, inbuf, INBUFSIZ);
901 - error("RAMDISK: ran out of compressed data");
908 + int r = sys_read(crd_infd, buf, len);
910 + printk(KERN_ERR "RAMDISK: error while reading compressed data");
912 + printk(KERN_ERR "RAMDISK: EOF while reading compressed data");
916 -/* ===========================================================================
917 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
918 - * (Used for the decompressed data only.)
920 -static void __init flush_window(void)
921 +static int __init compr_flush(void *window, unsigned int outcnt)
923 - ulg c = crc; /* temporary variable */
924 - unsigned n, written;
927 - written = sys_write(crd_outfd, window, outcnt);
928 - if (written != outcnt && unzip_error == 0) {
929 - printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %ld\n",
930 - written, outcnt, bytes_out);
934 - for (n = 0; n < outcnt; n++) {
936 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
939 - bytes_out += (ulg)outcnt;
941 + int written = sys_write(crd_outfd, window, outcnt);
942 + if (written != outcnt) {
943 + if (decompress_error == 0)
945 + "RAMDISK: incomplete write (%d != %d)\n",
947 + decompress_error = 1;
953 static void __init error(char *x)
955 printk(KERN_ERR "%s\n", x);
958 + decompress_error = 1;
961 -static int __init crd_load(int in_fd, int out_fd)
962 +static int __init crd_load(int in_fd, int out_fd, decompress_fn deco)
966 - insize = 0; /* valid bytes in inbuf */
967 - inptr = 0; /* index of next byte to be processed in inbuf */
968 - outcnt = 0; /* bytes in output buffer */
971 - crc = (ulg)0xffffffffL; /* shift register contents */
975 - inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
977 - printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
980 - window = kmalloc(WSIZE, GFP_KERNEL);
982 - printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
989 + result = deco(NULL, 0, compr_fill, compr_flush, NULL, NULL, error);
990 + if (decompress_error)
996 diff -urN linux-2.6.28.9/init/initramfs.c linux-2.6.28.9.new/init/initramfs.c
997 --- linux-2.6.28.9/init/initramfs.c 2009-03-23 22:55:52.000000000 +0100
998 +++ linux-2.6.28.9.new/init/initramfs.c 2009-04-24 14:13:53.000000000 +0200
999 @@ -389,11 +389,14 @@
1003 -static void __init flush_buffer(char *buf, unsigned len)
1005 +static int __init flush_buffer(void *bufv, unsigned len)
1007 + char *buf = (char *) bufv;
1009 + int origLen = len;
1013 while ((written = write_buffer(buf, len)) < len && !message) {
1014 char c = buf[written];
1016 @@ -407,73 +410,14 @@
1018 error("junk in compressed archive");
1024 - * gzip declarations
1027 -#define OF(args) args
1030 -#define memzero(s, n) memset ((s), 0, (n))
1032 +static unsigned my_inptr; /* index of next byte to be processed in inbuf */
1034 -typedef unsigned char uch;
1035 -typedef unsigned short ush;
1036 -typedef unsigned long ulg;
1038 -#define WSIZE 0x8000 /* window size--must be a power of two, and */
1039 - /* at least 32K for zip's deflate method */
1042 -static uch *window;
1044 -static unsigned insize; /* valid bytes in inbuf */
1045 -static unsigned inptr; /* index of next byte to be processed in inbuf */
1046 -static unsigned outcnt; /* bytes in output buffer */
1047 -static long bytes_out;
1049 -#define get_byte() (inptr < insize ? inbuf[inptr++] : -1)
1051 -/* Diagnostic functions (stubbed out) */
1052 -#define Assert(cond,msg)
1056 -#define Tracec(c,x)
1057 -#define Tracecv(c,x)
1059 -#define STATIC static
1060 -#define INIT __init
1062 -static void __init flush_window(void);
1063 -static void __init error(char *m);
1065 -#define NO_INFLATE_MALLOC
1067 -#include "../lib/inflate.c"
1069 -/* ===========================================================================
1070 - * Write the output window window[0..outcnt-1] and update crc and bytes_out.
1071 - * (Used for the decompressed data only.)
1073 -static void __init flush_window(void)
1075 - ulg c = crc; /* temporary variable */
1079 - flush_buffer(window, outcnt);
1081 - for (n = 0; n < outcnt; n++) {
1083 - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
1086 - bytes_out += (ulg)outcnt;
1089 +#include <linux/decompress/bunzip2.h>
1090 +#include <linux/decompress/unlzma.h>
1091 +#include <linux/decompress/inflate.h>
1093 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
1095 @@ -482,9 +426,10 @@
1096 header_buf = kmalloc(110, GFP_KERNEL);
1097 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
1098 name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
1099 - window = kmalloc(WSIZE, GFP_KERNEL);
1100 - if (!window || !header_buf || !symlink_buf || !name_buf)
1102 + if (!header_buf || !symlink_buf || !name_buf)
1103 panic("can't allocate buffers");
1108 @@ -504,22 +449,38 @@
1115 - outcnt = 0; /* bytes in output buffer */
1117 - crc = (ulg)0xffffffffL; /* shift register contents */
1120 + if (!gunzip(buf, len, NULL, flush_buffer, NULL,
1121 + &my_inptr, error) &&
1125 +#ifdef CONFIG_RD_BZIP2
1126 + message = NULL; /* Zero out message, or else cpio will think an error has already occured */
1127 + if (!bunzip2(buf, len, NULL, flush_buffer, NULL,
1128 + &my_inptr, error) < 0
1130 + message == NULL) {
1135 +#ifdef CONFIG_RD_LZMA
1136 + message = NULL; /* Zero out message, or else cpio will think an error has already occured */
1137 + if (!unlzma(buf, len, NULL, flush_buffer, NULL,
1138 + &my_inptr, error) < 0
1140 + message == NULL) {
1146 - error("junk in gzipped archive");
1147 - this_header = saved_offset + inptr;
1150 + error("junk in compressed archive");
1151 + this_header = saved_offset + my_inptr;
1160 diff -urN linux-2.6.28.9/lib/Makefile linux-2.6.28.9.new/lib/Makefile
1161 --- linux-2.6.28.9/lib/Makefile 2009-04-24 13:59:44.000000000 +0200
1162 +++ linux-2.6.28.9.new/lib/Makefile 2009-04-24 14:08:08.000000000 +0200
1164 rbtree.o radix-tree.o dump_stack.o \
1165 idr.o int_sqrt.o extable.o prio_tree.o \
1166 sha1.o irq_regs.o reciprocal_div.o argv_split.o \
1167 - proportions.o prio_heap.o ratelimit.o show_mem.o
1168 + proportions.o prio_heap.o ratelimit.o show_mem.o \
1169 + inflate.o decompress_bunzip2.o decompress_unlzma.o
1171 lib-$(CONFIG_MMU) += ioremap.o
1172 lib-$(CONFIG_SMP) += cpumask.o
1173 diff -urN linux-2.6.28.9/lib/decompress_bunzip2.c linux-2.6.28.9.new/lib/decompress_bunzip2.c
1174 --- linux-2.6.28.9/lib/decompress_bunzip2.c 1970-01-01 01:00:00.000000000 +0100
1175 +++ linux-2.6.28.9.new/lib/decompress_bunzip2.c 2009-04-24 14:08:08.000000000 +0200
1177 +/* vi: set sw = 4 ts = 4: */
1178 +/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
1180 + Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
1181 + which also acknowledges contributions by Mike Burrows, David Wheeler,
1182 + Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
1183 + Robert Sedgewick, and Jon L. Bentley.
1185 + This code is licensed under the LGPLv2:
1186 + LGPL (http://www.gnu.org/copyleft/lgpl.html
1190 + Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org).
1192 + More efficient reading of Huffman codes, a streamlined read_bunzip()
1193 + function, and various other tweaks. In (limited) tests, approximately
1194 + 20% faster than bzcat on x86 and about 10% faster on arm.
1196 + Note that about 2/3 of the time is spent in read_unzip() reversing
1197 + the Burrows-Wheeler transformation. Much of that time is delay
1198 + resulting from cache misses.
1200 + I would ask that anyone benefiting from this work, especially those
1201 + using it in commercial products, consider making a donation to my local
1202 + non-profit hospice organization in the name of the woman I loved, who
1203 + passed away Feb. 12, 2003.
1205 + In memory of Toni W. Hagan
1207 + Hospice of Acadiana, Inc.
1208 + 2600 Johnston St., Suite 200
1209 + Lafayette, LA 70503-3240
1211 + Phone (337) 232-1234 or 1-800-738-2226
1212 + Fax (337) 232-1297
1214 + http://www.hospiceacadiana.com/
1220 + Made it fit for running in Linux Kernel by Alain Knaff (alain@knaff.lu)
1225 +#include <linux/decompress/bunzip2.h>
1226 +#endif /* !STATIC */
1228 +#include <linux/decompress/mm.h>
1231 +#define INT_MAX 0x7fffffff
1234 +/* Constants for Huffman coding */
1235 +#define MAX_GROUPS 6
1236 +#define GROUP_SIZE 50 /* 64 would have been more efficient */
1237 +#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
1238 +#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
1239 +#define SYMBOL_RUNA 0
1240 +#define SYMBOL_RUNB 1
1242 +/* Status return values */
1243 +#define RETVAL_OK 0
1244 +#define RETVAL_LAST_BLOCK (-1)
1245 +#define RETVAL_NOT_BZIP_DATA (-2)
1246 +#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
1247 +#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
1248 +#define RETVAL_DATA_ERROR (-5)
1249 +#define RETVAL_OUT_OF_MEMORY (-6)
1250 +#define RETVAL_OBSOLETE_INPUT (-7)
1252 +/* Other housekeeping constants */
1253 +#define BZIP2_IOBUF_SIZE 4096
1255 +/* This is what we know about each Huffman coding group */
1256 +struct group_data {
1257 + /* We have an extra slot at the end of limit[] for a sentinal value. */
1258 + int limit[MAX_HUFCODE_BITS+1];
1259 + int base[MAX_HUFCODE_BITS];
1260 + int permute[MAX_SYMBOLS];
1261 + int minLen, maxLen;
1264 +/* Structure holding all the housekeeping data, including IO buffers and
1265 + memory that persists between calls to bunzip */
1266 +struct bunzip_data {
1267 + /* State for interrupting output loop */
1268 + int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
1269 + /* I/O tracking data (file handles, buffers, positions, etc.) */
1270 + int (*fill)(void*, unsigned int);
1271 + int inbufCount, inbufPos /*, outbufPos*/;
1272 + unsigned char *inbuf /*,*outbuf*/;
1273 + unsigned int inbufBitCount, inbufBits;
1274 + /* The CRC values stored in the block header and calculated from the
1276 + unsigned int crc32Table[256], headerCRC, totalCRC, writeCRC;
1277 + /* Intermediate buffer and its size (in bytes) */
1278 + unsigned int *dbuf, dbufSize;
1279 + /* These things are a bit too big to go on the stack */
1280 + unsigned char selectors[32768]; /* nSelectors = 15 bits */
1281 + struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
1282 + int io_error; /* non-zero if we have IO error */
1286 +/* Return the next nnn bits of input. All reads from the compressed input
1287 + are done through this function. All reads are big endian */
1288 +static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)
1290 + unsigned int bits = 0;
1292 + /* If we need to get more data from the byte buffer, do so.
1293 + (Loop getting one byte at a time to enforce endianness and avoid
1294 + unaligned access.) */
1295 + while (bd->inbufBitCount < bits_wanted) {
1296 + /* If we need to read more data from file into byte buffer, do
1298 + if (bd->inbufPos == bd->inbufCount) {
1301 + bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE);
1302 + if (bd->inbufCount <= 0) {
1303 + bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF;
1308 + /* Avoid 32-bit overflow (dump bit buffer to top of output) */
1309 + if (bd->inbufBitCount >= 24) {
1310 + bits = bd->inbufBits&((1 << bd->inbufBitCount)-1);
1311 + bits_wanted -= bd->inbufBitCount;
1312 + bits <<= bits_wanted;
1313 + bd->inbufBitCount = 0;
1315 + /* Grab next 8 bits of input from buffer. */
1316 + bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
1317 + bd->inbufBitCount += 8;
1319 + /* Calculate result */
1320 + bd->inbufBitCount -= bits_wanted;
1321 + bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1);
1326 +/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
1328 +static int INIT get_next_block(struct bunzip_data *bd)
1330 + struct group_data *hufGroup = NULL;
1332 + int *limit = NULL;
1333 + int dbufCount, nextSym, dbufSize, groupCount, selector,
1334 + i, j, k, t, runPos, symCount, symTotal, nSelectors,
1336 + unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
1337 + unsigned int *dbuf, origPtr;
1340 + dbufSize = bd->dbufSize;
1341 + selectors = bd->selectors;
1343 + /* Read in header signature and CRC, then validate signature.
1344 + (last block signature means CRC is for whole file, return now) */
1345 + i = get_bits(bd, 24);
1346 + j = get_bits(bd, 24);
1347 + bd->headerCRC = get_bits(bd, 32);
1348 + if ((i == 0x177245) && (j == 0x385090))
1349 + return RETVAL_LAST_BLOCK;
1350 + if ((i != 0x314159) || (j != 0x265359))
1351 + return RETVAL_NOT_BZIP_DATA;
1352 + /* We can add support for blockRandomised if anybody complains.
1353 + There was some code for this in busybox 1.0.0-pre3, but nobody ever
1354 + noticed that it didn't actually work. */
1355 + if (get_bits(bd, 1))
1356 + return RETVAL_OBSOLETE_INPUT;
1357 + origPtr = get_bits(bd, 24);
1358 + if (origPtr > dbufSize)
1359 + return RETVAL_DATA_ERROR;
1360 + /* mapping table: if some byte values are never used (encoding things
1361 + like ascii text), the compression code removes the gaps to have fewer
1362 + symbols to deal with, and writes a sparse bitfield indicating which
1363 + values were present. We make a translation table to convert the
1364 + symbols back to the corresponding bytes. */
1365 + t = get_bits(bd, 16);
1367 + for (i = 0; i < 16; i++) {
1368 + if (t&(1 << (15-i))) {
1369 + k = get_bits(bd, 16);
1370 + for (j = 0; j < 16; j++)
1371 + if (k&(1 << (15-j)))
1372 + symToByte[symTotal++] = (16*i)+j;
1375 + /* How many different Huffman coding groups does this block use? */
1376 + groupCount = get_bits(bd, 3);
1377 + if (groupCount < 2 || groupCount > MAX_GROUPS)
1378 + return RETVAL_DATA_ERROR;
1379 + /* nSelectors: Every GROUP_SIZE many symbols we select a new
1380 + Huffman coding group. Read in the group selector list,
1381 + which is stored as MTF encoded bit runs. (MTF = Move To
1382 + Front, as each value is used it's moved to the start of the
1384 + nSelectors = get_bits(bd, 15);
1386 + return RETVAL_DATA_ERROR;
1387 + for (i = 0; i < groupCount; i++)
1389 + for (i = 0; i < nSelectors; i++) {
1390 + /* Get next value */
1391 + for (j = 0; get_bits(bd, 1); j++)
1392 + if (j >= groupCount)
1393 + return RETVAL_DATA_ERROR;
1394 + /* Decode MTF to get the next selector */
1395 + uc = mtfSymbol[j];
1397 + mtfSymbol[j] = mtfSymbol[j-1];
1398 + mtfSymbol[0] = selectors[i] = uc;
1400 + /* Read the Huffman coding tables for each group, which code
1401 + for symTotal literal symbols, plus two run symbols (RUNA,
1403 + symCount = symTotal+2;
1404 + for (j = 0; j < groupCount; j++) {
1405 + unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
1406 + int minLen, maxLen, pp;
1407 + /* Read Huffman code lengths for each symbol. They're
1408 + stored in a way similar to mtf; record a starting
1409 + value for the first symbol, and an offset from the
1410 + previous value for everys symbol after that.
1411 + (Subtracting 1 before the loop and then adding it
1412 + back at the end is an optimization that makes the
1413 + test inside the loop simpler: symbol length 0
1414 + becomes negative, so an unsigned inequality catches
1416 + t = get_bits(bd, 5)-1;
1417 + for (i = 0; i < symCount; i++) {
1419 + if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
1420 + return RETVAL_DATA_ERROR;
1422 + /* If first bit is 0, stop. Else
1423 + second bit indicates whether to
1424 + increment or decrement the value.
1425 + Optimization: grab 2 bits and unget
1426 + the second if the first was 0. */
1428 + k = get_bits(bd, 2);
1430 + bd->inbufBitCount++;
1433 + /* Add one if second bit 1, else
1434 + * subtract 1. Avoids if/else */
1435 + t += (((k+1)&2)-1);
1437 + /* Correct for the initial -1, to get the
1438 + * final symbol length */
1441 + /* Find largest and smallest lengths in this group */
1442 + minLen = maxLen = length[0];
1444 + for (i = 1; i < symCount; i++) {
1445 + if (length[i] > maxLen)
1446 + maxLen = length[i];
1447 + else if (length[i] < minLen)
1448 + minLen = length[i];
1451 + /* Calculate permute[], base[], and limit[] tables from
1454 + * permute[] is the lookup table for converting
1455 + * Huffman coded symbols into decoded symbols. base[]
1456 + * is the amount to subtract from the value of a
1457 + * Huffman symbol of a given length when using
1460 + * limit[] indicates the largest numerical value a
1461 + * symbol with a given number of bits can have. This
1462 + * is how the Huffman codes can vary in length: each
1463 + * code with a value > limit[length] needs another
1466 + hufGroup = bd->groups+j;
1467 + hufGroup->minLen = minLen;
1468 + hufGroup->maxLen = maxLen;
1469 + /* Note that minLen can't be smaller than 1, so we
1470 + adjust the base and limit array pointers so we're
1471 + not always wasting the first entry. We do this
1472 + again when using them (during symbol decoding).*/
1473 + base = hufGroup->base-1;
1474 + limit = hufGroup->limit-1;
1475 + /* Calculate permute[]. Concurently, initialize
1476 + * temp[] and limit[]. */
1478 + for (i = minLen; i <= maxLen; i++) {
1479 + temp[i] = limit[i] = 0;
1480 + for (t = 0; t < symCount; t++)
1481 + if (length[t] == i)
1482 + hufGroup->permute[pp++] = t;
1484 + /* Count symbols coded for at each bit length */
1485 + for (i = 0; i < symCount; i++)
1486 + temp[length[i]]++;
1487 + /* Calculate limit[] (the largest symbol-coding value
1488 + *at each bit length, which is (previous limit <<
1489 + *1)+symbols at this level), and base[] (number of
1490 + *symbols to ignore at each bit length, which is limit
1491 + *minus the cumulative count of symbols coded for
1494 + for (i = minLen; i < maxLen; i++) {
1496 + /* We read the largest possible symbol size
1497 + and then unget bits after determining how
1498 + many we need, and those extra bits could be
1499 + set to anything. (They're noise from
1500 + future symbols.) At each level we're
1501 + really only interested in the first few
1502 + bits, so here we set all the trailing
1503 + to-be-ignored bits to 1 so they don't
1504 + affect the value > limit[length]
1506 + limit[i] = (pp << (maxLen - i)) - 1;
1508 + base[i+1] = pp-(t += temp[i]);
1510 + limit[maxLen+1] = INT_MAX; /* Sentinal value for
1511 + * reading next sym. */
1512 + limit[maxLen] = pp+temp[maxLen]-1;
1515 + /* We've finished reading and digesting the block header. Now
1516 + read this block's Huffman coded symbols from the file and
1517 + undo the Huffman coding and run length encoding, saving the
1518 + result into dbuf[dbufCount++] = uc */
1520 + /* Initialize symbol occurrence counters and symbol Move To
1522 + for (i = 0; i < 256; i++) {
1524 + mtfSymbol[i] = (unsigned char)i;
1526 + /* Loop through compressed symbols. */
1527 + runPos = dbufCount = symCount = selector = 0;
1529 + /* Determine which Huffman coding group to use. */
1530 + if (!(symCount--)) {
1531 + symCount = GROUP_SIZE-1;
1532 + if (selector >= nSelectors)
1533 + return RETVAL_DATA_ERROR;
1534 + hufGroup = bd->groups+selectors[selector++];
1535 + base = hufGroup->base-1;
1536 + limit = hufGroup->limit-1;
1538 + /* Read next Huffman-coded symbol. */
1539 + /* Note: It is far cheaper to read maxLen bits and
1540 + back up than it is to read minLen bits and then an
1541 + additional bit at a time, testing as we go.
1542 + Because there is a trailing last block (with file
1543 + CRC), there is no danger of the overread causing an
1544 + unexpected EOF for a valid compressed file. As a
1545 + further optimization, we do the read inline
1546 + (falling back to a call to get_bits if the buffer
1547 + runs dry). The following (up to got_huff_bits:) is
1548 + equivalent to j = get_bits(bd, hufGroup->maxLen);
1550 + while (bd->inbufBitCount < hufGroup->maxLen) {
1551 + if (bd->inbufPos == bd->inbufCount) {
1552 + j = get_bits(bd, hufGroup->maxLen);
1553 + goto got_huff_bits;
1556 + (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
1557 + bd->inbufBitCount += 8;
1559 + bd->inbufBitCount -= hufGroup->maxLen;
1560 + j = (bd->inbufBits >> bd->inbufBitCount)&
1561 + ((1 << hufGroup->maxLen)-1);
1563 + /* Figure how how many bits are in next symbol and
1565 + i = hufGroup->minLen;
1566 + while (j > limit[i])
1568 + bd->inbufBitCount += (hufGroup->maxLen - i);
1569 + /* Huffman decode value to get nextSym (with bounds checking) */
1570 + if ((i > hufGroup->maxLen)
1571 + || (((unsigned)(j = (j>>(hufGroup->maxLen-i))-base[i]))
1573 + return RETVAL_DATA_ERROR;
1574 + nextSym = hufGroup->permute[j];
1575 + /* We have now decoded the symbol, which indicates
1576 + either a new literal byte, or a repeated run of the
1577 + most recent literal byte. First, check if nextSym
1578 + indicates a repeated run, and if so loop collecting
1579 + how many times to repeat the last literal. */
1580 + if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
1581 + /* If this is the start of a new run, zero out
1587 + /* Neat trick that saves 1 symbol: instead of
1588 + or-ing 0 or 1 at each bit position, add 1
1589 + or 2 instead. For example, 1011 is 1 << 0
1590 + + 1 << 1 + 2 << 2. 1010 is 2 << 0 + 2 << 1
1591 + + 1 << 2. You can make any bit pattern
1592 + that way using 1 less symbol than the basic
1593 + or 0/1 method (except all bits 0, which
1594 + would use no symbols, but a run of length 0
1595 + doesn't mean anything in this context).
1596 + Thus space is saved. */
1597 + t += (runPos << nextSym);
1598 + /* +runPos if RUNA; +2*runPos if RUNB */
1603 + /* When we hit the first non-run symbol after a run,
1604 + we now know how many times to repeat the last
1605 + literal, so append that many copies to our buffer
1606 + of decoded symbols (dbuf) now. (The last literal
1607 + used is the one at the head of the mtfSymbol
1611 + if (dbufCount+t >= dbufSize)
1612 + return RETVAL_DATA_ERROR;
1614 + uc = symToByte[mtfSymbol[0]];
1615 + byteCount[uc] += t;
1617 + dbuf[dbufCount++] = uc;
1619 + /* Is this the terminating symbol? */
1620 + if (nextSym > symTotal)
1622 + /* At this point, nextSym indicates a new literal
1623 + character. Subtract one to get the position in the
1624 + MTF array at which this literal is currently to be
1625 + found. (Note that the result can't be -1 or 0,
1626 + because 0 and 1 are RUNA and RUNB. But another
1627 + instance of the first symbol in the mtf array,
1628 + position 0, would have been handled as part of a
1629 + run above. Therefore 1 unused mtf position minus 2
1630 + non-literal nextSym values equals -1.) */
1631 + if (dbufCount >= dbufSize)
1632 + return RETVAL_DATA_ERROR;
1634 + uc = mtfSymbol[i];
1635 + /* Adjust the MTF array. Since we typically expect to
1636 + *move only a small number of symbols, and are bound
1637 + *by 256 in any case, using memmove here would
1638 + *typically be bigger and slower due to function call
1639 + *overhead and other assorted setup costs. */
1641 + mtfSymbol[i] = mtfSymbol[i-1];
1643 + mtfSymbol[0] = uc;
1644 + uc = symToByte[uc];
1645 + /* We have our literal byte. Save it into dbuf. */
1647 + dbuf[dbufCount++] = (unsigned int)uc;
1649 + /* At this point, we've read all the Huffman-coded symbols
1650 + (and repeated runs) for this block from the input stream,
1651 + and decoded them into the intermediate buffer. There are
1652 + dbufCount many decoded bytes in dbuf[]. Now undo the
1653 + Burrows-Wheeler transform on dbuf. See
1654 + http://dogma.net/markn/articles/bwt/bwt.htm
1656 + /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
1658 + for (i = 0; i < 256; i++) {
1659 + k = j+byteCount[i];
1663 + /* Figure out what order dbuf would be in if we sorted it. */
1664 + for (i = 0; i < dbufCount; i++) {
1665 + uc = (unsigned char)(dbuf[i] & 0xff);
1666 + dbuf[byteCount[uc]] |= (i << 8);
1669 + /* Decode first byte by hand to initialize "previous" byte.
1670 + Note that it doesn't get output, and if the first three
1671 + characters are identical it doesn't qualify as a run (hence
1672 + writeRunCountdown = 5). */
1674 + if (origPtr >= dbufCount)
1675 + return RETVAL_DATA_ERROR;
1676 + bd->writePos = dbuf[origPtr];
1677 + bd->writeCurrent = (unsigned char)(bd->writePos&0xff);
1678 + bd->writePos >>= 8;
1679 + bd->writeRunCountdown = 5;
1681 + bd->writeCount = dbufCount;
1686 +/* Undo burrows-wheeler transform on intermediate buffer to produce output.
1687 + If start_bunzip was initialized with out_fd =-1, then up to len bytes of
1688 + data are written to outbuf. Return value is number of bytes written or
1689 + error (all errors are negative numbers). If out_fd!=-1, outbuf and len
1690 + are ignored, data is written to out_fd and return is RETVAL_OK or error.
1693 +static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len)
1695 + const unsigned int *dbuf;
1696 + int pos, xcurrent, previous, gotcount;
1698 + /* If last read was short due to end of file, return last block now */
1699 + if (bd->writeCount < 0)
1700 + return bd->writeCount;
1704 + pos = bd->writePos;
1705 + xcurrent = bd->writeCurrent;
1707 + /* We will always have pending decoded data to write into the output
1708 + buffer unless this is the very first call (in which case we haven't
1709 + Huffman-decoded a block into the intermediate buffer yet). */
1711 + if (bd->writeCopies) {
1712 + /* Inside the loop, writeCopies means extra copies (beyond 1) */
1713 + --bd->writeCopies;
1714 + /* Loop outputting bytes */
1716 + /* If the output buffer is full, snapshot
1717 + * state and return */
1718 + if (gotcount >= len) {
1719 + bd->writePos = pos;
1720 + bd->writeCurrent = xcurrent;
1721 + bd->writeCopies++;
1724 + /* Write next byte into output buffer, updating CRC */
1725 + outbuf[gotcount++] = xcurrent;
1726 + bd->writeCRC = (((bd->writeCRC) << 8)
1727 + ^bd->crc32Table[((bd->writeCRC) >> 24)
1729 + /* Loop now if we're outputting multiple
1730 + * copies of this byte */
1731 + if (bd->writeCopies) {
1732 + --bd->writeCopies;
1736 + if (!bd->writeCount--)
1738 + /* Follow sequence vector to undo
1739 + * Burrows-Wheeler transform */
1740 + previous = xcurrent;
1742 + xcurrent = pos&0xff;
1744 + /* After 3 consecutive copies of the same
1745 + byte, the 4th is a repeat count. We count
1746 + down from 4 instead *of counting up because
1747 + testing for non-zero is faster */
1748 + if (--bd->writeRunCountdown) {
1749 + if (xcurrent != previous)
1750 + bd->writeRunCountdown = 4;
1752 + /* We have a repeated run, this byte
1753 + * indicates the count */
1754 + bd->writeCopies = xcurrent;
1755 + xcurrent = previous;
1756 + bd->writeRunCountdown = 5;
1757 + /* Sometimes there are just 3 bytes
1758 + * (run length 0) */
1759 + if (!bd->writeCopies)
1760 + goto decode_next_byte;
1761 + /* Subtract the 1 copy we'd output
1762 + * anyway to get extras */
1763 + --bd->writeCopies;
1766 + /* Decompression of this block completed successfully */
1767 + bd->writeCRC = ~bd->writeCRC;
1768 + bd->totalCRC = ((bd->totalCRC << 1) |
1769 + (bd->totalCRC >> 31)) ^ bd->writeCRC;
1770 + /* If this block had a CRC error, force file level CRC error. */
1771 + if (bd->writeCRC != bd->headerCRC) {
1772 + bd->totalCRC = bd->headerCRC+1;
1773 + return RETVAL_LAST_BLOCK;
1777 + /* Refill the intermediate buffer by Huffman-decoding next
1778 + * block of input */
1779 + /* (previous is just a convenient unused temp variable here) */
1780 + previous = get_next_block(bd);
1782 + bd->writeCount = previous;
1783 + return (previous != RETVAL_LAST_BLOCK) ? previous : gotcount;
1785 + bd->writeCRC = 0xffffffffUL;
1786 + pos = bd->writePos;
1787 + xcurrent = bd->writeCurrent;
1788 + goto decode_next_byte;
1791 +static int INIT nofill(void *buf, unsigned int len)
1796 +/* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain
1797 + a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
1798 + ignored, and data is read from file handle into temporary buffer. */
1799 +static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
1800 + int (*fill)(void*, unsigned int))
1802 + struct bunzip_data *bd;
1803 + unsigned int i, j, c;
1804 + const unsigned int BZh0 =
1805 + (((unsigned int)'B') << 24)+(((unsigned int)'Z') << 16)
1806 + +(((unsigned int)'h') << 8)+(unsigned int)'0';
1808 + /* Figure out how much data to allocate */
1809 + i = sizeof(struct bunzip_data);
1811 + /* Allocate bunzip_data. Most fields initialize to zero. */
1812 + bd = *bdp = malloc(i);
1813 + memset(bd, 0, sizeof(struct bunzip_data));
1814 + /* Setup input buffer */
1815 + bd->inbuf = inbuf;
1816 + bd->inbufCount = len;
1820 + bd->fill = nofill;
1822 + /* Init the CRC32 table (big endian) */
1823 + for (i = 0; i < 256; i++) {
1825 + for (j = 8; j; j--)
1826 + c = c&0x80000000 ? (c << 1)^0x04c11db7 : (c << 1);
1827 + bd->crc32Table[i] = c;
1830 + /* Ensure that file starts with "BZh['1'-'9']." */
1831 + i = get_bits(bd, 32);
1832 + if (((unsigned int)(i-BZh0-1)) >= 9)
1833 + return RETVAL_NOT_BZIP_DATA;
1835 + /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
1836 + uncompressed data. Allocate intermediate buffer for block. */
1837 + bd->dbufSize = 100000*(i-BZh0);
1839 + bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
1843 +/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data,
1844 + not end of file.) */
1845 +STATIC int INIT bunzip2(unsigned char *buf, int len,
1846 + int(*fill)(void*, unsigned int),
1847 + int(*flush)(void*, unsigned int),
1848 + unsigned char *outbuf,
1850 + void(*error_fn)(char *x))
1852 + struct bunzip_data *bd;
1854 + unsigned char *inbuf;
1856 + set_error_fn(error_fn);
1858 + outbuf = malloc(BZIP2_IOBUF_SIZE);
1860 + len -= 4; /* Uncompressed size hack active in pre-boot
1863 + error("Could not allocate output bufer");
1869 + inbuf = malloc(BZIP2_IOBUF_SIZE);
1871 + error("Could not allocate input bufer");
1874 + i = start_bunzip(&bd, inbuf, len, fill);
1877 + i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE);
1883 + if (i != flush(outbuf, i)) {
1884 + i = RETVAL_UNEXPECTED_OUTPUT_EOF;
1889 + /* Check CRC and release memory */
1890 + if (i == RETVAL_LAST_BLOCK) {
1891 + if (bd->headerCRC != bd->totalCRC)
1892 + error("Data integrity error when decompressing.");
1895 + } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
1896 + error("Compressed file ends unexpectedly");
1899 + large_free(bd->dbuf);
1901 + *pos = bd->inbufPos;
1911 +#define decompress bunzip2
1912 diff -urN linux-2.6.28.9/lib/decompress_unlzma.c linux-2.6.28.9.new/lib/decompress_unlzma.c
1913 --- linux-2.6.28.9/lib/decompress_unlzma.c 1970-01-01 01:00:00.000000000 +0100
1914 +++ linux-2.6.28.9.new/lib/decompress_unlzma.c 2009-04-24 14:08:08.000000000 +0200
1916 +/* Lzma decompressor for Linux kernel. Shamelessly snarfed
1917 + *from busybox 1.1.1
1919 + *Linux kernel adaptation
1920 + *Copyright (C) 2006 Alain < alain@knaff.lu >
1922 + *Based on small lzma deflate implementation/Small range coder
1923 + *implementation for lzma.
1924 + *Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
1926 + *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
1927 + *Copyright (C) 1999-2005 Igor Pavlov
1929 + *Copyrights of the parts, see headers below.
1932 + *This program is free software; you can redistribute it and/or
1933 + *modify it under the terms of the GNU Lesser General Public
1934 + *License as published by the Free Software Foundation; either
1935 + *version 2.1 of the License, or (at your option) any later version.
1937 + *This program is distributed in the hope that it will be useful,
1938 + *but WITHOUT ANY WARRANTY; without even the implied warranty of
1939 + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1940 + *Lesser General Public License for more details.
1942 + *You should have received a copy of the GNU Lesser General Public
1943 + *License along with this library; if not, write to the Free Software
1944 + *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1948 +#include <linux/decompress/unlzma.h>
1949 +#endif /* STATIC */
1951 +#include <linux/decompress/mm.h>
1953 +#define MIN(a, b) (((a) < (b)) ? (a) : (b))
1955 +static long long INIT read_int(unsigned char *ptr, int size)
1958 + long long ret = 0;
1960 + for (i = 0; i < size; i++)
1961 + ret = (ret << 8) | ptr[size-i-1];
1965 +#define ENDIAN_CONVERT(x) \
1966 + x = (typeof(x))read_int((unsigned char *)&x, sizeof(x))
1969 +/* Small range coder implementation for lzma.
1970 + *Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
1972 + *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
1973 + *Copyright (c) 1999-2005 Igor Pavlov
1976 +#include <linux/compiler.h>
1978 +#define LZMA_IOBUF_SIZE 0x10000
1981 + int (*fill)(void*, unsigned int);
1984 + uint8_t *buffer_end;
1992 +#define RC_TOP_BITS 24
1993 +#define RC_MOVE_BITS 5
1994 +#define RC_MODEL_TOTAL_BITS 11
1997 +/* Called twice: once at startup and once in rc_normalize() */
1998 +static void INIT rc_read(struct rc *rc)
2000 + rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
2001 + if (rc->buffer_size <= 0)
2002 + error("unexpected EOF");
2003 + rc->ptr = rc->buffer;
2004 + rc->buffer_end = rc->buffer + rc->buffer_size;
2008 +static inline void INIT rc_init(struct rc *rc,
2009 + int (*fill)(void*, unsigned int),
2010 + char *buffer, int buffer_size)
2013 + rc->buffer = (uint8_t *)buffer;
2014 + rc->buffer_size = buffer_size;
2015 + rc->buffer_end = rc->buffer + rc->buffer_size;
2016 + rc->ptr = rc->buffer;
2019 + rc->range = 0xFFFFFFFF;
2022 +static inline void INIT rc_init_code(struct rc *rc)
2026 + for (i = 0; i < 5; i++) {
2027 + if (rc->ptr >= rc->buffer_end)
2029 + rc->code = (rc->code << 8) | *rc->ptr++;
2034 +/* Called once. TODO: bb_maybe_free() */
2035 +static inline void INIT rc_free(struct rc *rc)
2040 +/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
2041 +static void INIT rc_do_normalize(struct rc *rc)
2043 + if (rc->ptr >= rc->buffer_end)
2046 + rc->code = (rc->code << 8) | *rc->ptr++;
2048 +static inline void INIT rc_normalize(struct rc *rc)
2050 + if (rc->range < (1 << RC_TOP_BITS))
2051 + rc_do_normalize(rc);
2054 +/* Called 9 times */
2055 +/* Why rc_is_bit_0_helper exists?
2056 + *Because we want to always expose (rc->code < rc->bound) to optimizer
2058 +static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p)
2061 + rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
2064 +static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p)
2066 + uint32_t t = rc_is_bit_0_helper(rc, p);
2067 + return rc->code < t;
2070 +/* Called ~10 times, but very small, thus inlined */
2071 +static inline void INIT rc_update_bit_0(struct rc *rc, uint16_t *p)
2073 + rc->range = rc->bound;
2074 + *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
2076 +static inline void rc_update_bit_1(struct rc *rc, uint16_t *p)
2078 + rc->range -= rc->bound;
2079 + rc->code -= rc->bound;
2080 + *p -= *p >> RC_MOVE_BITS;
2083 +/* Called 4 times in unlzma loop */
2084 +static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
2086 + if (rc_is_bit_0(rc, p)) {
2087 + rc_update_bit_0(rc, p);
2091 + rc_update_bit_1(rc, p);
2092 + *symbol = *symbol * 2 + 1;
2098 +static inline int INIT rc_direct_bit(struct rc *rc)
2102 + if (rc->code >= rc->range) {
2103 + rc->code -= rc->range;
2110 +static inline void INIT
2111 +rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol)
2113 + int i = num_levels;
2117 + rc_get_bit(rc, p + *symbol, symbol);
2118 + *symbol -= 1 << num_levels;
2123 + * Small lzma deflate implementation.
2124 + * Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
2126 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
2127 + * Copyright (C) 1999-2005 Igor Pavlov
2131 +struct lzma_header {
2133 + uint32_t dict_size;
2134 + uint64_t dst_size;
2135 +} __attribute__ ((packed)) ;
2138 +#define LZMA_BASE_SIZE 1846
2139 +#define LZMA_LIT_SIZE 768
2141 +#define LZMA_NUM_POS_BITS_MAX 4
2143 +#define LZMA_LEN_NUM_LOW_BITS 3
2144 +#define LZMA_LEN_NUM_MID_BITS 3
2145 +#define LZMA_LEN_NUM_HIGH_BITS 8
2147 +#define LZMA_LEN_CHOICE 0
2148 +#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
2149 +#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
2150 +#define LZMA_LEN_MID (LZMA_LEN_LOW \
2151 + + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
2152 +#define LZMA_LEN_HIGH (LZMA_LEN_MID \
2153 + +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
2154 +#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
2156 +#define LZMA_NUM_STATES 12
2157 +#define LZMA_NUM_LIT_STATES 7
2159 +#define LZMA_START_POS_MODEL_INDEX 4
2160 +#define LZMA_END_POS_MODEL_INDEX 14
2161 +#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
2163 +#define LZMA_NUM_POS_SLOT_BITS 6
2164 +#define LZMA_NUM_LEN_TO_POS_STATES 4
2166 +#define LZMA_NUM_ALIGN_BITS 4
2168 +#define LZMA_MATCH_MIN_LEN 2
2170 +#define LZMA_IS_MATCH 0
2171 +#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
2172 +#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
2173 +#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
2174 +#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
2175 +#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
2176 +#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
2177 + + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
2178 +#define LZMA_SPEC_POS (LZMA_POS_SLOT \
2179 + +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
2180 +#define LZMA_ALIGN (LZMA_SPEC_POS \
2181 + + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
2182 +#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
2183 +#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
2184 +#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
2189 + uint8_t previous_byte;
2190 + size_t buffer_pos;
2192 + size_t global_pos;
2193 + int(*flush)(void*, unsigned int);
2194 + struct lzma_header *header;
2199 + uint32_t rep0, rep1, rep2, rep3;
2202 +static inline size_t INIT get_pos(struct writer *wr)
2205 + wr->global_pos + wr->buffer_pos;
2208 +static inline uint8_t INIT peek_old_byte(struct writer *wr,
2213 + while (offs > wr->header->dict_size)
2214 + offs -= wr->header->dict_size;
2215 + pos = wr->buffer_pos - offs;
2216 + return wr->buffer[pos];
2218 + uint32_t pos = wr->buffer_pos - offs;
2219 + while (pos >= wr->header->dict_size)
2220 + pos += wr->header->dict_size;
2221 + return wr->buffer[pos];
2226 +static inline void INIT write_byte(struct writer *wr, uint8_t byte)
2228 + wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
2229 + if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
2230 + wr->buffer_pos = 0;
2231 + wr->global_pos += wr->header->dict_size;
2232 + wr->flush((char *)wr->buffer, wr->header->dict_size);
2237 +static inline void INIT copy_byte(struct writer *wr, uint32_t offs)
2239 + write_byte(wr, peek_old_byte(wr, offs));
2242 +static inline void INIT copy_bytes(struct writer *wr,
2243 + uint32_t rep0, int len)
2246 + copy_byte(wr, rep0);
2248 + } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
2251 +static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
2252 + struct cstate *cst, uint16_t *p,
2253 + int pos_state, uint16_t *prob,
2254 + int lc, uint32_t literal_pos_mask) {
2256 + rc_update_bit_0(rc, prob);
2257 + prob = (p + LZMA_LITERAL +
2259 + * (((get_pos(wr) & literal_pos_mask) << lc)
2260 + + (wr->previous_byte >> (8 - lc))))
2263 + if (cst->state >= LZMA_NUM_LIT_STATES) {
2264 + int match_byte = peek_old_byte(wr, cst->rep0);
2267 + uint16_t *prob_lit;
2270 + bit = match_byte & 0x100;
2271 + prob_lit = prob + 0x100 + bit + mi;
2272 + if (rc_get_bit(rc, prob_lit, &mi)) {
2279 + } while (mi < 0x100);
2281 + while (mi < 0x100) {
2282 + uint16_t *prob_lit = prob + mi;
2283 + rc_get_bit(rc, prob_lit, &mi);
2285 + write_byte(wr, mi);
2286 + if (cst->state < 4)
2288 + else if (cst->state < 10)
2294 +static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
2295 + struct cstate *cst, uint16_t *p,
2296 + int pos_state, uint16_t *prob) {
2298 + uint16_t *prob_len;
2302 + rc_update_bit_1(rc, prob);
2303 + prob = p + LZMA_IS_REP + cst->state;
2304 + if (rc_is_bit_0(rc, prob)) {
2305 + rc_update_bit_0(rc, prob);
2306 + cst->rep3 = cst->rep2;
2307 + cst->rep2 = cst->rep1;
2308 + cst->rep1 = cst->rep0;
2309 + cst->state = cst->state < LZMA_NUM_LIT_STATES ? 0 : 3;
2310 + prob = p + LZMA_LEN_CODER;
2312 + rc_update_bit_1(rc, prob);
2313 + prob = p + LZMA_IS_REP_G0 + cst->state;
2314 + if (rc_is_bit_0(rc, prob)) {
2315 + rc_update_bit_0(rc, prob);
2316 + prob = (p + LZMA_IS_REP_0_LONG
2318 + LZMA_NUM_POS_BITS_MAX) +
2320 + if (rc_is_bit_0(rc, prob)) {
2321 + rc_update_bit_0(rc, prob);
2323 + cst->state = cst->state < LZMA_NUM_LIT_STATES ?
2325 + copy_byte(wr, cst->rep0);
2328 + rc_update_bit_1(rc, prob);
2331 + uint32_t distance;
2333 + rc_update_bit_1(rc, prob);
2334 + prob = p + LZMA_IS_REP_G1 + cst->state;
2335 + if (rc_is_bit_0(rc, prob)) {
2336 + rc_update_bit_0(rc, prob);
2337 + distance = cst->rep1;
2339 + rc_update_bit_1(rc, prob);
2340 + prob = p + LZMA_IS_REP_G2 + cst->state;
2341 + if (rc_is_bit_0(rc, prob)) {
2342 + rc_update_bit_0(rc, prob);
2343 + distance = cst->rep2;
2345 + rc_update_bit_1(rc, prob);
2346 + distance = cst->rep3;
2347 + cst->rep3 = cst->rep2;
2349 + cst->rep2 = cst->rep1;
2351 + cst->rep1 = cst->rep0;
2352 + cst->rep0 = distance;
2354 + cst->state = cst->state < LZMA_NUM_LIT_STATES ? 8 : 11;
2355 + prob = p + LZMA_REP_LEN_CODER;
2358 + prob_len = prob + LZMA_LEN_CHOICE;
2359 + if (rc_is_bit_0(rc, prob_len)) {
2360 + rc_update_bit_0(rc, prob_len);
2361 + prob_len = (prob + LZMA_LEN_LOW
2363 + LZMA_LEN_NUM_LOW_BITS));
2365 + num_bits = LZMA_LEN_NUM_LOW_BITS;
2367 + rc_update_bit_1(rc, prob_len);
2368 + prob_len = prob + LZMA_LEN_CHOICE_2;
2369 + if (rc_is_bit_0(rc, prob_len)) {
2370 + rc_update_bit_0(rc, prob_len);
2371 + prob_len = (prob + LZMA_LEN_MID
2373 + LZMA_LEN_NUM_MID_BITS));
2374 + offset = 1 << LZMA_LEN_NUM_LOW_BITS;
2375 + num_bits = LZMA_LEN_NUM_MID_BITS;
2377 + rc_update_bit_1(rc, prob_len);
2378 + prob_len = prob + LZMA_LEN_HIGH;
2379 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
2380 + + (1 << LZMA_LEN_NUM_MID_BITS));
2381 + num_bits = LZMA_LEN_NUM_HIGH_BITS;
2385 + rc_bit_tree_decode(rc, prob_len, num_bits, &len);
2388 + if (cst->state < 4) {
2391 + cst->state += LZMA_NUM_LIT_STATES;
2393 + p + LZMA_POS_SLOT +
2395 + LZMA_NUM_LEN_TO_POS_STATES ? len :
2396 + LZMA_NUM_LEN_TO_POS_STATES - 1)
2397 + << LZMA_NUM_POS_SLOT_BITS);
2398 + rc_bit_tree_decode(rc, prob,
2399 + LZMA_NUM_POS_SLOT_BITS,
2401 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
2403 + num_bits = (pos_slot >> 1) - 1;
2404 + cst->rep0 = 2 | (pos_slot & 1);
2405 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
2406 + cst->rep0 <<= num_bits;
2407 + prob = p + LZMA_SPEC_POS +
2408 + cst->rep0 - pos_slot - 1;
2410 + num_bits -= LZMA_NUM_ALIGN_BITS;
2411 + while (num_bits--)
2412 + cst->rep0 = (cst->rep0 << 1) |
2413 + rc_direct_bit(rc);
2414 + prob = p + LZMA_ALIGN;
2415 + cst->rep0 <<= LZMA_NUM_ALIGN_BITS;
2416 + num_bits = LZMA_NUM_ALIGN_BITS;
2420 + while (num_bits--) {
2421 + if (rc_get_bit(rc, prob + mi, &mi))
2426 + cst->rep0 = pos_slot;
2427 + if (++(cst->rep0) == 0)
2431 + len += LZMA_MATCH_MIN_LEN;
2433 + copy_bytes(wr, cst->rep0, len);
2438 +STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
2439 + int(*fill)(void*, unsigned int),
2440 + int(*flush)(void*, unsigned int),
2441 + unsigned char *output,
2443 + void(*error_fn)(char *x)
2446 + struct lzma_header header;
2448 + uint32_t pos_state_mask;
2449 + uint32_t literal_pos_mask;
2455 + struct cstate cst;
2456 + unsigned char *inbuf;
2459 + set_error_fn(error_fn);
2461 + in_len -= 4; /* Uncompressed size hack active in pre-boot
2466 + inbuf = malloc(LZMA_IOBUF_SIZE);
2468 + error("Could not allocate input bufer");
2473 + cst.rep0 = cst.rep1 = cst.rep2 = cst.rep3 = 1;
2475 + wr.header = &header;
2477 + wr.global_pos = 0;
2478 + wr.previous_byte = 0;
2479 + wr.buffer_pos = 0;
2481 + rc_init(&rc, fill, inbuf, in_len);
2483 + for (i = 0; i < sizeof(header); i++) {
2484 + if (rc.ptr >= rc.buffer_end)
2486 + ((unsigned char *)&header)[i] = *rc.ptr++;
2489 + if (header.pos >= (9 * 5 * 5))
2490 + error("bad header");
2504 + pos_state_mask = (1 << pb) - 1;
2505 + literal_pos_mask = (1 << lp) - 1;
2507 + ENDIAN_CONVERT(header.dict_size);
2508 + ENDIAN_CONVERT(header.dst_size);
2510 + if (header.dict_size == 0)
2511 + header.dict_size = 1;
2514 + wr.buffer = output;
2516 + wr.bufsize = MIN(header.dst_size, header.dict_size);
2517 + wr.buffer = large_malloc(wr.bufsize);
2519 + if (wr.buffer == NULL)
2522 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
2523 + p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
2526 + num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
2527 + for (i = 0; i < num_probs; i++)
2528 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
2530 + rc_init_code(&rc);
2532 + while (get_pos(&wr) < header.dst_size) {
2533 + int pos_state = get_pos(&wr) & pos_state_mask;
2534 + uint16_t *prob = p + LZMA_IS_MATCH +
2535 + (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
2536 + if (rc_is_bit_0(&rc, prob))
2537 + process_bit0(&wr, &rc, &cst, p, pos_state, prob,
2538 + lc, literal_pos_mask);
2540 + process_bit1(&wr, &rc, &cst, p, pos_state, prob);
2541 + if (cst.rep0 == 0)
2547 + *posp = rc.ptr-rc.buffer;
2549 + wr.flush(wr.buffer, wr.buffer_pos);
2554 + large_free(wr.buffer);
2562 +#define decompress unlzma
2563 diff -urN linux-2.6.28.9/lib/inflate.c linux-2.6.28.9.new/lib/inflate.c
2564 --- linux-2.6.28.9/lib/inflate.c 2009-03-23 22:55:52.000000000 +0100
2565 +++ linux-2.6.28.9.new/lib/inflate.c 2009-04-24 14:08:08.000000000 +0200
2566 @@ -109,20 +109,78 @@
2570 +#include <linux/decompress/inflate.h>
2571 +#endif /* ! STATIC */
2573 -#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
2574 -# include <sys/types.h>
2575 -# include <stdlib.h>
2576 +#include <linux/decompress/mm.h>
2578 +#include <linux/string.h>
2581 +static int(*flush_cb)(void*, unsigned int);
2582 +static int(*fill_cb)(void*, unsigned int);
2584 +/* Begin stuff copied from initramfs */
2586 + * gzip declarations
2589 +#define OF(args) args
2592 +#define memzero(s, n) memset((s), 0, (n))
2597 -#endif /* !STATIC */
2598 +#define INBUFSIZ 4096
2600 +#define WSIZE 0x8000 /* window size--must be a power of two, and */
2601 + /* at least 32K for zip's deflate method */
2603 +static uint8_t *inbuf;
2604 +static uint8_t *window;
2606 +static unsigned insize; /* valid bytes in inbuf */
2607 +static unsigned outcnt; /* bytes in output buffer */
2608 +static long bytes_out;
2612 +static unsigned inptr; /* index of next byte to be processed in inbuf */
2616 +/* ===========================================================================
2617 + * Fill the input buffer. This is called only when the buffer is empty
2618 + * and at least one byte is really needed.
2619 + * Returning -1 does not guarantee that gunzip() will ever return.
2621 +static int INIT fill_inbuf(void)
2623 + insize = fill_cb(inbuf, INBUFSIZ);
2624 + if (insize <= 0) {
2625 + error("RAMDISK: ran out of compressed data");
2634 +#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
2636 +/* Diagnostic functions (stubbed out) */
2637 +#define Assert(cond, msg)
2641 +#define Tracec(c, x)
2642 +#define Tracecv(c, x)
2646 +static void flush_window(void);
2647 +/* End stuff copied from initramfs */
2651 #define slide window
2653 /* Huffman code lookup table entry--this entry is four bytes for machines
2654 @@ -133,10 +191,10 @@
2655 an unused code. If a code with e == 99 is looked up, this implies an
2656 error in the data. */
2658 - uch e; /* number of extra bits or operation */
2659 - uch b; /* number of bits in this code or subcode */
2660 + uint8_t e; /* number of extra bits or operation */
2661 + uint8_t b; /* number of bits in this code or subcode */
2663 - ush n; /* literal, length base, or distance base */
2664 + uint16_t n; /* literal, length base, or distance base */
2665 struct huft *t; /* pointer to next level of table */
2670 /* Function prototypes */
2671 STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned,
2672 - const ush *, const ush *, struct huft **, int *));
2673 + const uint16_t *, const uint16_t *, struct huft **, int *));
2674 STATIC int INIT huft_free OF((struct huft *));
2675 STATIC int INIT inflate_codes OF((struct huft *, struct huft *, int, int));
2676 STATIC int INIT inflate_stored OF((void));
2677 @@ -159,28 +217,28 @@
2678 circular buffer. The index is updated simply by incrementing and then
2679 ANDing with 0x7fff (32K-1). */
2680 /* It is left to other modules to supply the 32 K area. It is assumed
2681 - to be usable as if it were declared "uch slide[32768];" or as just
2682 - "uch *slide;" and then malloc'ed in the latter case. The definition
2683 + to be usable as if it were declared "uint8_t slide[32768];" or as just
2684 + "uint8_t *slide;" and then malloc'ed in the latter case. The definition
2685 must be in unzip.h, included above. */
2686 /* unsigned wp; current position in slide */
2688 #define flush_output(w) (wp=(w),flush_window())
2690 /* Tables for deflate from PKZIP's appnote.txt. */
2691 -static const unsigned border[] = { /* Order of the bit length code lengths */
2692 +static const unsigned border[] = { /* Order of the bit length code lengths */
2693 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
2694 -static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */
2695 +static const uint16_t cplens[] = { /* Copy lengths for literal codes 257..285 */
2696 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
2697 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
2698 /* note: see note #13 above about the 258 in this list. */
2699 -static const ush cplext[] = { /* Extra bits for literal codes 257..285 */
2700 +static const uint16_t cplext[] = { /* Extra bits for literal codes 257..285 */
2701 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
2702 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
2703 -static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
2704 +static const uint16_t cpdist[] = { /* Copy offsets for distance codes 0..29 */
2705 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
2706 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
2707 8193, 12289, 16385, 24577};
2708 -static const ush cpdext[] = { /* Extra bits for distance codes */
2709 +static const uint16_t cpdext[] = { /* Extra bits for distance codes */
2710 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
2711 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
2713 @@ -217,59 +275,21 @@
2717 -STATIC ulg bb; /* bit buffer */
2718 +STATIC uint32_t bb; /* bit buffer */
2719 STATIC unsigned bk; /* bits in bit buffer */
2721 -STATIC const ush mask_bits[] = {
2722 +STATIC const uint16_t mask_bits[] = {
2724 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
2725 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
2728 -#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (uch)v; })
2729 -#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
2730 +#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; \
2732 +#define NEEDBITS(n) {while (k < (n)) \
2733 + {b |= ((uint32_t)NEXTBYTE())<<k; k += 8; } }
2734 #define DUMPBITS(n) {b>>=(n);k-=(n);}
2736 -#ifndef NO_INFLATE_MALLOC
2737 -/* A trivial malloc implementation, adapted from
2738 - * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
2741 -static unsigned long malloc_ptr;
2742 -static int malloc_count;
2744 -static void *malloc(int size)
2749 - error("Malloc error");
2751 - malloc_ptr = free_mem_ptr;
2753 - malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
2755 - p = (void *)malloc_ptr;
2756 - malloc_ptr += size;
2758 - if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
2759 - error("Out of memory");
2765 -static void free(void *where)
2768 - if (!malloc_count)
2769 - malloc_ptr = free_mem_ptr;
2772 -#define malloc(a) kmalloc(a, GFP_KERNEL)
2773 -#define free(a) kfree(a)
2777 Huffman code decoding is performed using a multi-level table lookup.
2778 The fastest way to decode is to simply build a lookup table whose
2780 STATIC const int dbits = 6; /* bits in base distance lookup table */
2783 -/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
2784 +/* If BMAX needs to be larger than 16, then h and x[] should be uint32_t. */
2785 #define BMAX 16 /* maximum bit length of any code (16 for explode) */
2786 #define N_MAX 288 /* maximum number of codes in any set */
2789 unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
2790 unsigned n, /* number of codes (assumed <= N_MAX) */
2791 unsigned s, /* number of simple-valued codes (0..s-1) */
2792 - const ush *d, /* list of base values for non-simple codes */
2793 - const ush *e, /* list of extra bits for non-simple codes */
2794 + const uint16_t *d, /* list of base values for non-simple codes */
2795 + const uint16_t *e, /* list of extra bits for non-simple codes */
2796 struct huft **t, /* result: starting table */
2797 int *m /* maximum lookup bits, returns actual */
2802 x[h] = i; /* save pattern for backing up */
2803 - r.b = (uch)l; /* bits to dump before this table */
2804 - r.e = (uch)(16 + j); /* bits in this table */
2805 + r.b = (uint8_t)l; /* bits to dump before this table */
2806 + r.e = (uint8_t)(16 + j); /* bits in this table */
2807 r.v.t = q; /* pointer to this table */
2808 j = i >> (w - l); /* (get around Turbo C bug) */
2809 u[h-1][j] = r; /* connect to last table */
2810 @@ -511,18 +531,18 @@
2813 /* set up table entry in r */
2814 - r.b = (uch)(k - w);
2815 + r.b = (uint8_t)(k - w);
2817 r.e = 99; /* out of values--invalid code */
2820 - r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
2821 - r.v.n = (ush)(*p); /* simple code is just the value */
2822 + r.e = (uint8_t)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
2823 + r.v.n = (uint16_t)(*p); /* simple code is just the value */
2824 p++; /* one compiler does not like *p++ */
2828 - r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
2829 + r.e = (uint8_t)e[*p - s]; /* non-simple--look up in lists */
2830 r.v.n = d[*p++ - s];
2833 @@ -592,11 +612,12 @@
2834 Return an error code or zero if it all goes ok. */
2836 register unsigned e; /* table entry flag/number of extra bits */
2837 - unsigned n, d; /* length and index for copy */
2839 + int d; /* source index for copy */
2840 unsigned w; /* current window position */
2841 struct huft *t; /* pointer to table entry */
2842 unsigned ml, md; /* masks for bl and bd bits */
2843 - register ulg b; /* bit buffer */
2844 + register uint32_t b; /* bit buffer */
2845 register unsigned k; /* number of bits in bit buffer */
2850 if (e == 16) /* then it's a literal */
2852 - slide[w++] = (uch)t->v.n;
2853 + slide[w++] = (uint8_t)t->v.n;
2854 Tracevv((stderr, "%c", slide[w-1]));
2857 @@ -659,11 +680,25 @@
2861 - n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
2865 + /* Sliding window emulated using circular buffer:
2866 + * manage wrap-around */
2867 + e = WSIZE - ((d &= WSIZE-1) > w ? d : w);
2877 #if !defined(NOMEMCPY) && !defined(DEBUG)
2878 if (w - d >= e) /* (this test assumes unsigned comparison) */
2880 - memcpy(slide + w, slide + d, e);
2881 + memcpy(slide + w, slide + d, e);
2886 slide[w++] = slide[d++];
2887 Tracevv((stderr, "%c", slide[w-1]));
2899 unsigned n; /* number of bytes in block */
2900 unsigned w; /* current window position */
2901 - register ulg b; /* bit buffer */
2902 + register uint32_t b; /* bit buffer */
2903 register unsigned k; /* number of bits in bit buffer */
2910 - slide[w++] = (uch)b;
2911 + slide[w++] = (uint8_t)b;
2916 unsigned nl; /* number of literal/length codes */
2917 unsigned nd; /* number of distance codes */
2918 unsigned *ll; /* literal/length and distance code lengths */
2919 - register ulg b; /* bit buffer */
2920 + register uint32_t b; /* bit buffer */
2921 register unsigned k; /* number of bits in bit buffer */
2924 @@ -1033,7 +1067,7 @@
2925 /* decompress an inflated block */
2927 unsigned t; /* block type */
2928 - register ulg b; /* bit buffer */
2929 + register uint32_t b; /* bit buffer */
2930 register unsigned k; /* number of bits in bit buffer */
2933 @@ -1130,8 +1164,8 @@
2935 **********************************************************************/
2937 -static ulg crc_32_tab[256];
2938 -static ulg crc; /* initialized in makecrc() so it'll reside in bss */
2939 +static uint32_t crc_32_tab[256];
2940 +static uint32_t crc; /* initialized in makecrc() so it'll reside in bss */
2941 #define CRC_VALUE (crc ^ 0xffffffffUL)
2944 @@ -1172,7 +1206,7 @@
2947 /* this is initialized here so this code could reside in ROM */
2948 - crc = (ulg)0xffffffffUL; /* shift register contents */
2949 + crc = (uint32_t)0xffffffffUL; /* shift register contents */
2952 /* gzip flag byte */
2953 @@ -1184,18 +1218,89 @@
2954 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
2955 #define RESERVED 0xC0 /* bit 6,7: reserved */
2958 +/* ===========================================================================
2959 + * Write the output window window[0..outcnt-1] and update crc and bytes_out.
2960 + * (Used for the decompressed data only.)
2962 +static void INIT flush_window(void)
2964 + uint32_t c = crc; /* temporary variable */
2969 + for (n = 0; n < outcnt; n++) {
2971 + c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
2974 + bytes_out += (uint32_t)outcnt;
2975 + if (flush_cb != NULL)
2976 + flush_cb(window, outcnt); /* TODO: handle unzip_error */
2982 +static int empty_fill(void *buf, unsigned int len)
2990 * Do the uncompression!
2992 -static int INIT gunzip(void)
2993 +STATIC int INIT gunzip(
2995 + unsigned char *buf, int len,
2996 + int(*fill)(void*, unsigned int),
2997 + int(*flush)(void*, unsigned int),
2998 + unsigned char *output,
3000 + void(*error_fn)(char *x)
3008 unsigned char magic[2]; /* magic header */
3010 - ulg orig_crc = 0; /* original crc */
3011 - ulg orig_len = 0; /* original uncompressed length */
3012 + uint32_t orig_crc = 0; /* original crc */
3013 + uint32_t orig_len = 0; /* original uncompressed length */
3017 + set_error_fn(error_fn);
3019 + fill_cb = empty_fill;
3025 + window = malloc(0x8000);
3027 + panic("can't allocate buffers");
3035 + inbuf = malloc(INBUFSIZ);
3039 + outcnt = 0; /* bytes in output buffer */
3041 + crc = (uint32_t)0xffffffffL; /* shift register contents */
3044 magic[0] = NEXTBYTE();
3045 magic[1] = NEXTBYTE();
3046 method = NEXTBYTE();
3047 @@ -1212,7 +1317,7 @@
3051 - flags = (uch)get_byte();
3052 + flags = (uint8_t)get_byte();
3053 if ((flags & ENCRYPTED) != 0) {
3054 error("Input is encrypted");
3056 @@ -1277,15 +1382,15 @@
3057 /* crc32 (see algorithm.doc)
3058 * uncompressed input size modulo 2^32
3060 - orig_crc = (ulg) NEXTBYTE();
3061 - orig_crc |= (ulg) NEXTBYTE() << 8;
3062 - orig_crc |= (ulg) NEXTBYTE() << 16;
3063 - orig_crc |= (ulg) NEXTBYTE() << 24;
3064 + orig_crc = (uint32_t) NEXTBYTE();
3065 + orig_crc |= (uint32_t) NEXTBYTE() << 8;
3066 + orig_crc |= (uint32_t) NEXTBYTE() << 16;
3067 + orig_crc |= (uint32_t) NEXTBYTE() << 24;
3069 - orig_len = (ulg) NEXTBYTE();
3070 - orig_len |= (ulg) NEXTBYTE() << 8;
3071 - orig_len |= (ulg) NEXTBYTE() << 16;
3072 - orig_len |= (ulg) NEXTBYTE() << 24;
3073 + orig_len = (uint32_t) NEXTBYTE();
3074 + orig_len |= (uint32_t) NEXTBYTE() << 8;
3075 + orig_len |= (uint32_t) NEXTBYTE() << 16;
3076 + orig_len |= (uint32_t) NEXTBYTE() << 24;
3078 /* Validate decompression */
3079 if (orig_crc != CRC_VALUE) {
3080 @@ -1296,11 +1401,22 @@
3081 error("length error");
3092 underrun: /* NEXTBYTE() goto's here if needed */
3098 error("out of input data");
3103 +#define decompress gunzip
3104 diff -urN linux-2.6.28.9/scripts/Makefile.lib linux-2.6.28.9.new/scripts/Makefile.lib
3105 --- linux-2.6.28.9/scripts/Makefile.lib 2009-03-23 22:55:52.000000000 +0100
3106 +++ linux-2.6.28.9.new/scripts/Makefile.lib 2009-04-24 14:08:08.000000000 +0200
3107 @@ -183,3 +183,17 @@
3108 cmd_gzip = gzip -f -9 < $< > $@
3112 +# ---------------------------------------------------------------------------
3114 +# Bzip2 does not include size in file... so we have to fake that
3115 +size_append=$(CONFIG_SHELL) $(srctree)/scripts/bin_size
3117 +quiet_cmd_bzip2 = BZIP2 $@
3118 +cmd_bzip2 = (bzip2 -9 < $< ; $(size_append) $<) > $@ || (rm -f $@ ; false)
3121 +# ---------------------------------------------------------------------------
3123 +quiet_cmd_lzma = LZMA $@
3124 +cmd_lzma = (/usr/bin/lzma -9 -c $< ; $(size_append) $<) >$@ || (rm -f $@ ; false)
3125 diff -urN linux-2.6.28.9/scripts/bin_size linux-2.6.28.9.new/scripts/bin_size
3126 --- linux-2.6.28.9/scripts/bin_size 1970-01-01 01:00:00.000000000 +0100
3127 +++ linux-2.6.28.9.new/scripts/bin_size 2009-04-24 14:08:08.000000000 +0200
3131 +if [ $# = 0 ] ; then
3132 + echo Usage: $0 file
3135 +size_dec=`stat -c "%s" $1`
3136 +size_hex_echo_string=`printf "%08x" $size_dec |
3137 + sed 's/\(..\)\(..\)\(..\)\(..\)/\\\\x\4\\\\x\3\\\\x\2\\\\x\1/g'`
3138 +/bin/echo -ne $size_hex_echo_string