1 // SPDX-License-Identifier: GPL-2.0
5 * This is a collection of several routines from gzip-1.0.3
8 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
10 * adaptation for Linux/CRIS Axis Communications AB, 1999
14 /* where the piggybacked kernel image expects itself to live.
15 * it is the same address we use when we network load an uncompressed
16 * image into DRAM, and it is the address the kernel is linked to live
20 #define KERNEL_LOAD_ADR 0x40004000
22 #include <linux/types.h>
24 #ifdef CONFIG_ETRAX_ARCH_V32
25 #include <hwregs/reg_rdwr.h>
26 #include <hwregs/reg_map.h>
27 #include <hwregs/ser_defs.h>
28 #include <hwregs/pinmux_defs.h>
29 #ifdef CONFIG_CRIS_MACH_ARTPEC3
30 #include <hwregs/clkgen_defs.h>
33 #include <arch/svinto.h>
43 void *memset(void *s
, int c
, size_t n
);
44 void *memcpy(void *__dest
, __const
void *__src
, size_t __n
);
46 #define memzero(s, n) memset((s), 0, (n))
48 typedef unsigned char uch
;
49 typedef unsigned short ush
;
50 typedef unsigned long ulg
;
52 #define WSIZE 0x8000 /* Window size must be at least 32k, */
53 /* and a power of two */
55 static uch
*inbuf
; /* input buffer */
56 static uch window
[WSIZE
]; /* Sliding window buffer */
58 unsigned inptr
= 0; /* index of next byte to be processed in inbuf
59 * After decompression it will contain the
60 * compressed size, and head.S will read it.
63 static unsigned outcnt
= 0; /* bytes in output buffer */
66 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
67 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
68 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
69 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
70 #define COMMENT 0x10 /* bit 4 set: file comment present */
71 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
72 #define RESERVED 0xC0 /* bit 6,7: reserved */
74 #define get_byte() (inbuf[inptr++])
76 /* Diagnostic functions */
78 # define Assert(cond, msg) do { \
82 # define Trace(x) fprintf x
83 # define Tracev(x) do { \
87 # define Tracevv(x) do { \
91 # define Tracec(c, x) do { \
95 # define Tracecv(c, x) do { \
96 if (verbose > 1 && (c)) \
100 # define Assert(cond, msg)
104 # define Tracec(c, x)
105 # define Tracecv(c, x)
108 static void flush_window(void);
109 static void error(char *m
);
110 static void aputs(const char *s
);
112 extern char *input_data
; /* lives in head.S */
114 static long bytes_out
;
115 static uch
*output_data
;
116 static unsigned long output_ptr
;
118 /* the "heap" is put directly after the BSS ends, at end */
121 static long free_mem_ptr
= (long)&_end
;
122 static long free_mem_end_ptr
;
124 #include "../../../../../lib/inflate.c"
126 /* decompressor info and error messages to serial console */
128 #ifdef CONFIG_ETRAX_ARCH_V32
129 static inline void serout(const char *s
, reg_scope_instances regi_ser
)
131 reg_ser_rs_stat_din rs
;
132 reg_ser_rw_dout dout
= {.data
= *s
};
135 rs
= REG_RD(ser
, regi_ser
, rs_stat_din
);
137 while (!rs
.tr_rdy
);/* Wait for transceiver. */
139 REG_WR(ser
, regi_ser
, rw_dout
, dout
);
141 #define SEROUT(S, N) \
143 serout(S, regi_ser ## N); \
147 #define SEROUT(S, N) do { \
148 while (!(*R_SERIAL ## N ## _STATUS & (1 << 5))) \
150 *R_SERIAL ## N ## _TR_DATA = *s++; \
154 static void aputs(const char *s
)
156 #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
158 #ifdef CONFIG_ETRAX_DEBUG_PORT0
161 #ifdef CONFIG_ETRAX_DEBUG_PORT1
164 #ifdef CONFIG_ETRAX_DEBUG_PORT2
167 #ifdef CONFIG_ETRAX_DEBUG_PORT3
171 #endif /* CONFIG_ETRAX_DEBUG_PORT_NULL */
174 void *memset(void *s
, int c
, size_t n
)
179 for (i
=0;i
<n
;i
++) ss
[i
] = c
;
184 void *memcpy(void *__dest
, __const
void *__src
, size_t __n
)
187 char *d
= (char *)__dest
, *s
= (char *)__src
;
189 for (i
= 0; i
< __n
; i
++)
195 /* ===========================================================================
196 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
197 * (Used for the decompressed data only.)
200 static void flush_window(void)
202 ulg c
= crc
; /* temporary variable */
207 out
= &output_data
[output_ptr
];
208 for (n
= 0; n
< outcnt
; n
++) {
212 c
= crc_32_tab
[((int)c
^ ch
) & 0xff] ^ (c
>> 8);
215 bytes_out
+= (ulg
)outcnt
;
216 output_ptr
+= (ulg
)outcnt
;
220 static void error(char *x
)
224 aputs("\n\n -- System halted\n");
229 void setup_normal_output_buffer(void)
231 output_data
= (char *)KERNEL_LOAD_ADR
;
234 #ifdef CONFIG_ETRAX_ARCH_V32
235 static inline void serial_setup(reg_scope_instances regi_ser
)
237 reg_ser_rw_xoff xoff
;
238 reg_ser_rw_tr_ctrl tr_ctrl
;
239 reg_ser_rw_rec_ctrl rec_ctrl
;
240 reg_ser_rw_tr_baud_div tr_baud
;
241 reg_ser_rw_rec_baud_div rec_baud
;
244 xoff
= REG_RD(ser
, regi_ser
, rw_xoff
);
247 xoff
.automatic
= regk_ser_no
;
249 REG_WR(ser
, regi_ser
, rw_xoff
, xoff
);
251 /* Set baudrate and stopbits. */
252 tr_ctrl
= REG_RD(ser
, regi_ser
, rw_tr_ctrl
);
253 rec_ctrl
= REG_RD(ser
, regi_ser
, rw_rec_ctrl
);
254 tr_baud
= REG_RD(ser
, regi_ser
, rw_tr_baud_div
);
255 rec_baud
= REG_RD(ser
, regi_ser
, rw_rec_baud_div
);
257 tr_ctrl
.stop_bits
= 1; /* 2 stop bits. */
258 tr_ctrl
.en
= 1; /* enable transmitter */
259 rec_ctrl
.en
= 1; /* enabler receiver */
262 * The baudrate setup used to be a bit fishy, but now transmitter and
263 * receiver are both set to the intended baud rate, 115200.
264 * The magic value is 29.493 MHz.
266 tr_ctrl
.base_freq
= regk_ser_f29_493
;
267 rec_ctrl
.base_freq
= regk_ser_f29_493
;
268 tr_baud
.div
= (29493000 / 8) / 115200;
269 rec_baud
.div
= (29493000 / 8) / 115200;
271 REG_WR(ser
, regi_ser
, rw_tr_ctrl
, tr_ctrl
);
272 REG_WR(ser
, regi_ser
, rw_tr_baud_div
, tr_baud
);
273 REG_WR(ser
, regi_ser
, rw_rec_ctrl
, rec_ctrl
);
274 REG_WR(ser
, regi_ser
, rw_rec_baud_div
, rec_baud
);
278 void decompress_kernel(void)
283 #ifdef CONFIG_ETRAX_ARCH_V32
284 /* Need at least a CRISv32 to run. */
286 #if defined(CONFIG_ETRAX_DEBUG_PORT1) || \
287 defined(CONFIG_ETRAX_DEBUG_PORT2) || \
288 defined(CONFIG_ETRAX_DEBUG_PORT3)
289 reg_pinmux_rw_hwprot hwprot
;
291 #ifdef CONFIG_CRIS_MACH_ARTPEC3
292 reg_clkgen_rw_clk_ctrl clk_ctrl
;
294 /* Enable corresponding clock region when serial 1..3 selected */
296 clk_ctrl
= REG_RD(clkgen
, regi_clkgen
, rw_clk_ctrl
);
297 clk_ctrl
.sser_ser_dma6_7
= regk_clkgen_yes
;
298 REG_WR(clkgen
, regi_clkgen
, rw_clk_ctrl
, clk_ctrl
);
301 /* pinmux setup for ports 1..3 */
302 hwprot
= REG_RD(pinmux
, regi_pinmux
, rw_hwprot
);
306 #ifdef CONFIG_ETRAX_DEBUG_PORT0
307 serial_setup(regi_ser0
);
309 #ifdef CONFIG_ETRAX_DEBUG_PORT1
310 hwprot
.ser1
= regk_pinmux_yes
;
311 serial_setup(regi_ser1
);
313 #ifdef CONFIG_ETRAX_DEBUG_PORT2
314 hwprot
.ser2
= regk_pinmux_yes
;
315 serial_setup(regi_ser2
);
317 #ifdef CONFIG_ETRAX_DEBUG_PORT3
318 hwprot
.ser3
= regk_pinmux_yes
;
319 serial_setup(regi_ser3
);
321 #if defined(CONFIG_ETRAX_DEBUG_PORT1) || \
322 defined(CONFIG_ETRAX_DEBUG_PORT2) || \
323 defined(CONFIG_ETRAX_DEBUG_PORT3)
324 REG_WR(pinmux
, regi_pinmux
, rw_hwprot
, hwprot
);
327 /* input_data is set in head.S */
330 /* Need at least a crisv10 to run. */
333 /* input_data is set in head.S */
336 #ifdef CONFIG_ETRAX_DEBUG_PORT0
338 *R_SERIAL0_BAUD
= 0x99;
339 *R_SERIAL0_TR_CTRL
= 0x40;
341 #ifdef CONFIG_ETRAX_DEBUG_PORT1
343 *R_SERIAL1_BAUD
= 0x99;
344 *R_SERIAL1_TR_CTRL
= 0x40;
346 #ifdef CONFIG_ETRAX_DEBUG_PORT2
347 *R_GEN_CONFIG
= 0x08;
349 *R_SERIAL2_BAUD
= 0x99;
350 *R_SERIAL2_TR_CTRL
= 0x40;
352 #ifdef CONFIG_ETRAX_DEBUG_PORT3
353 *R_GEN_CONFIG
= 0x100;
355 *R_SERIAL3_BAUD
= 0x99;
356 *R_SERIAL3_TR_CTRL
= 0x40;
360 setup_normal_output_buffer();
364 __asm__
volatile ("move $vr,%0" : "=rm" (revision
));
365 if (revision
< compile_rev
) {
366 #ifdef CONFIG_ETRAX_ARCH_V32
367 aputs("You need at least ETRAX FS to run Linux 2.6/crisv32\n");
369 aputs("You need an ETRAX 100LX to run linux 2.6/crisv10\n");
374 aputs("Uncompressing Linux...\n");
376 aputs("Done. Now booting the kernel\n");