aboutsummaryrefslogtreecommitdiffstats
path: root/arch/cris/arch-v10/boot/compressed
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/cris/arch-v10/boot/compressed
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/cris/arch-v10/boot/compressed')
-rw-r--r--arch/cris/arch-v10/boot/compressed/Makefile40
-rw-r--r--arch/cris/arch-v10/boot/compressed/README25
-rw-r--r--arch/cris/arch-v10/boot/compressed/decompress.ld29
-rw-r--r--arch/cris/arch-v10/boot/compressed/head.S111
-rw-r--r--arch/cris/arch-v10/boot/compressed/misc.c273
5 files changed, 478 insertions, 0 deletions
diff --git a/arch/cris/arch-v10/boot/compressed/Makefile b/arch/cris/arch-v10/boot/compressed/Makefile
new file mode 100644
index 000000000000..5f71c2c819e6
--- /dev/null
+++ b/arch/cris/arch-v10/boot/compressed/Makefile
@@ -0,0 +1,40 @@
1#
2# linux/arch/etrax100/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux files and romfs
5#
6
7CC = gcc-cris -melf -I $(TOPDIR)/include
8CFLAGS = -O2
9LD = ld-cris
10OBJCOPY = objcopy-cris
11OBJCOPYFLAGS = -O binary --remove-section=.bss
12OBJECTS = head.o misc.o
13
14# files to compress
15SYSTEM = $(TOPDIR)/vmlinux.bin
16
17all: vmlinuz
18
19decompress.bin: $(OBJECTS)
20 $(LD) -T decompress.ld -o decompress.o $(OBJECTS)
21 $(OBJCOPY) $(OBJCOPYFLAGS) decompress.o decompress.bin
22# save it for mkprod in the topdir.
23 cp decompress.bin $(TOPDIR)
24
25
26vmlinuz: piggy.img decompress.bin
27 cat decompress.bin piggy.img > vmlinuz
28 rm -f piggy.img
29
30head.o: head.S
31 $(CC) -D__ASSEMBLY__ -traditional -c head.S -o head.o
32
33# gzip the kernel image
34
35piggy.img: $(SYSTEM)
36 cat $(SYSTEM) | gzip -f -9 > piggy.img
37
38clean:
39 rm -f piggy.img vmlinuz vmlinuz.o
40
diff --git a/arch/cris/arch-v10/boot/compressed/README b/arch/cris/arch-v10/boot/compressed/README
new file mode 100644
index 000000000000..48b3db9924b9
--- /dev/null
+++ b/arch/cris/arch-v10/boot/compressed/README
@@ -0,0 +1,25 @@
1Creation of the self-extracting compressed kernel image (vmlinuz)
2-----------------------------------------------------------------
3$Id: README,v 1.1 2001/12/17 13:59:27 bjornw Exp $
4
5This can be slightly confusing because it's a process with many steps.
6
7The kernel object built by the arch/etrax100/Makefile, vmlinux, is split
8by that makefile into text and data binary files, vmlinux.text and
9vmlinux.data.
10
11Those files together with a ROM filesystem can be catted together and
12burned into a flash or executed directly at the DRAM origin.
13
14They can also be catted together and compressed with gzip, which is what
15happens in this makefile. Together they make up piggy.img.
16
17The decompressor is built into the file decompress.o. It is turned into
18the binary file decompress.bin, which is catted together with piggy.img
19into the file vmlinuz. It can be executed in an arbitrary place in flash.
20
21Be careful - it assumes some things about free locations in DRAM. It
22assumes the DRAM starts at 0x40000000 and that it is at least 8 MB,
23so it puts its code at 0x40700000, and initial stack at 0x40800000.
24
25-Bjorn
diff --git a/arch/cris/arch-v10/boot/compressed/decompress.ld b/arch/cris/arch-v10/boot/compressed/decompress.ld
new file mode 100644
index 000000000000..0b0a14fe6177
--- /dev/null
+++ b/arch/cris/arch-v10/boot/compressed/decompress.ld
@@ -0,0 +1,29 @@
1OUTPUT_FORMAT(elf32-us-cris)
2
3MEMORY
4 {
5 dram : ORIGIN = 0x40700000,
6 LENGTH = 0x00100000
7 }
8
9SECTIONS
10{
11 .text :
12 {
13 _stext = . ;
14 *(.text)
15 *(.rodata)
16 *(.rodata.*)
17 _etext = . ;
18 } > dram
19 .data :
20 {
21 *(.data)
22 _edata = . ;
23 } > dram
24 .bss :
25 {
26 *(.bss)
27 _end = ALIGN( 0x10 ) ;
28 } > dram
29}
diff --git a/arch/cris/arch-v10/boot/compressed/head.S b/arch/cris/arch-v10/boot/compressed/head.S
new file mode 100644
index 000000000000..4cbdd4b1d9d6
--- /dev/null
+++ b/arch/cris/arch-v10/boot/compressed/head.S
@@ -0,0 +1,111 @@
1/*
2 * arch/cris/boot/compressed/head.S
3 *
4 * Copyright (C) 1999, 2001 Axis Communications AB
5 *
6 * Code that sets up the DRAM registers, calls the
7 * decompressor to unpack the piggybacked kernel, and jumps.
8 *
9 */
10
11#include <linux/config.h>
12#define ASSEMBLER_MACROS_ONLY
13#include <asm/arch/sv_addr_ag.h>
14
15#define RAM_INIT_MAGIC 0x56902387
16
17 ;; Exported symbols
18
19 .globl _input_data
20
21
22 .text
23
24 nop
25 di
26
27;; We need to initialze DRAM registers before we start using the DRAM
28
29 cmp.d RAM_INIT_MAGIC, r8 ; Already initialized?
30 beq dram_init_finished
31 nop
32
33#include "../../lib/dram_init.S"
34
35dram_init_finished:
36
37 ;; Initiate the PA and PB ports
38
39 move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, r0
40 move.b r0, [R_PORT_PA_DATA]
41
42 move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR, r0
43 move.b r0, [R_PORT_PA_DIR]
44
45 move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, r0
46 move.b r0, [R_PORT_PB_DATA]
47
48 move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR, r0
49 move.b r0, [R_PORT_PB_DIR]
50
51 ;; Setup the stack to a suitably high address.
52 ;; We assume 8 MB is the minimum DRAM in an eLinux
53 ;; product and put the sp at the top for now.
54
55 move.d 0x40800000, sp
56
57 ;; Figure out where the compressed piggyback image is
58 ;; in the flash (since we wont try to copy it to DRAM
59 ;; before unpacking). It is at _edata, but in flash.
60 ;; Use (_edata - basse) as offset to the current PC.
61
62basse: move.d pc, r5
63 and.d 0x7fffffff, r5 ; strip any non-cache bit
64 subq 2, r5 ; compensate for the move.d pc instr
65 move.d r5, r0 ; save for later - flash address of 'basse'
66 add.d _edata, r5
67 sub.d basse, r5 ; r5 = flash address of '_edata'
68
69 ;; Copy text+data to DRAM
70
71 move.d basse, r1 ; destination
72 move.d _edata, r2 ; end destination
731: move.w [r0+], r3
74 move.w r3, [r1+]
75 cmp.d r2, r1
76 bcs 1b
77 nop
78
79 move.d r5, [_input_data] ; for the decompressor
80
81
82 ;; Clear the decompressors BSS (between _edata and _end)
83
84 moveq 0, r0
85 move.d _edata, r1
86 move.d _end, r2
871: move.w r0, [r1+]
88 cmp.d r2, r1
89 bcs 1b
90 nop
91
92 ;; Do the decompression and save compressed size in _inptr
93
94 jsr _decompress_kernel
95
96 ;; Put start address of root partition in r9 so the kernel can use it
97 ;; when mounting from flash
98
99 move.d [_input_data], r9 ; flash address of compressed kernel
100 add.d [_inptr], r9 ; size of compressed kernel
101
102 ;; Enter the decompressed kernel
103 move.d RAM_INIT_MAGIC, r8 ; Tell kernel that DRAM is initialized
104 jump 0x40004000 ; kernel is linked to this address
105
106 .data
107
108_input_data:
109 .dword 0 ; used by the decompressor
110
111#include "../../lib/hw_settings.S"
diff --git a/arch/cris/arch-v10/boot/compressed/misc.c b/arch/cris/arch-v10/boot/compressed/misc.c
new file mode 100644
index 000000000000..1b5e83f1f846
--- /dev/null
+++ b/arch/cris/arch-v10/boot/compressed/misc.c
@@ -0,0 +1,273 @@
1/*
2 * misc.c
3 *
4 * $Id: misc.c,v 1.6 2003/10/27 08:04:31 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/svinto.h>
27
28/*
29 * gzip declarations
30 */
31
32#define OF(args) args
33#define STATIC static
34
35void* memset(void* s, int c, size_t n);
36void* memcpy(void* __dest, __const void* __src,
37 size_t __n);
38
39#define memzero(s, n) memset ((s), 0, (n))
40
41
42typedef unsigned char uch;
43typedef unsigned short ush;
44typedef unsigned long ulg;
45
46#define WSIZE 0x8000 /* Window size must be at least 32k, */
47 /* and a power of two */
48
49static uch *inbuf; /* input buffer */
50static uch window[WSIZE]; /* Sliding window buffer */
51
52unsigned inptr = 0; /* index of next byte to be processed in inbuf
53 * After decompression it will contain the
54 * compressed size, and head.S will read it.
55 */
56
57static unsigned outcnt = 0; /* bytes in output buffer */
58
59/* gzip flag byte */
60#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
61#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
62#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
63#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
64#define COMMENT 0x10 /* bit 4 set: file comment present */
65#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
66#define RESERVED 0xC0 /* bit 6,7: reserved */
67
68#define get_byte() inbuf[inptr++]
69
70/* Diagnostic functions */
71#ifdef DEBUG
72# define Assert(cond,msg) {if(!(cond)) error(msg);}
73# define Trace(x) fprintf x
74# define Tracev(x) {if (verbose) fprintf x ;}
75# define Tracevv(x) {if (verbose>1) fprintf x ;}
76# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
77# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
78#else
79# define Assert(cond,msg)
80# define Trace(x)
81# define Tracev(x)
82# define Tracevv(x)
83# define Tracec(c,x)
84# define Tracecv(c,x)
85#endif
86
87static int fill_inbuf(void);
88static void flush_window(void);
89static void error(char *m);
90static void gzip_mark(void **);
91static void gzip_release(void **);
92
93extern char *input_data; /* lives in head.S */
94
95static long bytes_out = 0;
96static uch *output_data;
97static unsigned long output_ptr = 0;
98
99static void *malloc(int size);
100static void free(void *where);
101static void error(char *m);
102static void gzip_mark(void **);
103static void gzip_release(void **);
104
105static void puts(const char *);
106
107/* the "heap" is put directly after the BSS ends, at end */
108
109extern int end;
110static long free_mem_ptr = (long)&end;
111
112#include "../../../../../lib/inflate.c"
113
114static void *malloc(int size)
115{
116 void *p;
117
118 if (size <0) error("Malloc error");
119
120 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
121
122 p = (void *)free_mem_ptr;
123 free_mem_ptr += size;
124
125 return p;
126}
127
128static void free(void *where)
129{ /* Don't care */
130}
131
132static void gzip_mark(void **ptr)
133{
134 *ptr = (void *) free_mem_ptr;
135}
136
137static void gzip_release(void **ptr)
138{
139 free_mem_ptr = (long) *ptr;
140}
141
142/* decompressor info and error messages to serial console */
143
144static void
145puts(const char *s)
146{
147#ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
148 while(*s) {
149#ifdef CONFIG_ETRAX_DEBUG_PORT0
150 while(!(*R_SERIAL0_STATUS & (1 << 5))) ;
151 *R_SERIAL0_TR_DATA = *s++;
152#endif
153#ifdef CONFIG_ETRAX_DEBUG_PORT1
154 while(!(*R_SERIAL1_STATUS & (1 << 5))) ;
155 *R_SERIAL1_TR_DATA = *s++;
156#endif
157#ifdef CONFIG_ETRAX_DEBUG_PORT2
158 while(!(*R_SERIAL2_STATUS & (1 << 5))) ;
159 *R_SERIAL2_TR_DATA = *s++;
160#endif
161#ifdef CONFIG_ETRAX_DEBUG_PORT3
162 while(!(*R_SERIAL3_STATUS & (1 << 5))) ;
163 *R_SERIAL3_TR_DATA = *s++;
164#endif
165 }
166#endif
167}
168
169void*
170memset(void* s, int c, size_t n)
171{
172 int i;
173 char *ss = (char*)s;
174
175 for (i=0;i<n;i++) ss[i] = c;
176}
177
178void*
179memcpy(void* __dest, __const void* __src,
180 size_t __n)
181{
182 int i;
183 char *d = (char *)__dest, *s = (char *)__src;
184
185 for (i=0;i<__n;i++) d[i] = s[i];
186}
187
188/* ===========================================================================
189 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
190 * (Used for the decompressed data only.)
191 */
192
193static void
194flush_window()
195{
196 ulg c = crc; /* temporary variable */
197 unsigned n;
198 uch *in, *out, ch;
199
200 in = window;
201 out = &output_data[output_ptr];
202 for (n = 0; n < outcnt; n++) {
203 ch = *out++ = *in++;
204 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
205 }
206 crc = c;
207 bytes_out += (ulg)outcnt;
208 output_ptr += (ulg)outcnt;
209 outcnt = 0;
210}
211
212static void
213error(char *x)
214{
215 puts("\n\n");
216 puts(x);
217 puts("\n\n -- System halted\n");
218
219 while(1); /* Halt */
220}
221
222void
223setup_normal_output_buffer()
224{
225 output_data = (char *)KERNEL_LOAD_ADR;
226}
227
228void
229decompress_kernel()
230{
231 char revision;
232
233 /* input_data is set in head.S */
234 inbuf = input_data;
235
236#ifdef CONFIG_ETRAX_DEBUG_PORT0
237 *R_SERIAL0_XOFF = 0;
238 *R_SERIAL0_BAUD = 0x99;
239 *R_SERIAL0_TR_CTRL = 0x40;
240#endif
241#ifdef CONFIG_ETRAX_DEBUG_PORT1
242 *R_SERIAL1_XOFF = 0;
243 *R_SERIAL1_BAUD = 0x99;
244 *R_SERIAL1_TR_CTRL = 0x40;
245#endif
246#ifdef CONFIG_ETRAX_DEBUG_PORT2
247 *R_GEN_CONFIG = 0x08;
248 *R_SERIAL2_XOFF = 0;
249 *R_SERIAL2_BAUD = 0x99;
250 *R_SERIAL2_TR_CTRL = 0x40;
251#endif
252#ifdef CONFIG_ETRAX_DEBUG_PORT3
253 *R_GEN_CONFIG = 0x100;
254 *R_SERIAL3_XOFF = 0;
255 *R_SERIAL3_BAUD = 0x99;
256 *R_SERIAL3_TR_CTRL = 0x40;
257#endif
258
259 setup_normal_output_buffer();
260
261 makecrc();
262
263 __asm__ volatile ("move vr,%0" : "=rm" (revision));
264 if (revision < 10)
265 {
266 puts("You need an ETRAX 100LX to run linux 2.6\n");
267 while(1);
268 }
269
270 puts("Uncompressing Linux...\n");
271 gunzip();
272 puts("Done. Now booting the kernel.\n");
273}