1 --- a/scripts/gen_initramfs_list.sh
2 +++ b/scripts/gen_initramfs_list.sh
4 if [ "${is_cpio_compressed}" = "compressed" ]; then
5 cat ${cpio_tfile} > ${output_file}
7 - cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
8 + lzma e -lc1 -lp2 -pb2 ${cpio_tfile} ${output_file}
10 [ -z ${cpio_file} ] && rm ${cpio_tfile}
12 --- a/init/initramfs.c
13 +++ b/init/initramfs.c
18 +#include <linux/LzmaDecode.h>
19 +static int __init lzma_unzip(void)
21 + unsigned int i; /* temp value */
22 + unsigned int lc; /* literal context bits */
23 + unsigned int lp; /* literal pos state bits */
24 + unsigned int pb; /* pos state bits */
25 + unsigned int osize; /* uncompressed size */
26 + unsigned char *workspace;
27 + unsigned char* outputbuffer;
28 + unsigned int outsizeProcessed = 0;
34 + lc = i % 9, i = i / 9;
35 + lp = i % 5, pb = i / 5;
37 + // skip dictionary size
38 + for (i = 0; i < 4; i++)
41 + /* read the lower half of uncompressed size in the header */
42 + osize = ((unsigned int)get_byte()) +
43 + ((unsigned int)get_byte() << 8) +
44 + ((unsigned int)get_byte() << 16) +
45 + ((unsigned int)get_byte() << 24);
47 + /* skip rest of the header (upper half of uncompressed size) */
48 + for (i = 0; i < 4; i++)
51 + workspace_size = ((LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb)) + 100;
52 + printk( KERN_NOTICE "initramfs: LZMA lc=%d,lp=%d,pb=%d,origSize=%d\n",
54 + outputbuffer = kmalloc(osize, GFP_KERNEL);
55 + if (outputbuffer == 0) {
56 + printk(KERN_ERR "initramfs: Couldn't allocate lzma output buffer\n");
60 + workspace = kmalloc(workspace_size, GFP_KERNEL);
61 + if (workspace == NULL) {
62 + printk(KERN_ERR "initramfs: Couldn't allocate lzma workspace\n");
66 + res = LzmaDecode(workspace, workspace_size, lc, lp, pb, inbuf + inptr, insize - inptr, outputbuffer, osize, &outsizeProcessed);
68 + panic( KERN_ERR "initramfs: Lzma decode failure\n");
72 + flush_buffer(outputbuffer, outsizeProcessed);
75 + kfree(outputbuffer);
81 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
86 outcnt = 0; /* bytes in output buffer */
88 - crc = (ulg)0xffffffffL; /* shift register contents */
92 + if( inbuf[0] == 037 && ((inbuf[1] == 0213) || (inbuf[1] == 0236)))
94 + printk( KERN_NOTICE "detected gzip initramfs\n");
95 + crc = (ulg)0xffffffffL; /* shift register contents */
99 error("junk in gzipped archive");
100 - this_header = saved_offset + inptr;
102 + else if(!memcmp(inbuf+1, "\x00\x00\x80\x00", 4)) /* FIXME: hardcoded dictionary size */
104 + printk( KERN_NOTICE "detected lzma initramfs\n");
110 + crc = (ulg)0xffffffffL; /* shift register contents */
114 + this_header = saved_offset + inptr;