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 * adoptation 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
21 #include <linux/config.h>
23 #include <linux/types.h>
24 #include <asm/svinto.h>
33 void* memset(void* s, int c, size_t n);
34 void* memcpy(void* __dest, __const void* __src,
37 #define memzero(s, n) memset ((s), 0, (n))
40 typedef unsigned char uch;
41 typedef unsigned short ush;
42 typedef unsigned long ulg;
44 #define WSIZE 0x8000 /* Window size must be at least 32k, */
45 /* and a power of two */
47 static uch *inbuf; /* input buffer */
48 static uch window[WSIZE]; /* Sliding window buffer */
50 unsigned inptr = 0; /* index of next byte to be processed in inbuf
51 * After decompression it will contain the
52 * compressed size, and head.S will read it.
55 static unsigned outcnt = 0; /* bytes in output buffer */
58 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
59 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
60 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
61 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
62 #define COMMENT 0x10 /* bit 4 set: file comment present */
63 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
64 #define RESERVED 0xC0 /* bit 6,7: reserved */
66 #define get_byte() inbuf[inptr++]
68 /* Diagnostic functions */
70 # define Assert(cond,msg) {if(!(cond)) error(msg);}
71 # define Trace(x) fprintf x
72 # define Tracev(x) {if (verbose) fprintf x ;}
73 # define Tracevv(x) {if (verbose>1) fprintf x ;}
74 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
75 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
77 # define Assert(cond,msg)
85 static int fill_inbuf(void);
86 static void flush_window(void);
87 static void error(char *m);
88 static void gzip_mark(void **);
89 static void gzip_release(void **);
91 extern char *input_data; /* lives in head.S */
93 static long bytes_out = 0;
94 static uch *output_data;
95 static unsigned long output_ptr = 0;
97 static void *malloc(int size);
98 static void free(void *where);
99 static void error(char *m);
100 static void gzip_mark(void **);
101 static void gzip_release(void **);
103 static void puts(const char *);
105 /* the "heap" is put directly after the BSS ends, at end */
108 static long free_mem_ptr = (long)&end;
110 #include "../../../../lib/inflate.c"
112 static void *malloc(int size)
116 if (size <0) error("Malloc error\n");
118 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
120 p = (void *)free_mem_ptr;
121 free_mem_ptr += size;
126 static void free(void *where)
130 static void gzip_mark(void **ptr)
132 *ptr = (void *) free_mem_ptr;
135 static void gzip_release(void **ptr)
137 free_mem_ptr = (long) *ptr;
140 /* decompressor info and error messages to serial console */
145 #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
147 #ifdef CONFIG_ETRAX_DEBUG_PORT0
148 while(!(*R_SERIAL0_STATUS & (1 << 5))) ;
149 *R_SERIAL0_TR_DATA = *s++;
151 #ifdef CONFIG_ETRAX_DEBUG_PORT1
152 while(!(*R_SERIAL1_STATUS & (1 << 5))) ;
153 *R_SERIAL1_TR_DATA = *s++;
155 #ifdef CONFIG_ETRAX_DEBUG_PORT2
156 while(!(*R_SERIAL2_STATUS & (1 << 5))) ;
157 *R_SERIAL2_TR_DATA = *s++;
159 #ifdef CONFIG_ETRAX_DEBUG_PORT3
160 while(!(*R_SERIAL3_STATUS & (1 << 5))) ;
161 *R_SERIAL3_TR_DATA = *s++;
168 memset(void* s, int c, size_t n)
173 for (i=0;i<n;i++) ss[i] = c;
177 memcpy(void* __dest, __const void* __src,
181 char *d = (char *)__dest, *s = (char *)__src;
183 for (i=0;i<__n;i++) d[i] = s[i];
186 /* ===========================================================================
187 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
188 * (Used for the decompressed data only.)
194 ulg c = crc; /* temporary variable */
199 out = &output_data[output_ptr];
200 for (n = 0; n < outcnt; n++) {
202 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
205 bytes_out += (ulg)outcnt;
206 output_ptr += (ulg)outcnt;
215 puts("\n\n -- System halted\n");
221 setup_normal_output_buffer()
223 output_data = (char *)KERNEL_LOAD_ADR;
231 /* input_data is set in head.S */
234 #ifdef CONFIG_ETRAX_DEBUG_PORT0
236 *R_SERIAL0_BAUD = 0x99;
237 *R_SERIAL0_TR_CTRL = 0x40;
239 #ifdef CONFIG_ETRAX_DEBUG_PORT1
241 *R_SERIAL1_BAUD = 0x99;
242 *R_SERIAL1_TR_CTRL = 0x40;
244 #ifdef CONFIG_ETRAX_DEBUG_PORT2
245 *R_GEN_CONFIG = 0x08;
247 *R_SERIAL2_BAUD = 0x99;
248 *R_SERIAL2_TR_CTRL = 0x40;
250 #ifdef CONFIG_ETRAX_DEBUG_PORT3
251 *R_GEN_CONFIG = 0x100;
253 *R_SERIAL3_BAUD = 0x99;
254 *R_SERIAL3_TR_CTRL = 0x40;
257 setup_normal_output_buffer();
261 __asm__ volatile ("move vr,%0" : "=rm" (revision));
264 puts("You need an ETRAX 100LX to run linux 2.4\n");
268 puts("Uncompressing Linux...\n");
270 puts("Done. Now booting the kernel.\n");