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 unused)
133 unsigned long *new_sp;
134 unsigned long monitor_len;
135 unsigned long monitor_addr;
138 /* Initialize the global data pointer */
139 memset(&gd_data, 0, sizeof(gd_data));
142 /* Perform initialization sequence */
143 board_early_init_f();
150 board_init_memories();
152 /* If we have no SDRAM, we can't go on */
154 panic("No working SDRAM available\n");
157 * Now that we have DRAM mapped and working, we can
158 * relocate the code and continue running from DRAM.
160 * Reserve memory at end of RAM for (top down in that order):
162 * - heap for malloc()
163 * - board info struct
164 * - global data struct
167 addr = CFG_SDRAM_BASE + gd->sdram_size;
168 monitor_len = _end - _text;
171 * Reserve memory for u-boot code, data and bss.
172 * Round down to next 4 kB limit.
175 addr &= ~(4096UL - 1);
178 /* Reserve memory for malloc() */
179 addr -= CFG_MALLOC_LEN;
181 /* Allocate a Board Info struct on a word boundary */
182 addr -= sizeof(bd_t);
184 gd->bd = bd = (bd_t *)addr;
186 /* Allocate a new global data copy on a 8-byte boundary. */
187 addr -= sizeof(gd_t);
189 new_gd = (gd_t *)addr;
191 /* And finally, a new, bigger stack. */
192 new_sp = (unsigned long *)addr;
193 gd->stack_end = addr;
198 * Initialize the board information struct with the
199 * information we have.
201 bd->bi_dram[0].start = CFG_SDRAM_BASE;
202 bd->bi_dram[0].size = gd->sdram_size;
203 bd->bi_baudrate = gd->baudrate;
205 memcpy(new_gd, gd, sizeof(gd_t));
207 relocate_code((unsigned long)new_sp, new_gd, monitor_addr);
210 void board_init_r(gd_t *new_gd, ulong dest_addr)
212 extern void malloc_bin_reloc (void);
213 #ifndef CFG_ENV_IS_NOWHERE
214 extern char * env_name_spec;
222 gd->flags |= GD_FLG_RELOC;
223 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
225 monitor_flash_len = _edata - _text;
228 * We have to relocate the command table manually
230 for (cmdtp = &__u_boot_cmd_start;
231 cmdtp != &__u_boot_cmd_end; cmdtp++) {
234 addr = (unsigned long)cmdtp->cmd + gd->reloc_off;
235 cmdtp->cmd = (typeof(cmdtp->cmd))addr;
237 addr = (unsigned long)cmdtp->name + gd->reloc_off;
238 cmdtp->name = (typeof(cmdtp->name))addr;
241 addr = (unsigned long)cmdtp->usage + gd->reloc_off;
242 cmdtp->usage = (typeof(cmdtp->usage))addr;
246 addr = (unsigned long)cmdtp->help + gd->reloc_off;
247 cmdtp->help = (typeof(cmdtp->help))addr;
252 /* there are some other pointer constants we must deal with */
253 #ifndef CFG_ENV_IS_NOWHERE
254 env_name_spec += gd->reloc_off;
263 if (bd->bi_flashsize)
264 display_flash_config();
265 if (bd->bi_dram[0].size)
266 display_dram_config();
268 gd->bd->bi_boot_params = malloc(CFG_BOOTPARAMS_LEN);
269 if (!gd->bd->bi_boot_params)
270 puts("WARNING: Cannot allocate space for boot parameters\n");
272 /* initialize environment */