2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #ifndef CONFIG_IDENT_STRING
28 #define CONFIG_IDENT_STRING ""
31 /* last three long word reserved for cache status */
32 #define CACR_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-12)
33 #define ICACHE_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END- 8)
34 #define DCACHE_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END- 4)
40 move.w #0x2700,%sr; /* disable intrs */ \
41 subl #60,%sp; /* space for 15 regs */ \
42 moveml %d0-%d7/%a0-%a6,%sp@;
45 moveml %sp@,%d0-%d7/%a0-%a6; \
46 addl #60,%sp; /* space for 15 regs */ \
49 #if defined(CONFIG_CF_SBF)
50 #define ASM_DRAMINIT (asm_dram_init - TEXT_BASE + CFG_INIT_RAM_ADDR)
51 #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - TEXT_BASE + CFG_INIT_RAM_ADDR)
57 * Vector table. This is used for initial platform startup.
58 * These vectors are to catch any un-intended traps.
61 #if defined(CONFIG_CF_SBF)
63 INITSP: .long 0 /* Initial SP */
64 INITPC: .long ASM_DRAMINIT /* Initial PC */
68 INITSP: .long 0 /* Initial SP */
69 INITPC: .long _START /* Initial PC */
73 vector02: .long _FAULT /* Access Error */
74 vector03: .long _FAULT /* Address Error */
75 vector04: .long _FAULT /* Illegal Instruction */
76 vector05: .long _FAULT /* Reserved */
77 vector06: .long _FAULT /* Reserved */
78 vector07: .long _FAULT /* Reserved */
79 vector08: .long _FAULT /* Privilege Violation */
80 vector09: .long _FAULT /* Trace */
81 vector0A: .long _FAULT /* Unimplemented A-Line */
82 vector0B: .long _FAULT /* Unimplemented F-Line */
83 vector0C: .long _FAULT /* Debug Interrupt */
84 vector0D: .long _FAULT /* Reserved */
85 vector0E: .long _FAULT /* Format Error */
86 vector0F: .long _FAULT /* Unitialized Int. */
90 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92 vector18: .long _FAULT /* Spurious Interrupt */
93 vector19: .long _FAULT /* Autovector Level 1 */
94 vector1A: .long _FAULT /* Autovector Level 2 */
95 vector1B: .long _FAULT /* Autovector Level 3 */
96 vector1C: .long _FAULT /* Autovector Level 4 */
97 vector1D: .long _FAULT /* Autovector Level 5 */
98 vector1E: .long _FAULT /* Autovector Level 6 */
99 vector1F: .long _FAULT /* Autovector Level 7 */
101 #if !defined(CONFIG_CF_SBF)
105 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
106 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
110 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
111 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
114 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
115 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
116 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
117 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
118 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
119 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
120 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
121 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
124 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
125 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
126 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
127 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
128 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
129 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
130 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
131 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
134 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
135 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
136 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
137 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
138 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
139 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
140 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
141 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
144 #if defined(CONFIG_CF_SBF)
145 /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
147 .long 0x00000000 /* checksum, not yet implemented */
148 .long 0x00030000 /* image length */
149 .long TEXT_BASE /* image to be relocated at */
152 move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_RAM_CTRL), %d0
153 movec %d0, %RAMBAR1 /* init Rambar */
154 move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp
157 /* Must disable global address */
158 move.l #0xFC008000, %a1
159 move.l #(CFG_CS0_BASE), (%a1)
160 move.l #0xFC008008, %a1
161 move.l #(CFG_CS0_CTRL), (%a1)
162 move.l #0xFC008004, %a1
163 move.l #(CFG_CS0_MASK), (%a1)
166 * Dram Initialization
170 move.l #0xFC0A4074, %a1
171 move.b #(CFG_SDRAM_DRV_STRENGTH), (%a1)
174 /* SDRAM Chip 0 and 1 */
175 move.l #0xFC0B8110, %a1
176 move.l #0xFC0B8114, %a2
178 /* calculate the size */
180 move.l #(CFG_SDRAM_SIZE), %d2
181 #ifdef CFG_SDRAM_BASE1
191 /* SDRAM Chip 0 and 1 */
192 move.l #(CFG_SDRAM_BASE), (%a1)
194 #ifdef CFG_SDRAM_BASE1
195 move.l #(CFG_SDRAM_BASE1), (%a2)
200 /* dram cfg1 and cfg2 */
201 move.l #0xFC0B8008, %a1
202 move.l #(CFG_SDRAM_CFG1), (%a1)
204 move.l #0xFC0B800C, %a2
205 move.l #(CFG_SDRAM_CFG2), (%a2)
208 move.l #0xFC0B8000, %a1 /* Mode */
209 move.l #0xFC0B8004, %a2 /* Ctrl */
211 #ifdef CONFIG_M54455EVB
213 move.l #(CFG_SDRAM_CTRL + 2), (%a2)
217 move.l #(CFG_SDRAM_EMOD + 0x408), (%a1)
219 move.l #(CFG_SDRAM_MODE + 0x300), (%a1)
230 move.l #(CFG_SDRAM_CTRL + 2), (%a2)
233 /* Perform two refresh cycles */
234 move.l #(CFG_SDRAM_CTRL + 4), %d0
240 #ifdef CONFIG_M54455EVB
241 move.l #(CFG_SDRAM_MODE + 0x200), (%a1)
243 #elif defined(CONFIG_M54451EVB)
245 move.l #(CFG_SDRAM_MODE), (%a2)
247 move.l #(CFG_SDRAM_EMOD), (%a2)
257 move.l #(CFG_SDRAM_CTRL), %d0
258 and.l #0x7FFFFFFF, %d0
259 #ifdef CONFIG_M54455EVB
260 or.l #0x10000c00, %d0
261 #elif defined(CONFIG_M54451EVB)
262 or.l #0x10000000, %d0
268 * DSPI Initialization
269 * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
275 /* Enable pins for DSPI mode - chip-selects are enabled later */
276 move.l #0xFC0A4063, %a0
279 /* Configure DSPI module */
280 move.l #0xFC05C000, %a0
281 move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
283 move.l #0xFC05C00C, %a0
284 move.l #0x3E000011, (%a0)
286 move.l #0xFC05C034, %a2 /* dtfr */
287 move.l #0xFC05C03B, %a3 /* drfr */
289 move.l #(ASM_SBF_IMG_HDR + 4), %a1
293 move.l #(CFG_INIT_RAM_ADDR + CFG_SBFHDR_DATA_OFFSET), %a0
294 move.l #(CFG_SBFHDR_SIZE), %d4
296 move.l #0xFC05C02C, %a1 /* dspi status */
298 /* Issue commands and address */
299 move.l #0x8002000B, %d2 /* Fast Read Cmd */
300 jsr asm_dspi_wr_status
301 jsr asm_dspi_rd_status
303 move.l #0x80020000, %d2 /* Address byte 2 */
304 jsr asm_dspi_wr_status
305 jsr asm_dspi_rd_status
307 move.l #0x80020000, %d2 /* Address byte 1 */
308 jsr asm_dspi_wr_status
309 jsr asm_dspi_rd_status
311 move.l #0x80020000, %d2 /* Address byte 0 */
312 jsr asm_dspi_wr_status
313 jsr asm_dspi_rd_status
315 move.l #0x80020000, %d2 /* Dummy Wr and Rd */
316 jsr asm_dspi_wr_status
317 jsr asm_dspi_rd_status
319 /* Transfer serial boot header to sram */
321 move.l #0x80020000, %d2
322 jsr asm_dspi_wr_status
323 jsr asm_dspi_rd_status
325 move.b %d1, (%a0) /* read, copy to dst */
327 add.l #1, %a0 /* inc dst by 1 */
328 sub.l #1, %d4 /* dec cnt by 1 */
329 bne asm_dspi_rd_loop1
331 /* Transfer u-boot from serial flash to memory */
333 move.l #0x80020000, %d2
334 jsr asm_dspi_wr_status
335 jsr asm_dspi_rd_status
337 move.b %d1, (%a4) /* read, copy to dst */
339 add.l #1, %a4 /* inc dst by 1 */
340 sub.l #1, %d5 /* dec cnt by 1 */
341 bne asm_dspi_rd_loop2
343 move.l #0x00020000, %d2 /* Terminate */
344 jsr asm_dspi_wr_status
345 jsr asm_dspi_rd_status
347 /* jump to memory and execute */
348 move.l #(TEXT_BASE + 0x400), %a0
352 move.l (%a1), %d0 /* status */
353 and.l #0x0000F000, %d0
354 cmp.l #0x00003000, %d0
355 bgt asm_dspi_wr_status
361 move.l (%a1), %d0 /* status */
362 and.l #0x000000F0, %d0
365 beq asm_dspi_rd_status
369 #endif /* CONFIG_CF_SBF */
377 move.w #0x2700,%sr /* Mask off Interrupt */
379 /* Set vector base register at the beginning of the Flash */
380 #if defined(CONFIG_CF_SBF)
381 move.l #TEXT_BASE, %d0
384 move.l #CFG_FLASH_BASE, %d0
387 move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_RAM_CTRL), %d0
391 /* initialize general use internal ram */
393 move.l #(CACR_STATUS), %a1 /* CACR */
394 move.l #(ICACHE_STATUS), %a2 /* icache */
395 move.l #(DCACHE_STATUS), %a3 /* dcache */
400 /* invalidate and disable cache */
401 move.l #0x01004100, %d0 /* Invalidate cache cmd */
402 movec %d0, %CACR /* Invalidate cache */
409 /* set stackpointer to end of internal ram to get some stackspace for
411 move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp
414 move.l #__got_start, %a5 /* put relocation table address to a5 */
416 bsr cpu_init_f /* run low-level CPU init code (from flash) */
417 bsr board_init_f /* run low-level board init code (from flash) */
419 /* board_init_f() does not return */
421 /*------------------------------------------------------------------------------*/
424 * void relocate_code (addr_sp, gd, addr_moni)
426 * This "function" does not return, instead it continues in RAM
427 * after relocating the monitor code.
431 * r5 = length in bytes
437 move.l 8(%a6), %sp /* set new stack pointer */
439 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
440 move.l 16(%a6), %a0 /* Save copy of Destination Address */
442 move.l #CFG_MONITOR_BASE, %a1
443 move.l #__init_end, %a2
446 /* copy the code to RAM */
448 move.l (%a1)+, (%a3)+
453 * We are done. Do not return, instead branch to second part of board
454 * initialization, now running from RAM.
457 add.l #(in_ram - CFG_MONITOR_BASE), %a1
464 * Now clear BSS segment
467 add.l #(_sbss - CFG_MONITOR_BASE),%a1
469 add.l #(_ebss - CFG_MONITOR_BASE),%d1
476 * fix got table in RAM
479 add.l #(__got_start - CFG_MONITOR_BASE),%a1
480 move.l %a1,%a5 /* * fix got pointer register a5 */
483 add.l #(__got_end - CFG_MONITOR_BASE),%a2
493 /* calculate relative jump to board_init_r in ram */
495 add.l #(board_init_r - CFG_MONITOR_BASE), %a1
497 /* set parameters for board_init_r */
498 move.l %a0,-(%sp) /* dest_addr */
499 move.l %d0,-(%sp) /* gd */
502 /*------------------------------------------------------------------------------*/
524 /*------------------------------------------------------------------------------*/
525 /* cache functions */
528 move.l #(CACR_STATUS), %a1 /* read CACR Status */
531 move.l #0x00040100, %d0 /* Invalidate icache */
534 move.l #(CFG_SDRAM_BASE + 0x1c000), %d0 /* Setup icache */
537 move.l #0x04088020, %d0 /* Enable bcache and icache */
540 move.l #(ICACHE_STATUS), %a1
545 .globl icache_disable
547 move.l #(CACR_STATUS), %a1 /* read CACR Status */
550 move.l #0xFFF77BFF, %d0
551 or.l #0x00040100, %d0 /* Setup cache mask */
552 movec %d0, %CACR /* Invalidate icache */
557 move.l #(ICACHE_STATUS), %a1
564 move.l #(ICACHE_STATUS), %a1
568 .globl icache_invalid
570 move.l #(CACR_STATUS), %a1 /* read CACR Status */
573 move.l #0x00040100, %d0 /* Invalidate icache */
574 movec %d0, %CACR /* Enable and invalidate cache */
579 move.l #(CACR_STATUS), %a1 /* read CACR Status */
582 move.l #0x01040100, %d0
583 movec %d0, %CACR /* Invalidate dcache */
585 move.l #0x80088020, %d0 /* Enable bcache and icache */
588 move.l #(DCACHE_STATUS), %a1
593 .globl dcache_disable
595 move.l #(CACR_STATUS), %a1 /* read CACR Status */
598 and.l #0x7FFFFFFF, %d0
599 or.l #0x01000000, %d0 /* Setup cache mask */
600 movec %d0, %CACR /* Disable dcache */
605 move.l #(DCACHE_STATUS), %a1
610 .globl dcache_invalid
612 move.l #(CACR_STATUS), %a1 /* read CACR Status */
615 move.l #0x81088020, %d0 /* Setup cache mask */
616 movec %d0, %CACR /* Enable and invalidate cache */
621 move.l #(DCACHE_STATUS), %a1
625 /*------------------------------------------------------------------------------*/
627 .globl version_string
629 .ascii U_BOOT_VERSION
630 .ascii " (", __DATE__, " - ", __TIME__, ")"
631 .ascii CONFIG_IDENT_STRING, "\0"