2 * Copyright (C) 2004-2006 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/initcalls.h>
30 #include <asm/sections.h>
32 #ifndef CONFIG_IDENT_STRING
33 #define CONFIG_IDENT_STRING ""
36 DECLARE_GLOBAL_DATA_PTR;
38 const char version_string[] =
39 U_BOOT_VERSION " (" __DATE__ " - " __TIME__ ") " CONFIG_IDENT_STRING;
41 unsigned long monitor_flash_len;
44 * Begin and end of memory area for malloc(), and current "brk"
46 static unsigned long mem_malloc_start = 0;
47 static unsigned long mem_malloc_end = 0;
48 static unsigned long mem_malloc_brk = 0;
50 /* The malloc area is right below the monitor image in RAM */
51 static void mem_malloc_init(void)
53 unsigned long monitor_addr;
55 monitor_addr = CFG_MONITOR_BASE + gd->reloc_off;
56 mem_malloc_end = monitor_addr;
57 mem_malloc_start = mem_malloc_end - CFG_MALLOC_LEN;
58 mem_malloc_brk = mem_malloc_start;
60 printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
61 mem_malloc_start, mem_malloc_end);
63 memset ((void *)mem_malloc_start, 0,
64 mem_malloc_end - mem_malloc_start);
67 void *sbrk(ptrdiff_t increment)
69 unsigned long old = mem_malloc_brk;
70 unsigned long new = old + increment;
72 if ((new < mem_malloc_start) || (new > mem_malloc_end))
79 static int init_baudrate(void)
84 i = getenv_r("baudrate", tmp, sizeof(tmp));
86 gd->baudrate = simple_strtoul(tmp, NULL, 10);
88 gd->baudrate = CONFIG_BAUDRATE;
94 static int display_banner (void)
96 printf ("\n\n%s\n\n", version_string);
97 printf ("U-Boot code: %p -> %p data: %p -> %p\n",
98 _text, _etext, _data, _end);
107 static int display_dram_config (void)
111 puts ("DRAM Configuration:\n");
113 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
114 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
115 print_size (gd->bd->bi_dram[i].size, "\n");
121 static void display_flash_config (void)
124 print_size(gd->bd->bi_flashsize, " ");
125 printf("at address 0x%08lx\n", gd->bd->bi_flashstart);
128 void board_init_f(ulong board_type)
133 unsigned long *new_sp;
134 unsigned long monitor_len;
135 unsigned long monitor_addr;
139 /* Initialize the global data pointer */
140 memset(&gd_data, 0, sizeof(gd_data));
143 /* Perform initialization sequence */
144 board_early_init_f();
151 sdram_size = initdram(board_type);
153 /* If we have no SDRAM, we can't go on */
155 panic("No working SDRAM available\n");
158 * Now that we have DRAM mapped and working, we can
159 * relocate the code and continue running from DRAM.
161 * Reserve memory at end of RAM for (top down in that order):
163 * - heap for malloc()
164 * - board info struct
165 * - global data struct
168 addr = CFG_SDRAM_BASE + sdram_size;
169 monitor_len = _end - _text;
172 * Reserve memory for u-boot code, data and bss.
173 * Round down to next 4 kB limit.
176 addr &= ~(4096UL - 1);
179 /* Reserve memory for malloc() */
180 addr -= CFG_MALLOC_LEN;
182 /* Allocate a Board Info struct on a word boundary */
183 addr -= sizeof(bd_t);
185 gd->bd = bd = (bd_t *)addr;
187 /* Allocate a new global data copy on a 8-byte boundary. */
188 addr -= sizeof(gd_t);
190 new_gd = (gd_t *)addr;
192 /* And finally, a new, bigger stack. */
193 new_sp = (unsigned long *)addr;
194 gd->stack_end = addr;
199 * Initialize the board information struct with the
200 * information we have.
202 bd->bi_dram[0].start = CFG_SDRAM_BASE;
203 bd->bi_dram[0].size = sdram_size;
204 bd->bi_baudrate = gd->baudrate;
206 memcpy(new_gd, gd, sizeof(gd_t));
208 relocate_code((unsigned long)new_sp, new_gd, monitor_addr);
211 void board_init_r(gd_t *new_gd, ulong dest_addr)
213 extern void malloc_bin_reloc (void);
214 #ifndef CFG_ENV_IS_NOWHERE
215 extern char * env_name_spec;
223 gd->flags |= GD_FLG_RELOC;
224 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
226 monitor_flash_len = _edata - _text;
229 * We have to relocate the command table manually
231 for (cmdtp = &__u_boot_cmd_start;
232 cmdtp != &__u_boot_cmd_end; cmdtp++) {
235 addr = (unsigned long)cmdtp->cmd + gd->reloc_off;
236 cmdtp->cmd = (typeof(cmdtp->cmd))addr;
238 addr = (unsigned long)cmdtp->name + gd->reloc_off;
239 cmdtp->name = (typeof(cmdtp->name))addr;
242 addr = (unsigned long)cmdtp->usage + gd->reloc_off;
243 cmdtp->usage = (typeof(cmdtp->usage))addr;
247 addr = (unsigned long)cmdtp->help + gd->reloc_off;
248 cmdtp->help = (typeof(cmdtp->help))addr;
253 /* there are some other pointer constants we must deal with */
254 #ifndef CFG_ENV_IS_NOWHERE
255 env_name_spec += gd->reloc_off;
264 if (bd->bi_flashsize)
265 display_flash_config();
266 if (bd->bi_dram[0].size)
267 display_dram_config();
269 gd->bd->bi_boot_params = malloc(CFG_BOOTPARAMS_LEN);
270 if (!gd->bd->bi_boot_params)
271 puts("WARNING: Cannot allocate space for boot parameters\n");
273 /* initialize environment */