[brcm63xx] fix SPI register definitions
[openwrt.git] / target / linux / brcm47xx / patches-2.6.28 / 500-lzma_initramfs.patch
1 diff --git a/init/initramfs.c b/init/initramfs.c
2 --- a/init/initramfs.c
3 +++ b/init/initramfs.c
4 @@ -475,6 +475,69 @@ static void __init flush_window(void)
5 outcnt = 0;
6 }
7
8 +#include <linux/LzmaDecode.h>
9 +static int __init lzma_unzip(void)
10 +{
11 + unsigned int i; /* temp value */
12 + unsigned int lc; /* literal context bits */
13 + unsigned int lp; /* literal pos state bits */
14 + unsigned int pb; /* pos state bits */
15 + unsigned int osize; /* uncompressed size */
16 + unsigned char *workspace;
17 + unsigned char* outputbuffer;
18 + unsigned int outsizeProcessed = 0;
19 + int workspace_size;
20 + int res;
21 +
22 + // lzma args
23 + i = get_byte();
24 + lc = i % 9, i = i / 9;
25 + lp = i % 5, pb = i / 5;
26 +
27 + // skip dictionary size
28 + for (i = 0; i < 4; i++)
29 + get_byte();
30 +
31 + /* read the lower half of uncompressed size in the header */
32 + osize = ((unsigned int)get_byte()) +
33 + ((unsigned int)get_byte() << 8) +
34 + ((unsigned int)get_byte() << 16) +
35 + ((unsigned int)get_byte() << 24);
36 +
37 + /* skip rest of the header (upper half of uncompressed size) */
38 + for (i = 0; i < 4; i++)
39 + get_byte();
40 +
41 + workspace_size = ((LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb)) + 100;
42 + printk( KERN_NOTICE "initramfs: LZMA lc=%d,lp=%d,pb=%d,origSize=%d\n",
43 + lc,lp,pb,osize);
44 + outputbuffer = kmalloc(osize, GFP_KERNEL);
45 + if (outputbuffer == 0) {
46 + printk(KERN_ERR "initramfs: Couldn't allocate lzma output buffer\n");
47 + return -1;
48 + }
49 +
50 + workspace = kmalloc(workspace_size, GFP_KERNEL);
51 + if (workspace == NULL) {
52 + printk(KERN_ERR "initramfs: Couldn't allocate lzma workspace\n");
53 + return -1;
54 + }
55 +
56 + res = LzmaDecode(workspace, workspace_size, lc, lp, pb, inbuf + inptr, insize - inptr, outputbuffer, osize, &outsizeProcessed);
57 + if( res != 0 ) {
58 + panic( KERN_ERR "initramfs: Lzma decode failure\n");
59 + return -1;
60 + }
61 +
62 + flush_buffer(outputbuffer, outsizeProcessed);
63 + inptr = insize;
64 +
65 + kfree(outputbuffer);
66 + kfree(workspace);
67 + state = Reset;
68 + return 0;
69 +}
70 +
71 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
72 {
73 int written;
74 @@ -509,12 +572,28 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
75 inptr = 0;
76 outcnt = 0; /* bytes in output buffer */
77 bytes_out = 0;
78 - crc = (ulg)0xffffffffL; /* shift register contents */
79 - makecrc();
80 - gunzip();
81 - if (state != Reset)
82 + if( inbuf[0] == 037 && ((inbuf[1] == 0213) || (inbuf[1] == 0236)))
83 + {
84 + printk( KERN_NOTICE "detected gzip initramfs\n");
85 + crc = (ulg)0xffffffffL; /* shift register contents */
86 + makecrc();
87 + gunzip();
88 + if (state != Reset)
89 error("junk in gzipped archive");
90 - this_header = saved_offset + inptr;
91 + }
92 + else if(!memcmp(inbuf+1, "\x00\x00\x80\x00", 4)) /* FIXME: hardcoded dictionary size */
93 + {
94 + printk( KERN_NOTICE "detected lzma initramfs\n");
95 + lzma_unzip();
96 + }
97 + else
98 + {
99 + // skip forward ?
100 + crc = (ulg)0xffffffffL; /* shift register contents */
101 + makecrc();
102 + gunzip();
103 + }
104 + this_header = saved_offset + inptr;
105 buf += inptr;
106 len -= inptr;
107 }
108 diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
109 --- a/scripts/gen_initramfs_list.sh
110 +++ b/scripts/gen_initramfs_list.sh
111 @@ -287,7 +287,7 @@ if [ ! -z ${output_file} ]; then
112 if [ "${is_cpio_compressed}" = "compressed" ]; then
113 cat ${cpio_tfile} > ${output_file}
114 else
115 - cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
116 + lzma e -lc1 -lp2 -pb2 ${cpio_tfile} ${output_file}
117 fi
118 [ -z ${cpio_file} ] && rm ${cpio_tfile}
119 fi
This page took 0.051405 seconds and 5 git commands to generate.