2008-03-30 19:46:13 +00:00
|
|
|
/*
|
2016-02-06 03:30:11 +00:00
|
|
|
* U-Boot - start.S Startup file for Blackfin U-Boot
|
2008-03-30 19:46:13 +00:00
|
|
|
*
|
2008-10-12 01:18:10 +00:00
|
|
|
* Copyright (c) 2005-2008 Analog Devices Inc.
|
2008-03-30 19:46:13 +00:00
|
|
|
*
|
|
|
|
* This file is based on head.S
|
|
|
|
* Copyright (c) 2003 Metrowerks/Motorola
|
|
|
|
* Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
|
|
|
|
* Kenneth Albanowski <kjahds@kjahds.com>,
|
|
|
|
* The Silver Hammer Group, Ltd.
|
|
|
|
* (c) 1995, Dionne & Associates
|
|
|
|
* (c) 1995, DKG Display Tech.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2008-03-30 19:46:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <asm/blackfin.h>
|
2013-04-07 10:02:37 +00:00
|
|
|
#include <asm/mach-common/bits/watchdog.h>
|
2008-03-30 19:46:13 +00:00
|
|
|
#include <asm/mach-common/bits/core.h>
|
|
|
|
#include <asm/mach-common/bits/pll.h>
|
2013-04-07 11:04:14 +00:00
|
|
|
#include <asm/serial.h>
|
2008-03-30 19:46:13 +00:00
|
|
|
|
|
|
|
/* It may seem odd that we make calls to functions even though we haven't
|
|
|
|
* relocated ourselves yet out of {flash,ram,wherever}. This is OK because
|
|
|
|
* the "call" instruction in the Blackfin architecture is actually PC
|
|
|
|
* relative. So we can call functions all we want and not worry about them
|
|
|
|
* not being relocated yet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
.text
|
|
|
|
ENTRY(_start)
|
|
|
|
|
|
|
|
/* Set our initial stack to L1 scratch space */
|
2008-10-12 01:18:10 +00:00
|
|
|
sp.l = LO(L1_SRAM_SCRATCH_END - 20);
|
|
|
|
sp.h = HI(L1_SRAM_SCRATCH_END - 20);
|
2008-03-30 19:46:13 +00:00
|
|
|
|
2010-12-24 19:46:12 +00:00
|
|
|
/* Optimization register tricks: keep a base value in the
|
|
|
|
* reserved P registers so we use the load/store with an
|
|
|
|
* offset syntax. R0 = [P5 + <constant>];
|
|
|
|
* P4 - system MMR base
|
|
|
|
* P5 - core MMR base
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_HW_WATCHDOG
|
|
|
|
p4.l = 0;
|
|
|
|
p4.h = HI(SYSMMR_BASE);
|
|
|
|
#endif
|
|
|
|
p5.l = 0;
|
|
|
|
p5.h = HI(COREMMR_BASE);
|
|
|
|
|
2008-03-30 19:46:13 +00:00
|
|
|
#ifdef CONFIG_HW_WATCHDOG
|
2013-04-07 10:02:37 +00:00
|
|
|
/* Program the watchdog with default timeout of ~5 seconds.
|
2008-03-30 19:46:13 +00:00
|
|
|
* That should be long enough to bootstrap ourselves up and
|
2016-02-06 03:30:11 +00:00
|
|
|
* then the common U-Boot code can take over.
|
2008-03-30 19:46:13 +00:00
|
|
|
*/
|
2013-04-07 10:02:37 +00:00
|
|
|
r1 = WDDIS;
|
|
|
|
# ifdef __ADSPBF60x__
|
|
|
|
[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
|
|
|
|
# else
|
|
|
|
W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
|
|
|
|
# endif
|
|
|
|
SSYNC;
|
2010-12-24 19:46:12 +00:00
|
|
|
r0 = 0;
|
2013-04-07 10:02:37 +00:00
|
|
|
r0.h = HI(MSEC_TO_SCLK(CONFIG_WATCHDOG_TIMEOUT_MSECS));
|
2010-12-24 19:46:12 +00:00
|
|
|
[p4 + (WDOG_CNT - SYSMMR_BASE)] = r0;
|
2013-04-07 10:02:37 +00:00
|
|
|
SSYNC;
|
|
|
|
r1 = WDEN;
|
2008-03-30 19:46:13 +00:00
|
|
|
/* fire up the watchdog - R0.L above needs to be 0x0000 */
|
2013-04-07 10:02:37 +00:00
|
|
|
# ifdef __ADSPBF60x__
|
|
|
|
[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
|
|
|
|
# else
|
|
|
|
W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
|
|
|
|
# endif
|
|
|
|
SSYNC;
|
2008-03-30 19:46:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Turn on the serial for debugging the init process */
|
|
|
|
serial_early_init
|
|
|
|
serial_early_set_baud
|
|
|
|
|
|
|
|
serial_early_puts("Init Registers");
|
|
|
|
|
2008-06-01 05:23:48 +00:00
|
|
|
/* Disable self-nested interrupts and enable CYCLES for udelay() */
|
2008-03-30 19:46:13 +00:00
|
|
|
R0 = CCEN | 0x30;
|
|
|
|
SYSCFG = R0;
|
|
|
|
|
|
|
|
/* Zero out registers required by Blackfin ABI.
|
|
|
|
* http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface
|
|
|
|
*/
|
|
|
|
r1 = 0 (x);
|
|
|
|
/* Disable circular buffers */
|
|
|
|
l0 = r1;
|
|
|
|
l1 = r1;
|
|
|
|
l2 = r1;
|
|
|
|
l3 = r1;
|
|
|
|
/* Disable hardware loops in case we were started by 'go' */
|
|
|
|
lc0 = r1;
|
|
|
|
lc1 = r1;
|
|
|
|
|
|
|
|
/* Save RETX so we can pass it while booting Linux */
|
|
|
|
r7 = RETX;
|
|
|
|
|
2009-11-10 00:38:23 +00:00
|
|
|
#if CONFIG_MEM_SIZE
|
2008-10-12 01:58:33 +00:00
|
|
|
/* Figure out where we are currently executing so that we can decide
|
|
|
|
* how to best reprogram and relocate things. We'll pass below:
|
|
|
|
* R4: load address of _start
|
|
|
|
* R5: current (not load) address of _start
|
2008-03-30 19:46:13 +00:00
|
|
|
*/
|
2008-10-12 01:58:33 +00:00
|
|
|
serial_early_puts("Find ourselves");
|
|
|
|
|
2008-03-30 19:46:13 +00:00
|
|
|
call _get_pc;
|
2008-10-12 01:58:33 +00:00
|
|
|
.Loffset:
|
|
|
|
r1.l = .Loffset;
|
|
|
|
r1.h = .Loffset;
|
|
|
|
r4.l = _start;
|
|
|
|
r4.h = _start;
|
|
|
|
r3 = r1 - r4;
|
|
|
|
r5 = r0 - r3;
|
|
|
|
|
|
|
|
/* Inform upper layers if we had to do the relocation ourselves.
|
|
|
|
* This allows us to detect whether we were loaded by 'go 0x1000'
|
|
|
|
* or by the bootrom from an LDR. "R6" is "loaded_from_ldr".
|
|
|
|
*/
|
|
|
|
r6 = 1 (x);
|
|
|
|
cc = r4 == r5;
|
|
|
|
if cc jump .Lnorelocate;
|
|
|
|
r6 = 0 (x);
|
2008-03-30 19:46:13 +00:00
|
|
|
|
2010-12-24 19:46:12 +00:00
|
|
|
/* Turn off caches as they require CPLBs and a CPLB miss requires
|
|
|
|
* a software exception handler to process it. But we're about to
|
|
|
|
* clobber any previous executing software (like U-Boot that just
|
|
|
|
* launched a new U-Boot via 'go'), so any handler state will be
|
|
|
|
* unreliable after the memcpy below.
|
|
|
|
*/
|
|
|
|
serial_early_puts("Kill Caches");
|
|
|
|
r0 = 0;
|
|
|
|
[p5 + (IMEM_CONTROL - COREMMR_BASE)] = r0;
|
|
|
|
[p5 + (DMEM_CONTROL - COREMMR_BASE)] = r0;
|
|
|
|
ssync;
|
|
|
|
|
2008-10-12 01:58:33 +00:00
|
|
|
/* In bypass mode, we don't have an LDR with an init block
|
|
|
|
* so we need to explicitly call it ourselves. This will
|
|
|
|
* reprogram our clocks, memory, and setup our async banks.
|
|
|
|
*/
|
2008-03-30 19:46:13 +00:00
|
|
|
serial_early_puts("Program Clocks");
|
|
|
|
|
2008-10-12 01:58:33 +00:00
|
|
|
/* if we're executing >=0x20000000, then we dont need to dma */
|
|
|
|
r3 = 0x0;
|
|
|
|
r3.h = 0x2000;
|
|
|
|
cc = r5 < r3 (iu);
|
|
|
|
if cc jump .Ldma_and_reprogram;
|
2009-11-10 00:38:23 +00:00
|
|
|
#else
|
|
|
|
r6 = 1 (x); /* fake loaded_from_ldr = 1 */
|
|
|
|
#endif
|
2009-02-13 22:10:58 +00:00
|
|
|
r0 = 0 (x); /* set bootstruct to NULL */
|
2008-03-30 19:46:13 +00:00
|
|
|
call _initcode;
|
2008-10-12 01:58:33 +00:00
|
|
|
jump .Lprogrammed;
|
|
|
|
|
|
|
|
/* we're sitting in external memory, so dma into L1 and reprogram */
|
|
|
|
.Ldma_and_reprogram:
|
|
|
|
r0.l = LO(L1_INST_SRAM);
|
|
|
|
r0.h = HI(L1_INST_SRAM);
|
2009-11-03 11:11:31 +00:00
|
|
|
r1.l = __initcode_lma;
|
|
|
|
r1.h = __initcode_lma;
|
|
|
|
r2.l = __initcode_len;
|
|
|
|
r2.h = __initcode_len;
|
2008-10-12 01:58:33 +00:00
|
|
|
r1 = r1 - r4; /* convert r1 from load address of initcode ... */
|
|
|
|
r1 = r1 + r5; /* ... to current (not load) address of initcode */
|
|
|
|
p3 = r0;
|
|
|
|
call _dma_memcpy_nocache;
|
2009-02-13 22:10:58 +00:00
|
|
|
r0 = 0 (x); /* set bootstruct to NULL */
|
2008-10-12 01:58:33 +00:00
|
|
|
call (p3);
|
2008-03-30 19:46:13 +00:00
|
|
|
|
|
|
|
/* Since we reprogrammed SCLK, we need to update the serial divisor */
|
2008-10-12 01:58:33 +00:00
|
|
|
.Lprogrammed:
|
2008-03-30 19:46:13 +00:00
|
|
|
serial_early_set_baud
|
|
|
|
|
2009-11-10 00:38:23 +00:00
|
|
|
#if CONFIG_MEM_SIZE
|
2008-10-12 01:40:26 +00:00
|
|
|
/* Relocate from wherever we are (FLASH/RAM/etc...) to the hardcoded
|
2008-06-01 05:21:34 +00:00
|
|
|
* monitor location in the end of RAM. We know that memcpy() only
|
2008-10-12 01:40:26 +00:00
|
|
|
* uses registers, so it is safe to call here. Note that this only
|
|
|
|
* copies to external memory ... we do not start executing out of
|
|
|
|
* it yet (see "lower to 15" below).
|
2008-03-30 19:46:13 +00:00
|
|
|
*/
|
|
|
|
serial_early_puts("Relocate");
|
2008-10-12 01:58:33 +00:00
|
|
|
r0 = r4;
|
|
|
|
r1 = r5;
|
2008-06-01 05:21:34 +00:00
|
|
|
r2.l = LO(CONFIG_SYS_MONITOR_LEN);
|
|
|
|
r2.h = HI(CONFIG_SYS_MONITOR_LEN);
|
|
|
|
call _memcpy_ASM;
|
2009-11-10 00:38:23 +00:00
|
|
|
#endif
|
2008-03-30 19:46:13 +00:00
|
|
|
|
2011-09-27 03:00:27 +00:00
|
|
|
.Lnorelocate:
|
2008-03-30 19:46:13 +00:00
|
|
|
/* Initialize BSS section ... we know that memset() does not
|
|
|
|
* use the BSS, so it is safe to call here. The bootrom LDR
|
|
|
|
* takes care of clearing things for us.
|
|
|
|
*/
|
|
|
|
serial_early_puts("Zero BSS");
|
2014-07-17 11:00:29 +00:00
|
|
|
r0.l = __bss_start;
|
|
|
|
r0.h = __bss_start;
|
2008-03-30 19:46:13 +00:00
|
|
|
r1 = 0 (x);
|
2009-11-03 11:11:31 +00:00
|
|
|
r2.l = __bss_len;
|
|
|
|
r2.h = __bss_len;
|
2008-03-30 19:46:13 +00:00
|
|
|
call _memset;
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup the actual stack in external memory */
|
2008-10-12 01:23:41 +00:00
|
|
|
sp.h = HI(CONFIG_STACKBASE);
|
|
|
|
sp.l = LO(CONFIG_STACKBASE);
|
2008-03-30 19:46:13 +00:00
|
|
|
fp = sp;
|
|
|
|
|
|
|
|
/* Now lower ourselves from the highest interrupt level to
|
|
|
|
* the lowest. We do this by masking all interrupts but 15,
|
2008-06-01 05:23:48 +00:00
|
|
|
* setting the 15 handler to ".Lenable_nested", raising the 15
|
2008-03-30 19:46:13 +00:00
|
|
|
* interrupt, and then returning from the highest interrupt
|
|
|
|
* level to the dummy "jump" until the interrupt controller
|
2008-10-12 01:40:26 +00:00
|
|
|
* services the pending 15 interrupt. If executing out of
|
|
|
|
* flash, these steps also changes the code flow from flash
|
|
|
|
* to external memory.
|
2008-03-30 19:46:13 +00:00
|
|
|
*/
|
|
|
|
serial_early_puts("Lower to 15");
|
|
|
|
r0 = r7;
|
|
|
|
r1 = r6;
|
2008-06-01 05:23:48 +00:00
|
|
|
p1.l = .Lenable_nested;
|
|
|
|
p1.h = .Lenable_nested;
|
2010-12-24 19:46:12 +00:00
|
|
|
[p5 + (EVT15 - COREMMR_BASE)] = p1;
|
2008-10-12 01:19:39 +00:00
|
|
|
r7 = EVT_IVG15 (z);
|
|
|
|
sti r7;
|
2008-03-30 19:46:13 +00:00
|
|
|
raise 15;
|
2010-12-24 19:46:12 +00:00
|
|
|
p3.l = .LWAIT_HERE;
|
|
|
|
p3.h = .LWAIT_HERE;
|
|
|
|
reti = p3;
|
2008-03-30 19:46:13 +00:00
|
|
|
rti;
|
|
|
|
|
2008-06-01 05:23:48 +00:00
|
|
|
/* Enable nested interrupts before continuing with cpu init */
|
|
|
|
.Lenable_nested:
|
|
|
|
cli r7;
|
|
|
|
[--sp] = reti;
|
|
|
|
jump.l _cpu_init_f;
|
|
|
|
|
2008-03-30 19:46:13 +00:00
|
|
|
.LWAIT_HERE:
|
|
|
|
jump .LWAIT_HERE;
|
|
|
|
ENDPROC(_start)
|
|
|
|
|
|
|
|
LENTRY(_get_pc)
|
|
|
|
r0 = rets;
|
|
|
|
#if ANOMALY_05000371
|
|
|
|
NOP;
|
|
|
|
NOP;
|
|
|
|
NOP;
|
|
|
|
#endif
|
|
|
|
rts;
|
|
|
|
ENDPROC(_get_pc)
|
2014-07-17 11:00:29 +00:00
|
|
|
|
|
|
|
ENTRY(_relocate_code)
|
|
|
|
/* Fake relocate code. Setup the new stack only */
|
|
|
|
sp = r0;
|
|
|
|
fp = sp;
|
|
|
|
r0 = p3;
|
|
|
|
r1.h = 0x2000;
|
|
|
|
r1.l = 0x10;
|
|
|
|
jump.l _board_init_r
|
|
|
|
ENDPROC(_relocate_code)
|