1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#define KERNEL_LOAD_ADR 0x40004000
20
21#include <linux/config.h>
22
23#include <linux/types.h>
24#include <asm/svinto.h>
25
26
27
28
29
30#define OF(args) args
31#define STATIC static
32
33void* memset(void* s, int c, size_t n);
34void* memcpy(void* __dest, __const void* __src,
35 size_t __n);
36
37#define memzero(s, n) memset ((s), 0, (n))
38
39
40typedef unsigned char uch;
41typedef unsigned short ush;
42typedef unsigned long ulg;
43
44#define WSIZE 0x8000
45
46
47static uch *inbuf;
48static uch window[WSIZE];
49
50unsigned inptr = 0;
51
52
53
54
55static unsigned outcnt = 0;
56
57
58#define ASCII_FLAG 0x01
59#define CONTINUATION 0x02
60#define EXTRA_FIELD 0x04
61#define ORIG_NAME 0x08
62#define COMMENT 0x10
63#define ENCRYPTED 0x20
64#define RESERVED 0xC0
65
66#define get_byte() inbuf[inptr++]
67
68
69#ifdef DEBUG
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 ;}
76#else
77# define Assert(cond,msg)
78# define Trace(x)
79# define Tracev(x)
80# define Tracevv(x)
81# define Tracec(c,x)
82# define Tracecv(c,x)
83#endif
84
85static int fill_inbuf(void);
86static void flush_window(void);
87static void error(char *m);
88static void gzip_mark(void **);
89static void gzip_release(void **);
90
91extern char *input_data;
92
93static long bytes_out = 0;
94static uch *output_data;
95static unsigned long output_ptr = 0;
96
97static void *malloc(int size);
98static void free(void *where);
99static void error(char *m);
100static void gzip_mark(void **);
101static void gzip_release(void **);
102
103static void puts(const char *);
104
105
106
107extern int end;
108static long free_mem_ptr = (long)&end;
109
110#include "../../../../lib/inflate.c"
111
112static void *malloc(int size)
113{
114 void *p;
115
116 if (size <0) error("Malloc error\n");
117
118 free_mem_ptr = (free_mem_ptr + 3) & ~3;
119
120 p = (void *)free_mem_ptr;
121 free_mem_ptr += size;
122
123 return p;
124}
125
126static void free(void *where)
127{
128}
129
130static void gzip_mark(void **ptr)
131{
132 *ptr = (void *) free_mem_ptr;
133}
134
135static void gzip_release(void **ptr)
136{
137 free_mem_ptr = (long) *ptr;
138}
139
140
141
142static void
143puts(const char *s)
144{
145#ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
146 while(*s) {
147#ifdef CONFIG_ETRAX_DEBUG_PORT0
148 while(!(*R_SERIAL0_STATUS & (1 << 5))) ;
149 *R_SERIAL0_TR_DATA = *s++;
150#endif
151#ifdef CONFIG_ETRAX_DEBUG_PORT1
152 while(!(*R_SERIAL1_STATUS & (1 << 5))) ;
153 *R_SERIAL1_TR_DATA = *s++;
154#endif
155#ifdef CONFIG_ETRAX_DEBUG_PORT2
156 while(!(*R_SERIAL2_STATUS & (1 << 5))) ;
157 *R_SERIAL2_TR_DATA = *s++;
158#endif
159#ifdef CONFIG_ETRAX_DEBUG_PORT3
160 while(!(*R_SERIAL3_STATUS & (1 << 5))) ;
161 *R_SERIAL3_TR_DATA = *s++;
162#endif
163 }
164#endif
165}
166
167void*
168memset(void* s, int c, size_t n)
169{
170 int i;
171 char *ss = (char*)s;
172
173 for (i=0;i<n;i++) ss[i] = c;
174}
175
176void*
177memcpy(void* __dest, __const void* __src,
178 size_t __n)
179{
180 int i;
181 char *d = (char *)__dest, *s = (char *)__src;
182
183 for (i=0;i<__n;i++) d[i] = s[i];
184}
185
186
187
188
189
190
191static void
192flush_window()
193{
194 ulg c = crc;
195 unsigned n;
196 uch *in, *out, ch;
197
198 in = window;
199 out = &output_data[output_ptr];
200 for (n = 0; n < outcnt; n++) {
201 ch = *out++ = *in++;
202 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
203 }
204 crc = c;
205 bytes_out += (ulg)outcnt;
206 output_ptr += (ulg)outcnt;
207 outcnt = 0;
208}
209
210static void
211error(char *x)
212{
213 puts("\n\n");
214 puts(x);
215 puts("\n\n -- System halted\n");
216
217 while(1);
218}
219
220void
221setup_normal_output_buffer()
222{
223 output_data = (char *)KERNEL_LOAD_ADR;
224}
225
226void
227decompress_kernel()
228{
229 char revision;
230
231
232 inbuf = input_data;
233
234#ifdef CONFIG_ETRAX_DEBUG_PORT0
235 *R_SERIAL0_XOFF = 0;
236 *R_SERIAL0_BAUD = 0x99;
237 *R_SERIAL0_TR_CTRL = 0x40;
238#endif
239#ifdef CONFIG_ETRAX_DEBUG_PORT1
240 *R_SERIAL1_XOFF = 0;
241 *R_SERIAL1_BAUD = 0x99;
242 *R_SERIAL1_TR_CTRL = 0x40;
243#endif
244#ifdef CONFIG_ETRAX_DEBUG_PORT2
245 *R_GEN_CONFIG = 0x08;
246 *R_SERIAL2_XOFF = 0;
247 *R_SERIAL2_BAUD = 0x99;
248 *R_SERIAL2_TR_CTRL = 0x40;
249#endif
250#ifdef CONFIG_ETRAX_DEBUG_PORT3
251 *R_GEN_CONFIG = 0x100;
252 *R_SERIAL3_XOFF = 0;
253 *R_SERIAL3_BAUD = 0x99;
254 *R_SERIAL3_TR_CTRL = 0x40;
255#endif
256
257 setup_normal_output_buffer();
258
259 makecrc();
260
261 __asm__ volatile ("move vr,%0" : "=rm" (revision));
262 if (revision < 10)
263 {
264 puts("You need an ETRAX 100LX to run linux 2.4\n");
265 while(1);
266 }
267
268 puts("Uncompressing Linux...\n");
269 gunzip();
270 puts("Done. Now booting the kernel.\n");
271}
272