diff options
Diffstat (limited to 'arch/cris/boot/compressed')
-rw-r--r-- | arch/cris/boot/compressed/Makefile | 38 | ||||
-rw-r--r-- | arch/cris/boot/compressed/README | 24 | ||||
-rw-r--r-- | arch/cris/boot/compressed/decompress_v10.lds | 30 | ||||
-rw-r--r-- | arch/cris/boot/compressed/decompress_v32.lds | 30 | ||||
-rw-r--r-- | arch/cris/boot/compressed/head_v10.S | 126 | ||||
-rw-r--r-- | arch/cris/boot/compressed/head_v32.S | 145 | ||||
-rw-r--r-- | arch/cris/boot/compressed/misc.c | 391 |
7 files changed, 784 insertions, 0 deletions
diff --git a/arch/cris/boot/compressed/Makefile b/arch/cris/boot/compressed/Makefile new file mode 100644 index 000000000000..8fe9338c1775 --- /dev/null +++ b/arch/cris/boot/compressed/Makefile | |||
@@ -0,0 +1,38 @@ | |||
1 | # | ||
2 | # arch/cris/boot/compressed/Makefile | ||
3 | # | ||
4 | |||
5 | asflags-y += $(LINUXINCLUDE) | ||
6 | ccflags-y += -O2 $(LINUXINCLUDE) | ||
7 | |||
8 | # asflags-$(CONFIG_ETRAX_ARCH_V32) += -I$(srctree)/include/asm/mach \ | ||
9 | # -I$(srctree)/include/asm/arch | ||
10 | # ccflags-$(CONFIG_ETRAX_ARCH_V32) += -O2 -I$(srctree)/include/asm/mach | ||
11 | # -I$(srctree)/include/asm/arch | ||
12 | |||
13 | arch-$(CONFIG_ETRAX_ARCH_V10) = v10 | ||
14 | arch-$(CONFIG_ETRAX_ARCH_V32) = v32 | ||
15 | |||
16 | ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds | ||
17 | |||
18 | OBJECTS-$(CONFIG_ETRAX_ARCH_V32) = $(obj)/head_v32.o | ||
19 | OBJECTS-$(CONFIG_ETRAX_ARCH_V10) = $(obj)/head_v10.o | ||
20 | OBJECTS= $(OBJECTS-y) $(obj)/misc.o | ||
21 | OBJCOPYFLAGS = -O binary --remove-section=.bss | ||
22 | |||
23 | quiet_cmd_image = BUILD $@ | ||
24 | cmd_image = cat $(obj)/decompress.bin $(obj)/piggy.gz > $@ | ||
25 | |||
26 | targets := vmlinux piggy.gz decompress.o decompress.bin | ||
27 | |||
28 | $(obj)/decompress.o: $(OBJECTS) FORCE | ||
29 | $(call if_changed,ld) | ||
30 | |||
31 | $(obj)/decompress.bin: $(obj)/decompress.o FORCE | ||
32 | $(call if_changed,objcopy) | ||
33 | |||
34 | $(obj)/vmlinux: $(obj)/piggy.gz $(obj)/decompress.bin FORCE | ||
35 | $(call if_changed,image) | ||
36 | |||
37 | $(obj)/piggy.gz: $(obj)/../Image FORCE | ||
38 | $(call if_changed,gzip) | ||
diff --git a/arch/cris/boot/compressed/README b/arch/cris/boot/compressed/README new file mode 100644 index 000000000000..182c5d75784b --- /dev/null +++ b/arch/cris/boot/compressed/README | |||
@@ -0,0 +1,24 @@ | |||
1 | Creation of the self-extracting compressed kernel image (vmlinuz) | ||
2 | ----------------------------------------------------------------- | ||
3 | |||
4 | This can be slightly confusing because it's a process with many steps. | ||
5 | |||
6 | The kernel object built by the arch/etrax100/Makefile, vmlinux, is split | ||
7 | by that makefile into text and data binary files, vmlinux.text and | ||
8 | vmlinux.data. | ||
9 | |||
10 | Those files together with a ROM filesystem can be catted together and | ||
11 | burned into a flash or executed directly at the DRAM origin. | ||
12 | |||
13 | They can also be catted together and compressed with gzip, which is what | ||
14 | happens in this makefile. Together they make up piggy.img. | ||
15 | |||
16 | The decompressor is built into the file decompress.o. It is turned into | ||
17 | the binary file decompress.bin, which is catted together with piggy.img | ||
18 | into the file vmlinuz. It can be executed in an arbitrary place in flash. | ||
19 | |||
20 | Be careful - it assumes some things about free locations in DRAM. It | ||
21 | assumes the DRAM starts at 0x40000000 and that it is at least 8 MB, | ||
22 | so it puts its code at 0x40700000, and initial stack at 0x40800000. | ||
23 | |||
24 | -Bjorn | ||
diff --git a/arch/cris/boot/compressed/decompress_v10.lds b/arch/cris/boot/compressed/decompress_v10.lds new file mode 100644 index 000000000000..e80f4594d543 --- /dev/null +++ b/arch/cris/boot/compressed/decompress_v10.lds | |||
@@ -0,0 +1,30 @@ | |||
1 | /* OUTPUT_FORMAT(elf32-us-cris) */ | ||
2 | OUTPUT_FORMAT(elf32-cris) | ||
3 | |||
4 | MEMORY | ||
5 | { | ||
6 | dram : ORIGIN = 0x40700000, | ||
7 | LENGTH = 0x00100000 | ||
8 | } | ||
9 | |||
10 | SECTIONS | ||
11 | { | ||
12 | .text : | ||
13 | { | ||
14 | _stext = . ; | ||
15 | *(.text) | ||
16 | *(.rodata) | ||
17 | *(.rodata.*) | ||
18 | _etext = . ; | ||
19 | } > dram | ||
20 | .data : | ||
21 | { | ||
22 | *(.data) | ||
23 | _edata = . ; | ||
24 | } > dram | ||
25 | .bss : | ||
26 | { | ||
27 | *(.bss) | ||
28 | _end = ALIGN( 0x10 ) ; | ||
29 | } > dram | ||
30 | } | ||
diff --git a/arch/cris/boot/compressed/decompress_v32.lds b/arch/cris/boot/compressed/decompress_v32.lds new file mode 100644 index 000000000000..3c837feca3ac --- /dev/null +++ b/arch/cris/boot/compressed/decompress_v32.lds | |||
@@ -0,0 +1,30 @@ | |||
1 | /*#OUTPUT_FORMAT(elf32-us-cris) */ | ||
2 | OUTPUT_ARCH (crisv32) | ||
3 | |||
4 | MEMORY | ||
5 | { | ||
6 | dram : ORIGIN = 0x40700000, | ||
7 | LENGTH = 0x00100000 | ||
8 | } | ||
9 | |||
10 | SECTIONS | ||
11 | { | ||
12 | .text : | ||
13 | { | ||
14 | _stext = . ; | ||
15 | *(.text) | ||
16 | *(.rodata) | ||
17 | *(.rodata.*) | ||
18 | _etext = . ; | ||
19 | } > dram | ||
20 | .data : | ||
21 | { | ||
22 | *(.data) | ||
23 | _edata = . ; | ||
24 | } > dram | ||
25 | .bss : | ||
26 | { | ||
27 | *(.bss) | ||
28 | _end = ALIGN( 0x10 ) ; | ||
29 | } > dram | ||
30 | } | ||
diff --git a/arch/cris/boot/compressed/head_v10.S b/arch/cris/boot/compressed/head_v10.S new file mode 100644 index 000000000000..9edb8ade7e1f --- /dev/null +++ b/arch/cris/boot/compressed/head_v10.S | |||
@@ -0,0 +1,126 @@ | |||
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 | #define ASSEMBLER_MACROS_ONLY | ||
12 | #include <arch/sv_addr_ag.h> | ||
13 | |||
14 | #define RAM_INIT_MAGIC 0x56902387 | ||
15 | #define COMMAND_LINE_MAGIC 0x87109563 | ||
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 "../../arch-v10/lib/dram_init.S" | ||
34 | |||
35 | dram_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 | |||
62 | basse: 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 | ||
73 | 1: 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 | ||
87 | 1: move.w $r0, [$r1+] | ||
88 | cmp.d $r2, $r1 | ||
89 | bcs 1b | ||
90 | nop | ||
91 | |||
92 | ;; Save command line magic and address. | ||
93 | move.d _cmd_line_magic, $r12 | ||
94 | move.d $r10, [$r12] | ||
95 | move.d _cmd_line_addr, $r12 | ||
96 | move.d $r11, [$r12] | ||
97 | |||
98 | ;; Do the decompression and save compressed size in inptr | ||
99 | |||
100 | jsr decompress_kernel | ||
101 | |||
102 | ;; Put start address of root partition in $r9 so the kernel can use it | ||
103 | ;; when mounting from flash | ||
104 | |||
105 | move.d [input_data], $r9 ; flash address of compressed kernel | ||
106 | add.d [inptr], $r9 ; size of compressed kernel | ||
107 | |||
108 | ;; Restore command line magic and address. | ||
109 | move.d _cmd_line_magic, $r10 | ||
110 | move.d [$r10], $r10 | ||
111 | move.d _cmd_line_addr, $r11 | ||
112 | move.d [$r11], $r11 | ||
113 | |||
114 | ;; Enter the decompressed kernel | ||
115 | move.d RAM_INIT_MAGIC, $r8 ; Tell kernel that DRAM is initialized | ||
116 | jump 0x40004000 ; kernel is linked to this address | ||
117 | |||
118 | .data | ||
119 | |||
120 | input_data: | ||
121 | .dword 0 ; used by the decompressor | ||
122 | _cmd_line_magic: | ||
123 | .dword 0 | ||
124 | _cmd_line_addr: | ||
125 | .dword 0 | ||
126 | #include "../../arch-v10/lib/hw_settings.S" | ||
diff --git a/arch/cris/boot/compressed/head_v32.S b/arch/cris/boot/compressed/head_v32.S new file mode 100644 index 000000000000..f483005f3d48 --- /dev/null +++ b/arch/cris/boot/compressed/head_v32.S | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | * Code that sets up the DRAM registers, calls the | ||
3 | * decompressor to unpack the piggybacked kernel, and jumps. | ||
4 | * | ||
5 | * Copyright (C) 1999 - 2006, Axis Communications AB | ||
6 | */ | ||
7 | |||
8 | #define ASSEMBLER_MACROS_ONLY | ||
9 | #include <hwregs/asm/reg_map_asm.h> | ||
10 | #include <mach/startup.inc> | ||
11 | |||
12 | #define RAM_INIT_MAGIC 0x56902387 | ||
13 | #define COMMAND_LINE_MAGIC 0x87109563 | ||
14 | |||
15 | ;; Exported symbols | ||
16 | |||
17 | .globl input_data | ||
18 | |||
19 | .text | ||
20 | start: | ||
21 | di | ||
22 | |||
23 | ;; Start clocks for used blocks. | ||
24 | START_CLOCKS | ||
25 | |||
26 | ;; Initialize the DRAM registers. | ||
27 | cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized? | ||
28 | beq dram_init_finished | ||
29 | nop | ||
30 | |||
31 | #if defined CONFIG_ETRAXFS | ||
32 | #include "../../arch-v32/mach-fs/dram_init.S" | ||
33 | #elif defined CONFIG_CRIS_MACH_ARTPEC3 | ||
34 | #include "../../arch-v32/mach-a3/dram_init.S" | ||
35 | #else | ||
36 | #error Only ETRAXFS and ARTPEC-3 supported! | ||
37 | #endif | ||
38 | |||
39 | dram_init_finished: | ||
40 | |||
41 | GIO_INIT | ||
42 | ;; Setup the stack to a suitably high address. | ||
43 | ;; We assume 8 MB is the minimum DRAM and put | ||
44 | ;; the SP at the top for now. | ||
45 | |||
46 | move.d 0x40800000, $sp | ||
47 | |||
48 | ;; Figure out where the compressed piggyback image is. | ||
49 | ;; It is either in [NOR] flash (we don't want to copy it | ||
50 | ;; to DRAM before unpacking), or copied to DRAM | ||
51 | ;; by the [NAND] flash boot loader. | ||
52 | ;; The piggyback image is at _edata, but relative to where the | ||
53 | ;; image is actually located in memory, not where it is linked | ||
54 | ;; (the decompressor is linked at 0x40700000+ and runs there). | ||
55 | ;; Use (_edata - herami) as offset to the current PC. | ||
56 | |||
57 | hereami: | ||
58 | lapcq ., $r5 ; get PC | ||
59 | and.d 0x7fffffff, $r5 ; strip any non-cache bit | ||
60 | move.d $r5, $r0 ; source address of 'herami' | ||
61 | add.d _edata, $r5 | ||
62 | sub.d hereami, $r5 ; r5 = flash address of '_edata' | ||
63 | move.d hereami, $r1 ; destination | ||
64 | |||
65 | ;; Copy text+data to DRAM | ||
66 | |||
67 | move.d _edata, $r2 ; end destination | ||
68 | 1: move.w [$r0+], $r3 ; from herami+ source | ||
69 | move.w $r3, [$r1+] ; to hereami+ destination (linked address) | ||
70 | cmp.d $r2, $r1 ; finish when destination == _edata | ||
71 | bcs 1b | ||
72 | nop | ||
73 | move.d input_data, $r0 ; for the decompressor | ||
74 | move.d $r5, [$r0] ; for the decompressor | ||
75 | |||
76 | ;; Clear the decompressors BSS (between _edata and _end) | ||
77 | |||
78 | moveq 0, $r0 | ||
79 | move.d _edata, $r1 | ||
80 | move.d _end, $r2 | ||
81 | 1: move.w $r0, [$r1+] | ||
82 | cmp.d $r2, $r1 | ||
83 | bcs 1b | ||
84 | nop | ||
85 | |||
86 | ;; Save command line magic and address. | ||
87 | move.d _cmd_line_magic, $r0 | ||
88 | move.d $r10, [$r0] | ||
89 | move.d _cmd_line_addr, $r0 | ||
90 | move.d $r11, [$r0] | ||
91 | |||
92 | ;; Save boot source indicator | ||
93 | move.d _boot_source, $r0 | ||
94 | move.d $r12, [$r0] | ||
95 | |||
96 | ;; Do the decompression and save compressed size in _inptr | ||
97 | |||
98 | jsr decompress_kernel | ||
99 | nop | ||
100 | |||
101 | ;; Restore boot source indicator | ||
102 | move.d _boot_source, $r12 | ||
103 | move.d [$r12], $r12 | ||
104 | |||
105 | ;; Restore command line magic and address. | ||
106 | move.d _cmd_line_magic, $r10 | ||
107 | move.d [$r10], $r10 | ||
108 | move.d _cmd_line_addr, $r11 | ||
109 | move.d [$r11], $r11 | ||
110 | |||
111 | ;; Put start address of root partition in r9 so the kernel can use it | ||
112 | ;; when mounting from flash | ||
113 | move.d input_data, $r0 | ||
114 | move.d [$r0], $r9 ; flash address of compressed kernel | ||
115 | move.d inptr, $r0 | ||
116 | add.d [$r0], $r9 ; size of compressed kernel | ||
117 | cmp.d 0x40000000, $r9 ; image in DRAM ? | ||
118 | blo enter_kernel ; no, must be [NOR] flash, jump | ||
119 | nop ; delay slot | ||
120 | and.d 0x001fffff, $r9 ; assume compressed kernel was < 2M | ||
121 | |||
122 | enter_kernel: | ||
123 | ;; Enter the decompressed kernel | ||
124 | move.d RAM_INIT_MAGIC, $r8 ; Tell kernel that DRAM is initialized | ||
125 | jump 0x40004000 ; kernel is linked to this address | ||
126 | nop | ||
127 | |||
128 | .data | ||
129 | |||
130 | input_data: | ||
131 | .dword 0 ; used by the decompressor | ||
132 | _cmd_line_magic: | ||
133 | .dword 0 | ||
134 | _cmd_line_addr: | ||
135 | .dword 0 | ||
136 | _boot_source: | ||
137 | .dword 0 | ||
138 | |||
139 | #if defined CONFIG_ETRAXFS | ||
140 | #include "../../arch-v32/mach-fs/hw_settings.S" | ||
141 | #elif defined CONFIG_CRIS_MACH_ARTPEC3 | ||
142 | #include "../../arch-v32/mach-a3/hw_settings.S" | ||
143 | #else | ||
144 | #error Only ETRAXFS and ARTPEC-3 supported! | ||
145 | #endif | ||
diff --git a/arch/cris/boot/compressed/misc.c b/arch/cris/boot/compressed/misc.c new file mode 100644 index 000000000000..47bc190ba6d4 --- /dev/null +++ b/arch/cris/boot/compressed/misc.c | |||
@@ -0,0 +1,391 @@ | |||
1 | /* | ||
2 | * 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 | * puts by Nick Holloway 1993, better puts by Martin Mares 1995 | ||
9 | * adaptation for Linux/CRIS Axis Communications AB, 1999 | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | /* where the piggybacked kernel image expects itself to live. | ||
14 | * it is the same address we use when we network load an uncompressed | ||
15 | * image into DRAM, and it is the address the kernel is linked to live | ||
16 | * at by vmlinux.lds.S | ||
17 | */ | ||
18 | |||
19 | #define KERNEL_LOAD_ADR 0x40004000 | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | |||
23 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
24 | #include <hwregs/reg_rdwr.h> | ||
25 | #include <hwregs/reg_map.h> | ||
26 | #include <hwregs/ser_defs.h> | ||
27 | #include <hwregs/pinmux_defs.h> | ||
28 | #ifdef CONFIG_CRIS_MACH_ARTPEC3 | ||
29 | #include <hwregs/clkgen_defs.h> | ||
30 | #endif | ||
31 | #else | ||
32 | #include <arch/svinto.h> | ||
33 | #endif | ||
34 | |||
35 | /* | ||
36 | * gzip declarations | ||
37 | */ | ||
38 | |||
39 | #define OF(args) args | ||
40 | #define STATIC static | ||
41 | |||
42 | void *memset(void *s, int c, size_t n); | ||
43 | void *memcpy(void *__dest, __const void *__src, size_t __n); | ||
44 | |||
45 | #define memzero(s, n) memset((s), 0, (n)) | ||
46 | |||
47 | typedef unsigned char uch; | ||
48 | typedef unsigned short ush; | ||
49 | typedef unsigned long ulg; | ||
50 | |||
51 | #define WSIZE 0x8000 /* Window size must be at least 32k, */ | ||
52 | /* and a power of two */ | ||
53 | |||
54 | static uch *inbuf; /* input buffer */ | ||
55 | static uch window[WSIZE]; /* Sliding window buffer */ | ||
56 | |||
57 | unsigned inptr = 0; /* index of next byte to be processed in inbuf | ||
58 | * After decompression it will contain the | ||
59 | * compressed size, and head.S will read it. | ||
60 | */ | ||
61 | |||
62 | static unsigned outcnt = 0; /* bytes in output buffer */ | ||
63 | |||
64 | /* gzip flag byte */ | ||
65 | #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ | ||
66 | #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ | ||
67 | #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ | ||
68 | #define ORIG_NAME 0x08 /* bit 3 set: original file name present */ | ||
69 | #define COMMENT 0x10 /* bit 4 set: file comment present */ | ||
70 | #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ | ||
71 | #define RESERVED 0xC0 /* bit 6,7: reserved */ | ||
72 | |||
73 | #define get_byte() (inbuf[inptr++]) | ||
74 | |||
75 | /* Diagnostic functions */ | ||
76 | #ifdef DEBUG | ||
77 | # define Assert(cond, msg) do { \ | ||
78 | if (!(cond)) \ | ||
79 | error(msg); \ | ||
80 | } while (0) | ||
81 | # define Trace(x) fprintf x | ||
82 | # define Tracev(x) do { \ | ||
83 | if (verbose) \ | ||
84 | fprintf x; \ | ||
85 | } while (0) | ||
86 | # define Tracevv(x) do { \ | ||
87 | if (verbose > 1) \ | ||
88 | fprintf x; \ | ||
89 | } while (0) | ||
90 | # define Tracec(c, x) do { \ | ||
91 | if (verbose && (c)) \ | ||
92 | fprintf x; \ | ||
93 | } while (0) | ||
94 | # define Tracecv(c, x) do { \ | ||
95 | if (verbose > 1 && (c)) \ | ||
96 | fprintf x; \ | ||
97 | } while (0) | ||
98 | #else | ||
99 | # define Assert(cond, msg) | ||
100 | # define Trace(x) | ||
101 | # define Tracev(x) | ||
102 | # define Tracevv(x) | ||
103 | # define Tracec(c, x) | ||
104 | # define Tracecv(c, x) | ||
105 | #endif | ||
106 | |||
107 | static void flush_window(void); | ||
108 | static void error(char *m); | ||
109 | static void puts(const char *); | ||
110 | |||
111 | extern char *input_data; /* lives in head.S */ | ||
112 | |||
113 | static long bytes_out; | ||
114 | static uch *output_data; | ||
115 | static unsigned long output_ptr; | ||
116 | |||
117 | /* the "heap" is put directly after the BSS ends, at end */ | ||
118 | |||
119 | extern int _end; | ||
120 | static long free_mem_ptr = (long)&_end; | ||
121 | static long free_mem_end_ptr; | ||
122 | |||
123 | #include "../../../../../lib/inflate.c" | ||
124 | |||
125 | /* decompressor info and error messages to serial console */ | ||
126 | |||
127 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
128 | static inline void serout(const char *s, reg_scope_instances regi_ser) | ||
129 | { | ||
130 | reg_ser_rs_stat_din rs; | ||
131 | reg_ser_rw_dout dout = {.data = *s}; | ||
132 | |||
133 | do { | ||
134 | rs = REG_RD(ser, regi_ser, rs_stat_din); | ||
135 | } | ||
136 | while (!rs.tr_rdy);/* Wait for transceiver. */ | ||
137 | |||
138 | REG_WR(ser, regi_ser, rw_dout, dout); | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | static void puts(const char *s) | ||
143 | { | ||
144 | #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL | ||
145 | while (*s) { | ||
146 | #ifdef CONFIG_ETRAX_DEBUG_PORT0 | ||
147 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
148 | serout(s, regi_ser0); | ||
149 | #else | ||
150 | while (!(*R_SERIAL0_STATUS & (1 << 5))) | ||
151 | ; | ||
152 | *R_SERIAL0_TR_DATA = *s++; | ||
153 | #endif | ||
154 | #endif | ||
155 | #ifdef CONFIG_ETRAX_DEBUG_PORT1 | ||
156 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
157 | serout(s, regi_ser1); | ||
158 | #else | ||
159 | while (!(*R_SERIAL1_STATUS & (1 << 5))) | ||
160 | ; | ||
161 | *R_SERIAL1_TR_DATA = *s++; | ||
162 | #endif | ||
163 | #endif | ||
164 | #ifdef CONFIG_ETRAX_DEBUG_PORT2 | ||
165 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
166 | serout(s, regi_ser2); | ||
167 | #else | ||
168 | while (!(*R_SERIAL2_STATUS & (1 << 5))) | ||
169 | ; | ||
170 | *R_SERIAL2_TR_DATA = *s++; | ||
171 | #endif | ||
172 | #endif | ||
173 | #ifdef CONFIG_ETRAX_DEBUG_PORT3 | ||
174 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
175 | serout(s, regi_ser3); | ||
176 | #else | ||
177 | while (!(*R_SERIAL3_STATUS & (1 << 5))) | ||
178 | ; | ||
179 | *R_SERIAL3_TR_DATA = *s++; | ||
180 | #endif | ||
181 | #endif | ||
182 | *s++; | ||
183 | } | ||
184 | /* CONFIG_ETRAX_DEBUG_PORT_NULL */ | ||
185 | #endif | ||
186 | } | ||
187 | |||
188 | void *memset(void *s, int c, size_t n) | ||
189 | { | ||
190 | int i; | ||
191 | char *ss = (char*)s; | ||
192 | |||
193 | for (i=0;i<n;i++) ss[i] = c; | ||
194 | |||
195 | return s; | ||
196 | } | ||
197 | |||
198 | void *memcpy(void *__dest, __const void *__src, size_t __n) | ||
199 | { | ||
200 | int i; | ||
201 | char *d = (char *)__dest, *s = (char *)__src; | ||
202 | |||
203 | for (i = 0; i < __n; i++) | ||
204 | d[i] = s[i]; | ||
205 | |||
206 | return __dest; | ||
207 | } | ||
208 | |||
209 | /* =========================================================================== | ||
210 | * Write the output window window[0..outcnt-1] and update crc and bytes_out. | ||
211 | * (Used for the decompressed data only.) | ||
212 | */ | ||
213 | |||
214 | static void flush_window(void) | ||
215 | { | ||
216 | ulg c = crc; /* temporary variable */ | ||
217 | unsigned n; | ||
218 | uch *in, *out, ch; | ||
219 | |||
220 | in = window; | ||
221 | out = &output_data[output_ptr]; | ||
222 | for (n = 0; n < outcnt; n++) { | ||
223 | ch = *out = *in; | ||
224 | out++; | ||
225 | in++; | ||
226 | c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8); | ||
227 | } | ||
228 | crc = c; | ||
229 | bytes_out += (ulg)outcnt; | ||
230 | output_ptr += (ulg)outcnt; | ||
231 | outcnt = 0; | ||
232 | } | ||
233 | |||
234 | static void error(char *x) | ||
235 | { | ||
236 | puts("\n\n"); | ||
237 | puts(x); | ||
238 | puts("\n\n -- System halted\n"); | ||
239 | |||
240 | while(1); /* Halt */ | ||
241 | } | ||
242 | |||
243 | void setup_normal_output_buffer(void) | ||
244 | { | ||
245 | output_data = (char *)KERNEL_LOAD_ADR; | ||
246 | } | ||
247 | |||
248 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
249 | static inline void serial_setup(reg_scope_instances regi_ser) | ||
250 | { | ||
251 | reg_ser_rw_xoff xoff; | ||
252 | reg_ser_rw_tr_ctrl tr_ctrl; | ||
253 | reg_ser_rw_rec_ctrl rec_ctrl; | ||
254 | reg_ser_rw_tr_baud_div tr_baud; | ||
255 | reg_ser_rw_rec_baud_div rec_baud; | ||
256 | |||
257 | /* Turn off XOFF. */ | ||
258 | xoff = REG_RD(ser, regi_ser, rw_xoff); | ||
259 | |||
260 | xoff.chr = 0; | ||
261 | xoff.automatic = regk_ser_no; | ||
262 | |||
263 | REG_WR(ser, regi_ser, rw_xoff, xoff); | ||
264 | |||
265 | /* Set baudrate and stopbits. */ | ||
266 | tr_ctrl = REG_RD(ser, regi_ser, rw_tr_ctrl); | ||
267 | rec_ctrl = REG_RD(ser, regi_ser, rw_rec_ctrl); | ||
268 | tr_baud = REG_RD(ser, regi_ser, rw_tr_baud_div); | ||
269 | rec_baud = REG_RD(ser, regi_ser, rw_rec_baud_div); | ||
270 | |||
271 | tr_ctrl.stop_bits = 1; /* 2 stop bits. */ | ||
272 | tr_ctrl.en = 1; /* enable transmitter */ | ||
273 | rec_ctrl.en = 1; /* enabler receiver */ | ||
274 | |||
275 | /* | ||
276 | * The baudrate setup used to be a bit fishy, but now transmitter and | ||
277 | * receiver are both set to the intended baud rate, 115200. | ||
278 | * The magic value is 29.493 MHz. | ||
279 | */ | ||
280 | tr_ctrl.base_freq = regk_ser_f29_493; | ||
281 | rec_ctrl.base_freq = regk_ser_f29_493; | ||
282 | tr_baud.div = (29493000 / 8) / 115200; | ||
283 | rec_baud.div = (29493000 / 8) / 115200; | ||
284 | |||
285 | REG_WR(ser, regi_ser, rw_tr_ctrl, tr_ctrl); | ||
286 | REG_WR(ser, regi_ser, rw_tr_baud_div, tr_baud); | ||
287 | REG_WR(ser, regi_ser, rw_rec_ctrl, rec_ctrl); | ||
288 | REG_WR(ser, regi_ser, rw_rec_baud_div, rec_baud); | ||
289 | } | ||
290 | #endif | ||
291 | |||
292 | void decompress_kernel(void) | ||
293 | { | ||
294 | char revision; | ||
295 | char compile_rev; | ||
296 | |||
297 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
298 | /* Need at least a CRISv32 to run. */ | ||
299 | compile_rev = 32; | ||
300 | #if defined(CONFIG_ETRAX_DEBUG_PORT1) || \ | ||
301 | defined(CONFIG_ETRAX_DEBUG_PORT2) || \ | ||
302 | defined(CONFIG_ETRAX_DEBUG_PORT3) | ||
303 | reg_pinmux_rw_hwprot hwprot; | ||
304 | |||
305 | #ifdef CONFIG_CRIS_MACH_ARTPEC3 | ||
306 | reg_clkgen_rw_clk_ctrl clk_ctrl; | ||
307 | |||
308 | /* Enable corresponding clock region when serial 1..3 selected */ | ||
309 | |||
310 | clk_ctrl = REG_RD(clkgen, regi_clkgen, rw_clk_ctrl); | ||
311 | clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; | ||
312 | REG_WR(clkgen, regi_clkgen, rw_clk_ctrl, clk_ctrl); | ||
313 | #endif | ||
314 | |||
315 | /* pinmux setup for ports 1..3 */ | ||
316 | hwprot = REG_RD(pinmux, regi_pinmux, rw_hwprot); | ||
317 | #endif | ||
318 | |||
319 | |||
320 | #ifdef CONFIG_ETRAX_DEBUG_PORT0 | ||
321 | serial_setup(regi_ser0); | ||
322 | #endif | ||
323 | #ifdef CONFIG_ETRAX_DEBUG_PORT1 | ||
324 | hwprot.ser1 = regk_pinmux_yes; | ||
325 | serial_setup(regi_ser1); | ||
326 | #endif | ||
327 | #ifdef CONFIG_ETRAX_DEBUG_PORT2 | ||
328 | hwprot.ser2 = regk_pinmux_yes; | ||
329 | serial_setup(regi_ser2); | ||
330 | #endif | ||
331 | #ifdef CONFIG_ETRAX_DEBUG_PORT3 | ||
332 | hwprot.ser3 = regk_pinmux_yes; | ||
333 | serial_setup(regi_ser3); | ||
334 | #endif | ||
335 | #if defined(CONFIG_ETRAX_DEBUG_PORT1) || \ | ||
336 | defined(CONFIG_ETRAX_DEBUG_PORT2) || \ | ||
337 | defined(CONFIG_ETRAX_DEBUG_PORT3) | ||
338 | REG_WR(pinmux, regi_pinmux, rw_hwprot, hwprot); | ||
339 | #endif | ||
340 | |||
341 | /* input_data is set in head.S */ | ||
342 | inbuf = input_data; | ||
343 | #else /* CRISv10 */ | ||
344 | /* Need at least a crisv10 to run. */ | ||
345 | compile_rev = 10; | ||
346 | |||
347 | /* input_data is set in head.S */ | ||
348 | inbuf = input_data; | ||
349 | |||
350 | #ifdef CONFIG_ETRAX_DEBUG_PORT0 | ||
351 | *R_SERIAL0_XOFF = 0; | ||
352 | *R_SERIAL0_BAUD = 0x99; | ||
353 | *R_SERIAL0_TR_CTRL = 0x40; | ||
354 | #endif | ||
355 | #ifdef CONFIG_ETRAX_DEBUG_PORT1 | ||
356 | *R_SERIAL1_XOFF = 0; | ||
357 | *R_SERIAL1_BAUD = 0x99; | ||
358 | *R_SERIAL1_TR_CTRL = 0x40; | ||
359 | #endif | ||
360 | #ifdef CONFIG_ETRAX_DEBUG_PORT2 | ||
361 | *R_GEN_CONFIG = 0x08; | ||
362 | *R_SERIAL2_XOFF = 0; | ||
363 | *R_SERIAL2_BAUD = 0x99; | ||
364 | *R_SERIAL2_TR_CTRL = 0x40; | ||
365 | #endif | ||
366 | #ifdef CONFIG_ETRAX_DEBUG_PORT3 | ||
367 | *R_GEN_CONFIG = 0x100; | ||
368 | *R_SERIAL3_XOFF = 0; | ||
369 | *R_SERIAL3_BAUD = 0x99; | ||
370 | *R_SERIAL3_TR_CTRL = 0x40; | ||
371 | #endif | ||
372 | #endif | ||
373 | |||
374 | setup_normal_output_buffer(); | ||
375 | |||
376 | makecrc(); | ||
377 | |||
378 | __asm__ volatile ("move $vr,%0" : "=rm" (revision)); | ||
379 | if (revision < compile_rev) { | ||
380 | #ifdef CONFIG_ETRAX_ARCH_V32 | ||
381 | puts("You need an ETRAX FS to run Linux 2.6/crisv32\n"); | ||
382 | #else | ||
383 | puts("You need an ETRAX 100LX to run linux 2.6\n"); | ||
384 | #endif | ||
385 | while(1); | ||
386 | } | ||
387 | |||
388 | puts("Uncompressing Linux...\n"); | ||
389 | gunzip(); | ||
390 | puts("Done. Now booting the kernel\n"); | ||
391 | } | ||