aboutsummaryrefslogtreecommitdiffstats
path: root/arch/cris/arch-v32/boot/compressed/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/cris/arch-v32/boot/compressed/misc.c')
-rw-r--r--arch/cris/arch-v32/boot/compressed/misc.c318
1 files changed, 318 insertions, 0 deletions
diff --git a/arch/cris/arch-v32/boot/compressed/misc.c b/arch/cris/arch-v32/boot/compressed/misc.c
new file mode 100644
index 000000000000..54644238ed59
--- /dev/null
+++ b/arch/cris/arch-v32/boot/compressed/misc.c
@@ -0,0 +1,318 @@
1/*
2 * misc.c
3 *
4 * $Id: misc.c,v 1.8 2005/04/24 18:34:29 starvik Exp $
5 *
6 * This is a collection of several routines from gzip-1.0.3
7 * adapted for Linux.
8 *
9 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
10 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
11 * adoptation for Linux/CRIS Axis Communications AB, 1999
12 *
13 */
14
15/* where the piggybacked kernel image expects itself to live.
16 * it is the same address we use when we network load an uncompressed
17 * image into DRAM, and it is the address the kernel is linked to live
18 * at by vmlinux.lds.S
19 */
20
21#define KERNEL_LOAD_ADR 0x40004000
22
23#include <linux/config.h>
24
25#include <linux/types.h>
26#include <asm/arch/hwregs/reg_rdwr.h>
27#include <asm/arch/hwregs/reg_map.h>
28#include <asm/arch/hwregs/ser_defs.h>
29
30/*
31 * gzip declarations
32 */
33
34#define OF(args) args
35#define STATIC static
36
37void* memset(void* s, int c, size_t n);
38void* memcpy(void* __dest, __const void* __src,
39 size_t __n);
40
41#define memzero(s, n) memset ((s), 0, (n))
42
43
44typedef unsigned char uch;
45typedef unsigned short ush;
46typedef unsigned long ulg;
47
48#define WSIZE 0x8000 /* Window size must be at least 32k, */
49 /* and a power of two */
50
51static uch *inbuf; /* input buffer */
52static uch window[WSIZE]; /* Sliding window buffer */
53
54unsigned inptr = 0; /* index of next byte to be processed in inbuf
55 * After decompression it will contain the
56 * compressed size, and head.S will read it.
57 */
58
59static unsigned outcnt = 0; /* bytes in output buffer */
60
61/* gzip flag byte */
62#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
63#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
64#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
65#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
66#define COMMENT 0x10 /* bit 4 set: file comment present */
67#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
68#define RESERVED 0xC0 /* bit 6,7: reserved */
69
70#define get_byte() inbuf[inptr++]
71
72/* Diagnostic functions */
73#ifdef DEBUG
74# define Assert(cond,msg) {if(!(cond)) error(msg);}
75# define Trace(x) fprintf x
76# define Tracev(x) {if (verbose) fprintf x ;}
77# define Tracevv(x) {if (verbose>1) fprintf x ;}
78# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
79# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
80#else
81# define Assert(cond,msg)
82# define Trace(x)
83# define Tracev(x)
84# define Tracevv(x)
85# define Tracec(c,x)
86# define Tracecv(c,x)
87#endif
88
89static int fill_inbuf(void);
90static void flush_window(void);
91static void error(char *m);
92static void gzip_mark(void **);
93static void gzip_release(void **);
94
95extern char *input_data; /* lives in head.S */
96
97static long bytes_out = 0;
98static uch *output_data;
99static unsigned long output_ptr = 0;
100
101static void *malloc(int size);
102static void free(void *where);
103static void error(char *m);
104static void gzip_mark(void **);
105static void gzip_release(void **);
106
107static void puts(const char *);
108
109/* the "heap" is put directly after the BSS ends, at end */
110
111extern int _end;
112static long free_mem_ptr = (long)&_end;
113
114#include "../../../../../lib/inflate.c"
115
116static void *malloc(int size)
117{
118 void *p;
119
120 if (size <0) error("Malloc error");
121
122 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
123
124 p = (void *)free_mem_ptr;
125 free_mem_ptr += size;
126
127 return p;
128}
129
130static void free(void *where)
131{ /* Don't care */
132}
133
134static void gzip_mark(void **ptr)
135{
136 *ptr = (void *) free_mem_ptr;
137}
138
139static void gzip_release(void **ptr)
140{
141 free_mem_ptr = (long) *ptr;
142}
143
144/* decompressor info and error messages to serial console */
145
146static inline void
147serout(const char *s, reg_scope_instances regi_ser)
148{
149 reg_ser_rs_stat_din rs;
150 reg_ser_rw_dout dout = {.data = *s};
151
152 do {
153 rs = REG_RD(ser, regi_ser, rs_stat_din);
154 }
155 while (!rs.tr_rdy);/* Wait for tranceiver. */
156
157 REG_WR(ser, regi_ser, rw_dout, dout);
158}
159
160static void
161puts(const char *s)
162{
163#ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
164 while (*s) {
165#ifdef CONFIG_ETRAX_DEBUG_PORT0
166 serout(s, regi_ser0);
167#endif
168#ifdef CONFIG_ETRAX_DEBUG_PORT1
169 serout(s, regi_ser1);
170#endif
171#ifdef CONFIG_ETRAX_DEBUG_PORT2
172 serout(s, regi_ser2);
173#endif
174#ifdef CONFIG_ETRAX_DEBUG_PORT3
175 serout(s, regi_ser3);
176#endif
177 *s++;
178 }
179/* CONFIG_ETRAX_DEBUG_PORT_NULL */
180#endif
181}
182
183void*
184memset(void* s, int c, size_t n)
185{
186 int i;
187 char *ss = (char*)s;
188
189 for (i=0;i<n;i++) ss[i] = c;
190}
191
192void*
193memcpy(void* __dest, __const void* __src,
194 size_t __n)
195{
196 int i;
197 char *d = (char *)__dest, *s = (char *)__src;
198
199 for (i=0;i<__n;i++) d[i] = s[i];
200}
201
202/* ===========================================================================
203 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
204 * (Used for the decompressed data only.)
205 */
206
207static void
208flush_window()
209{
210 ulg c = crc; /* temporary variable */
211 unsigned n;
212 uch *in, *out, ch;
213
214 in = window;
215 out = &output_data[output_ptr];
216 for (n = 0; n < outcnt; n++) {
217 ch = *out++ = *in++;
218 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
219 }
220 crc = c;
221 bytes_out += (ulg)outcnt;
222 output_ptr += (ulg)outcnt;
223 outcnt = 0;
224}
225
226static void
227error(char *x)
228{
229 puts("\n\n");
230 puts(x);
231 puts("\n\n -- System halted\n");
232
233 while(1); /* Halt */
234}
235
236void
237setup_normal_output_buffer()
238{
239 output_data = (char *)KERNEL_LOAD_ADR;
240}
241
242static inline void
243serial_setup(reg_scope_instances regi_ser)
244{
245 reg_ser_rw_xoff xoff;
246 reg_ser_rw_tr_ctrl tr_ctrl;
247 reg_ser_rw_rec_ctrl rec_ctrl;
248 reg_ser_rw_tr_baud_div tr_baud;
249 reg_ser_rw_rec_baud_div rec_baud;
250
251 /* Turn off XOFF. */
252 xoff = REG_RD(ser, regi_ser, rw_xoff);
253
254 xoff.chr = 0;
255 xoff.automatic = regk_ser_no;
256
257 REG_WR(ser, regi_ser, rw_xoff, xoff);
258
259 /* Set baudrate and stopbits. */
260 tr_ctrl = REG_RD(ser, regi_ser, rw_tr_ctrl);
261 rec_ctrl = REG_RD(ser, regi_ser, rw_rec_ctrl);
262 tr_baud = REG_RD(ser, regi_ser, rw_tr_baud_div);
263 rec_baud = REG_RD(ser, regi_ser, rw_rec_baud_div);
264
265 tr_ctrl.stop_bits = 1; /* 2 stop bits. */
266
267 /*
268 * The baudrate setup is a bit fishy, but in the end the tranceiver is
269 * set to 4800 and the receiver to 115200. The magic value is
270 * 29.493 MHz.
271 */
272 tr_ctrl.base_freq = regk_ser_f29_493;
273 rec_ctrl.base_freq = regk_ser_f29_493;
274 tr_baud.div = (29493000 / 8) / 4800;
275 rec_baud.div = (29493000 / 8) / 115200;
276
277 REG_WR(ser, regi_ser, rw_tr_ctrl, tr_ctrl);
278 REG_WR(ser, regi_ser, rw_tr_baud_div, tr_baud);
279 REG_WR(ser, regi_ser, rw_rec_ctrl, rec_ctrl);
280 REG_WR(ser, regi_ser, rw_rec_baud_div, rec_baud);
281}
282
283void
284decompress_kernel()
285{
286 char revision;
287
288 /* input_data is set in head.S */
289 inbuf = input_data;
290
291#ifdef CONFIG_ETRAX_DEBUG_PORT0
292 serial_setup(regi_ser0);
293#endif
294#ifdef CONFIG_ETRAX_DEBUG_PORT1
295 serial_setup(regi_ser1);
296#endif
297#ifdef CONFIG_ETRAX_DEBUG_PORT2
298 serial_setup(regi_ser2);
299#endif
300#ifdef CONFIG_ETRAX_DEBUG_PORT3
301 serial_setup(regi_ser3);
302#endif
303
304 setup_normal_output_buffer();
305
306 makecrc();
307
308 __asm__ volatile ("move $vr,%0" : "=rm" (revision));
309 if (revision < 32)
310 {
311 puts("You need an ETRAX FS to run Linux 2.6/crisv32.\n");
312 while(1);
313 }
314
315 puts("Uncompressing Linux...\n");
316 gunzip();
317 puts("Done. Now booting the kernel.\n");
318}