4 #include <linux/string.h>
5 #include <linux/syscalls.h>
6 #include <linux/utime.h>
7 +#include <linux/vmalloc.h>
9 static __initdata char *message;
10 static void __init error(char *x)
11 @@ -475,6 +476,69 @@ static void __init flush_window(void)
15 +#include <linux/LzmaDecode.h>
16 +static int __init lzma_unzip(void)
18 + unsigned int i; /* temp value */
19 + unsigned int lc; /* literal context bits */
20 + unsigned int lp; /* literal pos state bits */
21 + unsigned int pb; /* pos state bits */
22 + unsigned int osize; /* uncompressed size */
23 + unsigned char *workspace;
24 + unsigned char* outputbuffer;
25 + unsigned int outsizeProcessed = 0;
31 + lc = i % 9, i = i / 9;
32 + lp = i % 5, pb = i / 5;
34 + // skip dictionary size
35 + for (i = 0; i < 4; i++)
38 + /* read the lower half of uncompressed size in the header */
39 + osize = ((unsigned int)get_byte()) +
40 + ((unsigned int)get_byte() << 8) +
41 + ((unsigned int)get_byte() << 16) +
42 + ((unsigned int)get_byte() << 24);
44 + /* skip rest of the header (upper half of uncompressed size) */
45 + for (i = 0; i < 4; i++)
48 + workspace_size = ((LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb)) + 100;
49 + printk( KERN_NOTICE "initramfs: LZMA lc=%d,lp=%d,pb=%d,origSize=%d\n",
51 + outputbuffer = vmalloc(osize);
52 + if (outputbuffer == 0) {
53 + printk(KERN_ERR "initramfs: Couldn't allocate lzma output buffer\n");
57 + workspace = vmalloc(workspace_size);
58 + if (workspace == NULL) {
59 + printk(KERN_ERR "initramfs: Couldn't allocate lzma workspace\n");
63 + res = LzmaDecode(workspace, workspace_size, lc, lp, pb, inbuf + inptr, insize - inptr, outputbuffer, osize, &outsizeProcessed);
65 + panic( KERN_ERR "initramfs: Lzma decode failure\n");
69 + flush_buffer(outputbuffer, outsizeProcessed);
72 + vfree(outputbuffer);
78 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
81 @@ -509,12 +573,28 @@ static char * __init unpack_to_rootfs(ch
83 outcnt = 0; /* bytes in output buffer */
85 - crc = (ulg)0xffffffffL; /* shift register contents */
89 + if( inbuf[0] == 037 && ((inbuf[1] == 0213) || (inbuf[1] == 0236)))
91 + printk( KERN_NOTICE "detected gzip initramfs\n");
92 + crc = (ulg)0xffffffffL; /* shift register contents */
96 error("junk in gzipped archive");
97 - this_header = saved_offset + inptr;
99 + else if(!memcmp(inbuf+1, "\x00\x00\x80\x00", 4)) /* FIXME: hardcoded dictionary size */
101 + printk( KERN_NOTICE "detected lzma initramfs\n");
107 + crc = (ulg)0xffffffffL; /* shift register contents */
111 + this_header = saved_offset + inptr;
115 --- a/scripts/gen_initramfs_list.sh
116 +++ b/scripts/gen_initramfs_list.sh
117 @@ -287,7 +287,7 @@ if [ ! -z ${output_file} ]; then
118 if [ "${is_cpio_compressed}" = "compressed" ]; then
119 cat ${cpio_tfile} > ${output_file}
121 - cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
122 + lzma e -lc1 -lp2 -pb2 ${cpio_tfile} ${output_file}
124 [ -z ${cpio_file} ] && rm ${cpio_tfile}