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 #define ASSEMBLER_MACROS_ONLY
9 #include <asm/arch/hwregs/asm/reg_map_asm.h>
10 #include <asm/arch/hwregs/asm/gio_defs_asm.h>
11 #include <asm/arch/hwregs/asm/config_defs_asm.h>
13 #define RAM_INIT_MAGIC 0x56902387
14 #define COMMAND_LINE_MAGIC 0x87109563
24 ;; Start clocks for used blocks.
25 move.d REG_ADDR(config, regi_config, rw_clk_ctrl), $r1
27 or.d REG_STATE(config, rw_clk_ctrl, cpu, yes) | \
28 REG_STATE(config, rw_clk_ctrl, bif, yes) | \
29 REG_STATE(config, rw_clk_ctrl, fix_io, yes), $r0
32 ;; If booting from NAND flash we first have to copy some
33 ;; data from NAND flash to internal RAM to get the code
34 ;; that initializes the SDRAM. Lets copy 20 KB. This
35 ;; code executes at 0x38010000 if booting from NAND and
36 ;; we are guaranted that at least 0x200 bytes are good so
37 ;; lets start from there. The first 8192 bytes in the nand
38 ;; flash is spliced with zeroes and is thus 16384 bytes.
39 move.d 0x38010200, $r10
40 move.d 0x14200, $r11 ; Start offset in NAND flash 0x10200 + 16384
41 move.d 0x5000, $r12 ; Length of copy
43 ;; Before this code the tools add a partitiontable so the PC
44 ;; has an offset from the linked address.
46 lapcq ., $r13 ; get PC
47 add.d first_copy_complete-offset1, $r13
49 #include "../../lib/nand_init.S"
52 ;; Initialze the DRAM registers.
53 cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
54 beq dram_init_finished
57 #include "../../lib/dram_init.S"
60 lapcq ., $r13 ; get PC
61 add.d second_copy_complete-dram_init_finished, $r13
63 move.d REG_ADDR(config, regi_config, r_bootsel), $r0
65 and.d REG_MASK(config, r_bootsel, boot_mode), $r0
66 cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
67 bne second_copy_complete ; No NAND boot
70 ;; Copy 2MB from NAND flash to SDRAM (at 2-4MB into the SDRAM)
71 move.d 0x40204000, $r10
78 ;; Initiate the PA port.
79 move.d CONFIG_ETRAX_DEF_GIO_PA_OUT, $r0
80 move.d REG_ADDR(gio, regi_gio, rw_pa_dout), $r1
83 move.d CONFIG_ETRAX_DEF_GIO_PA_OE, $r0
84 move.d REG_ADDR(gio, regi_gio, rw_pa_oe), $r1
87 ;; Setup the stack to a suitably high address.
88 ;; We assume 8 MB is the minimum DRAM and put
89 ;; the SP at the top for now.
91 move.d 0x40800000, $sp
93 ;; Figure out where the compressed piggyback image is
94 ;; in the flash (since we wont try to copy it to DRAM
95 ;; before unpacking). It is at _edata, but in flash.
96 ;; Use (_edata - herami) as offset to the current PC.
98 move.d REG_ADDR(config, regi_config, r_bootsel), $r0
100 and.d REG_MASK(config, r_bootsel, boot_mode), $r0
101 cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
105 lapcq ., $r5 ; get PC
106 and.d 0x7fffffff, $r5 ; strip any non-cache bit
107 move.d $r5, $r0 ; save for later - flash address of 'herami'
109 sub.d hereami, $r5 ; r5 = flash address of '_edata'
110 move.d hereami, $r1 ; destination
114 lapcq ., $r5 ; get PC
115 and.d 0x00ffffff, $r5 ; strip any non-cache bit
118 move.d $r6, $r0 ; save for later - flash address of 'herami'
120 sub.d hereami2, $r5 ; r5 = flash address of '_edata'
121 add.d 0x40200000, $r5
122 move.d hereami2, $r1 ; destination
124 ;; Copy text+data to DRAM
126 move.d _edata, $r2 ; end destination
127 1: move.w [$r0+], $r3
133 move.d input_data, $r0 ; for the decompressor
134 move.d $r5, [$r0] ; for the decompressor
136 ;; Clear the decompressors BSS (between _edata and _end)
141 1: move.w $r0, [$r1+]
146 ;; Save command line magic and address.
147 move.d _cmd_line_magic, $r12
149 move.d _cmd_line_addr, $r12
152 ;; Do the decompression and save compressed size in _inptr
154 jsr decompress_kernel
157 ;; Restore command line magic and address.
158 move.d _cmd_line_magic, $r10
160 move.d _cmd_line_addr, $r11
163 ;; Put start address of root partition in r9 so the kernel can use it
164 ;; when mounting from flash
165 move.d input_data, $r0
166 move.d [$r0], $r9 ; flash address of compressed kernel
168 add.d [$r0], $r9 ; size of compressed kernel
169 cmp.d 0x40200000, $r9
172 sub.d 0x40200000, $r9
176 ;; Enter the decompressed kernel
177 move.d RAM_INIT_MAGIC, $r8 ; Tell kernel that DRAM is initialized
178 jump 0x40004000 ; kernel is linked to this address
184 .dword 0 ; used by the decompressor
192 #include "../../lib/hw_settings.S"