aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoshinori Sato <ysato@users.sourceforge.jp>2007-05-06 17:50:36 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-07 15:12:58 -0400
commit97a572b3b877173e284c687be34d8ae81b826160 (patch)
tree71c2db80449df6057e46940376e19813aac077db
parentc728d60455e8e8722ee08312a75f38dd7a866b5e (diff)
h8300: add zImage support
h8300 zImage target support. Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/h8300/boot/Makefile12
-rw-r--r--arch/h8300/boot/compressed/Makefile37
-rw-r--r--arch/h8300/boot/compressed/head.S47
-rw-r--r--arch/h8300/boot/compressed/misc.c219
4 files changed, 314 insertions, 1 deletions
diff --git a/arch/h8300/boot/Makefile b/arch/h8300/boot/Makefile
index 65086d925ca7..0bb62e064eea 100644
--- a/arch/h8300/boot/Makefile
+++ b/arch/h8300/boot/Makefile
@@ -1,12 +1,22 @@
1# arch/h8300/boot/Makefile 1# arch/h8300/boot/Makefile
2 2
3targets := vmlinux.srec vmlinux.bin 3targets := vmlinux.srec vmlinux.bin zImage
4subdir- := compressed
4 5
5OBJCOPYFLAGS_vmlinux.srec := -Osrec 6OBJCOPYFLAGS_vmlinux.srec := -Osrec
6OBJCOPYFLAGS_vmlinux.bin := -Obinary 7OBJCOPYFLAGS_vmlinux.bin := -Obinary
8OBJCOPYFLAGS_zImage := -O binary -R .note -R .comment -R .stab -R .stabstr -S
7 9
8$(obj)/vmlinux.srec $(obj)/vmlinux.bin: vmlinux FORCE 10$(obj)/vmlinux.srec $(obj)/vmlinux.bin: vmlinux FORCE
9 $(call if_changed,objcopy) 11 $(call if_changed,objcopy)
10 @echo ' Kernel: $@ is ready' 12 @echo ' Kernel: $@ is ready'
11 13
14$(obj)/zImage: $(obj)/compressed/vmlinux FORCE
15 $(call if_changed,objcopy)
16 @echo 'Kernel: $@ is ready'
17
18$(obj)/compressed/vmlinux: FORCE
19 $(Q)$(MAKE) $(build)=$(obj)/compressed $@
20
12CLEAN_FILES += arch/$(ARCH)/vmlinux.bin arch/$(ARCH)/vmlinux.srec 21CLEAN_FILES += arch/$(ARCH)/vmlinux.bin arch/$(ARCH)/vmlinux.srec
22
diff --git a/arch/h8300/boot/compressed/Makefile b/arch/h8300/boot/compressed/Makefile
new file mode 100644
index 000000000000..71aac82a8ae0
--- /dev/null
+++ b/arch/h8300/boot/compressed/Makefile
@@ -0,0 +1,37 @@
1#
2# linux/arch/sh/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
8EXTRA_AFLAGS := -traditional
9
10OBJECTS = $(obj)/head.o $(obj)/misc.o
11
12#
13# IMAGE_OFFSET is the load offset of the compression loader
14# Assign dummy values if these 2 variables are not defined,
15# in order to suppress error message.
16#
17CONFIG_MEMORY_START ?= 0x00400000
18CONFIG_BOOT_LINK_OFFSET ?= 0x00400000
19IMAGE_OFFSET := $(shell printf "0x%08x" $$[$(CONFIG_MEMORY_START)+$(CONFIG_BOOT_LINK_OFFSET)])
20
21LDFLAGS_vmlinux := -T $(obj)/vmlinux.lds
22
23$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o FORCE
24 $(call if_changed,ld)
25 @:
26
27$(obj)/vmlinux.bin: vmlinux FORCE
28 $(call if_changed,objcopy)
29
30$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
31 $(call if_changed,gzip)
32
33LDFLAGS_piggy.o := -r --format binary --oformat elf32-h8300 -T
34OBJCOPYFLAGS := -O binary
35
36$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
37 $(call if_changed,ld)
diff --git a/arch/h8300/boot/compressed/head.S b/arch/h8300/boot/compressed/head.S
new file mode 100644
index 000000000000..b8e90d12d19e
--- /dev/null
+++ b/arch/h8300/boot/compressed/head.S
@@ -0,0 +1,47 @@
1/*
2 * linux/arch/h8300/boot/compressed/head.S
3 *
4 * Copyright (C) 2006 Yoshinori Sato
5 */
6
7.h8300h
8#include <linux/linkage.h>
9
10#define SRAM_START 0xff4000
11
12 .section .text.startup
13 .global startup
14startup:
15 mov.l #SRAM_START+0x8000, sp
16 mov.l #__sbss, er0
17 mov.l #__ebss, er1
18 sub.l er0, er1
19 shlr er1
20 shlr er1
21 sub.l er2, er2
221:
23 mov.l er2, @er0
24 adds #4, er0
25 dec.l #1, er1
26 bne 1b
27 jsr @_decompress_kernel
28 jmp @0x400000
29
30 .align 9
31fake_headers_as_bzImage:
32 .word 0
33 .ascii "HdrS" ; header signature
34 .word 0x0202 ; header version number (>= 0x0105)
35 ; or else old loadlin-1.5 will fail)
36 .word 0 ; default_switch
37 .word 0 ; SETUPSEG
38 .word 0x1000
39 .word 0 ; pointing to kernel version string
40 .byte 0 ; = 0, old one (LILO, Loadlin,
41 ; 0xTV: T=0 for LILO
42 ; V = version
43 .byte 1 ; Load flags bzImage=1
44 .word 0x8000 ; size to move, when setup is not
45 .long 0x100000 ; 0x100000 = default for big kernel
46 .long 0 ; address of loaded ramdisk image
47 .long 0 ; its size in bytes
diff --git a/arch/h8300/boot/compressed/misc.c b/arch/h8300/boot/compressed/misc.c
new file mode 100644
index 000000000000..845074588af0
--- /dev/null
+++ b/arch/h8300/boot/compressed/misc.c
@@ -0,0 +1,219 @@
1/*
2 * arch/h8300/boot/compressed/misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 *
9 * Adapted for h8300 by Yoshinori Sato 2006
10 */
11
12#include <asm/uaccess.h>
13
14/*
15 * gzip declarations
16 */
17
18#define OF(args) args
19#define STATIC static
20
21#undef memset
22#undef memcpy
23#define memzero(s, n) memset ((s), 0, (n))
24
25typedef unsigned char uch;
26typedef unsigned short ush;
27typedef unsigned long ulg;
28
29#define WSIZE 0x8000 /* Window size must be at least 32k, */
30 /* and a power of two */
31
32static uch *inbuf; /* input buffer */
33static uch window[WSIZE]; /* Sliding window buffer */
34
35static unsigned insize = 0; /* valid bytes in inbuf */
36static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
37static unsigned outcnt = 0; /* bytes in output buffer */
38
39/* gzip flag byte */
40#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
41#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
42#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
43#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
44#define COMMENT 0x10 /* bit 4 set: file comment present */
45#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
46#define RESERVED 0xC0 /* bit 6,7: reserved */
47
48#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
49
50/* Diagnostic functions */
51#ifdef DEBUG
52# define Assert(cond,msg) {if(!(cond)) error(msg);}
53# define Trace(x) fprintf x
54# define Tracev(x) {if (verbose) fprintf x ;}
55# define Tracevv(x) {if (verbose>1) fprintf x ;}
56# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
57# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
58#else
59# define Assert(cond,msg)
60# define Trace(x)
61# define Tracev(x)
62# define Tracevv(x)
63# define Tracec(c,x)
64# define Tracecv(c,x)
65#endif
66
67static int fill_inbuf(void);
68static void flush_window(void);
69static void error(char *m);
70static void gzip_mark(void **);
71static void gzip_release(void **);
72
73extern char input_data[];
74extern int input_len;
75
76static long bytes_out = 0;
77static uch *output_data;
78static unsigned long output_ptr = 0;
79
80static void *malloc(int size);
81static void free(void *where);
82static void error(char *m);
83static void gzip_mark(void **);
84static void gzip_release(void **);
85
86int puts(const char *);
87
88extern int _text; /* Defined in vmlinux.lds.S */
89extern int _end;
90static unsigned long free_mem_ptr;
91static unsigned long free_mem_end_ptr;
92
93#define HEAP_SIZE 0x10000
94
95#include "../../../../lib/inflate.c"
96
97#define SCR *((volatile unsigned char *)0xffff8a)
98#define TDR *((volatile unsigned char *)0xffff8b)
99#define SSR *((volatile unsigned char *)0xffff8c)
100
101static void *malloc(int size)
102{
103 void *p;
104
105 if (size <0) error("Malloc error");
106 if (free_mem_ptr == 0) error("Memory error");
107
108 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
109
110 p = (void *)free_mem_ptr;
111 free_mem_ptr += size;
112
113 if (free_mem_ptr >= free_mem_end_ptr)
114 error("Out of memory");
115
116 return p;
117}
118
119static void free(void *where)
120{ /* Don't care */
121}
122
123static void gzip_mark(void **ptr)
124{
125 *ptr = (void *) free_mem_ptr;
126}
127
128static void gzip_release(void **ptr)
129{
130 free_mem_ptr = (long) *ptr;
131}
132
133int puts(const char *s)
134{
135 return 0;
136}
137
138void* memset(void* s, int c, size_t n)
139{
140 int i;
141 char *ss = (char*)s;
142
143 for (i=0;i<n;i++) ss[i] = c;
144 return s;
145}
146
147void* memcpy(void* __dest, __const void* __src,
148 size_t __n)
149{
150 int i;
151 char *d = (char *)__dest, *s = (char *)__src;
152
153 for (i=0;i<__n;i++) d[i] = s[i];
154 return __dest;
155}
156
157/* ===========================================================================
158 * Fill the input buffer. This is called only when the buffer is empty
159 * and at least one byte is really needed.
160 */
161static int fill_inbuf(void)
162{
163 if (insize != 0) {
164 error("ran out of input data");
165 }
166
167 inbuf = input_data;
168 insize = input_len;
169 inptr = 1;
170 return inbuf[0];
171}
172
173/* ===========================================================================
174 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
175 * (Used for the decompressed data only.)
176 */
177static void flush_window(void)
178{
179 ulg c = crc; /* temporary variable */
180 unsigned n;
181 uch *in, *out, ch;
182
183 in = window;
184 out = &output_data[output_ptr];
185 for (n = 0; n < outcnt; n++) {
186 ch = *out++ = *in++;
187 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
188 }
189 crc = c;
190 bytes_out += (ulg)outcnt;
191 output_ptr += (ulg)outcnt;
192 outcnt = 0;
193}
194
195static void error(char *x)
196{
197 puts("\n\n");
198 puts(x);
199 puts("\n\n -- System halted");
200
201 while(1); /* Halt */
202}
203
204#define STACK_SIZE (4096)
205long user_stack [STACK_SIZE];
206long* stack_start = &user_stack[STACK_SIZE];
207
208void decompress_kernel(void)
209{
210 output_data = 0;
211 output_ptr = (unsigned long)0x400000;
212 free_mem_ptr = (unsigned long)&_end;
213 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
214
215 makecrc();
216 puts("Uncompressing Linux... ");
217 gunzip();
218 puts("Ok, booting the kernel.\n");
219}