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,
25 #include <timestamp.h>
28 #ifndef CONFIG_IDENT_STRING
29 #define CONFIG_IDENT_STRING ""
32 /* last three long word reserved for cache status */
33 #define CACR_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-12)
34 #define ICACHE_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END- 8)
35 #define DCACHE_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END- 4)
41 move.w #0x2700,%sr; /* disable intrs */ \
42 subl #60,%sp; /* space for 15 regs */ \
43 moveml %d0-%d7/%a0-%a6,%sp@;
46 moveml %sp@,%d0-%d7/%a0-%a6; \
47 addl #60,%sp; /* space for 15 regs */ \
50 #if defined(CONFIG_CF_SBF)
51 #define ASM_DRAMINIT (asm_dram_init - TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
52 #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
58 * Vector table. This is used for initial platform startup.
59 * These vectors are to catch any un-intended traps.
62 #if defined(CONFIG_CF_SBF)
64 INITSP: .long 0 /* Initial SP */
65 INITPC: .long ASM_DRAMINIT /* Initial PC */
69 INITSP: .long 0 /* Initial SP */
70 INITPC: .long _START /* Initial PC */
74 vector02: .long _FAULT /* Access Error */
75 vector03: .long _FAULT /* Address Error */
76 vector04: .long _FAULT /* Illegal Instruction */
77 vector05: .long _FAULT /* Reserved */
78 vector06: .long _FAULT /* Reserved */
79 vector07: .long _FAULT /* Reserved */
80 vector08: .long _FAULT /* Privilege Violation */
81 vector09: .long _FAULT /* Trace */
82 vector0A: .long _FAULT /* Unimplemented A-Line */
83 vector0B: .long _FAULT /* Unimplemented F-Line */
84 vector0C: .long _FAULT /* Debug Interrupt */
85 vector0D: .long _FAULT /* Reserved */
86 vector0E: .long _FAULT /* Format Error */
87 vector0F: .long _FAULT /* Unitialized Int. */
91 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
93 vector18: .long _FAULT /* Spurious Interrupt */
94 vector19: .long _FAULT /* Autovector Level 1 */
95 vector1A: .long _FAULT /* Autovector Level 2 */
96 vector1B: .long _FAULT /* Autovector Level 3 */
97 vector1C: .long _FAULT /* Autovector Level 4 */
98 vector1D: .long _FAULT /* Autovector Level 5 */
99 vector1E: .long _FAULT /* Autovector Level 6 */
100 vector1F: .long _FAULT /* Autovector Level 7 */
102 #if !defined(CONFIG_CF_SBF)
106 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
107 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
111 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
112 .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
122 .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
132 .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
142 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
145 #if defined(CONFIG_CF_SBF)
146 /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
148 .long 0x00000000 /* checksum, not yet implemented */
149 .long 0x00030000 /* image length */
150 .long TEXT_BASE /* image to be relocated at */
153 move.w #0x2700,%sr /* Mask off Interrupt */
155 move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
158 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
161 /* initialize general use internal ram */
163 move.l #(CACR_STATUS), %a1 /* CACR */
164 move.l #(ICACHE_STATUS), %a2 /* icache */
165 move.l #(DCACHE_STATUS), %a3 /* dcache */
170 /* invalidate and disable cache */
171 move.l #0x01004100, %d0 /* Invalidate cache cmd */
172 movec %d0, %CACR /* Invalidate cache */
179 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
182 /* Must disable global address */
183 move.l #0xFC008000, %a1
184 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
185 move.l #0xFC008008, %a1
186 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
187 move.l #0xFC008004, %a1
188 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
190 /* Dram Initialization a1, a2, and d0 */
192 move.l #0xFC0A4074, %a1
193 move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
196 /* SDRAM Chip 0 and 1 */
197 move.l #0xFC0B8110, %a1
198 move.l #0xFC0B8114, %a2
200 /* calculate the size */
202 move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
203 #ifdef CONFIG_SYS_SDRAM_BASE1
213 /* SDRAM Chip 0 and 1 */
214 move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
216 #ifdef CONFIG_SYS_SDRAM_BASE1
217 move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
222 /* dram cfg1 and cfg2 */
223 move.l #0xFC0B8008, %a1
224 move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
226 move.l #0xFC0B800C, %a2
227 move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
230 move.l #0xFC0B8000, %a1 /* Mode */
231 move.l #0xFC0B8004, %a2 /* Ctrl */
234 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
237 #ifdef CONFIG_M54455EVB
239 move.l #(CONFIG_SYS_SDRAM_EMOD + 0x408), (%a1)
241 move.l #(CONFIG_SYS_SDRAM_MODE + 0x300), (%a1)
249 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
252 /* Perform two refresh cycles */
253 move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
259 #ifdef CONFIG_M54455EVB
260 move.l #(CONFIG_SYS_SDRAM_MODE + 0x200), (%a1)
262 #elif defined(CONFIG_M54451EVB)
264 move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
266 move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
272 move.l #(CONFIG_SYS_SDRAM_CTRL), %d1
273 and.l #0x7FFFFFFF, %d1
274 #ifdef CONFIG_M54455EVB
275 or.l #0x10000C00, %d1
276 #elif defined(CONFIG_M54451EVB)
277 or.l #0x10000C00, %d1
286 * DSPI Initialization
287 * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
293 /* Enable pins for DSPI mode - chip-selects are enabled later */
295 move.l #0xFC0A4063, %a0
298 /* Configure DSPI module */
299 move.l #0xFC05C000, %a0
300 move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
302 move.l #0xFC05C00C, %a0
303 move.l #0x3E000011, (%a0)
305 move.l #0xFC05C034, %a2 /* dtfr */
306 move.l #0xFC05C03B, %a3 /* drfr */
308 move.l #(ASM_SBF_IMG_HDR + 4), %a1
312 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
313 move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
315 move.l #0xFC05C02C, %a1 /* dspi status */
317 /* Issue commands and address */
318 move.l #0x8002000B, %d2 /* Fast Read Cmd */
319 jsr asm_dspi_wr_status
320 jsr asm_dspi_rd_status
322 move.l #0x80020000, %d2 /* Address byte 2 */
323 jsr asm_dspi_wr_status
324 jsr asm_dspi_rd_status
326 move.l #0x80020000, %d2 /* Address byte 1 */
327 jsr asm_dspi_wr_status
328 jsr asm_dspi_rd_status
330 move.l #0x80020000, %d2 /* Address byte 0 */
331 jsr asm_dspi_wr_status
332 jsr asm_dspi_rd_status
334 move.l #0x80020000, %d2 /* Dummy Wr and Rd */
335 jsr asm_dspi_wr_status
336 jsr asm_dspi_rd_status
338 /* Transfer serial boot header to sram */
340 move.l #0x80020000, %d2
341 jsr asm_dspi_wr_status
342 jsr asm_dspi_rd_status
344 move.b %d1, (%a0) /* read, copy to dst */
346 add.l #1, %a0 /* inc dst by 1 */
347 sub.l #1, %d4 /* dec cnt by 1 */
348 bne asm_dspi_rd_loop1
350 /* Transfer u-boot from serial flash to memory */
352 move.l #0x80020000, %d2
353 jsr asm_dspi_wr_status
354 jsr asm_dspi_rd_status
356 move.b %d1, (%a4) /* read, copy to dst */
358 add.l #1, %a4 /* inc dst by 1 */
359 sub.l #1, %d5 /* dec cnt by 1 */
360 bne asm_dspi_rd_loop2
362 move.l #0x00020000, %d2 /* Terminate */
363 jsr asm_dspi_wr_status
364 jsr asm_dspi_rd_status
366 /* jump to memory and execute */
367 move.l #(TEXT_BASE + 0x400), %a0
371 move.l (%a1), %d0 /* status */
372 and.l #0x0000F000, %d0
373 cmp.l #0x00003000, %d0
374 bgt asm_dspi_wr_status
380 move.l (%a1), %d0 /* status */
381 and.l #0x000000F0, %d0
384 beq asm_dspi_rd_status
394 #endif /* CONFIG_CF_SBF */
400 #if !defined(CONFIG_CF_SBF)
403 move.w #0x2700,%sr /* Mask off Interrupt */
405 /* Set vector base register at the beginning of the Flash */
406 move.l #CONFIG_SYS_FLASH_BASE, %d0
409 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
412 /* initialize general use internal ram */
414 move.l #(CACR_STATUS), %a1 /* CACR */
415 move.l #(ICACHE_STATUS), %a2 /* icache */
416 move.l #(DCACHE_STATUS), %a3 /* dcache */
421 /* invalidate and disable cache */
422 move.l #0x01004100, %d0 /* Invalidate cache cmd */
423 movec %d0, %CACR /* Invalidate cache */
430 /* set stackpointer to end of internal ram to get some stackspace for
432 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
436 move.l #__got_start, %a5 /* put relocation table address to a5 */
438 bsr cpu_init_f /* run low-level CPU init code (from flash) */
439 bsr board_init_f /* run low-level board init code (from flash) */
441 /* board_init_f() does not return */
443 /*------------------------------------------------------------------------------*/
446 * void relocate_code (addr_sp, gd, addr_moni)
448 * This "function" does not return, instead it continues in RAM
449 * after relocating the monitor code.
453 * r5 = length in bytes
459 move.l 8(%a6), %sp /* set new stack pointer */
461 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
462 move.l 16(%a6), %a0 /* Save copy of Destination Address */
464 move.l #CONFIG_SYS_MONITOR_BASE, %a1
465 move.l #__init_end, %a2
468 /* copy the code to RAM */
470 move.l (%a1)+, (%a3)+
475 * We are done. Do not return, instead branch to second part of board
476 * initialization, now running from RAM.
479 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
486 * Now clear BSS segment
489 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
491 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
498 * fix got table in RAM
501 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
502 move.l %a1,%a5 /* * fix got pointer register a5 */
505 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
515 /* calculate relative jump to board_init_r in ram */
517 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
519 /* set parameters for board_init_r */
520 move.l %a0,-(%sp) /* dest_addr */
521 move.l %d0,-(%sp) /* gd */
524 /*------------------------------------------------------------------------------*/
546 /*------------------------------------------------------------------------------*/
547 /* cache functions */
550 move.l #(CACR_STATUS), %a1 /* read CACR Status */
553 move.l #0x00040100, %d0 /* Invalidate icache */
556 move.l #(CONFIG_SYS_SDRAM_BASE + 0xC000), %d0 /* Setup icache */
559 move.l #0x04088020, %d0 /* Enable bcache and icache */
562 move.l #(ICACHE_STATUS), %a1
567 .globl icache_disable
569 move.l #(CACR_STATUS), %a1 /* read CACR Status */
572 move.l #0xFFF77BFF, %d0
573 or.l #0x00040100, %d0 /* Setup cache mask */
574 movec %d0, %CACR /* Invalidate icache */
579 move.l #(ICACHE_STATUS), %a1
586 move.l #(ICACHE_STATUS), %a1
590 .globl icache_invalid
592 move.l #(CACR_STATUS), %a1 /* read CACR Status */
595 move.l #0x00040100, %d0 /* Invalidate icache */
596 movec %d0, %CACR /* Enable and invalidate cache */
601 move.l #(CACR_STATUS), %a1 /* read CACR Status */
604 move.l #0x01040100, %d0
605 movec %d0, %CACR /* Invalidate dcache */
607 move.l #0x80088020, %d0 /* Enable bcache and icache */
610 move.l #(DCACHE_STATUS), %a1
615 .globl dcache_disable
617 move.l #(CACR_STATUS), %a1 /* read CACR Status */
620 and.l #0x7FFFFFFF, %d0
621 or.l #0x01000000, %d0 /* Setup cache mask */
622 movec %d0, %CACR /* Disable dcache */
627 move.l #(DCACHE_STATUS), %a1
632 .globl dcache_invalid
634 move.l #(CACR_STATUS), %a1 /* read CACR Status */
637 move.l #0x81088020, %d0 /* Setup cache mask */
638 movec %d0, %CACR /* Enable and invalidate cache */
643 move.l #(DCACHE_STATUS), %a1
647 /*------------------------------------------------------------------------------*/
649 .globl version_string
651 .ascii U_BOOT_VERSION
652 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
653 .ascii CONFIG_IDENT_STRING, "\0"