2004-04-18 21:13:41 +00:00
|
|
|
/*
|
2007-03-11 12:48:24 +00:00
|
|
|
* (C) Copyright 2007 Michal Simek
|
2004-04-18 21:13:41 +00:00
|
|
|
* (C) Copyright 2004 Atmark Techno, Inc.
|
|
|
|
*
|
2007-03-11 12:48:24 +00:00
|
|
|
* Michal SIMEK <monstr@monstr.eu>
|
2004-04-18 21:13:41 +00:00
|
|
|
* Yasushi SHOJI <yashi@atmark-techno.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-03-11 12:48:24 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-18 21:13:41 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
2008-11-03 15:30:59 +00:00
|
|
|
#include <timestamp.h>
|
2004-04-18 21:13:41 +00:00
|
|
|
#include <version.h>
|
2004-04-18 21:45:42 +00:00
|
|
|
#include <watchdog.h>
|
2004-04-18 21:13:41 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2008-11-03 15:30:59 +00:00
|
|
|
const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
|
2007-03-11 12:48:24 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_GPIO_0
|
2007-03-11 12:48:24 +00:00
|
|
|
extern int gpio_init (void);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_INTC_0
|
2007-03-11 12:48:24 +00:00
|
|
|
extern int interrupts_init (void);
|
|
|
|
#endif
|
2007-07-09 23:02:11 +00:00
|
|
|
#if defined(CONFIG_CMD_NET)
|
2007-03-11 12:48:24 +00:00
|
|
|
extern int eth_init (bd_t * bis);
|
|
|
|
extern int getenv_IPaddr (char *);
|
|
|
|
#endif
|
2004-04-18 21:13:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Begin and End of memory area for malloc(), and current "brk"
|
|
|
|
*/
|
|
|
|
static ulong mem_malloc_start;
|
|
|
|
static ulong mem_malloc_end;
|
|
|
|
static ulong mem_malloc_brk;
|
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
/*
|
|
|
|
* The Malloc area is immediately below the monitor copy in DRAM
|
2008-10-16 13:01:15 +00:00
|
|
|
* aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
|
2007-03-11 12:48:24 +00:00
|
|
|
* as our monitory code is run from SDRAM
|
|
|
|
*/
|
|
|
|
static void mem_malloc_init (void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
mem_malloc_end = (CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
|
|
|
|
mem_malloc_start = CONFIG_SYS_MALLOC_BASE;
|
2007-03-11 12:48:24 +00:00
|
|
|
mem_malloc_brk = mem_malloc_start;
|
|
|
|
memset ((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
|
|
|
|
}
|
2004-04-18 21:13:41 +00:00
|
|
|
|
|
|
|
void *sbrk (ptrdiff_t increment)
|
|
|
|
{
|
|
|
|
ulong old = mem_malloc_brk;
|
|
|
|
ulong new = old + increment;
|
|
|
|
|
|
|
|
if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
mem_malloc_brk = new;
|
2007-03-11 12:48:24 +00:00
|
|
|
return ((void *)old);
|
2004-04-18 21:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*/
|
|
|
|
typedef int (init_fnc_t) (void);
|
|
|
|
|
|
|
|
init_fnc_t *init_sequence[] = {
|
2007-03-11 12:48:24 +00:00
|
|
|
env_init,
|
|
|
|
serial_init,
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_GPIO_0
|
2007-03-11 12:48:24 +00:00
|
|
|
gpio_init,
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_INTC_0
|
2007-03-11 12:48:24 +00:00
|
|
|
interrupts_init,
|
|
|
|
#endif
|
2004-04-18 21:13:41 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
void board_init (void)
|
2004-04-18 21:45:42 +00:00
|
|
|
{
|
2004-07-10 23:48:41 +00:00
|
|
|
bd_t *bd;
|
2004-04-18 21:45:42 +00:00
|
|
|
init_fnc_t **init_fnc_ptr;
|
2008-10-16 13:01:15 +00:00
|
|
|
gd = (gd_t *) CONFIG_SYS_GBL_DATA_OFFSET;
|
2007-07-09 23:02:11 +00:00
|
|
|
#if defined(CONFIG_CMD_FLASH)
|
2007-03-11 12:48:24 +00:00
|
|
|
ulong flash_size = 0;
|
|
|
|
#endif
|
|
|
|
asm ("nop"); /* FIXME gd is not initialize - wait */
|
2008-10-16 13:01:15 +00:00
|
|
|
memset ((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
|
2007-03-11 12:48:24 +00:00
|
|
|
gd->bd = (bd_t *) (gd + 1); /* At end of global data */
|
2004-07-10 23:48:41 +00:00
|
|
|
gd->baudrate = CONFIG_BAUDRATE;
|
|
|
|
bd = gd->bd;
|
|
|
|
bd->bi_baudrate = CONFIG_BAUDRATE;
|
2008-10-16 13:01:15 +00:00
|
|
|
bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
|
|
|
|
bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
|
2007-03-11 12:48:24 +00:00
|
|
|
|
|
|
|
/* Initialise malloc() area */
|
|
|
|
mem_malloc_init ();
|
2004-07-10 23:48:41 +00:00
|
|
|
|
2004-04-18 21:45:42 +00:00
|
|
|
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
|
|
|
|
WATCHDOG_RESET ();
|
|
|
|
if ((*init_fnc_ptr) () != 0) {
|
|
|
|
hang ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-09 23:02:11 +00:00
|
|
|
#if defined(CONFIG_CMD_FLASH)
|
2008-10-16 13:01:15 +00:00
|
|
|
bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
|
2007-03-11 12:48:24 +00:00
|
|
|
if (0 < (flash_size = flash_init ())) {
|
|
|
|
bd->bi_flashsize = flash_size;
|
2008-10-16 13:01:15 +00:00
|
|
|
bd->bi_flashoffset = CONFIG_SYS_FLASH_BASE + flash_size;
|
2007-03-11 12:48:24 +00:00
|
|
|
} else {
|
|
|
|
puts ("Flash init FAILED");
|
|
|
|
bd->bi_flashstart = 0;
|
|
|
|
bd->bi_flashsize = 0;
|
|
|
|
bd->bi_flashoffset = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-09 23:02:11 +00:00
|
|
|
#if defined(CONFIG_CMD_NET)
|
2007-03-11 12:48:24 +00:00
|
|
|
char *s, *e;
|
|
|
|
int i;
|
|
|
|
/* board MAC address */
|
|
|
|
s = getenv ("ethaddr");
|
|
|
|
for (i = 0; i < 6; ++i) {
|
|
|
|
bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
|
|
|
|
if (s)
|
|
|
|
s = (*e) ? e + 1 : e;
|
|
|
|
}
|
|
|
|
/* IP Address */
|
|
|
|
bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
|
|
|
|
eth_init (bd);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* relocate environment function pointers etc. */
|
|
|
|
env_relocate ();
|
|
|
|
|
2004-04-18 21:45:42 +00:00
|
|
|
/* main_loop */
|
|
|
|
for (;;) {
|
|
|
|
WATCHDOG_RESET ();
|
|
|
|
main_loop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-18 21:13:41 +00:00
|
|
|
void hang (void)
|
|
|
|
{
|
|
|
|
puts ("### ERROR ### Please RESET the board ###\n");
|
2007-03-11 12:48:24 +00:00
|
|
|
for (;;) ;
|
2004-04-18 21:13:41 +00:00
|
|
|
}
|