2003-03-27 12:09:35 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2003-03-27 12:09:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
2012-12-11 17:52:50 +00:00
|
|
|
#include <serial.h>
|
2009-05-16 10:14:54 +00:00
|
|
|
#include <stdio_dev.h>
|
2003-03-27 12:09:35 +00:00
|
|
|
#include <version.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <environment.h>
|
2008-05-29 15:53:37 +00:00
|
|
|
#include <nand.h>
|
2008-11-12 12:18:19 +00:00
|
|
|
#include <onenand_uboot.h>
|
2008-05-29 15:53:37 +00:00
|
|
|
#include <spi.h>
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
#include <miiphy.h>
|
|
|
|
#endif
|
|
|
|
|
2005-12-01 01:15:07 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2003-05-30 12:48:29 +00:00
|
|
|
ulong monitor_flash_len;
|
|
|
|
|
2003-03-27 12:09:35 +00:00
|
|
|
static char *failed = "*** failed ***\n";
|
|
|
|
|
2008-11-12 12:18:02 +00:00
|
|
|
int __board_early_init_f(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Nothing to do in this dummy implementation
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-08 02:01:49 +00:00
|
|
|
int board_early_init_f(void)
|
|
|
|
__attribute__((weak, alias("__board_early_init_f")));
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
static int init_func_ram(void)
|
2003-03-27 12:09:35 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_BOARD_TYPES
|
|
|
|
int board_type = gd->board_type;
|
|
|
|
#else
|
|
|
|
int board_type = 0; /* use dummy arg */
|
|
|
|
#endif
|
2011-12-08 02:01:49 +00:00
|
|
|
puts("DRAM: ");
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
gd->ram_size = initdram(board_type);
|
|
|
|
if (gd->ram_size > 0) {
|
|
|
|
print_size(gd->ram_size, "\n");
|
|
|
|
return 0;
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
2011-12-08 02:01:49 +00:00
|
|
|
puts(failed);
|
|
|
|
return 1;
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int display_banner(void)
|
|
|
|
{
|
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
printf("\n\n%s\n\n", version_string);
|
|
|
|
return 0;
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
2003-03-27 12:09:35 +00:00
|
|
|
static void display_flash_config(ulong size)
|
|
|
|
{
|
2011-12-08 02:01:49 +00:00
|
|
|
puts("Flash: ");
|
|
|
|
print_size(size, "\n");
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
2008-02-17 15:58:04 +00:00
|
|
|
#endif
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
static int init_baudrate(void)
|
2003-03-27 12:09:35 +00:00
|
|
|
{
|
2011-10-13 14:43:11 +00:00
|
|
|
gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
|
|
|
|
return 0;
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Breath some life into the board...
|
|
|
|
*
|
|
|
|
* The first part of initialization is running from Flash memory;
|
|
|
|
* its main purpose is to initialize the RAM so that we
|
|
|
|
* can relocate the monitor code to RAM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All attempts to come up with a "common" initialization sequence
|
|
|
|
* that works for all boards and architectures failed: some of the
|
|
|
|
* requirements are just _too_ different. To get rid of the resulting
|
|
|
|
* mess of board dependend #ifdef'ed code we now make the whole
|
|
|
|
* initialization sequence configurable to the user.
|
|
|
|
*
|
|
|
|
* The requirements for any new initalization function is simple: it
|
|
|
|
* receives a pointer to the "global data" structure as it's only
|
|
|
|
* argument, and returns an integer return code, where 0 means
|
|
|
|
* "continue" and != 0 means "fatal error, hang the system".
|
|
|
|
*/
|
2011-12-08 02:01:49 +00:00
|
|
|
typedef int (init_fnc_t)(void);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
init_fnc_t *init_sequence[] = {
|
2008-11-12 12:18:02 +00:00
|
|
|
board_early_init_f,
|
2003-03-27 12:09:35 +00:00
|
|
|
timer_init,
|
|
|
|
env_init, /* initialize environment */
|
2011-12-08 02:01:49 +00:00
|
|
|
init_baudrate, /* initialize baudrate settings */
|
2003-03-27 12:09:35 +00:00
|
|
|
serial_init, /* serial communications setup */
|
|
|
|
console_init_f,
|
|
|
|
display_banner, /* say that we are here */
|
2003-03-31 16:34:49 +00:00
|
|
|
checkboard,
|
2003-03-27 12:09:35 +00:00
|
|
|
init_func_ram,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void board_init_f(ulong bootflag)
|
|
|
|
{
|
|
|
|
gd_t gd_data, *id;
|
|
|
|
bd_t *bd;
|
|
|
|
init_fnc_t **init_fnc_ptr;
|
2013-02-12 21:22:12 +00:00
|
|
|
ulong addr, addr_sp, len;
|
2005-12-01 01:15:07 +00:00
|
|
|
ulong *s;
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2004-05-29 16:53:29 +00:00
|
|
|
/* Pointer is writable since we allocated a register for it.
|
|
|
|
*/
|
2003-03-27 12:09:35 +00:00
|
|
|
gd = &gd_data;
|
2004-07-01 20:28:03 +00:00
|
|
|
/* compiler optimization barrier needed for GCC >= 3.4 */
|
2011-12-08 02:01:49 +00:00
|
|
|
__asm__ __volatile__("" : : : "memory");
|
2004-07-01 20:28:03 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
memset((void *)gd, 0, sizeof(gd_t));
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
|
2011-12-08 02:01:49 +00:00
|
|
|
if ((*init_fnc_ptr)() != 0)
|
|
|
|
hang();
|
2003-03-27 12:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we have DRAM mapped and working, we can
|
|
|
|
* relocate the code and continue running from DRAM.
|
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2004-05-29 16:53:29 +00:00
|
|
|
/* We can reserve some RAM "on top" here.
|
|
|
|
*/
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2004-05-29 16:53:29 +00:00
|
|
|
/* round down to next 4 kB limit.
|
|
|
|
*/
|
2003-03-27 12:09:35 +00:00
|
|
|
addr &= ~(4096 - 1);
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2004-05-29 16:53:29 +00:00
|
|
|
/* Reserve memory for U-Boot code, data & bss
|
|
|
|
* round down to next 16 kB limit
|
|
|
|
*/
|
2013-02-12 21:22:12 +00:00
|
|
|
len = bss_end() - CONFIG_SYS_MONITOR_BASE;
|
2003-03-27 12:09:35 +00:00
|
|
|
addr -= len;
|
2003-05-30 12:48:29 +00:00
|
|
|
addr &= ~(16 * 1024 - 1);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2004-05-29 16:53:29 +00:00
|
|
|
/* Reserve memory for malloc() arena.
|
|
|
|
*/
|
2003-03-27 12:09:35 +00:00
|
|
|
addr_sp = addr - TOTAL_MALLOC_LEN;
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Reserving %dk for malloc() at: %08lx\n",
|
2003-03-27 12:09:35 +00:00
|
|
|
TOTAL_MALLOC_LEN >> 10, addr_sp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (permanently) allocate a Board Info struct
|
|
|
|
* and a permanent copy of the "global" data
|
|
|
|
*/
|
|
|
|
addr_sp -= sizeof(bd_t);
|
|
|
|
bd = (bd_t *)addr_sp;
|
|
|
|
gd->bd = bd;
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Reserving %zu Bytes for Board Info at: %08lx\n",
|
2003-03-27 12:09:35 +00:00
|
|
|
sizeof(bd_t), addr_sp);
|
2004-05-29 16:53:29 +00:00
|
|
|
|
2003-03-27 12:09:35 +00:00
|
|
|
addr_sp -= sizeof(gd_t);
|
|
|
|
id = (gd_t *)addr_sp;
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Reserving %zu Bytes for Global Data at: %08lx\n",
|
|
|
|
sizeof(gd_t), addr_sp);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2008-02-17 15:58:04 +00:00
|
|
|
/* Reserve memory for boot params.
|
2004-05-29 16:53:29 +00:00
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
|
2003-03-27 12:09:35 +00:00
|
|
|
bd->bi_boot_params = addr_sp;
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Reserving %dk for boot params() at: %08lx\n",
|
2008-10-16 13:01:15 +00:00
|
|
|
CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, we set up a new (bigger) stack.
|
|
|
|
*
|
|
|
|
* Leave some safety gap for SP, force alignment on 16 byte boundary
|
|
|
|
* Clear initial stack frame
|
|
|
|
*/
|
|
|
|
addr_sp -= 16;
|
|
|
|
addr_sp &= ~0xF;
|
2005-12-01 01:15:07 +00:00
|
|
|
s = (ulong *)addr_sp;
|
|
|
|
*s-- = 0;
|
|
|
|
*s-- = 0;
|
|
|
|
addr_sp = (ulong)s;
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Stack Pointer at: %08lx\n", addr_sp);
|
2004-05-29 16:53:29 +00:00
|
|
|
|
2003-03-27 12:09:35 +00:00
|
|
|
/*
|
|
|
|
* Save local variables to board info struct
|
|
|
|
*/
|
2011-12-08 02:01:49 +00:00
|
|
|
bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM */
|
|
|
|
bd->bi_memsize = gd->ram_size; /* size of DRAM in bytes */
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
memcpy(id, (void *)gd, sizeof(gd_t));
|
2003-04-05 00:53:31 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
relocate_code(addr_sp, id, addr);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
/* NOTREACHED - relocate_code() does not return */
|
|
|
|
}
|
2011-12-08 02:01:49 +00:00
|
|
|
|
|
|
|
/*
|
2003-03-27 12:09:35 +00:00
|
|
|
* This is the next part if the initialization sequence: we are now
|
|
|
|
* running from RAM and have a "normal" C environment, i. e. global
|
|
|
|
* data can be written, BSS has been cleared, the stack size in not
|
|
|
|
* that critical any more, etc.
|
|
|
|
*/
|
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
void board_init_r(gd_t *id, ulong dest_addr)
|
2003-03-27 12:09:35 +00:00
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
2003-03-27 12:09:35 +00:00
|
|
|
ulong size;
|
|
|
|
#endif
|
|
|
|
bd_t *bd;
|
|
|
|
|
|
|
|
gd = id;
|
|
|
|
gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
|
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2013-02-12 21:22:12 +00:00
|
|
|
monitor_flash_len = image_copy_end() - dest_addr;
|
2003-05-30 12:48:29 +00:00
|
|
|
|
2012-12-11 17:52:50 +00:00
|
|
|
serial_initialize();
|
|
|
|
|
2008-02-17 15:58:04 +00:00
|
|
|
bd = gd->bd;
|
|
|
|
|
2009-08-22 04:05:21 +00:00
|
|
|
/* The Malloc area is immediately below the monitor copy in DRAM */
|
2009-08-22 04:05:20 +00:00
|
|
|
mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
|
|
|
|
TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
|
2009-05-11 13:50:12 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
2003-03-27 12:09:35 +00:00
|
|
|
/* configure available FLASH banks */
|
|
|
|
size = flash_init();
|
2011-12-08 02:01:49 +00:00
|
|
|
display_flash_config(size);
|
2012-04-02 02:57:54 +00:00
|
|
|
bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
|
2008-02-17 15:58:04 +00:00
|
|
|
bd->bi_flashsize = size;
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
|
2003-05-30 12:48:29 +00:00
|
|
|
bd->bi_flashoffset = monitor_flash_len; /* reserved area for U-Boot */
|
2003-03-27 12:09:35 +00:00
|
|
|
#else
|
|
|
|
bd->bi_flashoffset = 0;
|
|
|
|
#endif
|
2012-04-02 02:57:54 +00:00
|
|
|
#else
|
|
|
|
bd->bi_flashstart = 0;
|
|
|
|
bd->bi_flashsize = 0;
|
|
|
|
bd->bi_flashoffset = 0;
|
|
|
|
#endif
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2008-11-12 12:18:19 +00:00
|
|
|
#ifdef CONFIG_CMD_NAND
|
2011-12-08 02:01:49 +00:00
|
|
|
puts("NAND: ");
|
|
|
|
nand_init(); /* go init the NAND */
|
2008-11-12 12:18:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_ONENAND)
|
|
|
|
onenand_init();
|
|
|
|
#endif
|
|
|
|
|
2003-03-27 12:09:35 +00:00
|
|
|
/* relocate environment function pointers etc. */
|
|
|
|
env_relocate();
|
|
|
|
|
2004-02-07 01:27:10 +00:00
|
|
|
#if defined(CONFIG_PCI)
|
|
|
|
/*
|
|
|
|
* Do pci configuration
|
|
|
|
*/
|
|
|
|
pci_init();
|
|
|
|
#endif
|
|
|
|
|
2003-03-27 12:09:35 +00:00
|
|
|
/** leave this here (after malloc(), environment and PCI are working) **/
|
2009-05-16 10:14:54 +00:00
|
|
|
/* Initialize stdio devices */
|
2011-12-08 02:01:49 +00:00
|
|
|
stdio_init();
|
2003-03-27 12:09:35 +00:00
|
|
|
|
2011-12-08 02:01:49 +00:00
|
|
|
jumptable_init();
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
/* Initialize the console (after the relocation and devices init) */
|
2011-12-08 02:01:49 +00:00
|
|
|
console_init_r();
|
2003-03-27 12:09:35 +00:00
|
|
|
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
|
|
|
|
|
2003-04-05 00:53:31 +00:00
|
|
|
/* Initialize from environment */
|
2011-10-13 14:43:11 +00:00
|
|
|
load_addr = getenv_ulong("loadaddr", 16, load_addr);
|
2003-04-05 00:53:31 +00:00
|
|
|
|
2008-05-29 15:53:37 +00:00
|
|
|
#ifdef CONFIG_CMD_SPI
|
2011-12-08 02:01:49 +00:00
|
|
|
puts("SPI: ");
|
|
|
|
spi_init(); /* go init the SPI */
|
|
|
|
puts("ready\n");
|
2008-05-29 15:53:37 +00:00
|
|
|
#endif
|
|
|
|
|
2003-04-05 00:53:31 +00:00
|
|
|
#if defined(CONFIG_MISC_INIT_R)
|
|
|
|
/* miscellaneous platform dependent initialisations */
|
2011-12-08 02:01:49 +00:00
|
|
|
misc_init_r();
|
2003-04-05 00:53:31 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
bb_miiphy_init();
|
|
|
|
#endif
|
2007-07-09 23:02:11 +00:00
|
|
|
#if defined(CONFIG_CMD_NET)
|
2011-12-08 02:01:49 +00:00
|
|
|
puts("Net: ");
|
2003-03-27 12:09:35 +00:00
|
|
|
eth_initialize(gd->bd);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* main_loop() can return to retry autoboot, if so just run it again. */
|
2011-12-08 02:01:49 +00:00
|
|
|
for (;;)
|
|
|
|
main_loop();
|
2003-03-27 12:09:35 +00:00
|
|
|
|
|
|
|
/* NOTREACHED - no way out of command loop except booting */
|
|
|
|
}
|