2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm-offsets.h>
11 #include <asm/cache.h>
13 #ifndef CONFIG_IDENT_STRING
14 #define CONFIG_IDENT_STRING ""
21 move.w #0x2700,%sr; /* disable intrs */ \
22 subl #60,%sp; /* space for 15 regs */ \
23 moveml %d0-%d7/%a0-%a6,%sp@;
26 moveml %sp@,%d0-%d7/%a0-%a6; \
27 addl #60,%sp; /* space for 15 regs */ \
30 #if defined(CONFIG_CF_SBF)
31 #define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
32 #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
37 * Vector table. This is used for initial platform startup.
38 * These vectors are to catch any un-intended traps.
42 #if defined(CONFIG_CF_SBF)
43 INITSP: .long 0 /* Initial SP */
44 INITPC: .long ASM_DRAMINIT /* Initial PC */
46 INITSP: .long 0 /* Initial SP */
47 INITPC: .long _START /* Initial PC */
50 vector02: .long _FAULT /* Access Error */
51 vector03: .long _FAULT /* Address Error */
52 vector04: .long _FAULT /* Illegal Instruction */
53 vector05: .long _FAULT /* Reserved */
54 vector06: .long _FAULT /* Reserved */
55 vector07: .long _FAULT /* Reserved */
56 vector08: .long _FAULT /* Privilege Violation */
57 vector09: .long _FAULT /* Trace */
58 vector0A: .long _FAULT /* Unimplemented A-Line */
59 vector0B: .long _FAULT /* Unimplemented F-Line */
60 vector0C: .long _FAULT /* Debug Interrupt */
61 vector0D: .long _FAULT /* Reserved */
62 vector0E: .long _FAULT /* Format Error */
63 vector0F: .long _FAULT /* Unitialized Int. */
67 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69 vector18: .long _FAULT /* Spurious Interrupt */
70 vector19: .long _FAULT /* Autovector Level 1 */
71 vector1A: .long _FAULT /* Autovector Level 2 */
72 vector1B: .long _FAULT /* Autovector Level 3 */
73 vector1C: .long _FAULT /* Autovector Level 4 */
74 vector1D: .long _FAULT /* Autovector Level 5 */
75 vector1E: .long _FAULT /* Autovector Level 6 */
76 vector1F: .long _FAULT /* Autovector Level 7 */
78 #if !defined(CONFIG_CF_SBF)
81 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
82 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
86 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
87 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
90 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
91 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
93 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
94 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
95 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
96 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
97 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
100 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
101 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
102 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
103 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
104 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
105 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
106 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
107 .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
112 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
113 .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
120 #if defined(CONFIG_CF_SBF)
121 /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
123 .long 0x00000000 /* checksum, not yet implemented */
124 .long 0x00020000 /* image length */
125 .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
128 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
129 movec %d0, %RAMBAR1 /* init Rambar */
130 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
133 /* Must disable global address */
134 move.l #0xFC008000, %a1
135 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
136 move.l #0xFC008008, %a1
137 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
138 move.l #0xFC008004, %a1
139 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
142 * Dram Initialization
146 move.l #0xFC0A4074, %a1
147 move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
150 /* SDRAM Chip 0 and 1 */
151 move.l #0xFC0B8110, %a1
152 move.l #0xFC0B8114, %a2
154 /* calculate the size */
156 move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
157 #ifdef CONFIG_SYS_SDRAM_BASE1
167 /* SDRAM Chip 0 and 1 */
168 move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
170 #ifdef CONFIG_SYS_SDRAM_BASE1
171 move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
176 /* dram cfg1 and cfg2 */
177 move.l #0xFC0B8008, %a1
178 move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
180 move.l #0xFC0B800C, %a2
181 move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
184 move.l #0xFC0B8000, %a1 /* Mode */
185 move.l #0xFC0B8004, %a2 /* Ctrl */
188 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
192 move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
194 move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
204 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
207 /* Perform two refresh cycles */
208 move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
214 move.l #(CONFIG_SYS_SDRAM_CTRL), %d0
215 and.l #0x7FFFFFFF, %d0
216 or.l #0x10000c00, %d0
221 * DSPI Initialization
222 * a0 - general, sram - 0x80008000 - 32, see M52277EVB.h
229 /* Enable pins for DSPI mode - chip-selects are enabled later */
230 move.l #0xFC0A4036, %a0
235 #ifdef CONFIG_SYS_DSPI_CS0
240 #ifdef CONFIG_SYS_DSPI_CS2
241 move.l #0xFC0A4037, %a0
248 /* Configure DSPI module */
249 move.l #0xFC05C000, %a0
250 move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
252 move.l #0xFC05C00C, %a0
253 move.l #0x3E000011, (%a0)
255 move.l #0xFC05C034, %a2 /* dtfr */
256 move.l #0xFC05C03B, %a3 /* drfr */
258 move.l #(ASM_SBF_IMG_HDR + 4), %a1
262 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
263 move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
265 move.l #0xFC05C02C, %a1 /* dspi status */
267 /* Issue commands and address */
268 move.l #0x8004000B, %d2 /* Fast Read Cmd */
269 jsr asm_dspi_wr_status
270 jsr asm_dspi_rd_status
272 move.l #0x80040000, %d2 /* Address byte 2 */
273 jsr asm_dspi_wr_status
274 jsr asm_dspi_rd_status
276 move.l #0x80040000, %d2 /* Address byte 1 */
277 jsr asm_dspi_wr_status
278 jsr asm_dspi_rd_status
280 move.l #0x80040000, %d2 /* Address byte 0 */
281 jsr asm_dspi_wr_status
282 jsr asm_dspi_rd_status
284 move.l #0x80040000, %d2 /* Dummy Wr and Rd */
285 jsr asm_dspi_wr_status
286 jsr asm_dspi_rd_status
288 /* Transfer serial boot header to sram */
290 move.l #0x80040000, %d2
291 jsr asm_dspi_wr_status
292 jsr asm_dspi_rd_status
294 move.b %d1, (%a0) /* read, copy to dst */
296 add.l #1, %a0 /* inc dst by 1 */
297 sub.l #1, %d4 /* dec cnt by 1 */
298 bne asm_dspi_rd_loop1
300 /* Transfer u-boot from serial flash to memory */
302 move.l #0x80040000, %d2
303 jsr asm_dspi_wr_status
304 jsr asm_dspi_rd_status
306 move.b %d1, (%a4) /* read, copy to dst */
308 add.l #1, %a4 /* inc dst by 1 */
309 sub.l #1, %d5 /* dec cnt by 1 */
310 bne asm_dspi_rd_loop2
312 move.l #0x00040000, %d2 /* Terminate */
313 jsr asm_dspi_wr_status
314 jsr asm_dspi_rd_status
316 /* jump to memory and execute */
317 move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
322 move.l (%a1), %d0 /* status */
323 and.l #0x0000F000, %d0
324 cmp.l #0x00003000, %d0
325 bgt asm_dspi_wr_status
331 move.l (%a1), %d0 /* status */
332 and.l #0x000000F0, %d0
335 beq asm_dspi_rd_status
339 #endif /* CONFIG_CF_SBF */
347 move.w #0x2700,%sr /* Mask off Interrupt */
349 /* Set vector base register at the beginning of the Flash */
350 #if defined(CONFIG_CF_SBF)
351 move.l #CONFIG_SYS_TEXT_BASE, %d0
354 move.l #CONFIG_SYS_FLASH_BASE, %d0
357 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
361 /* invalidate and disable cache */
362 move.l #CF_CACR_CINV, %d0 /* Invalidate cache cmd */
363 movec %d0, %CACR /* Invalidate cache */
368 /* initialize general use internal ram */
370 move.l #(ICACHE_STATUS), %a1 /* icache */
371 move.l #(DCACHE_STATUS), %a2 /* icache */
375 /* set stackpointer to end of internal ram to get some stackspace for
377 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
380 move.l #__got_start, %a5 /* put relocation table address to a5 */
382 bsr cpu_init_f /* run low-level CPU init code (from flash) */
383 bsr board_init_f /* run low-level board init code (from flash) */
385 /* board_init_f() does not return */
387 /*------------------------------------------------------------------------------*/
390 * void relocate_code (addr_sp, gd, addr_moni)
392 * This "function" does not return, instead it continues in RAM
393 * after relocating the monitor code.
397 * r5 = length in bytes
403 move.l 8(%a6), %sp /* set new stack pointer */
405 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
406 move.l 16(%a6), %a0 /* Save copy of Destination Address */
408 move.l #CONFIG_SYS_MONITOR_BASE, %a1
409 move.l #__init_end, %a2
412 /* copy the code to RAM */
414 move.l (%a1)+, (%a3)+
419 * We are done. Do not return, instead branch to second part of board
420 * initialization, now running from RAM.
423 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
430 * Now clear BSS segment
433 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
435 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
442 * fix got table in RAM
445 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
446 move.l %a1,%a5 /* * fix got pointer register a5 */
449 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
459 /* calculate relative jump to board_init_r in ram */
461 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
463 /* set parameters for board_init_r */
464 move.l %a0,-(%sp) /* dest_addr */
465 move.l %d0,-(%sp) /* gd */
468 /*------------------------------------------------------------------------------*/
490 /*------------------------------------------------------------------------------*/
492 .globl version_string
494 .ascii U_BOOT_VERSION_STRING, "\0"