2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
5 * Copyright 2010-2012 Freescale Semiconductor, Inc.
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm-offsets.h>
14 #include <timestamp.h>
16 #include <asm/cache.h>
22 move.w #0x2700,%sr; /* disable intrs */ \
23 subl #60,%sp; /* space for 15 regs */ \
24 moveml %d0-%d7/%a0-%a6,%sp@;
27 moveml %sp@,%d0-%d7/%a0-%a6; \
28 addl #60,%sp; /* space for 15 regs */ \
31 #if defined(CONFIG_SERIAL_BOOT)
32 #define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + \
33 CONFIG_SYS_INIT_RAM_ADDR)
34 #define ASM_DRAMINIT_N (asm_dram_init - CONFIG_SYS_TEXT_BASE)
35 #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + \
36 CONFIG_SYS_INIT_RAM_ADDR)
42 * Vector table. This is used for initial platform startup.
43 * These vectors are to catch any un-intended traps.
46 #if defined(CONFIG_SERIAL_BOOT)
48 INITSP: .long 0 /* Initial SP */
50 INITPC: .long ASM_DRAMINIT /* Initial PC */
52 #ifdef CONFIG_SYS_NAND_BOOT
53 INITPC: .long ASM_DRAMINIT_N /* Initial PC */
58 INITSP: .long 0 /* Initial SP */
59 INITPC: .long _START /* Initial PC */
64 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
65 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
72 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74 #if !defined(CONFIG_SERIAL_BOOT)
78 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
79 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
84 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
87 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
88 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
89 .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
97 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
98 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
99 .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
107 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
108 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
109 .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
117 #if defined(CONFIG_SERIAL_BOOT)
118 /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
120 .long 0x00000000 /* checksum, not yet implemented */
121 .long 0x00040000 /* image length */
122 .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
125 move.w #0x2700,%sr /* Mask off Interrupt */
127 #ifdef CONFIG_SYS_NAND_BOOT
128 /* for assembly stack */
129 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
132 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
137 move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
140 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
143 /* initialize general use internal ram */
145 move.l #(ICACHE_STATUS), %a1 /* icache */
146 move.l #(DCACHE_STATUS), %a2 /* dcache */
150 /* invalidate and disable cache */
151 move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
152 movec %d0, %CACR /* Invalidate cache */
159 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
162 #ifdef CONFIG_SYS_CS0_BASE
163 /* Must disable global address */
164 move.l #0xFC008000, %a1
165 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
166 move.l #0xFC008008, %a1
167 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
168 move.l #0xFC008004, %a1
169 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
171 #endif /* CONFIG_CF_SBF */
173 #ifdef CONFIG_MCF5441x
174 /* TC: enable all peripherals,
175 in the future only enable certain peripherals */
176 move.l #0xFC04002D, %a1
178 #if defined(CONFIG_CF_SBF)
179 move.b #23, (%a1) /* dspi */
181 #endif /* CONFIG_MCF5441x */
183 /* mandatory board level ddr-sdram init,
184 * for both 5441x and 5445x
190 * DSPI Initialization
191 * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
197 /* Enable pins for DSPI mode - chip-selects are enabled later */
199 #ifdef CONFIG_MCF5441x
200 move.l #0xEC09404E, %a1
201 move.l #0xEC09404F, %a2
206 #ifdef CONFIG_MCF5445x
207 move.l #0xFC0A4063, %a0
210 /* Configure DSPI module */
211 move.l #0xFC05C000, %a0
212 move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
214 move.l #0xFC05C00C, %a0
215 #ifdef CONFIG_MCF5441x
216 move.l #0x3E000016, (%a0)
218 #ifdef CONFIG_MCF5445x
219 move.l #0x3E000011, (%a0)
222 move.l #0xFC05C034, %a2 /* dtfr */
223 move.l #0xFC05C03B, %a3 /* drfr */
225 move.l #(ASM_SBF_IMG_HDR + 4), %a1
229 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
230 move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
232 move.l #0xFC05C02C, %a1 /* dspi status */
234 /* Issue commands and address */
235 move.l #0x8002000B, %d2 /* Fast Read Cmd */
236 jsr asm_dspi_wr_status
237 jsr asm_dspi_rd_status
239 move.l #0x80020000, %d2 /* Address byte 2 */
240 jsr asm_dspi_wr_status
241 jsr asm_dspi_rd_status
243 move.l #0x80020000, %d2 /* Address byte 1 */
244 jsr asm_dspi_wr_status
245 jsr asm_dspi_rd_status
247 move.l #0x80020000, %d2 /* Address byte 0 */
248 jsr asm_dspi_wr_status
249 jsr asm_dspi_rd_status
251 move.l #0x80020000, %d2 /* Dummy Wr and Rd */
252 jsr asm_dspi_wr_status
253 jsr asm_dspi_rd_status
255 /* Transfer serial boot header to sram */
257 move.l #0x80020000, %d2
258 jsr asm_dspi_wr_status
259 jsr asm_dspi_rd_status
261 move.b %d1, (%a0) /* read, copy to dst */
263 add.l #1, %a0 /* inc dst by 1 */
264 sub.l #1, %d4 /* dec cnt by 1 */
265 bne asm_dspi_rd_loop1
267 /* Transfer u-boot from serial flash to memory */
269 move.l #0x80020000, %d2
270 jsr asm_dspi_wr_status
271 jsr asm_dspi_rd_status
273 move.b %d1, (%a4) /* read, copy to dst */
275 add.l #1, %a4 /* inc dst by 1 */
276 sub.l #1, %d5 /* dec cnt by 1 */
277 bne asm_dspi_rd_loop2
279 move.l #0x00020000, %d2 /* Terminate */
280 jsr asm_dspi_wr_status
281 jsr asm_dspi_rd_status
283 /* jump to memory and execute */
284 move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
288 move.l (%a1), %d0 /* status */
289 and.l #0x0000F000, %d0
290 cmp.l #0x00003000, %d0
291 bgt asm_dspi_wr_status
297 move.l (%a1), %d0 /* status */
298 and.l #0x000000F0, %d0
301 beq asm_dspi_rd_status
305 #endif /* CONFIG_CF_SBF */
307 #ifdef CONFIG_SYS_NAND_BOOT
308 /* copy 4 boot pages to dram as soon as possible */
309 /* each page is 996 bytes (1056 total with 60 ECC bytes */
310 move.l #0x00000000, %a1 /* src */
311 move.l #CONFIG_SYS_TEXT_BASE, %a2 /* dst */
312 move.l #0x3E0, %d0 /* sz in long */
315 move.l (%a1)+, (%a2)+
317 bne asm_boot_nand_copy
319 /* jump to memory and execute */
320 move.l #(asm_nand_init), %a0
324 /* exit nand boot-mode */
325 move.l #0xFC0FFF30, %a1
326 or.l #0x00000040, %d1
329 /* initialize general use internal ram */
331 move.l #(CACR_STATUS), %a1 /* CACR */
332 move.l #(ICACHE_STATUS), %a2 /* icache */
333 move.l #(DCACHE_STATUS), %a3 /* dcache */
338 /* invalidate and disable cache */
339 move.l #0x01004100, %d0 /* Invalidate cache cmd */
340 movec %d0, %CACR /* Invalidate cache */
347 #ifdef CONFIG_SYS_CS0_BASE
348 /* Must disable global address */
349 move.l #0xFC008000, %a1
350 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
351 move.l #0xFC008008, %a1
352 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
353 move.l #0xFC008004, %a1
354 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
357 /* NAND port configuration */
358 move.l #0xEC094048, %a1
364 move.l #0xFC0FFF38, %a1 /* isr */
365 move.l #0x000e0000, (%a1)
366 move.l #0xFC0FFF08, %a2
367 move.l #0x00000000, (%a2)+ /* car */
368 move.l #0x11000000, (%a2)+ /* rar */
369 move.l #0x00000000, (%a2)+ /* rpt */
370 move.l #0x00000000, (%a2)+ /* rai */
371 move.l #0xFC0FFF2c, %a2 /* cfg */
372 move.l #0x00000000, (%a2)+ /* secsz */
373 move.l #0x000e0681, (%a2)+
374 move.l #0xFC0FFF04, %a2 /* cmd2 */
375 move.l #0xFF404001, (%a2)
376 move.l #0x000e0000, (%a1)
382 move.l #0xFC0FFF00, %a1
383 move.l #0x30700000, (%a1)+ /* cmd1 */
384 move.l #0x007EF000, (%a1)+ /* cmd2 */
386 move.l #0xFC0FFF2C, %a1
387 move.l #0x00000841, (%a1)+ /* secsz */
388 move.l #0x000e0681, (%a1)+ /* cfg */
390 move.l #100, %d4 /* 100 pages ~200KB */
391 move.l #4, %d2 /* start at 4 */
392 move.l #0xFC0FFF04, %a0 /* cmd2 */
393 move.l #0xFC0FFF0C, %a1 /* rar */
394 move.l #(CONFIG_SYS_TEXT_BASE + 0xF80), %a2
397 move.l #0x11000000, %d0 /* rar */
402 move.l (%a0), %d0 /* cmd2 */
410 move.l #0xFC0FFF38, %a4 /* isr */
412 and.l #0x40000000, %d0
414 beq asm_nand_chk_status
416 move.l #0xFC0FFF38, %a4 /* isr */
418 or.l #0x000E0000, %d0
422 move.l #0xFC0FC000, %a3 /* buf 1 */
424 move.l (%a3)+, (%a2)+
431 /* jump to memory and execute */
432 move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
435 #endif /* CONFIG_SYS_NAND_BOOT */
443 #endif /* CONFIG_CF_SBF || CONFIG_NAND_U_BOOT */
449 #if !defined(CONFIG_SERIAL_BOOT)
452 move.w #0x2700,%sr /* Mask off Interrupt */
454 /* Set vector base register at the beginning of the Flash */
455 move.l #CONFIG_SYS_FLASH_BASE, %d0
458 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
461 /* initialize general use internal ram */
463 move.l #(ICACHE_STATUS), %a1 /* icache */
464 move.l #(DCACHE_STATUS), %a2 /* dcache */
468 /* invalidate and disable cache */
469 move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
470 movec %d0, %CACR /* Invalidate cache */
477 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
481 /* put relocation table address to a5 */
482 move.l #__got_start, %a5
484 /* setup stack initially on top of internal static ram */
485 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
488 * if configured, malloc_f arena will be reserved first,
489 * then (and always) gd struct space will be reserved
492 move.l #board_init_f_alloc_reserve, %a1
495 /* update stack and frame-pointers */
499 /* initialize reserved area */
501 move.l #board_init_f_init_reserve, %a1
504 /* run low-level CPU init code (from flash) */
505 move.l #cpu_init_f, %a1
508 /* run low-level board init code (from flash) */
510 move.l #board_init_f, %a1
513 /* board_init_f() does not return */
515 /******************************************************************************/
518 * void relocate_code (addr_sp, gd, addr_moni)
520 * This "function" does not return, instead it continues in RAM
521 * after relocating the monitor code.
525 * r5 = length in bytes
531 move.l 8(%a6), %sp /* set new stack pointer */
533 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
534 move.l 16(%a6), %a0 /* Save copy of Destination Address */
536 move.l #CONFIG_SYS_MONITOR_BASE, %a1
537 move.l #__init_end, %a2
540 /* copy the code to RAM */
542 move.l (%a1)+, (%a3)+
547 * We are done. Do not return, instead branch to second part of board
548 * initialization, now running from RAM.
551 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
558 * Now clear BSS segment
561 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
563 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
570 * fix got table in RAM
573 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
574 move.l %a1,%a5 /* fix got pointer register a5 */
577 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
587 /* calculate relative jump to board_init_r in ram */
589 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
591 /* set parameters for board_init_r */
592 move.l %a0,-(%sp) /* dest_addr */
593 move.l %d0,-(%sp) /* gd */
596 /******************************************************************************/
619 /******************************************************************************/
621 .globl version_string
623 .ascii U_BOOT_VERSION_STRING, "\0"