wok-next diff linux/stuff/linux-lzma-2.6.25.5.u @ rev 886
Up: linux (2.5.25.5)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 07 22:04:11 2008 +0000 (2008-06-07) |
parents | |
children | 9e2bae22918d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux/stuff/linux-lzma-2.6.25.5.u Sat Jun 07 22:04:11 2008 +0000 1.3 @@ -0,0 +1,2127 @@ 1.4 +--- linux-2.6.25.5/arch/x86/boot/compressed/Makefile 1.5 ++++ linux-2.6.25.5/arch/x86/boot/compressed/Makefile 1.6 +@@ -4,7 +4,7 @@ 1.7 + # create a compressed vmlinux image from the original vmlinux 1.8 + # 1.9 + 1.10 +-targets := vmlinux vmlinux.bin vmlinux.bin.gz head_$(BITS).o misc.o piggy.o 1.11 ++targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head_$(BITS).o misc.o piggy.o 1.12 + 1.13 + KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 1.14 + KBUILD_CFLAGS += -fno-strict-aliasing -fPIC 1.15 +@@ -50,15 +50,41 @@ 1.16 + $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE 1.17 + $(call if_changed,gzip) 1.18 + endif 1.19 ++ 1.20 ++ifdef CONFIG_RELOCATABLE 1.21 ++$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin.all FORCE 1.22 ++ $(call if_changed,bzip2) 1.23 ++else 1.24 ++$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE 1.25 ++ $(call if_changed,bzip2) 1.26 ++endif 1.27 ++ 1.28 ++ifdef CONFIG_RELOCATABLE 1.29 ++$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE 1.30 ++ $(call if_changed,lzma) 1.31 ++else 1.32 ++$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE 1.33 ++ $(call if_changed,lzma) 1.34 ++endif 1.35 ++ 1.36 + LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T 1.37 + 1.38 + else 1.39 ++$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE 1.40 ++ $(call if_changed,bzip2) 1.41 ++ 1.42 ++$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE 1.43 ++ $(call if_changed,lzma) 1.44 ++ 1.45 + $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE 1.46 + $(call if_changed,gzip) 1.47 + 1.48 + LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T 1.49 + endif 1.50 + 1.51 ++suffix_$(CONFIG_KERNEL_GZIP) = gz 1.52 ++suffix_$(CONFIG_KERNEL_BZIP2) = bz2 1.53 ++suffix_$(CONFIG_KERNEL_LZMA) = lzma 1.54 + 1.55 +-$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE 1.56 ++$(obj)/piggy.o: $(src)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE 1.57 + $(call if_changed,ld) 1.58 + 1.59 +--- linux-2.6.25.5/arch/x86/boot/compressed/misc.c 1.60 ++++ linux-2.6.25.5/arch/x86/boot/compressed/misc.c 1.61 +@@ -130,9 +130,12 @@ 1.62 + * always be larger than our output buffer. 1.63 + */ 1.64 + 1.65 ++#ifdef CONFIG_KERNEL_GZIP 1.66 + static uch *inbuf; /* input buffer */ 1.67 ++#endif 1.68 + static uch *window; /* Sliding window buffer, (and final output buffer) */ 1.69 + 1.70 ++#ifdef CONFIG_KERNEL_GZIP 1.71 + static unsigned insize; /* valid bytes in inbuf */ 1.72 + static unsigned inptr; /* index of next byte to be processed in inbuf */ 1.73 + static unsigned outcnt; /* bytes in output buffer */ 1.74 +@@ -167,9 +170,12 @@ 1.75 + 1.76 + static int fill_inbuf(void); 1.77 + static void flush_window(void); 1.78 ++#endif 1.79 + static void error(char *m); 1.80 ++#ifdef CONFIG_KERNEL_GZIP 1.81 + static void gzip_mark(void **); 1.82 + static void gzip_release(void **); 1.83 ++#endif 1.84 + 1.85 + /* 1.86 + * This is set up by the setup-routine at boot-time 1.87 +@@ -185,12 +191,12 @@ 1.88 + extern unsigned char input_data[]; 1.89 + extern int input_len; 1.90 + 1.91 +-static long bytes_out = 0; 1.92 +- 1.93 + static void *malloc(int size); 1.94 + static void free(void *where); 1.95 + 1.96 ++#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2) 1.97 + static void *memset(void *s, int c, unsigned n); 1.98 ++#endif 1.99 + static void *memcpy(void *dest, const void *src, unsigned n); 1.100 + 1.101 + static void putstr(const char *); 1.102 +@@ -204,11 +210,15 @@ 1.103 + static memptr free_mem_ptr; 1.104 + static memptr free_mem_end_ptr; 1.105 + 1.106 ++#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA) 1.107 ++#define HEAP_SIZE 0x400000 1.108 ++#else 1.109 + #ifdef CONFIG_X86_64 1.110 + #define HEAP_SIZE 0x7000 1.111 + #else 1.112 + #define HEAP_SIZE 0x4000 1.113 + #endif 1.114 ++#endif 1.115 + 1.116 + static char *vidmem = (char *)0xb8000; 1.117 + static int vidport; 1.118 +@@ -218,7 +228,29 @@ 1.119 + void *xquad_portio; 1.120 + #endif 1.121 + 1.122 ++#if (defined CONFIG_KERNEL_BZIP2 || defined CONFIG_KERNEL_LZMA) 1.123 ++ 1.124 ++#define large_malloc malloc 1.125 ++#define large_free free 1.126 ++ 1.127 ++#ifdef current 1.128 ++#undef current 1.129 ++#endif 1.130 ++ 1.131 ++#define INCLUDED 1.132 ++#endif 1.133 ++ 1.134 ++#ifdef CONFIG_KERNEL_GZIP 1.135 + #include "../../../../lib/inflate.c" 1.136 ++#endif 1.137 ++ 1.138 ++#ifdef CONFIG_KERNEL_BZIP2 1.139 ++#include "../../../../lib/decompress_bunzip2.c" 1.140 ++#endif 1.141 ++ 1.142 ++#ifdef CONFIG_KERNEL_LZMA 1.143 ++#include "../../../../lib/decompress_unlzma.c" 1.144 ++#endif 1.145 + 1.146 + static void *malloc(int size) 1.147 + { 1.148 +@@ -242,6 +274,7 @@ 1.149 + { /* Don't care */ 1.150 + } 1.151 + 1.152 ++#ifdef CONFIG_KERNEL_GZIP 1.153 + static void gzip_mark(void **ptr) 1.154 + { 1.155 + *ptr = (void *) free_mem_ptr; 1.156 +@@ -251,6 +284,7 @@ 1.157 + { 1.158 + free_mem_ptr = (memptr) *ptr; 1.159 + } 1.160 ++#endif 1.161 + 1.162 + static void scroll(void) 1.163 + { 1.164 +@@ -303,6 +337,7 @@ 1.165 + outb(0xff & (pos >> 1), vidport+1); 1.166 + } 1.167 + 1.168 ++#if (defined CONFIG_KERNEL_GZIP || defined CONFIG_KERNEL_BZIP2) 1.169 + static void* memset(void* s, int c, unsigned n) 1.170 + { 1.171 + int i; 1.172 +@@ -311,6 +346,7 @@ 1.173 + for (i=0;i<n;i++) ss[i] = c; 1.174 + return s; 1.175 + } 1.176 ++#endif 1.177 + 1.178 + static void* memcpy(void* dest, const void* src, unsigned n) 1.179 + { 1.180 +@@ -322,6 +358,26 @@ 1.181 + return dest; 1.182 + } 1.183 + 1.184 ++#ifdef CONFIG_KERNEL_BZIP2 1.185 ++/* =========================================================================== 1.186 ++ * Write the output window window[0..outcnt-1]. 1.187 ++ * (Used for the decompressed data only.) 1.188 ++ */ 1.189 ++static int compr_flush(char *data, unsigned int len) 1.190 ++{ 1.191 ++ unsigned n; 1.192 ++ uch *out; 1.193 ++ 1.194 ++ out = window; 1.195 ++ for (n = 0; n < len; n++) { 1.196 ++ *out++ = *data++; 1.197 ++ } 1.198 ++ window += (ulg)len; 1.199 ++ return len; 1.200 ++} 1.201 ++ 1.202 ++#endif 1.203 ++#ifdef CONFIG_KERNEL_GZIP 1.204 + /* =========================================================================== 1.205 + * Fill the input buffer. This is called only when the buffer is empty 1.206 + * and at least one byte is really needed. 1.207 +@@ -333,7 +389,7 @@ 1.208 + } 1.209 + 1.210 + /* =========================================================================== 1.211 +- * Write the output window window[0..outcnt-1] and update crc and bytes_out. 1.212 ++ * Write the output window window[0..outcnt-1] and update crc. 1.213 + * (Used for the decompressed data only.) 1.214 + */ 1.215 + static void flush_window(void) 1.216 +@@ -351,9 +407,9 @@ 1.217 + c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8); 1.218 + } 1.219 + crc = c; 1.220 +- bytes_out += (ulg)outcnt; 1.221 + outcnt = 0; 1.222 + } 1.223 ++#endif 1.224 + 1.225 + static void error(char *x) 1.226 + { 1.227 +@@ -385,9 +441,11 @@ 1.228 + window = output; /* Output buffer (Normally at 1M) */ 1.229 + free_mem_ptr = heap; /* Heap */ 1.230 + free_mem_end_ptr = heap + HEAP_SIZE; 1.231 ++#ifdef CONFIG_KERNEL_GZIP 1.232 + inbuf = input_data; /* Input buffer */ 1.233 + insize = input_len; 1.234 + inptr = 0; 1.235 ++#endif 1.236 + 1.237 + #ifdef CONFIG_X86_64 1.238 + if ((ulg)output & (__KERNEL_ALIGN - 1)) 1.239 +@@ -405,9 +463,21 @@ 1.240 + #endif 1.241 + #endif 1.242 + 1.243 ++#ifdef CONFIG_KERNEL_BZIP2 1.244 ++ putstr("\nBunzipping Linux... "); 1.245 ++ bunzip2(input_data, input_len-4, NULL, compr_flush, NULL); 1.246 ++#endif 1.247 ++ 1.248 ++#ifdef CONFIG_KERNEL_LZMA 1.249 ++ putstr("\nUnlzmaing Linux... "); 1.250 ++ unlzma(input_data, input_len-4, NULL, NULL, window); 1.251 ++#endif 1.252 ++ 1.253 ++#ifdef CONFIG_KERNEL_GZIP 1.254 + makecrc(); 1.255 + putstr("\nDecompressing Linux... "); 1.256 + gunzip(); 1.257 ++#endif 1.258 + putstr("done.\nBooting the kernel.\n"); 1.259 + return; 1.260 + } 1.261 + 1.262 +--- linux-2.6.25.5/drivers/block/Kconfig 1.263 ++++ linux-2.6.25.5/drivers/block/Kconfig 1.264 +@@ -357,6 +357,30 @@ 1.265 + will prevent RAM block device backing store memory from being 1.266 + allocated from highmem (only a problem for highmem systems). 1.267 + 1.268 ++config RD_BZIP2 1.269 ++ bool "Initial ramdisk compressed using bzip2" 1.270 ++ default n 1.271 ++ depends on BLK_DEV_INITRD=y 1.272 ++ help 1.273 ++ Support loading of a bzip2 encoded initial ramdisk or cpio buffer 1.274 ++ If unsure, say N. 1.275 ++ 1.276 ++config RD_LZMA 1.277 ++ bool "Initial ramdisk compressed using lzma" 1.278 ++ default n 1.279 ++ depends on BLK_DEV_INITRD=y 1.280 ++ help 1.281 ++ Support loading of a lzma encoded initial ramdisk or cpio buffer 1.282 ++ If unsure, say N. 1.283 ++ 1.284 ++config RD_GZIP 1.285 ++ bool "Initial ramdisk compressed using gzip" 1.286 ++ default y 1.287 ++ depends on BLK_DEV_INITRD=y 1.288 ++ help 1.289 ++ Support loading of a gzip encoded initial ramdisk or cpio buffer. 1.290 ++ If unsure, say Y. 1.291 ++ 1.292 + config CDROM_PKTCDVD 1.293 + tristate "Packet writing on CD/DVD media" 1.294 + depends on !UML 1.295 + 1.296 +--- linux-2.6.25.5/include/linux/decompress_bunzip2.h 1.297 ++++ linux-2.6.25.5/include/linux/decompress_bunzip2.h 1.298 +@@ -0,0 +1,16 @@ 1.299 ++#ifndef DECOMPRESS_BUNZIP2_H 1.300 ++#define DECOMPRESS_BUNZIP2_H 1.301 ++ 1.302 ++/* Other housekeeping constants */ 1.303 ++#define BZIP2_IOBUF_SIZE 4096 1.304 ++ 1.305 ++#ifndef STATIC 1.306 ++#define STATIC /**/ 1.307 ++#endif 1.308 ++ 1.309 ++STATIC int bunzip2(char *inbuf, int len, 1.310 ++ int(*fill)(void*,unsigned int), 1.311 ++ int(*writebb)(char*,unsigned int), 1.312 ++ int *pos); 1.313 ++ 1.314 ++#endif 1.315 + 1.316 +--- linux-2.6.25.5/include/linux/decompress_generic.h 1.317 ++++ linux-2.6.25.5/include/linux/decompress_generic.h 1.318 +@@ -0,0 +1,28 @@ 1.319 ++#ifndef DECOMPRESS_GENERIC_H 1.320 ++#define DECOMPRESS_GENERIC_H 1.321 ++ 1.322 ++/* Minimal chunksize to be read. 1.323 ++ * Bzip2 prefers at least 4096 1.324 ++ * Lzma prefers 0x10000 */ 1.325 ++#define COMPR_IOBUF_SIZE 4096 1.326 ++ 1.327 ++typedef int (*uncompress_fn) (char *inbuf, int len, 1.328 ++ int(*fill)(char*,unsigned int), 1.329 ++ int(*writebb)(char*,unsigned int), 1.330 ++ int *posp); 1.331 ++ 1.332 ++/* inbuf - input buffer 1.333 ++ * len - len of pre-read data in inbuf 1.334 ++ * fill - function to fill inbuf if empty 1.335 ++ * writebb - function to write out outbug 1.336 ++ * posp - if non-null, input position (number of bytes read) will be 1.337 ++ * returned here 1.338 ++ * 1.339 ++ * If len != 0, the inbuf is initialized (with as much data), and fill 1.340 ++ * should not be called 1.341 ++ * If len = 0, the inbuf is allocated, but empty. Its size is IOBUF_SIZE 1.342 ++ * fill should be called (repeatedly...) to read data, at most IOBUF_SIZE 1.343 ++ */ 1.344 ++ 1.345 ++ 1.346 ++#endif 1.347 + 1.348 +--- linux-2.6.25.5/include/linux/decompress_unlzma.h 1.349 ++++ linux-2.6.25.5/include/linux/decompress_unlzma.h 1.350 +@@ -0,0 +1,15 @@ 1.351 ++#ifndef DECOMPRESS_UNLZMA_H 1.352 ++#define DECOMPRESS_UNLZMA_H 1.353 ++ 1.354 ++#define LZMA_IOBUF_SIZE 0x10000 1.355 ++ 1.356 ++#ifndef STATIC 1.357 ++#define STATIC /**/ 1.358 ++#endif 1.359 ++ 1.360 ++STATIC int unlzma(char *inbuf, int len, 1.361 ++ int(*fill)(void*,unsigned int), 1.362 ++ int(*writebb)(char*,unsigned int), 1.363 ++ int *pos); 1.364 ++ 1.365 ++#endif 1.366 + 1.367 +--- linux-2.6.25.5/init/do_mounts_rd.c 1.368 ++++ linux-2.6.25.5/init/do_mounts_rd.c 1.369 +@@ -8,6 +8,16 @@ 1.370 + #include <linux/initrd.h> 1.371 + #include <linux/string.h> 1.372 + 1.373 ++#ifdef CONFIG_RD_BZIP2 1.374 ++#include <linux/decompress_bunzip2.h> 1.375 ++#undef STATIC 1.376 ++#endif 1.377 ++ 1.378 ++#ifdef CONFIG_RD_LZMA 1.379 ++#include <linux/decompress_unlzma.h> 1.380 ++#undef STATIC 1.381 ++#endif 1.382 ++ 1.383 + #include "do_mounts.h" 1.384 + 1.385 + #define BUILD_CRAMDISK 1.386 +@@ -30,7 +40,15 @@ static int __init ramdisk_start_setup(ch 1.387 + } 1.388 + __setup("ramdisk_start=", ramdisk_start_setup); 1.389 + 1.390 ++#ifdef CONFIG_RD_GZIP 1.391 + static int __init crd_load(int in_fd, int out_fd); 1.392 ++#endif 1.393 ++#ifdef CONFIG_RD_BZIP2 1.394 ++static int __init crd_load_bzip2(int in_fd, int out_fd); 1.395 ++#endif 1.396 ++#ifdef CONFIG_RD_LZMA 1.397 ++static int __init crd_load_lzma(int in_fd, int out_fd); 1.398 ++#endif 1.399 + 1.400 + /* 1.401 + * This routine tries to find a RAM disk image to load, and returns the 1.402 +@@ -46,7 +64,7 @@ static int __init crd_load(int in_fd, in 1.403 + * gzip 1.404 + */ 1.405 + static int __init 1.406 +-identify_ramdisk_image(int fd, int start_block) 1.407 ++identify_ramdisk_image(int fd, int start_block, int *ztype) 1.408 + { 1.409 + const int size = 512; 1.410 + struct minix_super_block *minixsb; 1.411 +@@ -72,6 +90,7 @@ identify_ramdisk_image(int fd, int start 1.412 + sys_lseek(fd, start_block * BLOCK_SIZE, 0); 1.413 + sys_read(fd, buf, size); 1.414 + 1.415 ++#ifdef CONFIG_RD_GZIP 1.416 + /* 1.417 + * If it matches the gzip magic numbers, return -1 1.418 + */ 1.419 +@@ -79,9 +98,40 @@ identify_ramdisk_image(int fd, int start 1.420 + printk(KERN_NOTICE 1.421 + "RAMDISK: Compressed image found at block %d\n", 1.422 + start_block); 1.423 ++ *ztype = 0; 1.424 ++ nblocks = 0; 1.425 ++ goto done; 1.426 ++ } 1.427 ++#endif 1.428 ++ 1.429 ++#ifdef CONFIG_RD_BZIP2 1.430 ++ /* 1.431 ++ * If it matches the bzip magic numbers, return -1 1.432 ++ */ 1.433 ++ if (buf[0] == 0x42 && (buf[1] == 0x5a)) { 1.434 ++ printk(KERN_NOTICE 1.435 ++ "RAMDISK: Bzipped image found at block %d\n", 1.436 ++ start_block); 1.437 ++ *ztype = 1; 1.438 ++ nblocks = 0; 1.439 ++ goto done; 1.440 ++ } 1.441 ++#endif 1.442 ++ 1.443 ++#ifdef CONFIG_RD_LZMA 1.444 ++ /* 1.445 ++ * If it matches the bzip magic numbers, return -1 1.446 ++ */ 1.447 ++ if (buf[0] == 0x5d && (buf[1] == 0x00)) { 1.448 ++ printk(KERN_NOTICE 1.449 ++ "RAMDISK: Lzma image found at block %d\n", 1.450 ++ start_block); 1.451 ++ *ztype = 2; 1.452 + nblocks = 0; 1.453 + goto done; 1.454 + } 1.455 ++#endif 1.456 ++ 1.457 + 1.458 + /* romfs is at block zero too */ 1.459 + if (romfsb->word0 == ROMSB_WORD0 && 1.460 +@@ -145,6 +195,7 @@ int __init rd_load_image(char *from) 1.461 + int nblocks, i, disk; 1.462 + char *buf = NULL; 1.463 + unsigned short rotate = 0; 1.464 ++ int ztype=-1; 1.465 + #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES) 1.466 + char rotator[4] = { '|' , '/' , '-' , '\\' }; 1.467 + #endif 1.468 +@@ -157,14 +208,38 @@ int __init rd_load_image(char *from) 1.469 + if (in_fd < 0) 1.470 + goto noclose_input; 1.471 + 1.472 +- nblocks = identify_ramdisk_image(in_fd, rd_image_start); 1.473 ++ nblocks = identify_ramdisk_image(in_fd, rd_image_start, &ztype); 1.474 + if (nblocks < 0) 1.475 + goto done; 1.476 + 1.477 + if (nblocks == 0) { 1.478 + #ifdef BUILD_CRAMDISK 1.479 +- if (crd_load(in_fd, out_fd) == 0) 1.480 +- goto successful_load; 1.481 ++ switch(ztype) { 1.482 ++ 1.483 ++#ifdef CONFIG_RD_GZIP 1.484 ++ case 0: 1.485 ++ if (crd_load(in_fd, out_fd) == 0) 1.486 ++ goto successful_load; 1.487 ++ break; 1.488 ++#endif 1.489 ++ 1.490 ++#ifdef CONFIG_RD_BZIP2 1.491 ++ case 1: 1.492 ++ if (crd_load_bzip2(in_fd, out_fd) == 0) 1.493 ++ goto successful_load; 1.494 ++ break; 1.495 ++#endif 1.496 ++ 1.497 ++#ifdef CONFIG_RD_LZMA 1.498 ++ case 2: 1.499 ++ if (crd_load_lzma(in_fd, out_fd) == 0) 1.500 ++ goto successful_load; 1.501 ++ break; 1.502 ++#endif 1.503 ++ 1.504 ++ default: 1.505 ++ break; 1.506 ++ } 1.507 + #else 1.508 + printk(KERN_NOTICE 1.509 + "RAMDISK: Kernel does not support compressed " 1.510 +@@ -269,6 +344,7 @@ int __init rd_load_disk(int n) 1.511 + 1.512 + #ifdef BUILD_CRAMDISK 1.513 + 1.514 ++#ifdef CONFIG_RD_GZIP 1.515 + /* 1.516 + * gzip declarations 1.517 + */ 1.518 +@@ -296,8 +372,11 @@ static unsigned outcnt; /* bytes in out 1.519 + static int exit_code; 1.520 + static int unzip_error; 1.521 + static long bytes_out; 1.522 ++#endif 1.523 ++ 1.524 + static int crd_infd, crd_outfd; 1.525 + 1.526 ++#ifdef CONFIG_RD_GZIP 1.527 + #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) 1.528 + 1.529 + /* Diagnostic functions (stubbed out) */ 1.530 +@@ -359,7 +438,22 @@ static int __init fill_inbuf(void) 1.531 + 1.532 + return inbuf[0]; 1.533 + } 1.534 ++#endif 1.535 ++ 1.536 ++#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA) 1.537 ++static int __init compr_fill(void *buf, unsigned int len) 1.538 ++{ 1.539 ++ int r = sys_read(crd_infd, buf, len); 1.540 ++ if(r < 0) { 1.541 ++ printk(KERN_ERR "RAMDISK: error while reading compressed data"); 1.542 ++ } else if(r == 0) { 1.543 ++ printk(KERN_ERR "RAMDISK: EOF while reading compressed data"); 1.544 ++ } 1.545 ++ return r; 1.546 ++} 1.547 ++#endif 1.548 + 1.549 ++#ifdef CONFIG_RD_GZIP 1.550 + /* =========================================================================== 1.551 + * Write the output window window[0..outcnt-1] and update crc and bytes_out. 1.552 + * (Used for the decompressed data only.) 1.553 +@@ -385,7 +479,24 @@ static void __init flush_window(void) 1.554 + bytes_out += (ulg)outcnt; 1.555 + outcnt = 0; 1.556 + } 1.557 ++#endif 1.558 ++ 1.559 ++#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA) 1.560 ++static int __init compr_flush(void *window, unsigned int outcnt) { 1.561 ++ static int progressDots=0; 1.562 ++ int written = sys_write(crd_outfd, window, outcnt); 1.563 ++ if (written != outcnt) { 1.564 ++ printk(KERN_ERR "RAMDISK: incomplete write (%d != %d)\n", 1.565 ++ written, outcnt); 1.566 ++ } 1.567 ++ progressDots = (progressDots+1)%10; 1.568 ++ if(!progressDots) 1.569 ++ printk("."); 1.570 ++ return outcnt; 1.571 ++} 1.572 ++#endif 1.573 + 1.574 ++#ifdef CONFIG_RD_GZIP 1.575 + static void __init error(char *x) 1.576 + { 1.577 + printk(KERN_ERR "%s\n", x); 1.578 +@@ -425,5 +536,43 @@ static int __init crd_load(int in_fd, in 1.579 + kfree(window); 1.580 + return result; 1.581 + } 1.582 ++#endif 1.583 ++ 1.584 ++#if (defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA) 1.585 ++static int __init crd_load_compr(int in_fd, int out_fd, int size, 1.586 ++ int (*deco)(char *,int, 1.587 ++ int(*fill)(void*,unsigned int), 1.588 ++ int(*flush)(void*,unsigned int), 1.589 ++ int *)) 1.590 ++{ 1.591 ++ int result; 1.592 ++ char *inbuf = kmalloc(size, GFP_KERNEL); 1.593 ++ crd_infd = in_fd; 1.594 ++ crd_outfd = out_fd; 1.595 ++ if (inbuf == 0) { 1.596 ++ printk(KERN_ERR "RAMDISK: Couldn't allocate decompression buffer\n"); 1.597 ++ return -1; 1.598 ++ } 1.599 ++ result=deco(inbuf, 0, compr_fill, compr_flush, NULL); 1.600 ++ kfree(inbuf); 1.601 ++ printk("\n"); 1.602 ++ return result; 1.603 ++} 1.604 ++#endif 1.605 ++ 1.606 ++#ifdef CONFIG_RD_BZIP2 1.607 ++static int __init crd_load_bzip2(int in_fd, int out_fd) 1.608 ++{ 1.609 ++ return crd_load_compr(in_fd, out_fd, BZIP2_IOBUF_SIZE, bunzip2); 1.610 ++} 1.611 ++#endif 1.612 ++ 1.613 ++#ifdef CONFIG_RD_LZMA 1.614 ++static int __init crd_load_lzma(int in_fd, int out_fd) 1.615 ++{ 1.616 ++ return crd_load_compr(in_fd, out_fd, LZMA_IOBUF_SIZE, unlzma); 1.617 ++} 1.618 ++ 1.619 ++#endif 1.620 + 1.621 + #endif /* BUILD_CRAMDISK */ 1.622 + 1.623 +--- linux-2.6.25.5/init/initramfs.c 1.624 ++++ linux-2.6.25.5/init/initramfs.c 1.625 +@@ -367,6 +367,18 @@ 1.626 + } 1.627 + } 1.628 + 1.629 ++#ifdef CONFIG_RD_BZIP2 1.630 ++#include <linux/decompress_bunzip2.h> 1.631 ++#undef STATIC 1.632 ++ 1.633 ++#endif 1.634 ++ 1.635 ++#ifdef CONFIG_RD_LZMA 1.636 ++#include <linux/decompress_unlzma.h> 1.637 ++#undef STATIC 1.638 ++ 1.639 ++#endif 1.640 ++ 1.641 + /* 1.642 + * gzip declarations 1.643 + */ 1.644 +@@ -441,6 +453,29 @@ 1.645 + outcnt = 0; 1.646 + } 1.647 + 1.648 ++#include <linux/initrd.h> 1.649 ++#ifdef CONFIG_RD_LZMA 1.650 ++#define INITRD_PAGE ((PAGE_SIZE > 1024*1024) ? PAGE_SIZE : 1024*1024) 1.651 ++static int fill_offset, fill_total; 1.652 ++static int fill_buffer(void *buffer, unsigned size) 1.653 ++{ 1.654 ++ int max = initrd_end - initrd_start - fill_offset; 1.655 ++ if (size < max) max = size; 1.656 ++ memcpy(buffer, (void *)(initrd_start + fill_offset), max); 1.657 ++ fill_offset += max; 1.658 ++ fill_total += max; 1.659 ++ if (fill_offset >= INITRD_PAGE) { 1.660 ++ unsigned rem = fill_offset % INITRD_PAGE; 1.661 ++ unsigned end = initrd_start + fill_offset - rem; 1.662 ++ free_initrd_mem(initrd_start, end); 1.663 ++ printk("."); 1.664 ++ initrd_start = end; 1.665 ++ fill_offset = rem; 1.666 ++ } 1.667 ++ return max; 1.668 ++} 1.669 ++#endif 1.670 ++ 1.671 + static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) 1.672 + { 1.673 + int written; 1.674 +@@ -455,6 +490,9 @@ 1.675 + this_header = 0; 1.676 + message = NULL; 1.677 + while (!message && len) { 1.678 ++#ifdef CONFIG_RD_LZMA 1.679 ++ int status; 1.680 ++#endif 1.681 + loff_t saved_offset = this_header; 1.682 + if (*buf == '0' && !(this_header & 3)) { 1.683 + state = Start; 1.684 +@@ -477,9 +515,42 @@ 1.685 + bytes_out = 0; 1.686 + crc = (ulg)0xffffffffL; /* shift register contents */ 1.687 + makecrc(); 1.688 +- gunzip(); 1.689 ++ if(!gunzip() && message == NULL) 1.690 ++ goto ok; 1.691 ++ 1.692 ++#ifdef CONFIG_RD_BZIP2 1.693 ++ message = NULL; /* Zero out message, or else cpio will 1.694 ++ think an error has already occured */ 1.695 ++ if(!bunzip2(buf, len, NULL, flush_buffer, &inptr) < 0 && 1.696 ++ message == NULL) { 1.697 ++ goto ok; 1.698 ++ } 1.699 ++#endif 1.700 ++ 1.701 ++#ifdef CONFIG_RD_LZMA 1.702 ++ message = NULL; /* Zero out message, or else cpio will 1.703 ++ think an error has already occured */ 1.704 ++ status = -1; 1.705 ++ if(buf == (char *) initrd_start) { 1.706 ++ char *work_buffer = malloc(LZMA_IOBUF_SIZE); 1.707 ++ if (work_buffer) { 1.708 ++ fill_total = fill_offset = 0; 1.709 ++ fill_buffer(work_buffer, LZMA_IOBUF_SIZE); 1.710 ++ status = unlzma(work_buffer, LZMA_IOBUF_SIZE, 1.711 ++ fill_buffer, flush_buffer, NULL); 1.712 ++ inptr = fill_total; 1.713 ++ free(work_buffer); 1.714 ++ } 1.715 ++ } 1.716 ++ else status = unlzma(buf,len, NULL, flush_buffer, &inptr); 1.717 ++ if (status == 0 && message == NULL) { 1.718 ++ goto ok; 1.719 ++ } 1.720 ++#endif 1.721 ++ ok: 1.722 ++ 1.723 + if (state != Reset) 1.724 +- error("junk in gzipped archive"); 1.725 ++ error("junk in compressed archive"); 1.726 + this_header = saved_offset + inptr; 1.727 + buf += inptr; 1.728 + len -= inptr; 1.729 +@@ -545,7 +616,7 @@ 1.730 + if (err) 1.731 + panic(err); 1.732 + if (initrd_start) { 1.733 +-#ifdef CONFIG_BLK_DEV_RAM 1.734 ++#ifdef NOT_IN_SLITAZ_CONFIG_BLK_DEV_RAM 1.735 + int fd; 1.736 + printk(KERN_INFO "checking if image is initramfs..."); 1.737 + err = unpack_to_rootfs((char *)initrd_start, 1.738 + 1.739 +--- linux-2.6.25.5/init/Kconfig 1.740 ++++ linux-2.6.25.5/init/Kconfig 1.741 +@@ -100,6 +100,56 @@ 1.742 + 1.743 + which is done within the script "scripts/setlocalversion".) 1.744 + 1.745 ++choice 1.746 ++ prompt "Kernel compression mode" 1.747 ++ default KERNEL_GZIP 1.748 ++ help 1.749 ++ The linux kernel is a kind of self-extracting executable. 1.750 ++ Several compression algorithms are available, which differ 1.751 ++ in efficiency, compression and decompression speed. 1.752 ++ Compression speed is only relevant when building a kernel. 1.753 ++ Decompression speed is relevant at each boot. 1.754 ++ 1.755 ++ If you have any problems with bzip2 or lzma compressed 1.756 ++ kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older 1.757 ++ version of this functionality (bzip2 only), for 2.4, was 1.758 ++ supplied by Christian Ludwig) 1.759 ++ 1.760 ++ High compression options are mostly useful for users, who 1.761 ++ are low on disk space (embedded systems), but for whom ram 1.762 ++ size matters less. 1.763 ++ 1.764 ++ If in doubt, select 'gzip' 1.765 ++ 1.766 ++config KERNEL_GZIP 1.767 ++ bool "Gzip" 1.768 ++ help 1.769 ++ The old and tries gzip compression. Its compression ratio is 1.770 ++ the poorest among the 3 choices; however its speed (both 1.771 ++ compression and decompression) is the fastest. 1.772 ++ 1.773 ++config KERNEL_BZIP2 1.774 ++ bool "Bzip2" 1.775 ++ help 1.776 ++ Its compression ratio and speed is intermediate. 1.777 ++ Decompression speed is slowest among the 3. 1.778 ++ The kernel size is about 10 per cent smaller with bzip2, 1.779 ++ in comparison to gzip. 1.780 ++ Bzip2 uses a large amount of memory. For modern kernels 1.781 ++ you will need at least 8MB RAM or more for booting. 1.782 ++ 1.783 ++config KERNEL_LZMA 1.784 ++ bool "LZMA" 1.785 ++ help 1.786 ++ The most recent compression algorithm. 1.787 ++ Its ratio is best, decompression speed is between the other 1.788 ++ 2. Compression is slowest. 1.789 ++ The kernel size is about 33 per cent smaller with lzma, 1.790 ++ in comparison to gzip. 1.791 ++ 1.792 ++endchoice 1.793 ++ 1.794 ++ 1.795 + config SWAP 1.796 + bool "Support for paging of anonymous memory (swap)" 1.797 + depends on MMU && BLOCK 1.798 + 1.799 +--- linux-2.6.25.5/lib/decompress_bunzip2.c 1.800 ++++ linux-2.6.25.5/lib/decompress_bunzip2.c 1.801 +@@ -0,0 +1,645 @@ 1.802 ++/* vi: set sw=4 ts=4: */ 1.803 ++/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). 1.804 ++ 1.805 ++ Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), 1.806 ++ which also acknowledges contributions by Mike Burrows, David Wheeler, 1.807 ++ Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten, 1.808 ++ Robert Sedgewick, and Jon L. Bentley. 1.809 ++ 1.810 ++ This code is licensed under the LGPLv2: 1.811 ++ LGPL (http://www.gnu.org/copyleft/lgpl.html 1.812 ++*/ 1.813 ++ 1.814 ++/* 1.815 ++ Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org). 1.816 ++ 1.817 ++ More efficient reading of Huffman codes, a streamlined read_bunzip() 1.818 ++ function, and various other tweaks. In (limited) tests, approximately 1.819 ++ 20% faster than bzcat on x86 and about 10% faster on arm. 1.820 ++ 1.821 ++ Note that about 2/3 of the time is spent in read_unzip() reversing 1.822 ++ the Burrows-Wheeler transformation. Much of that time is delay 1.823 ++ resulting from cache misses. 1.824 ++ 1.825 ++ I would ask that anyone benefiting from this work, especially those 1.826 ++ using it in commercial products, consider making a donation to my local 1.827 ++ non-profit hospice organization in the name of the woman I loved, who 1.828 ++ passed away Feb. 12, 2003. 1.829 ++ 1.830 ++ In memory of Toni W. Hagan 1.831 ++ 1.832 ++ Hospice of Acadiana, Inc. 1.833 ++ 2600 Johnston St., Suite 200 1.834 ++ Lafayette, LA 70503-3240 1.835 ++ 1.836 ++ Phone (337) 232-1234 or 1-800-738-2226 1.837 ++ Fax (337) 232-1297 1.838 ++ 1.839 ++ http://www.hospiceacadiana.com/ 1.840 ++ 1.841 ++ Manuel 1.842 ++ */ 1.843 ++ 1.844 ++/* 1.845 ++ Made it fit for running in Linux Kernel by Alain Knaff (alain@knaff.lu) 1.846 ++*/ 1.847 ++ 1.848 ++ 1.849 ++#ifndef STATIC 1.850 ++ 1.851 ++#include <linux/kernel.h> 1.852 ++#include <linux/fs.h> 1.853 ++#include <linux/string.h> 1.854 ++ 1.855 ++#ifdef TEST 1.856 ++#include "test.h" 1.857 ++#else 1.858 ++#include <linux/vmalloc.h> 1.859 ++#endif 1.860 ++ 1.861 ++static void __init *large_malloc(size_t size) 1.862 ++{ 1.863 ++ return vmalloc(size); 1.864 ++} 1.865 ++ 1.866 ++static void __init large_free(void *where) 1.867 ++{ 1.868 ++ vfree(where); 1.869 ++} 1.870 ++ 1.871 ++#ifndef TEST 1.872 ++static void __init *malloc(size_t size) 1.873 ++{ 1.874 ++ return kmalloc(size, GFP_KERNEL); 1.875 ++} 1.876 ++ 1.877 ++static void __init free(void *where) 1.878 ++{ 1.879 ++ kfree(where); 1.880 ++} 1.881 ++ 1.882 ++static void __init error(char *x) 1.883 ++{ 1.884 ++ printk(KERN_ERR "%s\n", x); 1.885 ++} 1.886 ++#endif 1.887 ++ 1.888 ++#define STATIC /**/ 1.889 ++ 1.890 ++#endif 1.891 ++ 1.892 ++#include <linux/decompress_bunzip2.h> 1.893 ++ 1.894 ++ 1.895 ++/* Constants for Huffman coding */ 1.896 ++#define MAX_GROUPS 6 1.897 ++#define GROUP_SIZE 50 /* 64 would have been more efficient */ 1.898 ++#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */ 1.899 ++#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */ 1.900 ++#define SYMBOL_RUNA 0 1.901 ++#define SYMBOL_RUNB 1 1.902 ++ 1.903 ++/* Status return values */ 1.904 ++#define RETVAL_OK 0 1.905 ++#define RETVAL_LAST_BLOCK (-1) 1.906 ++#define RETVAL_NOT_BZIP_DATA (-2) 1.907 ++#define RETVAL_UNEXPECTED_INPUT_EOF (-3) 1.908 ++#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4) 1.909 ++#define RETVAL_DATA_ERROR (-5) 1.910 ++#define RETVAL_OUT_OF_MEMORY (-6) 1.911 ++#define RETVAL_OBSOLETE_INPUT (-7) 1.912 ++ 1.913 ++ 1.914 ++/* This is what we know about each Huffman coding group */ 1.915 ++struct group_data { 1.916 ++ /* We have an extra slot at the end of limit[] for a sentinal value. */ 1.917 ++ int limit[MAX_HUFCODE_BITS+1],base[MAX_HUFCODE_BITS],permute[MAX_SYMBOLS]; 1.918 ++ int minLen, maxLen; 1.919 ++}; 1.920 ++ 1.921 ++/* Structure holding all the housekeeping data, including IO buffers and 1.922 ++ memory that persists between calls to bunzip */ 1.923 ++typedef struct { 1.924 ++ /* State for interrupting output loop */ 1.925 ++ int writeCopies,writePos,writeRunCountdown,writeCount,writeCurrent; 1.926 ++ /* I/O tracking data (file handles, buffers, positions, etc.) */ 1.927 ++ int (*fill)(void*,unsigned int); 1.928 ++ int inbufCount,inbufPos /*,outbufPos*/; 1.929 ++ unsigned char *inbuf /*,*outbuf*/; 1.930 ++ unsigned int inbufBitCount, inbufBits; 1.931 ++ /* The CRC values stored in the block header and calculated from the data */ 1.932 ++ unsigned int crc32Table[256],headerCRC, totalCRC, writeCRC; 1.933 ++ /* Intermediate buffer and its size (in bytes) */ 1.934 ++ unsigned int *dbuf, dbufSize; 1.935 ++ /* These things are a bit too big to go on the stack */ 1.936 ++ unsigned char selectors[32768]; /* nSelectors=15 bits */ 1.937 ++ struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ 1.938 ++ int io_error; /* non-zero if we have IO error */ 1.939 ++} bunzip_data; 1.940 ++ 1.941 ++ 1.942 ++/* Return the next nnn bits of input. All reads from the compressed input 1.943 ++ are done through this function. All reads are big endian */ 1.944 ++static unsigned int get_bits(bunzip_data *bd, char bits_wanted) 1.945 ++{ 1.946 ++ unsigned int bits=0; 1.947 ++ 1.948 ++ /* If we need to get more data from the byte buffer, do so. (Loop getting 1.949 ++ one byte at a time to enforce endianness and avoid unaligned access.) */ 1.950 ++ while (bd->inbufBitCount<bits_wanted) { 1.951 ++ /* If we need to read more data from file into byte buffer, do so */ 1.952 ++ if(bd->inbufPos==bd->inbufCount) { 1.953 ++ if(bd->io_error) 1.954 ++ return 0; 1.955 ++ if((bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE)) <= 0) { 1.956 ++ bd->io_error=RETVAL_UNEXPECTED_INPUT_EOF; 1.957 ++ return 0; 1.958 ++ } 1.959 ++ bd->inbufPos=0; 1.960 ++ } 1.961 ++ /* Avoid 32-bit overflow (dump bit buffer to top of output) */ 1.962 ++ if(bd->inbufBitCount>=24) { 1.963 ++ bits=bd->inbufBits&((1<<bd->inbufBitCount)-1); 1.964 ++ bits_wanted-=bd->inbufBitCount; 1.965 ++ bits<<=bits_wanted; 1.966 ++ bd->inbufBitCount=0; 1.967 ++ } 1.968 ++ /* Grab next 8 bits of input from buffer. */ 1.969 ++ bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++]; 1.970 ++ bd->inbufBitCount+=8; 1.971 ++ } 1.972 ++ /* Calculate result */ 1.973 ++ bd->inbufBitCount-=bits_wanted; 1.974 ++ bits|=(bd->inbufBits>>bd->inbufBitCount)&((1<<bits_wanted)-1); 1.975 ++ 1.976 ++ return bits; 1.977 ++} 1.978 ++ 1.979 ++/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */ 1.980 ++ 1.981 ++static int get_next_block(bunzip_data *bd) 1.982 ++{ 1.983 ++ struct group_data *hufGroup=NULL; 1.984 ++ int *base=NULL; 1.985 ++ int *limit=NULL; 1.986 ++ int dbufCount,nextSym,dbufSize,groupCount,selector, 1.987 ++ i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256]; 1.988 ++ unsigned char uc, symToByte[256], mtfSymbol[256], *selectors; 1.989 ++ unsigned int *dbuf,origPtr; 1.990 ++ 1.991 ++ dbuf=bd->dbuf; 1.992 ++ dbufSize=bd->dbufSize; 1.993 ++ selectors=bd->selectors; 1.994 ++ 1.995 ++ /* Read in header signature and CRC, then validate signature. 1.996 ++ (last block signature means CRC is for whole file, return now) */ 1.997 ++ i = get_bits(bd,24); 1.998 ++ j = get_bits(bd,24); 1.999 ++ bd->headerCRC=get_bits(bd,32); 1.1000 ++ if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK; 1.1001 ++ if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA; 1.1002 ++ /* We can add support for blockRandomised if anybody complains. There was 1.1003 ++ some code for this in busybox 1.0.0-pre3, but nobody ever noticed that 1.1004 ++ it didn't actually work. */ 1.1005 ++ if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT; 1.1006 ++ if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR; 1.1007 ++ /* mapping table: if some byte values are never used (encoding things 1.1008 ++ like ascii text), the compression code removes the gaps to have fewer 1.1009 ++ symbols to deal with, and writes a sparse bitfield indicating which 1.1010 ++ values were present. We make a translation table to convert the symbols 1.1011 ++ back to the corresponding bytes. */ 1.1012 ++ t=get_bits(bd, 16); 1.1013 ++ symTotal=0; 1.1014 ++ for (i=0;i<16;i++) { 1.1015 ++ if(t&(1<<(15-i))) { 1.1016 ++ k=get_bits(bd,16); 1.1017 ++ for(j=0;j<16;j++) 1.1018 ++ if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j; 1.1019 ++ } 1.1020 ++ } 1.1021 ++ /* How many different Huffman coding groups does this block use? */ 1.1022 ++ groupCount=get_bits(bd,3); 1.1023 ++ if (groupCount<2 || groupCount>MAX_GROUPS) return RETVAL_DATA_ERROR; 1.1024 ++ /* nSelectors: Every GROUP_SIZE many symbols we select a new Huffman coding 1.1025 ++ group. Read in the group selector list, which is stored as MTF encoded 1.1026 ++ bit runs. (MTF=Move To Front, as each value is used it's moved to the 1.1027 ++ start of the list.) */ 1.1028 ++ if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR; 1.1029 ++ for(i=0; i<groupCount; i++) mtfSymbol[i] = i; 1.1030 ++ for(i=0; i<nSelectors; i++) { 1.1031 ++ /* Get next value */ 1.1032 ++ for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR; 1.1033 ++ /* Decode MTF to get the next selector */ 1.1034 ++ uc = mtfSymbol[j]; 1.1035 ++ for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1]; 1.1036 ++ mtfSymbol[0]=selectors[i]=uc; 1.1037 ++ } 1.1038 ++ /* Read the Huffman coding tables for each group, which code for symTotal 1.1039 ++ literal symbols, plus two run symbols (RUNA, RUNB) */ 1.1040 ++ symCount=symTotal+2; 1.1041 ++ for (j=0; j<groupCount; j++) { 1.1042 ++ unsigned char length[MAX_SYMBOLS],temp[MAX_HUFCODE_BITS+1]; 1.1043 ++ int minLen, maxLen, pp; 1.1044 ++ /* Read Huffman code lengths for each symbol. They're stored in 1.1045 ++ a way similar to mtf; record a starting value for the first symbol, 1.1046 ++ and an offset from the previous value for everys symbol after that. 1.1047 ++ (Subtracting 1 before the loop and then adding it back at the end is 1.1048 ++ an optimization that makes the test inside the loop simpler: symbol 1.1049 ++ length 0 becomes negative, so an unsigned inequality catches it.) */ 1.1050 ++ t=get_bits(bd, 5)-1; 1.1051 ++ for (i = 0; i < symCount; i++) { 1.1052 ++ for(;;) { 1.1053 ++ if (((unsigned)t) > (MAX_HUFCODE_BITS-1)) 1.1054 ++ return RETVAL_DATA_ERROR; 1.1055 ++ /* If first bit is 0, stop. Else second bit indicates whether 1.1056 ++ to increment or decrement the value. Optimization: grab 2 1.1057 ++ bits and unget the second if the first was 0. */ 1.1058 ++ k = get_bits(bd,2); 1.1059 ++ if (k < 2) { 1.1060 ++ bd->inbufBitCount++; 1.1061 ++ break; 1.1062 ++ } 1.1063 ++ /* Add one if second bit 1, else subtract 1. Avoids if/else */ 1.1064 ++ t+=(((k+1)&2)-1); 1.1065 ++ } 1.1066 ++ /* Correct for the initial -1, to get the final symbol length */ 1.1067 ++ length[i]=t+1; 1.1068 ++ } 1.1069 ++ /* Find largest and smallest lengths in this group */ 1.1070 ++ minLen=maxLen=length[0]; 1.1071 ++ for(i = 1; i < symCount; i++) { 1.1072 ++ if(length[i] > maxLen) maxLen = length[i]; 1.1073 ++ else if(length[i] < minLen) minLen = length[i]; 1.1074 ++ } 1.1075 ++ /* Calculate permute[], base[], and limit[] tables from length[]. 1.1076 ++ * 1.1077 ++ * permute[] is the lookup table for converting Huffman coded symbols 1.1078 ++ * into decoded symbols. base[] is the amount to subtract from the 1.1079 ++ * value of a Huffman symbol of a given length when using permute[]. 1.1080 ++ * 1.1081 ++ * limit[] indicates the largest numerical value a symbol with a given 1.1082 ++ * number of bits can have. This is how the Huffman codes can vary in 1.1083 ++ * length: each code with a value>limit[length] needs another bit. 1.1084 ++ */ 1.1085 ++ hufGroup=bd->groups+j; 1.1086 ++ hufGroup->minLen = minLen; 1.1087 ++ hufGroup->maxLen = maxLen; 1.1088 ++ /* Note that minLen can't be smaller than 1, so we adjust the base 1.1089 ++ and limit array pointers so we're not always wasting the first 1.1090 ++ entry. We do this again when using them (during symbol decoding).*/ 1.1091 ++ base=hufGroup->base-1; 1.1092 ++ limit=hufGroup->limit-1; 1.1093 ++ /* Calculate permute[]. Concurently, initialize temp[] and limit[]. */ 1.1094 ++ pp=0; 1.1095 ++ for(i=minLen;i<=maxLen;i++) { 1.1096 ++ temp[i]=limit[i]=0; 1.1097 ++ for(t=0;t<symCount;t++) 1.1098 ++ if(length[t]==i) hufGroup->permute[pp++] = t; 1.1099 ++ } 1.1100 ++ /* Count symbols coded for at each bit length */ 1.1101 ++ for (i=0;i<symCount;i++) temp[length[i]]++; 1.1102 ++ /* Calculate limit[] (the largest symbol-coding value at each bit 1.1103 ++ * length, which is (previous limit<<1)+symbols at this level), and 1.1104 ++ * base[] (number of symbols to ignore at each bit length, which is 1.1105 ++ * limit minus the cumulative count of symbols coded for already). */ 1.1106 ++ pp=t=0; 1.1107 ++ for (i=minLen; i<maxLen; i++) { 1.1108 ++ pp+=temp[i]; 1.1109 ++ /* We read the largest possible symbol size and then unget bits 1.1110 ++ after determining how many we need, and those extra bits could 1.1111 ++ be set to anything. (They're noise from future symbols.) At 1.1112 ++ each level we're really only interested in the first few bits, 1.1113 ++ so here we set all the trailing to-be-ignored bits to 1 so they 1.1114 ++ don't affect the value>limit[length] comparison. */ 1.1115 ++ limit[i]= (pp << (maxLen - i)) - 1; 1.1116 ++ pp<<=1; 1.1117 ++ base[i+1]=pp-(t+=temp[i]); 1.1118 ++ } 1.1119 ++ limit[maxLen+1] = INT_MAX; /* Sentinal value for reading next sym. */ 1.1120 ++ limit[maxLen]=pp+temp[maxLen]-1; 1.1121 ++ base[minLen]=0; 1.1122 ++ } 1.1123 ++ /* We've finished reading and digesting the block header. Now read this 1.1124 ++ block's Huffman coded symbols from the file and undo the Huffman coding 1.1125 ++ and run length encoding, saving the result into dbuf[dbufCount++]=uc */ 1.1126 ++ 1.1127 ++ /* Initialize symbol occurrence counters and symbol Move To Front table */ 1.1128 ++ for(i=0;i<256;i++) { 1.1129 ++ byteCount[i] = 0; 1.1130 ++ mtfSymbol[i]=(unsigned char)i; 1.1131 ++ } 1.1132 ++ /* Loop through compressed symbols. */ 1.1133 ++ runPos=dbufCount=symCount=selector=0; 1.1134 ++ for(;;) { 1.1135 ++ /* Determine which Huffman coding group to use. */ 1.1136 ++ if(!(symCount--)) { 1.1137 ++ symCount=GROUP_SIZE-1; 1.1138 ++ if(selector>=nSelectors) return RETVAL_DATA_ERROR; 1.1139 ++ hufGroup=bd->groups+selectors[selector++]; 1.1140 ++ base=hufGroup->base-1; 1.1141 ++ limit=hufGroup->limit-1; 1.1142 ++ } 1.1143 ++ /* Read next Huffman-coded symbol. */ 1.1144 ++ /* Note: It is far cheaper to read maxLen bits and back up than it is 1.1145 ++ to read minLen bits and then an additional bit at a time, testing 1.1146 ++ as we go. Because there is a trailing last block (with file CRC), 1.1147 ++ there is no danger of the overread causing an unexpected EOF for a 1.1148 ++ valid compressed file. As a further optimization, we do the read 1.1149 ++ inline (falling back to a call to get_bits if the buffer runs 1.1150 ++ dry). The following (up to got_huff_bits:) is equivalent to 1.1151 ++ j=get_bits(bd,hufGroup->maxLen); 1.1152 ++ */ 1.1153 ++ while (bd->inbufBitCount<hufGroup->maxLen) { 1.1154 ++ if(bd->inbufPos==bd->inbufCount) { 1.1155 ++ j = get_bits(bd,hufGroup->maxLen); 1.1156 ++ goto got_huff_bits; 1.1157 ++ } 1.1158 ++ bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++]; 1.1159 ++ bd->inbufBitCount+=8; 1.1160 ++ }; 1.1161 ++ bd->inbufBitCount-=hufGroup->maxLen; 1.1162 ++ j = (bd->inbufBits>>bd->inbufBitCount)&((1<<hufGroup->maxLen)-1); 1.1163 ++got_huff_bits: 1.1164 ++ /* Figure how how many bits are in next symbol and unget extras */ 1.1165 ++ i=hufGroup->minLen; 1.1166 ++ while(j>limit[i]) ++i; 1.1167 ++ bd->inbufBitCount += (hufGroup->maxLen - i); 1.1168 ++ /* Huffman decode value to get nextSym (with bounds checking) */ 1.1169 ++ if ((i > hufGroup->maxLen) 1.1170 ++ || (((unsigned)(j=(j>>(hufGroup->maxLen-i))-base[i])) 1.1171 ++ >= MAX_SYMBOLS)) 1.1172 ++ return RETVAL_DATA_ERROR; 1.1173 ++ nextSym = hufGroup->permute[j]; 1.1174 ++ /* We have now decoded the symbol, which indicates either a new literal 1.1175 ++ byte, or a repeated run of the most recent literal byte. First, 1.1176 ++ check if nextSym indicates a repeated run, and if so loop collecting 1.1177 ++ how many times to repeat the last literal. */ 1.1178 ++ if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */ 1.1179 ++ /* If this is the start of a new run, zero out counter */ 1.1180 ++ if(!runPos) { 1.1181 ++ runPos = 1; 1.1182 ++ t = 0; 1.1183 ++ } 1.1184 ++ /* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at 1.1185 ++ each bit position, add 1 or 2 instead. For example, 1.1186 ++ 1011 is 1<<0 + 1<<1 + 2<<2. 1010 is 2<<0 + 2<<1 + 1<<2. 1.1187 ++ You can make any bit pattern that way using 1 less symbol than 1.1188 ++ the basic or 0/1 method (except all bits 0, which would use no 1.1189 ++ symbols, but a run of length 0 doesn't mean anything in this 1.1190 ++ context). Thus space is saved. */ 1.1191 ++ t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */ 1.1192 ++ runPos <<= 1; 1.1193 ++ continue; 1.1194 ++ } 1.1195 ++ /* When we hit the first non-run symbol after a run, we now know 1.1196 ++ how many times to repeat the last literal, so append that many 1.1197 ++ copies to our buffer of decoded symbols (dbuf) now. (The last 1.1198 ++ literal used is the one at the head of the mtfSymbol array.) */ 1.1199 ++ if(runPos) { 1.1200 ++ runPos=0; 1.1201 ++ if(dbufCount+t>=dbufSize) return RETVAL_DATA_ERROR; 1.1202 ++ 1.1203 ++ uc = symToByte[mtfSymbol[0]]; 1.1204 ++ byteCount[uc] += t; 1.1205 ++ while(t--) dbuf[dbufCount++]=uc; 1.1206 ++ } 1.1207 ++ /* Is this the terminating symbol? */ 1.1208 ++ if(nextSym>symTotal) break; 1.1209 ++ /* At this point, nextSym indicates a new literal character. Subtract 1.1210 ++ one to get the position in the MTF array at which this literal is 1.1211 ++ currently to be found. (Note that the result can't be -1 or 0, 1.1212 ++ because 0 and 1 are RUNA and RUNB. But another instance of the 1.1213 ++ first symbol in the mtf array, position 0, would have been handled 1.1214 ++ as part of a run above. Therefore 1 unused mtf position minus 1.1215 ++ 2 non-literal nextSym values equals -1.) */ 1.1216 ++ if(dbufCount>=dbufSize) return RETVAL_DATA_ERROR; 1.1217 ++ i = nextSym - 1; 1.1218 ++ uc = mtfSymbol[i]; 1.1219 ++ /* Adjust the MTF array. Since we typically expect to move only a 1.1220 ++ * small number of symbols, and are bound by 256 in any case, using 1.1221 ++ * memmove here would typically be bigger and slower due to function 1.1222 ++ * call overhead and other assorted setup costs. */ 1.1223 ++ do { 1.1224 ++ mtfSymbol[i] = mtfSymbol[i-1]; 1.1225 ++ } while (--i); 1.1226 ++ mtfSymbol[0] = uc; 1.1227 ++ uc=symToByte[uc]; 1.1228 ++ /* We have our literal byte. Save it into dbuf. */ 1.1229 ++ byteCount[uc]++; 1.1230 ++ dbuf[dbufCount++] = (unsigned int)uc; 1.1231 ++ } 1.1232 ++ /* At this point, we've read all the Huffman-coded symbols (and repeated 1.1233 ++ runs) for this block from the input stream, and decoded them into the 1.1234 ++ intermediate buffer. There are dbufCount many decoded bytes in dbuf[]. 1.1235 ++ Now undo the Burrows-Wheeler transform on dbuf. 1.1236 ++ See http://dogma.net/markn/articles/bwt/bwt.htm 1.1237 ++ */ 1.1238 ++ /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */ 1.1239 ++ j=0; 1.1240 ++ for(i=0;i<256;i++) { 1.1241 ++ k=j+byteCount[i]; 1.1242 ++ byteCount[i] = j; 1.1243 ++ j=k; 1.1244 ++ } 1.1245 ++ /* Figure out what order dbuf would be in if we sorted it. */ 1.1246 ++ for (i=0;i<dbufCount;i++) { 1.1247 ++ uc=(unsigned char)(dbuf[i] & 0xff); 1.1248 ++ dbuf[byteCount[uc]] |= (i << 8); 1.1249 ++ byteCount[uc]++; 1.1250 ++ } 1.1251 ++ /* Decode first byte by hand to initialize "previous" byte. Note that it 1.1252 ++ doesn't get output, and if the first three characters are identical 1.1253 ++ it doesn't qualify as a run (hence writeRunCountdown=5). */ 1.1254 ++ if(dbufCount) { 1.1255 ++ if(origPtr>=dbufCount) return RETVAL_DATA_ERROR; 1.1256 ++ bd->writePos=dbuf[origPtr]; 1.1257 ++ bd->writeCurrent=(unsigned char)(bd->writePos&0xff); 1.1258 ++ bd->writePos>>=8; 1.1259 ++ bd->writeRunCountdown=5; 1.1260 ++ } 1.1261 ++ bd->writeCount=dbufCount; 1.1262 ++ 1.1263 ++ return RETVAL_OK; 1.1264 ++} 1.1265 ++ 1.1266 ++/* Undo burrows-wheeler transform on intermediate buffer to produce output. 1.1267 ++ If start_bunzip was initialized with out_fd=-1, then up to len bytes of 1.1268 ++ data are written to outbuf. Return value is number of bytes written or 1.1269 ++ error (all errors are negative numbers). If out_fd!=-1, outbuf and len 1.1270 ++ are ignored, data is written to out_fd and return is RETVAL_OK or error. 1.1271 ++*/ 1.1272 ++ 1.1273 ++static int read_bunzip(bunzip_data *bd, char *outbuf, int len) 1.1274 ++{ 1.1275 ++ const unsigned int *dbuf; 1.1276 ++ int pos,xcurrent,previous,gotcount; 1.1277 ++ 1.1278 ++ /* If last read was short due to end of file, return last block now */ 1.1279 ++ if(bd->writeCount<0) return bd->writeCount; 1.1280 ++ 1.1281 ++ gotcount = 0; 1.1282 ++ dbuf=bd->dbuf; 1.1283 ++ pos=bd->writePos; 1.1284 ++ xcurrent=bd->writeCurrent; 1.1285 ++ 1.1286 ++ /* We will always have pending decoded data to write into the output 1.1287 ++ buffer unless this is the very first call (in which case we haven't 1.1288 ++ Huffman-decoded a block into the intermediate buffer yet). */ 1.1289 ++ 1.1290 ++ if (bd->writeCopies) { 1.1291 ++ /* Inside the loop, writeCopies means extra copies (beyond 1) */ 1.1292 ++ --bd->writeCopies; 1.1293 ++ /* Loop outputting bytes */ 1.1294 ++ for(;;) { 1.1295 ++ /* If the output buffer is full, snapshot state and return */ 1.1296 ++ if(gotcount >= len) { 1.1297 ++ bd->writePos=pos; 1.1298 ++ bd->writeCurrent=xcurrent; 1.1299 ++ bd->writeCopies++; 1.1300 ++ return len; 1.1301 ++ } 1.1302 ++ /* Write next byte into output buffer, updating CRC */ 1.1303 ++ outbuf[gotcount++] = xcurrent; 1.1304 ++ bd->writeCRC=(((bd->writeCRC)<<8) 1.1305 ++ ^bd->crc32Table[((bd->writeCRC)>>24)^xcurrent]); 1.1306 ++ /* Loop now if we're outputting multiple copies of this byte */ 1.1307 ++ if (bd->writeCopies) { 1.1308 ++ --bd->writeCopies; 1.1309 ++ continue; 1.1310 ++ } 1.1311 ++decode_next_byte: 1.1312 ++ if (!bd->writeCount--) break; 1.1313 ++ /* Follow sequence vector to undo Burrows-Wheeler transform */ 1.1314 ++ previous=xcurrent; 1.1315 ++ pos=dbuf[pos]; 1.1316 ++ xcurrent=pos&0xff; 1.1317 ++ pos>>=8; 1.1318 ++ /* After 3 consecutive copies of the same byte, the 4th is a repeat 1.1319 ++ count. We count down from 4 instead 1.1320 ++ * of counting up because testing for non-zero is faster */ 1.1321 ++ if(--bd->writeRunCountdown) { 1.1322 ++ if(xcurrent!=previous) bd->writeRunCountdown=4; 1.1323 ++ } else { 1.1324 ++ /* We have a repeated run, this byte indicates the count */ 1.1325 ++ bd->writeCopies=xcurrent; 1.1326 ++ xcurrent=previous; 1.1327 ++ bd->writeRunCountdown=5; 1.1328 ++ /* Sometimes there are just 3 bytes (run length 0) */ 1.1329 ++ if(!bd->writeCopies) goto decode_next_byte; 1.1330 ++ /* Subtract the 1 copy we'd output anyway to get extras */ 1.1331 ++ --bd->writeCopies; 1.1332 ++ } 1.1333 ++ } 1.1334 ++ /* Decompression of this block completed successfully */ 1.1335 ++ bd->writeCRC=~bd->writeCRC; 1.1336 ++ bd->totalCRC=((bd->totalCRC<<1) | (bd->totalCRC>>31)) ^ bd->writeCRC; 1.1337 ++ /* If this block had a CRC error, force file level CRC error. */ 1.1338 ++ if(bd->writeCRC!=bd->headerCRC) { 1.1339 ++ bd->totalCRC=bd->headerCRC+1; 1.1340 ++ return RETVAL_LAST_BLOCK; 1.1341 ++ } 1.1342 ++ } 1.1343 ++ 1.1344 ++ /* Refill the intermediate buffer by Huffman-decoding next block of input */ 1.1345 ++ /* (previous is just a convenient unused temp variable here) */ 1.1346 ++ previous=get_next_block(bd); 1.1347 ++ if(previous) { 1.1348 ++ bd->writeCount=previous; 1.1349 ++ return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount; 1.1350 ++ } 1.1351 ++ bd->writeCRC=0xffffffffUL; 1.1352 ++ pos=bd->writePos; 1.1353 ++ xcurrent=bd->writeCurrent; 1.1354 ++ goto decode_next_byte; 1.1355 ++} 1.1356 ++ 1.1357 ++static int nofill(void *buf,unsigned int len) { 1.1358 ++ return -1; 1.1359 ++} 1.1360 ++ 1.1361 ++/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain 1.1362 ++ a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are 1.1363 ++ ignored, and data is read from file handle into temporary buffer. */ 1.1364 ++static int start_bunzip(bunzip_data **bdp, void *inbuf, int len, 1.1365 ++ int (*fill)(void*,unsigned int)) 1.1366 ++{ 1.1367 ++ bunzip_data *bd; 1.1368 ++ unsigned int i,j,c; 1.1369 ++ const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16) 1.1370 ++ +(((unsigned int)'h')<<8)+(unsigned int)'0'; 1.1371 ++ 1.1372 ++ /* Figure out how much data to allocate */ 1.1373 ++ i=sizeof(bunzip_data); 1.1374 ++ 1.1375 ++ /* Allocate bunzip_data. Most fields initialize to zero. */ 1.1376 ++ bd=*bdp=malloc(i); 1.1377 ++ memset(bd,0,sizeof(bunzip_data)); 1.1378 ++ /* Setup input buffer */ 1.1379 ++ bd->inbuf=inbuf; 1.1380 ++ bd->inbufCount=len; 1.1381 ++ if(fill != NULL) 1.1382 ++ bd->fill=fill; 1.1383 ++ else 1.1384 ++ bd->fill=nofill; 1.1385 ++ 1.1386 ++ /* Init the CRC32 table (big endian) */ 1.1387 ++ for(i=0;i<256;i++) { 1.1388 ++ c=i<<24; 1.1389 ++ for(j=8;j;j--) 1.1390 ++ c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1); 1.1391 ++ bd->crc32Table[i]=c; 1.1392 ++ } 1.1393 ++ 1.1394 ++ /* Ensure that file starts with "BZh['1'-'9']." */ 1.1395 ++ i = get_bits(bd,32); 1.1396 ++ if (((unsigned int)(i-BZh0-1)) >= 9) return RETVAL_NOT_BZIP_DATA; 1.1397 ++ 1.1398 ++ /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of 1.1399 ++ uncompressed data. Allocate intermediate buffer for block. */ 1.1400 ++ bd->dbufSize=100000*(i-BZh0); 1.1401 ++ 1.1402 ++ bd->dbuf=large_malloc(bd->dbufSize * sizeof(int)); 1.1403 ++ return RETVAL_OK; 1.1404 ++} 1.1405 ++ 1.1406 ++/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data, 1.1407 ++ not end of file.) */ 1.1408 ++STATIC int bunzip2(char *inbuf, int len, 1.1409 ++ int(*fill)(void*,unsigned int), 1.1410 ++ int(*writebb)(char*,unsigned int), 1.1411 ++ int *pos) 1.1412 ++{ 1.1413 ++ char *outbuf; 1.1414 ++ bunzip_data *bd; 1.1415 ++ int i; 1.1416 ++ 1.1417 ++ outbuf=malloc(BZIP2_IOBUF_SIZE); 1.1418 ++ if(!(i=start_bunzip(&bd,inbuf,len,fill))) { 1.1419 ++ for(;;) { 1.1420 ++ if((i=read_bunzip(bd,outbuf,BZIP2_IOBUF_SIZE)) <= 0) break; 1.1421 ++ if(i!=writebb(outbuf,i)) { 1.1422 ++ i=RETVAL_UNEXPECTED_OUTPUT_EOF; 1.1423 ++ break; 1.1424 ++ } 1.1425 ++ } 1.1426 ++ } 1.1427 ++ /* Check CRC and release memory */ 1.1428 ++ if(i==RETVAL_LAST_BLOCK) { 1.1429 ++ if (bd->headerCRC!=bd->totalCRC) { 1.1430 ++ error("Data integrity error when decompressing."); 1.1431 ++ } else { 1.1432 ++ i=RETVAL_OK; 1.1433 ++ } 1.1434 ++ } 1.1435 ++ else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { 1.1436 ++ error("Compressed file ends unexpectedly"); 1.1437 ++ } 1.1438 ++ if(bd->dbuf) large_free(bd->dbuf); 1.1439 ++ if(pos) 1.1440 ++ *pos = bd->inbufPos; 1.1441 ++ free(bd); 1.1442 ++ free(outbuf); 1.1443 ++ 1.1444 ++ return i; 1.1445 ++} 1.1446 ++ 1.1447 + 1.1448 +--- linux-2.6.25.5/lib/decompress_unlzma.c 1.1449 ++++ linux-2.6.25.5/lib/decompress_unlzma.c 1.1450 +@@ -0,0 +1,607 @@ 1.1451 ++/* Lzma decompressor for Linux kernel. Shamelessly snarfed 1.1452 ++ * from busybox 1.1.1 1.1453 ++ * 1.1454 ++ * Linux kernel adaptation 1.1455 ++ * Copyright (C) 2006 Alain <alain@knaff.lu> 1.1456 ++ * 1.1457 ++ * Based on small lzma deflate implementation/Small range coder 1.1458 ++ * implementation for lzma. 1.1459 ++ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> 1.1460 ++ * 1.1461 ++ * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/) 1.1462 ++ * Copyright (C) 1999-2005 Igor Pavlov 1.1463 ++ * 1.1464 ++ * Copyrights of the parts, see headers below. 1.1465 ++ * 1.1466 ++ * 1.1467 ++ * This program is free software; you can redistribute it and/or 1.1468 ++ * modify it under the terms of the GNU Lesser General Public 1.1469 ++ * License as published by the Free Software Foundation; either 1.1470 ++ * version 2.1 of the License, or (at your option) any later version. 1.1471 ++ * 1.1472 ++ * This program is distributed in the hope that it will be useful, 1.1473 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.1474 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.1475 ++ * Lesser General Public License for more details. 1.1476 ++ * 1.1477 ++ * You should have received a copy of the GNU Lesser General Public 1.1478 ++ * License along with this library; if not, write to the Free Software 1.1479 ++ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1.1480 ++ */ 1.1481 ++ 1.1482 ++#ifndef STATIC 1.1483 ++ 1.1484 ++#include <linux/kernel.h> 1.1485 ++#include <linux/fs.h> 1.1486 ++#include <linux/string.h> 1.1487 ++ 1.1488 ++#ifdef TEST 1.1489 ++#include "test.h" 1.1490 ++#else 1.1491 ++#include <linux/vmalloc.h> 1.1492 ++#endif 1.1493 ++ 1.1494 ++static void __init *large_malloc(size_t size) 1.1495 ++{ 1.1496 ++ return vmalloc(size); 1.1497 ++} 1.1498 ++ 1.1499 ++static void __init large_free(void *where) 1.1500 ++{ 1.1501 ++ vfree(where); 1.1502 ++} 1.1503 ++ 1.1504 ++#ifndef TEST 1.1505 ++static void __init error(char *x) 1.1506 ++{ 1.1507 ++ printk(KERN_ERR "%s\n", x); 1.1508 ++} 1.1509 ++ 1.1510 ++#endif 1.1511 ++ 1.1512 ++#define STATIC /**/ 1.1513 ++ 1.1514 ++#endif 1.1515 ++ 1.1516 ++#define CONFIG_FEATURE_LZMA_FAST 1.1517 ++#include <linux/decompress_unlzma.h> 1.1518 ++ 1.1519 ++#define MIN(a,b) (((a)<(b))?(a):(b)) 1.1520 ++ 1.1521 ++static long long read_int(unsigned char *ptr, int size) 1.1522 ++{ 1.1523 ++ int i; 1.1524 ++ long long ret=0; 1.1525 ++ 1.1526 ++ for(i=0; i<size; i++) { 1.1527 ++ ret = (ret << 8) | ptr[size-i-1]; 1.1528 ++ } 1.1529 ++ return ret; 1.1530 ++} 1.1531 ++ 1.1532 ++#define ENDIAN_CONVERT(x) x=(typeof(x))read_int((unsigned char*)&x,sizeof(x)) 1.1533 ++ 1.1534 ++ 1.1535 ++/* Small range coder implementation for lzma. 1.1536 ++ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> 1.1537 ++ * 1.1538 ++ * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/) 1.1539 ++ * Copyright (c) 1999-2005 Igor Pavlov 1.1540 ++ */ 1.1541 ++ 1.1542 ++#ifndef always_inline 1.1543 ++# if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >0) 1.1544 ++# define always_inline __attribute__((always_inline)) inline 1.1545 ++# else 1.1546 ++# define always_inline inline 1.1547 ++# endif 1.1548 ++#endif 1.1549 ++ 1.1550 ++#ifdef CONFIG_FEATURE_LZMA_FAST 1.1551 ++# define speed_inline always_inline 1.1552 ++#else 1.1553 ++# define speed_inline 1.1554 ++#endif 1.1555 ++ 1.1556 ++ 1.1557 ++typedef struct { 1.1558 ++ int (*fill)(void*,unsigned int); 1.1559 ++ uint8_t *ptr; 1.1560 ++ uint8_t *buffer; 1.1561 ++ uint8_t *buffer_end; 1.1562 ++ int buffer_size; 1.1563 ++ uint32_t code; 1.1564 ++ uint32_t range; 1.1565 ++ uint32_t bound; 1.1566 ++} rc_t; 1.1567 ++ 1.1568 ++ 1.1569 ++#define RC_TOP_BITS 24 1.1570 ++#define RC_MOVE_BITS 5 1.1571 ++#define RC_MODEL_TOTAL_BITS 11 1.1572 ++ 1.1573 ++ 1.1574 ++/* Called twice: once at startup and once in rc_normalize() */ 1.1575 ++static void rc_read(rc_t * rc) 1.1576 ++{ 1.1577 ++ rc->buffer_size = rc->fill((char*)rc->buffer, LZMA_IOBUF_SIZE); 1.1578 ++ if (rc->buffer_size <= 0) 1.1579 ++ error("unexpected EOF"); 1.1580 ++ rc->ptr = rc->buffer; 1.1581 ++ rc->buffer_end = rc->buffer + rc->buffer_size; 1.1582 ++} 1.1583 ++ 1.1584 ++/* Called once */ 1.1585 ++static always_inline void rc_init(rc_t * rc, int (*fill)(void*,unsigned int), 1.1586 ++ char *buffer, int buffer_size) 1.1587 ++{ 1.1588 ++ rc->fill = fill; 1.1589 ++ rc->buffer = (uint8_t *)buffer; 1.1590 ++ rc->buffer_size = buffer_size; 1.1591 ++ rc->buffer_end = rc->buffer + rc->buffer_size; 1.1592 ++ rc->ptr = rc->buffer; 1.1593 ++ 1.1594 ++ rc->code = 0; 1.1595 ++ rc->range = 0xFFFFFFFF; 1.1596 ++} 1.1597 ++ 1.1598 ++static always_inline void rc_init_code(rc_t * rc) 1.1599 ++{ 1.1600 ++ int i; 1.1601 ++ 1.1602 ++ for (i = 0; i < 5; i++) { 1.1603 ++ if (rc->ptr >= rc->buffer_end) 1.1604 ++ rc_read(rc); 1.1605 ++ rc->code = (rc->code << 8) | *rc->ptr++; 1.1606 ++ } 1.1607 ++} 1.1608 ++ 1.1609 ++/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */ 1.1610 ++static void rc_do_normalize(rc_t * rc) 1.1611 ++{ 1.1612 ++ if (rc->ptr >= rc->buffer_end) 1.1613 ++ rc_read(rc); 1.1614 ++ rc->range <<= 8; 1.1615 ++ rc->code = (rc->code << 8) | *rc->ptr++; 1.1616 ++} 1.1617 ++static always_inline void rc_normalize(rc_t * rc) 1.1618 ++{ 1.1619 ++ if (rc->range < (1 << RC_TOP_BITS)) { 1.1620 ++ rc_do_normalize(rc); 1.1621 ++ } 1.1622 ++} 1.1623 ++ 1.1624 ++/* Called 9 times */ 1.1625 ++/* Why rc_is_bit_0_helper exists? 1.1626 ++ * Because we want to always expose (rc->code < rc->bound) to optimizer 1.1627 ++ */ 1.1628 ++static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p) 1.1629 ++{ 1.1630 ++ rc_normalize(rc); 1.1631 ++ rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS); 1.1632 ++ return rc->bound; 1.1633 ++} 1.1634 ++static always_inline int rc_is_bit_0(rc_t * rc, uint16_t * p) 1.1635 ++{ 1.1636 ++ uint32_t t = rc_is_bit_0_helper(rc, p); 1.1637 ++ return rc->code < t; 1.1638 ++} 1.1639 ++ 1.1640 ++/* Called ~10 times, but very small, thus inlined */ 1.1641 ++static speed_inline void rc_update_bit_0(rc_t * rc, uint16_t * p) 1.1642 ++{ 1.1643 ++ rc->range = rc->bound; 1.1644 ++ *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS; 1.1645 ++} 1.1646 ++static speed_inline void rc_update_bit_1(rc_t * rc, uint16_t * p) 1.1647 ++{ 1.1648 ++ rc->range -= rc->bound; 1.1649 ++ rc->code -= rc->bound; 1.1650 ++ *p -= *p >> RC_MOVE_BITS; 1.1651 ++} 1.1652 ++ 1.1653 ++/* Called 4 times in unlzma loop */ 1.1654 ++static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol) 1.1655 ++{ 1.1656 ++ if (rc_is_bit_0(rc, p)) { 1.1657 ++ rc_update_bit_0(rc, p); 1.1658 ++ *symbol *= 2; 1.1659 ++ return 0; 1.1660 ++ } else { 1.1661 ++ rc_update_bit_1(rc, p); 1.1662 ++ *symbol = *symbol * 2 + 1; 1.1663 ++ return 1; 1.1664 ++ } 1.1665 ++} 1.1666 ++ 1.1667 ++/* Called once */ 1.1668 ++static always_inline int rc_direct_bit(rc_t * rc) 1.1669 ++{ 1.1670 ++ rc_normalize(rc); 1.1671 ++ rc->range >>= 1; 1.1672 ++ if (rc->code >= rc->range) { 1.1673 ++ rc->code -= rc->range; 1.1674 ++ return 1; 1.1675 ++ } 1.1676 ++ return 0; 1.1677 ++} 1.1678 ++ 1.1679 ++/* Called twice */ 1.1680 ++static speed_inline void 1.1681 ++rc_bit_tree_decode(rc_t * rc, uint16_t * p, int num_levels, int *symbol) 1.1682 ++{ 1.1683 ++ int i = num_levels; 1.1684 ++ 1.1685 ++ *symbol = 1; 1.1686 ++ while (i--) 1.1687 ++ rc_get_bit(rc, p + *symbol, symbol); 1.1688 ++ *symbol -= 1 << num_levels; 1.1689 ++} 1.1690 ++ 1.1691 ++ 1.1692 ++/* 1.1693 ++ * Small lzma deflate implementation. 1.1694 ++ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> 1.1695 ++ * 1.1696 ++ * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/) 1.1697 ++ * Copyright (C) 1999-2005 Igor Pavlov 1.1698 ++ */ 1.1699 ++ 1.1700 ++ 1.1701 ++typedef struct { 1.1702 ++ uint8_t pos; 1.1703 ++ uint32_t dict_size; 1.1704 ++ uint64_t dst_size; 1.1705 ++} __attribute__ ((packed)) lzma_header_t; 1.1706 ++ 1.1707 ++ 1.1708 ++#define LZMA_BASE_SIZE 1846 1.1709 ++#define LZMA_LIT_SIZE 768 1.1710 ++ 1.1711 ++#define LZMA_NUM_POS_BITS_MAX 4 1.1712 ++ 1.1713 ++#define LZMA_LEN_NUM_LOW_BITS 3 1.1714 ++#define LZMA_LEN_NUM_MID_BITS 3 1.1715 ++#define LZMA_LEN_NUM_HIGH_BITS 8 1.1716 ++ 1.1717 ++#define LZMA_LEN_CHOICE 0 1.1718 ++#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1) 1.1719 ++#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1) 1.1720 ++#define LZMA_LEN_MID (LZMA_LEN_LOW \ 1.1721 ++ + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS))) 1.1722 ++#define LZMA_LEN_HIGH (LZMA_LEN_MID \ 1.1723 ++ +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS))) 1.1724 ++#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS)) 1.1725 ++ 1.1726 ++#define LZMA_NUM_STATES 12 1.1727 ++#define LZMA_NUM_LIT_STATES 7 1.1728 ++ 1.1729 ++#define LZMA_START_POS_MODEL_INDEX 4 1.1730 ++#define LZMA_END_POS_MODEL_INDEX 14 1.1731 ++#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1)) 1.1732 ++ 1.1733 ++#define LZMA_NUM_POS_SLOT_BITS 6 1.1734 ++#define LZMA_NUM_LEN_TO_POS_STATES 4 1.1735 ++ 1.1736 ++#define LZMA_NUM_ALIGN_BITS 4 1.1737 ++ 1.1738 ++#define LZMA_MATCH_MIN_LEN 2 1.1739 ++ 1.1740 ++#define LZMA_IS_MATCH 0 1.1741 ++#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX)) 1.1742 ++#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES) 1.1743 ++#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES) 1.1744 ++#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES) 1.1745 ++#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES) 1.1746 ++#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \ 1.1747 ++ + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)) 1.1748 ++#define LZMA_SPEC_POS (LZMA_POS_SLOT \ 1.1749 ++ +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS)) 1.1750 ++#define LZMA_ALIGN (LZMA_SPEC_POS \ 1.1751 ++ + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX) 1.1752 ++#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS)) 1.1753 ++#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS) 1.1754 ++#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS) 1.1755 ++ 1.1756 ++ 1.1757 ++STATIC int unlzma(char *inbuf, int in_len, 1.1758 ++ int(*fill)(void*,unsigned int), 1.1759 ++ int(*writebb)(char*,unsigned int), 1.1760 ++ int *posp) 1.1761 ++{ 1.1762 ++ lzma_header_t header; 1.1763 ++ int lc, pb, lp; 1.1764 ++ uint32_t pos_state_mask; 1.1765 ++ uint32_t literal_pos_mask; 1.1766 ++ uint32_t pos; 1.1767 ++ uint16_t *p; 1.1768 ++ uint16_t *prob; 1.1769 ++ uint16_t *prob_lit; 1.1770 ++ int num_bits; 1.1771 ++ int num_probs; 1.1772 ++ rc_t rc; 1.1773 ++ int i, mi; 1.1774 ++ uint8_t *buffer; 1.1775 ++ uint8_t previous_byte = 0; 1.1776 ++ size_t buffer_pos = 0, global_pos = 0; 1.1777 ++ int len = 0; 1.1778 ++ int state = 0; 1.1779 ++ int bufsize; 1.1780 ++ uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 1.1781 ++ 1.1782 ++ rc_init(&rc, fill, inbuf, in_len); 1.1783 ++ 1.1784 ++ header.dict_size = header.dst_size = in_len; 1.1785 ++ if (inbuf && in_len > 0 && inbuf[0] == 0) { 1.1786 ++ const int LZMA_LC = 3, LZMA_LP = 0, LZMA_PB = 2; 1.1787 ++ header.pos = (LZMA_PB * 45) + (LZMA_LP * 5) + LZMA_LC; 1.1788 ++ rc.ptr++; 1.1789 ++ } 1.1790 ++ else { 1.1791 ++ int hdrsize = sizeof(header); 1.1792 ++ if (inbuf && in_len > 12 && 1.1793 ++ (1 + * (unsigned long *) &inbuf[9]) > 1U) 1.1794 ++ hdrsize = 5; 1.1795 ++ for (i = 0; i < hdrsize; i++) { 1.1796 ++ if (rc.ptr >= rc.buffer_end) 1.1797 ++ rc_read(&rc); 1.1798 ++ ((unsigned char *)&header)[i] = *rc.ptr++; 1.1799 ++ } 1.1800 ++ } 1.1801 ++ 1.1802 ++ if (header.pos >= (9 * 5 * 5)) 1.1803 ++ error("bad header"); 1.1804 ++ 1.1805 ++ mi = header.pos / 9; 1.1806 ++ lc = header.pos % 9; 1.1807 ++ pb = mi / 5; 1.1808 ++ lp = mi % 5; 1.1809 ++ pos_state_mask = (1 << pb) - 1; 1.1810 ++ literal_pos_mask = (1 << lp) - 1; 1.1811 ++ 1.1812 ++ ENDIAN_CONVERT(header.dict_size); 1.1813 ++ ENDIAN_CONVERT(header.dst_size); 1.1814 ++ 1.1815 ++ if (header.dict_size == 0) 1.1816 ++ header.dict_size = 1; 1.1817 ++ 1.1818 ++ bufsize = MIN(header.dst_size, header.dict_size); 1.1819 ++ buffer = (uint8_t *) posp; 1.1820 ++ if (writebb) buffer = large_malloc(bufsize); 1.1821 ++ if(buffer == NULL) 1.1822 ++ return -1; 1.1823 ++ 1.1824 ++ num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 1.1825 ++ p = large_malloc(num_probs * sizeof(*p)); 1.1826 ++ num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp)); 1.1827 ++ for (i = 0; i < num_probs; i++) 1.1828 ++ p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 1.1829 ++ 1.1830 ++ rc_init_code(&rc); 1.1831 ++ 1.1832 ++ while (global_pos + buffer_pos < header.dst_size) { 1.1833 ++ int pos_state = (buffer_pos + global_pos) & pos_state_mask; 1.1834 ++ 1.1835 ++ prob = 1.1836 ++ p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state; 1.1837 ++ if (rc_is_bit_0(&rc, prob)) { 1.1838 ++ mi = 1; 1.1839 ++ rc_update_bit_0(&rc, prob); 1.1840 ++ prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE 1.1841 ++ * ((((buffer_pos + global_pos) & literal_pos_mask) << lc) 1.1842 ++ + (previous_byte >> (8 - lc))))); 1.1843 ++ 1.1844 ++ if (state >= LZMA_NUM_LIT_STATES) { 1.1845 ++ int match_byte; 1.1846 ++ 1.1847 ++ pos = buffer_pos - rep0; 1.1848 ++ if (writebb) { 1.1849 ++ while (pos >= header.dict_size) 1.1850 ++ pos += header.dict_size; 1.1851 ++ if(pos >= bufsize) { 1.1852 ++ goto fail; 1.1853 ++ } 1.1854 ++ } 1.1855 ++ match_byte = buffer[pos]; 1.1856 ++ do { 1.1857 ++ int bit; 1.1858 ++ 1.1859 ++ match_byte <<= 1; 1.1860 ++ bit = match_byte & 0x100; 1.1861 ++ prob_lit = prob + 0x100 + bit + mi; 1.1862 ++ if (rc_get_bit(&rc, prob_lit, &mi)) { 1.1863 ++ if (!bit) 1.1864 ++ break; 1.1865 ++ } else { 1.1866 ++ if (bit) 1.1867 ++ break; 1.1868 ++ } 1.1869 ++ } while (mi < 0x100); 1.1870 ++ } 1.1871 ++ while (mi < 0x100) { 1.1872 ++ prob_lit = prob + mi; 1.1873 ++ rc_get_bit(&rc, prob_lit, &mi); 1.1874 ++ } 1.1875 ++ previous_byte = (uint8_t) mi; 1.1876 ++ if (state < 4) 1.1877 ++ state = 0; 1.1878 ++ else if (state < 10) 1.1879 ++ state -= 3; 1.1880 ++ else 1.1881 ++ state -= 6; 1.1882 ++ goto store_previous_byte; 1.1883 ++ } else { 1.1884 ++ int offset; 1.1885 ++ uint16_t *prob_len; 1.1886 ++ 1.1887 ++ rc_update_bit_1(&rc, prob); 1.1888 ++ prob = p + LZMA_IS_REP + state; 1.1889 ++ if (rc_is_bit_0(&rc, prob)) { 1.1890 ++ rc_update_bit_0(&rc, prob); 1.1891 ++ rep3 = rep2; 1.1892 ++ rep2 = rep1; 1.1893 ++ rep1 = rep0; 1.1894 ++ state = state < LZMA_NUM_LIT_STATES ? 0 : 3; 1.1895 ++ prob = p + LZMA_LEN_CODER; 1.1896 ++ } else { 1.1897 ++ rc_update_bit_1(&rc, prob); 1.1898 ++ prob = p + LZMA_IS_REP_G0 + state; 1.1899 ++ if (rc_is_bit_0(&rc, prob)) { 1.1900 ++ rc_update_bit_0(&rc, prob); 1.1901 ++ prob = (p + LZMA_IS_REP_0_LONG 1.1902 ++ + (state << LZMA_NUM_POS_BITS_MAX) + pos_state); 1.1903 ++ if (rc_is_bit_0(&rc, prob)) { 1.1904 ++ rc_update_bit_0(&rc, prob); 1.1905 ++ 1.1906 ++ state = state < LZMA_NUM_LIT_STATES ? 9 : 11; 1.1907 ++ pos = buffer_pos - rep0; 1.1908 ++ if (writebb) { 1.1909 ++ while (pos >= header.dict_size) 1.1910 ++ pos += header.dict_size; 1.1911 ++ if(pos >= bufsize) { 1.1912 ++ goto fail; 1.1913 ++ } 1.1914 ++ } 1.1915 ++ previous_byte = buffer[pos]; 1.1916 ++ store_previous_byte: 1.1917 ++ buffer[buffer_pos++] = previous_byte; 1.1918 ++ if (writebb && buffer_pos == header.dict_size) { 1.1919 ++ buffer_pos = 0; 1.1920 ++ global_pos += header.dict_size; 1.1921 ++ writebb((char*)buffer, header.dict_size); 1.1922 ++ } 1.1923 ++ continue; 1.1924 ++ } else { 1.1925 ++ rc_update_bit_1(&rc, prob); 1.1926 ++ } 1.1927 ++ } else { 1.1928 ++ uint32_t distance; 1.1929 ++ 1.1930 ++ rc_update_bit_1(&rc, prob); 1.1931 ++ prob = p + LZMA_IS_REP_G1 + state; 1.1932 ++ if (rc_is_bit_0(&rc, prob)) { 1.1933 ++ rc_update_bit_0(&rc, prob); 1.1934 ++ distance = rep1; 1.1935 ++ } else { 1.1936 ++ rc_update_bit_1(&rc, prob); 1.1937 ++ prob = p + LZMA_IS_REP_G2 + state; 1.1938 ++ if (rc_is_bit_0(&rc, prob)) { 1.1939 ++ rc_update_bit_0(&rc, prob); 1.1940 ++ distance = rep2; 1.1941 ++ } else { 1.1942 ++ rc_update_bit_1(&rc, prob); 1.1943 ++ distance = rep3; 1.1944 ++ rep3 = rep2; 1.1945 ++ } 1.1946 ++ rep2 = rep1; 1.1947 ++ } 1.1948 ++ rep1 = rep0; 1.1949 ++ rep0 = distance; 1.1950 ++ } 1.1951 ++ state = state < LZMA_NUM_LIT_STATES ? 8 : 11; 1.1952 ++ prob = p + LZMA_REP_LEN_CODER; 1.1953 ++ } 1.1954 ++ 1.1955 ++ prob_len = prob + LZMA_LEN_CHOICE; 1.1956 ++ if (rc_is_bit_0(&rc, prob_len)) { 1.1957 ++ rc_update_bit_0(&rc, prob_len); 1.1958 ++ prob_len = (prob + LZMA_LEN_LOW 1.1959 ++ + (pos_state << LZMA_LEN_NUM_LOW_BITS)); 1.1960 ++ offset = 0; 1.1961 ++ num_bits = LZMA_LEN_NUM_LOW_BITS; 1.1962 ++ } else { 1.1963 ++ rc_update_bit_1(&rc, prob_len); 1.1964 ++ prob_len = prob + LZMA_LEN_CHOICE_2; 1.1965 ++ if (rc_is_bit_0(&rc, prob_len)) { 1.1966 ++ rc_update_bit_0(&rc, prob_len); 1.1967 ++ prob_len = (prob + LZMA_LEN_MID 1.1968 ++ + (pos_state << LZMA_LEN_NUM_MID_BITS)); 1.1969 ++ offset = 1 << LZMA_LEN_NUM_LOW_BITS; 1.1970 ++ num_bits = LZMA_LEN_NUM_MID_BITS; 1.1971 ++ } else { 1.1972 ++ rc_update_bit_1(&rc, prob_len); 1.1973 ++ prob_len = prob + LZMA_LEN_HIGH; 1.1974 ++ offset = ((1 << LZMA_LEN_NUM_LOW_BITS) 1.1975 ++ + (1 << LZMA_LEN_NUM_MID_BITS)); 1.1976 ++ num_bits = LZMA_LEN_NUM_HIGH_BITS; 1.1977 ++ } 1.1978 ++ } 1.1979 ++ rc_bit_tree_decode(&rc, prob_len, num_bits, &len); 1.1980 ++ len += offset; 1.1981 ++ 1.1982 ++ if (state < 4) { 1.1983 ++ int pos_slot; 1.1984 ++ 1.1985 ++ state += LZMA_NUM_LIT_STATES; 1.1986 ++ prob = 1.1987 ++ p + LZMA_POS_SLOT + 1.1988 ++ ((len < 1.1989 ++ LZMA_NUM_LEN_TO_POS_STATES ? len : 1.1990 ++ LZMA_NUM_LEN_TO_POS_STATES - 1) 1.1991 ++ << LZMA_NUM_POS_SLOT_BITS); 1.1992 ++ rc_bit_tree_decode(&rc, prob, LZMA_NUM_POS_SLOT_BITS, 1.1993 ++ &pos_slot); 1.1994 ++ if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { 1.1995 ++ num_bits = (pos_slot >> 1) - 1; 1.1996 ++ rep0 = 2 | (pos_slot & 1); 1.1997 ++ if (pos_slot < LZMA_END_POS_MODEL_INDEX) { 1.1998 ++ rep0 <<= num_bits; 1.1999 ++ prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1; 1.2000 ++ } else { 1.2001 ++ num_bits -= LZMA_NUM_ALIGN_BITS; 1.2002 ++ while (num_bits--) 1.2003 ++ rep0 = (rep0 << 1) | rc_direct_bit(&rc); 1.2004 ++ prob = p + LZMA_ALIGN; 1.2005 ++ rep0 <<= LZMA_NUM_ALIGN_BITS; 1.2006 ++ num_bits = LZMA_NUM_ALIGN_BITS; 1.2007 ++ } 1.2008 ++ i = 1; 1.2009 ++ mi = 1; 1.2010 ++ while (num_bits--) { 1.2011 ++ if (rc_get_bit(&rc, prob + mi, &mi)) 1.2012 ++ rep0 |= i; 1.2013 ++ i <<= 1; 1.2014 ++ } 1.2015 ++ } else 1.2016 ++ rep0 = pos_slot; 1.2017 ++ if (++rep0 == 0) 1.2018 ++ break; 1.2019 ++ } 1.2020 ++ 1.2021 ++ len += LZMA_MATCH_MIN_LEN; 1.2022 ++ 1.2023 ++ do { 1.2024 ++ pos = buffer_pos - rep0; 1.2025 ++ if (writebb) { 1.2026 ++ while (pos >= header.dict_size) 1.2027 ++ pos += header.dict_size; 1.2028 ++ if(pos >= bufsize) { 1.2029 ++ goto fail; 1.2030 ++ } 1.2031 ++ } 1.2032 ++ previous_byte = buffer[pos]; 1.2033 ++ buffer[buffer_pos++] = previous_byte; 1.2034 ++ if (writebb && buffer_pos == header.dict_size) { 1.2035 ++ buffer_pos = 0; 1.2036 ++ global_pos += header.dict_size; 1.2037 ++ writebb((char*)buffer, header.dict_size); 1.2038 ++ } 1.2039 ++ len--; 1.2040 ++ } while (len != 0 && buffer_pos < header.dst_size); 1.2041 ++ } 1.2042 ++ } 1.2043 ++ 1.2044 ++ if (writebb) { 1.2045 ++ writebb((char*)buffer, buffer_pos); 1.2046 ++ if(posp) { 1.2047 ++ *posp = rc.ptr-rc.buffer; 1.2048 ++ } 1.2049 ++ large_free(buffer); 1.2050 ++ } 1.2051 ++ large_free(p); 1.2052 ++ return 0; 1.2053 ++ fail: 1.2054 ++ if (writebb) large_free(buffer); 1.2055 ++ large_free(p); 1.2056 ++ return -1; 1.2057 ++} 1.2058 + 1.2059 +--- linux-2.6.25.5/lib/unlzma_syms.c 1.2060 ++++ linux-2.6.25.5/lib/unlzma_syms.c 1.2061 +@@ -0,0 +1,14 @@ 1.2062 ++/* 1.2063 ++ * linux/lib/unlzma_syms.c 1.2064 ++ * 1.2065 ++ * Exported symbols for the unlzma functionality. 1.2066 ++ * 1.2067 ++ */ 1.2068 ++ 1.2069 ++#include <linux/module.h> 1.2070 ++#include <linux/init.h> 1.2071 ++ 1.2072 ++#include <linux/decompress_unlzma.h> 1.2073 ++ 1.2074 ++EXPORT_SYMBOL(unlzma); 1.2075 ++MODULE_LICENSE("GPL"); 1.2076 + 1.2077 +--- linux-2.6.25.5/lib/Makefile 1.2078 ++++ linux-2.6.25.5/lib/Makefile 1.2079 +@@ -50,6 +50,9 @@ obj-$(CONFIG_CRC7) += crc7.o 1.2080 + obj-$(CONFIG_LIBCRC32C) += libcrc32c.o 1.2081 + obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o 1.2082 + 1.2083 ++obj-$(CONFIG_RD_BZIP2) += decompress_bunzip2.o 1.2084 ++obj-$(CONFIG_RD_LZMA) += decompress_unlzma.o unlzma_syms.o 1.2085 ++ 1.2086 + obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ 1.2087 + obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ 1.2088 + obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ 1.2089 + 1.2090 +--- linux-2.6.25.5/scripts/Makefile.lib 1.2091 ++++ linux-2.6.25.5/scripts/Makefile.lib 1.2092 +@@ -172,4 +172,17 @@ 1.2093 + quiet_cmd_gzip = GZIP $@ 1.2094 + cmd_gzip = gzip -f -9 < $< > $@ 1.2095 + 1.2096 ++# Append size 1.2097 ++size_append=perl -e 'print(pack("i",(stat($$ARGV[0]))[7]));' 1.2098 + 1.2099 ++# Bzip2 1.2100 ++# --------------------------------------------------------------------------- 1.2101 ++ 1.2102 ++quiet_cmd_bzip2 = BZIP2 $@ 1.2103 ++cmd_bzip2 = (bzip2 -9 < $< ; $(size_append) $<) > $@ 1.2104 ++ 1.2105 ++# Lzma 1.2106 ++# --------------------------------------------------------------------------- 1.2107 ++ 1.2108 ++quiet_cmd_lzma = LZMA $@ 1.2109 ++cmd_lzma = (lzma e $< -so ; $(size_append) $<) >$@ 1.2110 + 1.2111 +--- linux-2.6.25.5/arch/x86/mm/init_32.c 1.2112 ++++ linux-2.6.25.5/arch/x86/mm/init_32.c 1.2113 +@@ -788,7 +788,8 @@ 1.2114 + free_page(addr); 1.2115 + totalram_pages++; 1.2116 + } 1.2117 +- printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); 1.2118 ++ if (what) 1.2119 ++ printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); 1.2120 + #endif 1.2121 + } 1.2122 + 1.2123 +@@ -802,6 +803,6 @@ 1.2124 + #ifdef CONFIG_BLK_DEV_INITRD 1.2125 + void free_initrd_mem(unsigned long start, unsigned long end) 1.2126 + { 1.2127 +- free_init_pages("initrd memory", start, end); 1.2128 ++ free_init_pages(NULL, start, end); 1.2129 + } 1.2130 + #endif