3 @@ -475,6 +475,69 @@ static void __init flush_window(void)
7 +#include <linux/LzmaDecode.h>
8 +static int __init lzma_unzip(void)
10 + unsigned int i; /* temp value */
11 + unsigned int lc; /* literal context bits */
12 + unsigned int lp; /* literal pos state bits */
13 + unsigned int pb; /* pos state bits */
14 + unsigned int osize; /* uncompressed size */
15 + unsigned char *workspace;
16 + unsigned char* outputbuffer;
17 + unsigned int outsizeProcessed = 0;
23 + lc = i % 9, i = i / 9;
24 + lp = i % 5, pb = i / 5;
26 + // skip dictionary size
27 + for (i = 0; i < 4; i++)
30 + /* read the lower half of uncompressed size in the header */
31 + osize = ((unsigned int)get_byte()) +
32 + ((unsigned int)get_byte() << 8) +
33 + ((unsigned int)get_byte() << 16) +
34 + ((unsigned int)get_byte() << 24);
36 + /* skip rest of the header (upper half of uncompressed size) */
37 + for (i = 0; i < 4; i++)
40 + workspace_size = ((LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb)) + 100;
41 + printk( KERN_NOTICE "initramfs: LZMA lc=%d,lp=%d,pb=%d,origSize=%d\n",
43 + outputbuffer = kmalloc(osize, GFP_KERNEL);
44 + if (outputbuffer == 0) {
45 + printk(KERN_ERR "initramfs: Couldn't allocate lzma output buffer\n");
49 + workspace = kmalloc(workspace_size, GFP_KERNEL);
50 + if (workspace == NULL) {
51 + printk(KERN_ERR "initramfs: Couldn't allocate lzma workspace\n");
55 + res = LzmaDecode(workspace, workspace_size, lc, lp, pb, inbuf + inptr, insize - inptr, outputbuffer, osize, &outsizeProcessed);
57 + panic( KERN_ERR "initramfs: Lzma decode failure\n");
61 + flush_buffer(outputbuffer, outsizeProcessed);
64 + kfree(outputbuffer);
70 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
73 @@ -509,12 +572,28 @@ static char * __init unpack_to_rootfs(ch
75 outcnt = 0; /* bytes in output buffer */
77 - crc = (ulg)0xffffffffL; /* shift register contents */
81 + if( inbuf[0] == 037 && ((inbuf[1] == 0213) || (inbuf[1] == 0236)))
83 + printk( KERN_NOTICE "detected gzip initramfs\n");
84 + crc = (ulg)0xffffffffL; /* shift register contents */
88 error("junk in gzipped archive");
89 - this_header = saved_offset + inptr;
91 + else if(!memcmp(inbuf+1, "\x00\x00\x80\x00", 4)) /* FIXME: hardcoded dictionary size */
93 + printk( KERN_NOTICE "detected lzma initramfs\n");
99 + crc = (ulg)0xffffffffL; /* shift register contents */
103 + this_header = saved_offset + inptr;
107 --- a/scripts/gen_initramfs_list.sh
108 +++ b/scripts/gen_initramfs_list.sh
109 @@ -287,7 +287,7 @@ if [ ! -z ${output_file} ]; then
110 if [ "${is_cpio_compressed}" = "compressed" ]; then
111 cat ${cpio_tfile} > ${output_file}
113 - cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
114 + lzma e -lc1 -lp2 -pb2 ${cpio_tfile} ${output_file}
116 [ -z ${cpio_file} ] && rm ${cpio_tfile}