4 * This is a collection of several routines from gzip-1.0.3
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
9 * adaptation for Linux/CRIS Axis Communications AB, 1999
13 /* where the piggybacked kernel image expects itself to live.
14 * it is the same address we use when we network load an uncompressed
15 * image into DRAM, and it is the address the kernel is linked to live
19 #define KERNEL_LOAD_ADR 0x40004000
22 #include <linux/types.h>
23 #include <asm/arch/svinto.h>
32 void *memset(void *s, int c, size_t n);
33 void *memcpy(void *__dest, __const void *__src, size_t __n);
35 #define memzero(s, n) memset((s), 0, (n))
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[WSIZE]; /* Sliding window buffer */
47 unsigned inptr = 0; /* index of next byte to be processed in inbuf
48 * After decompression it will contain the
49 * compressed size, and head.S will read it.
52 static unsigned outcnt = 0; /* bytes in output buffer */
55 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
56 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
57 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
58 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
59 #define COMMENT 0x10 /* bit 4 set: file comment present */
60 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
61 #define RESERVED 0xC0 /* bit 6,7: reserved */
63 #define get_byte() (inbuf[inptr++])
65 /* Diagnostic functions */
67 # define Assert(cond, msg) do { \
71 # define Trace(x) fprintf x
72 # define Tracev(x) do { \
76 # define Tracevv(x) do { \
80 # define Tracec(c, x) do { \
84 # define Tracecv(c, x) do { \
85 if (verbose > 1 && (c)) \
89 # define Assert(cond, msg)
94 # define Tracecv(c, x)
97 static void flush_window(void);
98 static void error(char *m);
100 extern char *input_data; /* lives in head.S */
102 static long bytes_out = 0;
103 static uch *output_data;
104 static unsigned long output_ptr = 0;
106 static void *malloc(int size);
107 static void free(void *where);
108 static void gzip_mark(void **);
109 static void gzip_release(void **);
111 static void puts(const char *);
113 /* the "heap" is put directly after the BSS ends, at end */
116 static long free_mem_ptr = (long)&_end;
118 #include "../../../../../lib/inflate.c"
120 static void *malloc(int size)
125 error("Malloc error");
127 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
129 p = (void *)free_mem_ptr;
130 free_mem_ptr += size;
135 static void free(void *where)
139 static void gzip_mark(void **ptr)
141 *ptr = (void *) free_mem_ptr;
144 static void gzip_release(void **ptr)
146 free_mem_ptr = (long) *ptr;
149 /* decompressor info and error messages to serial console */
154 #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
156 #ifdef CONFIG_ETRAX_DEBUG_PORT0
157 while (!(*R_SERIAL0_STATUS & (1 << 5))) ;
158 *R_SERIAL0_TR_DATA = *s++;
160 #ifdef CONFIG_ETRAX_DEBUG_PORT1
161 while (!(*R_SERIAL1_STATUS & (1 << 5))) ;
162 *R_SERIAL1_TR_DATA = *s++;
164 #ifdef CONFIG_ETRAX_DEBUG_PORT2
165 while (!(*R_SERIAL2_STATUS & (1 << 5))) ;
166 *R_SERIAL2_TR_DATA = *s++;
168 #ifdef CONFIG_ETRAX_DEBUG_PORT3
169 while (!(*R_SERIAL3_STATUS & (1 << 5))) ;
170 *R_SERIAL3_TR_DATA = *s++;
176 void *memset(void *s, int c, size_t n)
179 char *ss = (char *)s;
181 for (i = 0; i < n; i++)
187 void *memcpy(void *__dest, __const void *__src, size_t __n)
190 char *d = (char *)__dest, *s = (char *)__src;
192 for (i = 0; i < __n; i++)
198 /* ===========================================================================
199 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
200 * (Used for the decompressed data only.)
203 static void flush_window(void)
205 ulg c = crc; /* temporary variable */
210 out = &output_data[output_ptr];
211 for (n = 0; n < outcnt; n++) {
215 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
218 bytes_out += (ulg)outcnt;
219 output_ptr += (ulg)outcnt;
223 static void error(char *x)
227 puts("\n\n -- System halted\n");
229 while (1); /* Halt */
232 void setup_normal_output_buffer(void)
234 output_data = (char *)KERNEL_LOAD_ADR;
237 void decompress_kernel(void)
241 /* input_data is set in head.S */
244 #ifdef CONFIG_ETRAX_DEBUG_PORT0
246 *R_SERIAL0_BAUD = 0x99;
247 *R_SERIAL0_TR_CTRL = 0x40;
249 #ifdef CONFIG_ETRAX_DEBUG_PORT1
251 *R_SERIAL1_BAUD = 0x99;
252 *R_SERIAL1_TR_CTRL = 0x40;
254 #ifdef CONFIG_ETRAX_DEBUG_PORT2
255 *R_GEN_CONFIG = 0x08;
257 *R_SERIAL2_BAUD = 0x99;
258 *R_SERIAL2_TR_CTRL = 0x40;
260 #ifdef CONFIG_ETRAX_DEBUG_PORT3
261 *R_GEN_CONFIG = 0x100;
263 *R_SERIAL3_BAUD = 0x99;
264 *R_SERIAL3_TR_CTRL = 0x40;
267 setup_normal_output_buffer();
271 __asm__ volatile ("move $vr,%0" : "=rm" (revision));
273 puts("You need an ETRAX 100LX to run linux 2.6\n");
277 puts("Uncompressing Linux...\n");
279 puts("Done. Now booting the kernel.\n");