wok-stable annotate linux/stuff/linux-lzma-2.6.29.3.u @ rev 4511

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