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.
19 unsigned int __machine_arch_type
;
21 #include <linux/kernel.h>
23 #include <asm/uaccess.h>
24 #include "uncompress.h"
26 #ifdef STANDALONE_DEBUG
30 #define __ptr_t void *
33 * Optimised C version of memzero for the ARM.
35 void __memzero (__ptr_t s
, size_t n
)
37 union { void *vp
; unsigned long *ulp
; unsigned char *ucp
; } u
;
42 for (i
= n
>> 5; i
> 0; i
--) {
77 static inline __ptr_t
memcpy(__ptr_t __dest
, __const __ptr_t __src
,
81 unsigned char *d
= (unsigned char *)__dest
, *s
= (unsigned char *)__src
;
83 for (i
= __n
>> 3; i
> 0; i
--) {
115 #define OF(args) args
116 #define STATIC static
118 typedef unsigned char uch
;
119 typedef unsigned short ush
;
120 typedef unsigned long ulg
;
122 #define WSIZE 0x8000 /* Window size must be at least 32k, */
123 /* and a power of two */
125 static uch
*inbuf
; /* input buffer */
126 static uch window
[WSIZE
]; /* Sliding window buffer */
128 static unsigned insize
; /* valid bytes in inbuf */
129 static unsigned inptr
; /* index of next byte to be processed in inbuf */
130 static unsigned outcnt
; /* bytes in output buffer */
133 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
134 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
135 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
136 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
137 #define COMMENT 0x10 /* bit 4 set: file comment present */
138 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
139 #define RESERVED 0xC0 /* bit 6,7: reserved */
141 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
143 /* Diagnostic functions */
145 # define Assert(cond,msg) {if(!(cond)) error(msg);}
146 # define Trace(x) fprintf x
147 # define Tracev(x) {if (verbose) fprintf x ;}
148 # define Tracevv(x) {if (verbose>1) fprintf x ;}
149 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
150 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
152 # define Assert(cond,msg)
157 # define Tracecv(c,x)
160 static int fill_inbuf(void);
161 static void flush_window(void);
162 static void error(char *m
);
163 static void gzip_mark(void **);
164 static void gzip_release(void **);
166 extern char input_data
[];
167 extern char input_data_end
[];
169 static uch
*output_data
;
170 static ulg output_ptr
;
171 static ulg bytes_out
;
173 static void *malloc(int size
);
174 static void free(void *where
);
175 static void error(char *m
);
176 static void gzip_mark(void **);
177 static void gzip_release(void **);
179 static void puts(const char *);
182 static ulg free_mem_ptr
;
183 static ulg free_mem_ptr_end
;
185 #define HEAP_SIZE 0x2000
187 #include "../../../../lib/inflate.c"
189 #ifndef STANDALONE_DEBUG
190 static void *malloc(int size
)
194 if (size
<0) error("Malloc error");
195 if (free_mem_ptr
<= 0) error("Memory error");
197 free_mem_ptr
= (free_mem_ptr
+ 3) & ~3; /* Align */
199 p
= (void *)free_mem_ptr
;
200 free_mem_ptr
+= size
;
202 if (free_mem_ptr
>= free_mem_ptr_end
)
203 error("Out of memory");
207 static void free(void *where
)
208 { /* gzip_mark & gzip_release do the free */
211 static void gzip_mark(void **ptr
)
214 *ptr
= (void *) free_mem_ptr
;
217 static void gzip_release(void **ptr
)
220 free_mem_ptr
= (long) *ptr
;
223 static void gzip_mark(void **ptr
)
227 static void gzip_release(void **ptr
)
232 /* ===========================================================================
233 * Fill the input buffer. This is called only when the buffer is empty
234 * and at least one byte is really needed.
239 error("ran out of input data");
242 insize
= &input_data_end
[0] - &input_data
[0];
248 /* ===========================================================================
249 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
250 * (Used for the decompressed data only.)
252 void flush_window(void)
259 out
= &output_data
[output_ptr
];
260 for (n
= 0; n
< outcnt
; n
++) {
262 c
= crc_32_tab
[((int)c
^ ch
) & 0xff] ^ (c
>> 8);
265 bytes_out
+= (ulg
)outcnt
;
266 output_ptr
+= (ulg
)outcnt
;
271 static void error(char *x
)
277 puts("\n\n -- System halted");
282 #ifndef STANDALONE_DEBUG
285 decompress_kernel(ulg output_start
, ulg free_mem_ptr_p
, ulg free_mem_ptr_end_p
,
288 output_data
= (uch
*)output_start
; /* Points to kernel start */
289 free_mem_ptr
= free_mem_ptr_p
;
290 free_mem_ptr_end
= free_mem_ptr_end_p
;
291 __machine_arch_type
= arch_id
;
296 puts("Uncompressing Linux...");
298 puts(" done, booting the kernel.\n");
303 char output_buffer
[1500*1024];
307 output_data
= output_buffer
;
310 puts("Uncompressing Linux...");