4 * This is a collection of several routines from gzip-1.0.3
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * Modified for ARM Linux by Russell King
11 * Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
12 * For this code to run directly from Flash, all constant variables must
13 * be marked with 'const' and all other variables initialized at run-time
14 * only. This way all non constant variables will end up in the bss segment,
15 * which should point to addresses in RAM and cleared to 0 on start.
16 * This allows for a much quicker boot time.
18 * Modified for Alpha, from the ARM version, by Jay Estabrook 2003.
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
24 #include <asm/uaccess.h>
26 #define memzero(s,n) memset ((s),0,(n))
27 #define puts srm_printk
28 extern long srm_printk(const char *, ...)
29 __attribute__ ((format (printf, 1, 2)));
37 typedef unsigned char uch;
38 typedef unsigned short ush;
39 typedef unsigned long ulg;
41 #define WSIZE 0x8000 /* Window size must be at least 32k, */
42 /* and a power of two */
44 static uch *inbuf; /* input buffer */
45 static uch *window; /* Sliding window buffer */
47 static unsigned insize; /* valid bytes in inbuf */
48 static unsigned inptr; /* index of next byte to be processed in inbuf */
49 static unsigned outcnt; /* bytes in output buffer */
52 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
53 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
54 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
55 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
56 #define COMMENT 0x10 /* bit 4 set: file comment present */
57 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
58 #define RESERVED 0xC0 /* bit 6,7: reserved */
60 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
62 /* Diagnostic functions */
64 # define Assert(cond,msg) {if(!(cond)) error(msg);}
65 # define Trace(x) fprintf x
66 # define Tracev(x) {if (verbose) fprintf x ;}
67 # define Tracevv(x) {if (verbose>1) fprintf x ;}
68 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
69 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
71 # define Assert(cond,msg)
79 static int fill_inbuf(void);
80 static void flush_window(void);
81 static void error(char *m);
83 static char *input_data;
84 static int input_data_size;
86 static uch *output_data;
87 static ulg output_ptr;
90 static void error(char *m);
91 static void gzip_mark(void **);
92 static void gzip_release(void **);
95 static ulg free_mem_ptr;
96 static ulg free_mem_end_ptr;
98 #define HEAP_SIZE 0x3000
100 #include "../../../lib/inflate.c"
102 /* ===========================================================================
103 * Fill the input buffer. This is called only when the buffer is empty
104 * and at least one byte is really needed.
109 error("ran out of input data");
112 insize = input_data_size;
118 /* ===========================================================================
119 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
120 * (Used for the decompressed data only.)
122 void flush_window(void)
129 out = &output_data[output_ptr];
130 for (n = 0; n < outcnt; n++) {
132 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
135 bytes_out += (ulg)outcnt;
136 output_ptr += (ulg)outcnt;
141 static void error(char *x)
145 puts("\n\n -- System halted");
151 decompress_kernel(void *output_start,
156 output_data = (uch *)output_start;
157 input_data = (uch *)input_start;
158 input_data_size = kzsize; /* use compressed size */
160 /* FIXME FIXME FIXME */
161 free_mem_ptr = (ulg)output_start + ksize;
162 free_mem_end_ptr = (ulg)output_start + ksize + 0x200000;
163 /* FIXME FIXME FIXME */
165 /* put in temp area to reduce initial footprint */
166 window = malloc(WSIZE);
169 /* puts("Uncompressing Linux..."); */
171 /* puts(" done, booting the kernel.\n"); */