2006-10-24 12:21:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004-2006 Atmel Corporation
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2006-10-24 12:21:16 +00:00
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
2009-05-16 10:14:54 +00:00
|
|
|
#include <stdio_dev.h>
|
2006-10-24 12:21:16 +00:00
|
|
|
#include <version.h>
|
|
|
|
#include <net.h>
|
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
#include <miiphy.h>
|
|
|
|
#endif
|
|
|
|
|
2006-10-24 12:21:16 +00:00
|
|
|
#include <asm/sections.h>
|
2010-08-12 06:52:54 +00:00
|
|
|
#include <asm/arch/mmu.h>
|
2011-10-21 12:49:25 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2006-10-24 12:21:16 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_IDENT_STRING
|
|
|
|
#define CONFIG_IDENT_STRING ""
|
|
|
|
#endif
|
|
|
|
|
2011-10-21 12:49:26 +00:00
|
|
|
#ifdef CONFIG_GENERIC_ATMEL_MCI
|
2011-10-21 12:49:25 +00:00
|
|
|
#include <mmc.h>
|
|
|
|
#endif
|
2006-10-24 12:21:16 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
unsigned long monitor_flash_len;
|
|
|
|
|
2015-02-06 22:06:43 +00:00
|
|
|
__weak void dram_init_banksize(void)
|
|
|
|
{
|
|
|
|
gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
|
|
|
|
gd->bd->bi_dram[0].size = gd->ram_size;
|
|
|
|
}
|
|
|
|
|
2008-08-31 16:24:24 +00:00
|
|
|
/* Weak aliases for optional board functions */
|
|
|
|
static int __do_nothing(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int board_postclk_init(void) __attribute__((weak, alias("__do_nothing")));
|
2008-08-31 16:46:35 +00:00
|
|
|
int board_early_init_r(void) __attribute__((weak, alias("__do_nothing")));
|
2008-08-31 16:24:24 +00:00
|
|
|
|
2006-10-24 12:21:16 +00:00
|
|
|
static int init_baudrate(void)
|
|
|
|
{
|
2011-10-13 14:43:07 +00:00
|
|
|
gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
|
2006-10-24 12:21:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int display_banner (void)
|
|
|
|
{
|
|
|
|
printf ("\n\n%s\n\n", version_string);
|
2010-06-14 10:14:00 +00:00
|
|
|
printf ("U-Boot code: %08lx -> %08lx data: %08lx -> %08lx\n",
|
|
|
|
(unsigned long)_text, (unsigned long)_etext,
|
2013-05-07 23:25:17 +00:00
|
|
|
(unsigned long)_data, (unsigned long)(&__bss_end));
|
2006-10-24 12:21:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int display_dram_config (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
puts ("DRAM Configuration:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
|
|
|
|
print_size (gd->bd->bi_dram[i].size, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_flash_config (void)
|
|
|
|
{
|
|
|
|
puts ("Flash: ");
|
|
|
|
print_size(gd->bd->bi_flashsize, " ");
|
|
|
|
printf("at address 0x%08lx\n", gd->bd->bi_flashstart);
|
|
|
|
}
|
|
|
|
|
2006-12-17 13:46:06 +00:00
|
|
|
void board_init_f(ulong board_type)
|
2006-10-24 12:21:16 +00:00
|
|
|
{
|
|
|
|
gd_t gd_data;
|
2006-11-20 14:53:10 +00:00
|
|
|
gd_t *new_gd;
|
|
|
|
bd_t *bd;
|
|
|
|
unsigned long *new_sp;
|
|
|
|
unsigned long monitor_len;
|
|
|
|
unsigned long monitor_addr;
|
|
|
|
unsigned long addr;
|
2006-10-24 12:21:16 +00:00
|
|
|
|
|
|
|
/* Initialize the global data pointer */
|
|
|
|
memset(&gd_data, 0, sizeof(gd_data));
|
|
|
|
gd = &gd_data;
|
|
|
|
|
|
|
|
/* Perform initialization sequence */
|
2006-11-19 17:06:53 +00:00
|
|
|
board_early_init_f();
|
2015-02-06 22:06:40 +00:00
|
|
|
arch_cpu_init();
|
2008-08-31 16:24:24 +00:00
|
|
|
board_postclk_init();
|
2006-10-24 12:21:16 +00:00
|
|
|
env_init();
|
|
|
|
init_baudrate();
|
|
|
|
serial_init();
|
|
|
|
console_init_f();
|
|
|
|
display_banner();
|
2015-02-06 22:06:43 +00:00
|
|
|
dram_init();
|
2006-10-24 12:21:16 +00:00
|
|
|
|
2006-11-20 14:53:10 +00:00
|
|
|
/* If we have no SDRAM, we can't go on */
|
2015-02-06 22:06:43 +00:00
|
|
|
if (gd->ram_size <= 0)
|
2006-11-20 14:53:10 +00:00
|
|
|
panic("No working SDRAM available\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we have DRAM mapped and working, we can
|
|
|
|
* relocate the code and continue running from DRAM.
|
|
|
|
*
|
|
|
|
* Reserve memory at end of RAM for (top down in that order):
|
|
|
|
* - u-boot image
|
|
|
|
* - heap for malloc()
|
|
|
|
* - board info struct
|
|
|
|
* - global data struct
|
|
|
|
* - stack
|
|
|
|
*/
|
2015-02-06 22:06:43 +00:00
|
|
|
addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
|
2013-05-07 23:25:17 +00:00
|
|
|
monitor_len = (char *)(&__bss_end) - _text;
|
2006-11-20 14:53:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve memory for u-boot code, data and bss.
|
|
|
|
* Round down to next 4 kB limit.
|
|
|
|
*/
|
|
|
|
addr -= monitor_len;
|
|
|
|
addr &= ~(4096UL - 1);
|
|
|
|
monitor_addr = addr;
|
|
|
|
|
|
|
|
/* Reserve memory for malloc() */
|
2008-10-16 13:01:15 +00:00
|
|
|
addr -= CONFIG_SYS_MALLOC_LEN;
|
2006-11-20 14:53:10 +00:00
|
|
|
|
2009-07-21 10:11:37 +00:00
|
|
|
#ifdef CONFIG_LCD
|
|
|
|
#ifdef CONFIG_FB_ADDR
|
2009-07-26 08:34:58 +00:00
|
|
|
printf("LCD: Frame buffer allocated at preset 0x%08x\n",
|
|
|
|
CONFIG_FB_ADDR);
|
2013-03-05 14:40:01 +00:00
|
|
|
gd->fb_base = CONFIG_FB_ADDR;
|
2009-07-21 10:11:37 +00:00
|
|
|
#else
|
|
|
|
addr = lcd_setmem(addr);
|
|
|
|
printf("LCD: Frame buffer allocated at 0x%08lx\n", addr);
|
2013-03-05 14:40:01 +00:00
|
|
|
gd->fb_base = addr;
|
2009-07-21 10:11:37 +00:00
|
|
|
#endif /* CONFIG_FB_ADDR */
|
|
|
|
#endif /* CONFIG_LCD */
|
|
|
|
|
2006-11-20 14:53:10 +00:00
|
|
|
/* Allocate a Board Info struct on a word boundary */
|
|
|
|
addr -= sizeof(bd_t);
|
|
|
|
addr &= ~3UL;
|
|
|
|
gd->bd = bd = (bd_t *)addr;
|
|
|
|
|
|
|
|
/* Allocate a new global data copy on a 8-byte boundary. */
|
|
|
|
addr -= sizeof(gd_t);
|
|
|
|
addr &= ~7UL;
|
|
|
|
new_gd = (gd_t *)addr;
|
|
|
|
|
|
|
|
/* And finally, a new, bigger stack. */
|
|
|
|
new_sp = (unsigned long *)addr;
|
2015-02-06 22:06:44 +00:00
|
|
|
gd->start_addr_sp = addr;
|
2006-11-20 14:53:10 +00:00
|
|
|
*(--new_sp) = 0;
|
|
|
|
*(--new_sp) = 0;
|
|
|
|
|
2015-02-06 22:06:43 +00:00
|
|
|
dram_init_banksize();
|
2006-11-20 14:53:10 +00:00
|
|
|
|
|
|
|
memcpy(new_gd, gd, sizeof(gd_t));
|
|
|
|
|
|
|
|
relocate_code((unsigned long)new_sp, new_gd, monitor_addr);
|
2006-11-18 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void board_init_r(gd_t *new_gd, ulong dest_addr)
|
|
|
|
{
|
2008-09-10 20:48:00 +00:00
|
|
|
#ifndef CONFIG_ENV_IS_NOWHERE
|
2006-11-20 14:53:10 +00:00
|
|
|
extern char * env_name_spec;
|
|
|
|
#endif
|
|
|
|
bd_t *bd;
|
|
|
|
|
2006-11-18 16:15:30 +00:00
|
|
|
gd = new_gd;
|
2006-11-20 14:53:10 +00:00
|
|
|
bd = gd->bd;
|
|
|
|
|
|
|
|
gd->flags |= GD_FLG_RELOC;
|
2008-10-16 13:01:15 +00:00
|
|
|
gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
|
2006-11-18 16:15:30 +00:00
|
|
|
|
2010-08-12 06:52:54 +00:00
|
|
|
/* Enable the MMU so that we can keep u-boot simple */
|
|
|
|
mmu_init_r(dest_addr);
|
|
|
|
|
2008-08-31 16:46:35 +00:00
|
|
|
board_early_init_r();
|
|
|
|
|
2006-11-18 16:15:30 +00:00
|
|
|
monitor_flash_len = _edata - _text;
|
|
|
|
|
2010-10-28 18:00:11 +00:00
|
|
|
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
|
2006-11-20 14:53:10 +00:00
|
|
|
/*
|
|
|
|
* We have to relocate the command table manually
|
|
|
|
*/
|
2012-10-12 10:27:04 +00:00
|
|
|
fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
|
|
|
|
ll_entry_count(cmd_tbl_t, cmd));
|
2010-10-28 18:00:11 +00:00
|
|
|
#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
|
2006-11-20 14:53:10 +00:00
|
|
|
|
|
|
|
/* there are some other pointer constants we must deal with */
|
2008-09-10 20:48:00 +00:00
|
|
|
#ifndef CONFIG_ENV_IS_NOWHERE
|
2006-11-20 14:53:10 +00:00
|
|
|
env_name_spec += gd->reloc_off;
|
|
|
|
#endif
|
2006-10-24 12:21:16 +00:00
|
|
|
|
2006-11-20 14:53:10 +00:00
|
|
|
timer_init();
|
2009-08-22 04:05:21 +00:00
|
|
|
|
|
|
|
/* The malloc area is right below the monitor image in RAM */
|
2009-08-22 04:05:20 +00:00
|
|
|
mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
|
|
|
|
CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
|
2007-10-06 16:55:35 +00:00
|
|
|
|
2007-12-14 15:51:22 +00:00
|
|
|
enable_interrupts();
|
|
|
|
|
2007-10-06 16:55:35 +00:00
|
|
|
bd->bi_flashstart = 0;
|
|
|
|
bd->bi_flashsize = 0;
|
|
|
|
bd->bi_flashoffset = 0;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
|
|
|
bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
|
2007-10-06 16:55:35 +00:00
|
|
|
bd->bi_flashsize = flash_init();
|
|
|
|
bd->bi_flashoffset = (unsigned long)_edata - (unsigned long)_text;
|
2006-10-24 12:21:16 +00:00
|
|
|
|
2006-11-20 14:53:10 +00:00
|
|
|
if (bd->bi_flashsize)
|
2006-10-24 12:21:16 +00:00
|
|
|
display_flash_config();
|
2007-10-06 16:55:35 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-20 14:53:10 +00:00
|
|
|
if (bd->bi_dram[0].size)
|
2006-10-24 12:21:16 +00:00
|
|
|
display_dram_config();
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
gd->bd->bi_boot_params = malloc(CONFIG_SYS_BOOTPARAMS_LEN);
|
2006-10-24 12:21:16 +00:00
|
|
|
if (!gd->bd->bi_boot_params)
|
|
|
|
puts("WARNING: Cannot allocate space for boot parameters\n");
|
|
|
|
|
|
|
|
/* initialize environment */
|
|
|
|
env_relocate();
|
|
|
|
|
2009-05-16 10:14:54 +00:00
|
|
|
stdio_init();
|
2006-10-24 12:21:16 +00:00
|
|
|
jumptable_init();
|
|
|
|
console_init_r();
|
|
|
|
|
2011-10-13 14:43:07 +00:00
|
|
|
/* Initialize from environment */
|
|
|
|
load_addr = getenv_ulong("loadaddr", 16, load_addr);
|
2007-11-24 17:15:31 +00:00
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
bb_miiphy_init();
|
|
|
|
#endif
|
2007-07-09 23:05:38 +00:00
|
|
|
#if defined(CONFIG_CMD_NET)
|
2006-12-17 16:14:30 +00:00
|
|
|
puts("Net: ");
|
2015-03-22 22:09:06 +00:00
|
|
|
eth_initialize();
|
2006-12-17 16:14:30 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-21 12:49:25 +00:00
|
|
|
#ifdef CONFIG_GENERIC_ATMEL_MCI
|
|
|
|
mmc_initialize(gd->bd);
|
|
|
|
#endif
|
2006-10-24 12:21:16 +00:00
|
|
|
for (;;) {
|
|
|
|
main_loop();
|
|
|
|
}
|
|
|
|
}
|