2 * armboot - Startup Code for ARM1176 CPU-core
4 * Copyright (c) 2007 Samsung Electronics
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
30 * Base codes by scsuh (sc.suh)
35 #ifdef CONFIG_ENABLE_MMU
36 #include <asm/proc/domain.h>
39 #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
40 #define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
44 *************************************************************************
46 * Jump vector table as in table 3.1 in [1]
48 *************************************************************************
53 #ifndef CONFIG_NAND_SPL
54 ldr pc, _undefined_instruction
55 ldr pc, _software_interrupt
56 ldr pc, _prefetch_abort
62 _undefined_instruction:
63 .word undefined_instruction
65 .word software_interrupt
77 .word 0x12345678 /* now 16*4=64 */
84 .balignl 16,0xdeadbeef
86 *************************************************************************
88 * Startup Code (reset vector)
90 * do important init only if we don't start from memory!
91 * setup Memory and board specific bits prior to relocation.
92 * relocate armboot to ram
95 *************************************************************************
103 * Below variable is very important because we use MMU in U-Boot.
104 * Without it, we cannot run code correctly before MMU is ON.
108 .word CONFIG_SYS_PHY_UBOOT_BASE
110 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
111 .globl _armboot_start
117 * These are defined in the board-specific linker script.
127 #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
128 /* IRQ stack memory (calculated at run-time) + 8 bytes */
129 .globl IRQ_STACK_START_IN
133 .globl _datarel_start
135 .word __datarel_start
137 .globl _datarelrolocal_start
138 _datarelrolocal_start:
139 .word __datarelrolocal_start
141 .globl _datarellocal_start
143 .word __datarellocal_start
145 .globl _datarelro_start
147 .word __datarelro_start
158 * the actual reset code
163 * set the cpu to SVC32 mode
171 *************************************************************************
173 * CPU_init_critical registers
175 * setup important registers
176 * setup memory timing
178 *************************************************************************
181 * we do sys-critical inits only at reboot,
182 * not when booting from ram!
186 * When booting from NAND - it has definitely been a reset, so, no need
187 * to flush caches and disable the MMU
189 #ifndef CONFIG_NAND_SPL
191 * flush v4 I/D caches
194 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
195 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
198 * disable MMU stuff and caches
200 mrc p15, 0, r0, c1, c0, 0
201 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
202 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
203 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
204 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
206 /* Prepare to disable the MMU */
207 adr r2, mmu_disable_phys
208 sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - TEXT_BASE)
212 /* Run in a single cache-line */
214 mcr p15, 0, r0, c1, c0, 0
220 #ifdef CONFIG_DISABLE_TCM
224 mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
230 mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
232 mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
237 #ifdef CONFIG_PERIPORT_REMAP
238 /* Peri port setup */
239 ldr r0, =CONFIG_PERIPORT_BASE
240 orr r0, r0, #CONFIG_PERIPORT_SIZE
241 mcr p15,0,r0,c15,c2,4
245 * Go setup Memory and board specific bits prior to relocation.
247 bl lowlevel_init /* go setup pll,mux,memory */
249 /* Set stackpointer in internal RAM to call board_init_f */
251 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
255 /*------------------------------------------------------------------------------*/
258 * void relocate_code (addr_sp, gd, addr_moni)
260 * This "function" does not return, instead it continues in RAM
261 * after relocating the monitor code.
266 mov r4, r0 /* save addr_sp */
267 mov r5, r1 /* save addr of gd */
268 mov r6, r2 /* save addr of destination */
269 mov r7, r2 /* save addr of destination */
271 /* Set up the stack */
278 sub r2, r3, r2 /* r2 <- size of armboot */
279 add r2, r0, r2 /* r2 <- source end address */
283 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
285 ldmia r0!, {r9-r10} /* copy from source address [r0] */
286 stmia r6!, {r9-r10} /* copy to target address [r1] */
287 cmp r0, r2 /* until source end address [r2] */
290 #ifndef CONFIG_PRELOADER
291 /* fix got entries */
292 ldr r1, _TEXT_BASE /* Text base */
293 mov r0, r7 /* reloc addr */
294 ldr r2, _got_start /* addr in Flash */
295 ldr r3, _got_end /* addr in Flash */
310 #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
312 #ifdef CONFIG_ENABLE_MMU
314 /* enable domain access */
316 mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
318 /* Set the TTB register */
319 ldr r0, _mmu_table_base
320 ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
324 mcr p15, 0, r1, c2, c0, 0
327 mrc p15, 0, r0, c1, c0, 0
328 orr r0, r0, #1 /* Set CR_M to enable MMU */
330 /* Prepare to enable the MMU */
340 /* Run in a single cache-line */
343 mcr p15, 0, r0, c1, c0, 0
351 #ifndef CONFIG_PRELOADER
354 ldr r3, _TEXT_BASE /* Text base */
355 mov r4, r7 /* reloc addr */
360 mov r2, #0x00000000 /* clear */
362 clbss_l:str r2, [r0] /* clear loop... */
372 * We are done. Do not return, instead branch to second part of board
373 * initialization, now running from RAM.
375 #ifdef CONFIG_NAND_SPL
378 _nand_boot: .word nand_boot
381 ldr r2, _board_init_r
383 add r2, r2, r7 /* position from board_init_r in RAM */
384 /* setup parameters for board_init_r */
385 mov r0, r5 /* gd_t */
386 mov r1, r7 /* dest_addr */
391 _board_init_r: .word board_init_r
394 #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
397 * the actual reset code
402 * set the cpu to SVC32 mode
410 *************************************************************************
412 * CPU_init_critical registers
414 * setup important registers
415 * setup memory timing
417 *************************************************************************
420 * we do sys-critical inits only at reboot,
421 * not when booting from ram!
425 * When booting from NAND - it has definitely been a reset, so, no need
426 * to flush caches and disable the MMU
428 #ifndef CONFIG_NAND_SPL
430 * flush v4 I/D caches
433 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
434 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
437 * disable MMU stuff and caches
439 mrc p15, 0, r0, c1, c0, 0
440 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
441 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
442 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
443 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
445 /* Prepare to disable the MMU */
446 adr r2, mmu_disable_phys
447 sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - TEXT_BASE)
451 /* Run in a single cache-line */
453 mcr p15, 0, r0, c1, c0, 0
459 #ifdef CONFIG_DISABLE_TCM
463 mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
469 mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
471 mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
476 #ifdef CONFIG_PERIPORT_REMAP
477 /* Peri port setup */
478 ldr r0, =CONFIG_PERIPORT_BASE
479 orr r0, r0, #CONFIG_PERIPORT_SIZE
480 mcr p15,0,r0,c15,c2,4
484 * Go setup Memory and board specific bits prior to relocation.
486 bl lowlevel_init /* go setup pll,mux,memory */
488 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
489 relocate: /* relocate U-Boot to RAM */
490 adr r0, _start /* r0 <- current position of code */
491 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
492 cmp r0, r1 /* don't reloc during debug */
495 ldr r2, _armboot_start
497 sub r2, r3, r2 /* r2 <- size of armboot */
498 add r2, r0, r2 /* r2 <- source end address */
501 ldmia r0!, {r3-r10} /* copy from source address [r0] */
502 stmia r1!, {r3-r10} /* copy to target address [r1] */
503 cmp r0, r2 /* until source end address [r2] */
505 #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
507 #ifdef CONFIG_ENABLE_MMU
509 /* enable domain access */
511 mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
513 /* Set the TTB register */
514 ldr r0, _mmu_table_base
515 ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
519 mcr p15, 0, r1, c2, c0, 0
522 mrc p15, 0, r0, c1, c0, 0
523 orr r0, r0, #1 /* Set CR_M to enable MMU */
525 /* Prepare to enable the MMU */
535 /* Run in a single cache-line */
538 mcr p15, 0, r0, c1, c0, 0
545 /* Set up the stack */
547 ldr r0, =CONFIG_SYS_UBOOT_BASE /* base of copy in DRAM */
548 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
549 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
550 sub sp, r0, #12 /* leave 3 words for abort-stack */
551 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
554 ldr r0, _bss_start /* find start of bss segment */
555 ldr r1, _bss_end /* stop here */
556 mov r2, #0 /* clear */
559 str r2, [r0] /* clear loop... */
564 #ifndef CONFIG_NAND_SPL
565 ldr pc, _start_armboot
574 #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
576 #ifdef CONFIG_ENABLE_MMU
581 #ifndef CONFIG_NAND_SPL
583 * we assume that cache operation is done before. (eg. cleanup_before_linux())
584 * actually, we don't need to do anything about cache if not use d-cache in
585 * U-Boot. So, in this function we clean only MMU. by scsuh
587 * void theLastJump(void *kernel, int arch_num, uint boot_params);
589 #ifdef CONFIG_ENABLE_MMU
594 ldr r4, _TEXT_PHY_BASE
595 adr r5, phy_last_jump
603 mrc p15, 0, r0, c1, c0, 0
604 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
605 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
606 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
607 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
608 mcr p15, 0, r0, c1, c0, 0
610 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
618 *************************************************************************
622 *************************************************************************
627 #define S_FRAME_SIZE 72
649 #define MODE_SVC 0x13
653 * use bad_save_user_regs for abort/prefetch/undef/swi ...
656 .macro bad_save_user_regs
657 /* carve out a frame on current user stack */
658 sub sp, sp, #S_FRAME_SIZE
659 /* Save user registers (now in svc mode) r0-r12 */
662 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
663 ldr r2, _armboot_start
664 sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
665 /* set base 2 words into abort stack */
666 sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
668 ldr r2, IRQ_STACK_START_IN
670 /* get values for "aborted" pc and cpsr (into parm regs) */
672 /* grab pointer to old stack */
673 add r0, sp, #S_FRAME_SIZE
677 /* save sp_SVC, lr_SVC, pc, cpsr */
679 /* save current stack into r0 (param register) */
684 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
685 /* setup our mode stack (enter in banked mode) */
686 ldr r13, _armboot_start
687 /* move past malloc pool */
688 sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
689 /* move to reserved a couple spots for abort stack */
690 sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
692 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
695 /* save caller lr in position 0 of saved stack */
699 /* save spsr in position 1 of saved stack */
702 /* prepare SVC-Mode */
705 /* switch modes, make sure moves will execute */
707 /* capture return pc */
709 /* jump to next instruction & switch modes. */
713 .macro get_bad_stack_swi
714 /* space on current stack for scratch reg. */
716 /* save R0's value. */
718 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
719 /* get data regions start */
720 ldr r0, _armboot_start
721 /* move past malloc pool */
722 sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
723 /* move past gbl and a couple spots for abort stack */
724 sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
726 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
728 /* save caller lr in position 0 of saved stack */
732 /* save spsr in position 1 of saved stack */
736 /* pop stack entry */
744 undefined_instruction:
747 bl do_undefined_instruction
753 bl do_software_interrupt
784 #endif /* CONFIG_NAND_SPL */