2 * Code that sets up the DRAM registers, calls the
3 * decompressor to unpack the piggybacked kernel, and jumps.
5 * Copyright (C) 1999 - 2003, Axis Communications AB
8 #include <linux/config.h>
9 #define ASSEMBLER_MACROS_ONLY
10 #include <asm/arch/hwregs/asm/reg_map_asm.h>
11 #include <asm/arch/hwregs/asm/gio_defs_asm.h>
12 #include <asm/arch/hwregs/asm/config_defs_asm.h>
14 #define RAM_INIT_MAGIC 0x56902387
15 #define COMMAND_LINE_MAGIC 0x87109563
25 ;; Start clocks for used blocks.
26 move.d REG_ADDR(config, regi_config, rw_clk_ctrl), $r1
28 or.d REG_STATE(config, rw_clk_ctrl, cpu, yes) | \
29 REG_STATE(config, rw_clk_ctrl, bif, yes) | \
30 REG_STATE(config, rw_clk_ctrl, fix_io, yes), $r0
33 ;; If booting from NAND flash we first have to copy some
34 ;; data from NAND flash to internal RAM to get the code
35 ;; that initializes the SDRAM. Lets copy 20 KB. This
36 ;; code executes at 0x38010000 if booting from NAND and
37 ;; we are guaranted that at least 0x200 bytes are good so
38 ;; lets start from there. The first 8192 bytes in the nand
39 ;; flash is spliced with zeroes and is thus 16384 bytes.
40 move.d 0x38010200, $r10
41 move.d 0x14200, $r11 ; Start offset in NAND flash 0x10200 + 16384
42 move.d 0x5000, $r12 ; Length of copy
44 ;; Before this code the tools add a partitiontable so the PC
45 ;; has an offset from the linked address.
47 lapcq ., $r13 ; get PC
48 add.d first_copy_complete-offset1, $r13
50 #include "../../lib/nand_init.S"
53 ;; Initialze the DRAM registers.
54 cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
55 beq dram_init_finished
58 #include "../../lib/dram_init.S"
61 lapcq ., $r13 ; get PC
62 add.d second_copy_complete-dram_init_finished, $r13
64 move.d REG_ADDR(config, regi_config, r_bootsel), $r0
66 and.d REG_MASK(config, r_bootsel, boot_mode), $r0
67 cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
68 bne second_copy_complete ; No NAND boot
71 ;; Copy 2MB from NAND flash to SDRAM (at 2-4MB into the SDRAM)
72 move.d 0x40204000, $r10
79 ;; Initiate the PA port.
80 move.d CONFIG_ETRAX_DEF_GIO_PA_OUT, $r0
81 move.d REG_ADDR(gio, regi_gio, rw_pa_dout), $r1
84 move.d CONFIG_ETRAX_DEF_GIO_PA_OE, $r0
85 move.d REG_ADDR(gio, regi_gio, rw_pa_oe), $r1
88 ;; Setup the stack to a suitably high address.
89 ;; We assume 8 MB is the minimum DRAM and put
90 ;; the SP at the top for now.
92 move.d 0x40800000, $sp
94 ;; Figure out where the compressed piggyback image is
95 ;; in the flash (since we wont try to copy it to DRAM
96 ;; before unpacking). It is at _edata, but in flash.
97 ;; Use (_edata - herami) as offset to the current PC.
99 move.d REG_ADDR(config, regi_config, r_bootsel), $r0
101 and.d REG_MASK(config, r_bootsel, boot_mode), $r0
102 cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
106 lapcq ., $r5 ; get PC
107 and.d 0x7fffffff, $r5 ; strip any non-cache bit
108 move.d $r5, $r0 ; save for later - flash address of 'herami'
110 sub.d hereami, $r5 ; r5 = flash address of '_edata'
111 move.d hereami, $r1 ; destination
115 lapcq ., $r5 ; get PC
116 and.d 0x00ffffff, $r5 ; strip any non-cache bit
119 move.d $r6, $r0 ; save for later - flash address of 'herami'
121 sub.d hereami2, $r5 ; r5 = flash address of '_edata'
122 add.d 0x40200000, $r5
123 move.d hereami2, $r1 ; destination
125 ;; Copy text+data to DRAM
127 move.d _edata, $r2 ; end destination
128 1: move.w [$r0+], $r3
134 move.d input_data, $r0 ; for the decompressor
135 move.d $r5, [$r0] ; for the decompressor
137 ;; Clear the decompressors BSS (between _edata and _end)
142 1: move.w $r0, [$r1+]
147 ;; Save command line magic and address.
148 move.d _cmd_line_magic, $r12
150 move.d _cmd_line_addr, $r12
153 ;; Do the decompression and save compressed size in _inptr
155 jsr decompress_kernel
158 ;; Restore command line magic and address.
159 move.d _cmd_line_magic, $r10
161 move.d _cmd_line_addr, $r11
164 ;; Put start address of root partition in r9 so the kernel can use it
165 ;; when mounting from flash
166 move.d input_data, $r0
167 move.d [$r0], $r9 ; flash address of compressed kernel
169 add.d [$r0], $r9 ; size of compressed kernel
170 cmp.d 0x40200000, $r9
173 sub.d 0x40200000, $r9
177 ;; Enter the decompressed kernel
178 move.d RAM_INIT_MAGIC, $r8 ; Tell kernel that DRAM is initialized
179 jump 0x40004000 ; kernel is linked to this address
185 .dword 0 ; used by the decompressor
193 #include "../../lib/hw_settings.S"