2 * U-boot - start.S Startup file for Blackfin u-boot
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * This file is based on head.S
7 * Copyright (c) 2003 Metrowerks/Motorola
8 * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
9 * Kenneth Albanowski <kjahds@kjahds.com>,
10 * The Silver Hammer Group, Ltd.
11 * (c) 1995, Dionne & Associates
12 * (c) 1995, DKG Display Tech.
14 * See file CREDITS for list of people who contributed to this
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
34 #include <asm/blackfin.h>
35 #include <asm/mach-common/bits/core.h>
36 #include <asm/mach-common/bits/dma.h>
37 #include <asm/mach-common/bits/pll.h>
41 /* It may seem odd that we make calls to functions even though we haven't
42 * relocated ourselves yet out of {flash,ram,wherever}. This is OK because
43 * the "call" instruction in the Blackfin architecture is actually PC
44 * relative. So we can call functions all we want and not worry about them
45 * not being relocated yet.
51 /* Set our initial stack to L1 scratch space */
52 sp.l = LO(L1_SRAM_SCRATCH_END - 20);
53 sp.h = HI(L1_SRAM_SCRATCH_END - 20);
55 #ifdef CONFIG_HW_WATCHDOG
56 # ifndef CONFIG_HW_WATCHDOG_TIMEOUT_START
57 # define CONFIG_HW_WATCHDOG_TIMEOUT_START 5000
59 /* Program the watchdog with an initial timeout of ~5 seconds.
60 * That should be long enough to bootstrap ourselves up and
61 * then the common u-boot code can take over.
66 R0.H = HI(MSEC_TO_SCLK(CONFIG_HW_WATCHDOG_TIMEOUT_START));
68 /* fire up the watchdog - R0.L above needs to be 0x0000 */
69 W[P0 + (WDOG_CTL - WDOG_CNT)] = R0;
72 /* Turn on the serial for debugging the init process */
76 serial_early_puts("Init Registers");
78 /* Disable self-nested interrupts and enable CYCLES for udelay() */
82 /* Zero out registers required by Blackfin ABI.
83 * http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface
86 /* Disable circular buffers */
91 /* Disable hardware loops in case we were started by 'go' */
95 /* Save RETX so we can pass it while booting Linux */
98 /* Figure out where we are currently executing so that we can decide
99 * how to best reprogram and relocate things. We'll pass below:
100 * R4: load address of _start
101 * R5: current (not load) address of _start
103 serial_early_puts("Find ourselves");
114 /* Inform upper layers if we had to do the relocation ourselves.
115 * This allows us to detect whether we were loaded by 'go 0x1000'
116 * or by the bootrom from an LDR. "R6" is "loaded_from_ldr".
120 if cc jump .Lnorelocate;
123 /* In bypass mode, we don't have an LDR with an init block
124 * so we need to explicitly call it ourselves. This will
125 * reprogram our clocks, memory, and setup our async banks.
127 serial_early_puts("Program Clocks");
129 /* if we're executing >=0x20000000, then we dont need to dma */
133 if cc jump .Ldma_and_reprogram;
134 r0 = 0 (x); /* set bootstruct to NULL */
138 /* we're sitting in external memory, so dma into L1 and reprogram */
140 r0.l = LO(L1_INST_SRAM);
141 r0.h = HI(L1_INST_SRAM);
142 r1.l = __initcode_start;
143 r1.h = __initcode_start;
144 r2.l = __initcode_end;
145 r2.h = __initcode_end;
146 r2 = r2 - r1; /* convert r2 into length of initcode */
147 r1 = r1 - r4; /* convert r1 from load address of initcode ... */
148 r1 = r1 + r5; /* ... to current (not load) address of initcode */
150 call _dma_memcpy_nocache;
151 r0 = 0 (x); /* set bootstruct to NULL */
154 /* Since we reprogrammed SCLK, we need to update the serial divisor */
156 serial_early_set_baud
158 /* Relocate from wherever we are (FLASH/RAM/etc...) to the hardcoded
159 * monitor location in the end of RAM. We know that memcpy() only
160 * uses registers, so it is safe to call here. Note that this only
161 * copies to external memory ... we do not start executing out of
162 * it yet (see "lower to 15" below).
164 serial_early_puts("Relocate");
167 r2.l = LO(CONFIG_SYS_MONITOR_LEN);
168 r2.h = HI(CONFIG_SYS_MONITOR_LEN);
171 /* Initialize BSS section ... we know that memset() does not
172 * use the BSS, so it is safe to call here. The bootrom LDR
173 * takes care of clearing things for us.
175 serial_early_puts("Zero BSS");
186 /* Setup the actual stack in external memory */
187 sp.h = HI(CONFIG_STACKBASE);
188 sp.l = LO(CONFIG_STACKBASE);
191 /* Now lower ourselves from the highest interrupt level to
192 * the lowest. We do this by masking all interrupts but 15,
193 * setting the 15 handler to ".Lenable_nested", raising the 15
194 * interrupt, and then returning from the highest interrupt
195 * level to the dummy "jump" until the interrupt controller
196 * services the pending 15 interrupt. If executing out of
197 * flash, these steps also changes the code flow from flash
198 * to external memory.
200 serial_early_puts("Lower to 15");
205 p1.l = .Lenable_nested;
206 p1.h = .Lenable_nested;
216 /* Enable nested interrupts before continuing with cpu init */