]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_avr32/board.c
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 /* Weak aliases for optional board functions */
51 static int __do_nothing(void)
55 int board_postclk_init(void) __attribute__((weak
, alias("__do_nothing")));
57 /* The malloc area is right below the monitor image in RAM */
58 static void mem_malloc_init(void)
60 unsigned long monitor_addr
;
62 monitor_addr
= CFG_MONITOR_BASE
+ gd
->reloc_off
;
63 mem_malloc_end
= monitor_addr
;
64 mem_malloc_start
= mem_malloc_end
- CFG_MALLOC_LEN
;
65 mem_malloc_brk
= mem_malloc_start
;
67 printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
68 mem_malloc_start
, mem_malloc_end
);
70 memset ((void *)mem_malloc_start
, 0,
71 mem_malloc_end
- mem_malloc_start
);
74 void *sbrk(ptrdiff_t increment
)
76 unsigned long old
= mem_malloc_brk
;
77 unsigned long new = old
+ increment
;
79 if ((new < mem_malloc_start
) || (new > mem_malloc_end
))
86 #ifdef CFG_DMA_ALLOC_LEN
87 #include <asm/cacheflush.h>
90 static unsigned long dma_alloc_start
;
91 static unsigned long dma_alloc_end
;
92 static unsigned long dma_alloc_brk
;
94 static void dma_alloc_init(void)
96 unsigned long monitor_addr
;
98 monitor_addr
= CFG_MONITOR_BASE
+ gd
->reloc_off
;
99 dma_alloc_end
= monitor_addr
- CFG_MALLOC_LEN
;
100 dma_alloc_start
= dma_alloc_end
- CFG_DMA_ALLOC_LEN
;
101 dma_alloc_brk
= dma_alloc_start
;
103 printf("DMA: Using memory from 0x%08lx to 0x%08lx\n",
104 dma_alloc_start
, dma_alloc_end
);
106 dcache_invalidate_range(cached(dma_alloc_start
),
107 dma_alloc_end
- dma_alloc_start
);
110 void *dma_alloc_coherent(size_t len
, unsigned long *handle
)
112 unsigned long paddr
= dma_alloc_brk
;
114 if (dma_alloc_brk
+ len
> dma_alloc_end
)
117 dma_alloc_brk
= ((paddr
+ len
+ CFG_DCACHE_LINESZ
- 1)
118 & ~(CFG_DCACHE_LINESZ
- 1));
121 return uncached(paddr
);
124 static inline void dma_alloc_init(void)
130 static int init_baudrate(void)
135 i
= getenv_r("baudrate", tmp
, sizeof(tmp
));
137 gd
->baudrate
= simple_strtoul(tmp
, NULL
, 10);
139 gd
->baudrate
= CONFIG_BAUDRATE
;
145 static int display_banner (void)
147 printf ("\n\n%s\n\n", version_string
);
148 printf ("U-Boot code: %p -> %p data: %p -> %p\n",
149 _text
, _etext
, _data
, _end
);
158 static int display_dram_config (void)
162 puts ("DRAM Configuration:\n");
164 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
165 printf ("Bank #%d: %08lx ", i
, gd
->bd
->bi_dram
[i
].start
);
166 print_size (gd
->bd
->bi_dram
[i
].size
, "\n");
172 static void display_flash_config (void)
175 print_size(gd
->bd
->bi_flashsize
, " ");
176 printf("at address 0x%08lx\n", gd
->bd
->bi_flashstart
);
179 void board_init_f(ulong board_type
)
184 unsigned long *new_sp
;
185 unsigned long monitor_len
;
186 unsigned long monitor_addr
;
190 /* Initialize the global data pointer */
191 memset(&gd_data
, 0, sizeof(gd_data
));
194 /* Perform initialization sequence */
195 board_early_init_f();
197 board_postclk_init();
203 sdram_size
= initdram(board_type
);
205 /* If we have no SDRAM, we can't go on */
207 panic("No working SDRAM available\n");
210 * Now that we have DRAM mapped and working, we can
211 * relocate the code and continue running from DRAM.
213 * Reserve memory at end of RAM for (top down in that order):
215 * - heap for malloc()
216 * - board info struct
217 * - global data struct
220 addr
= CFG_SDRAM_BASE
+ sdram_size
;
221 monitor_len
= _end
- _text
;
224 * Reserve memory for u-boot code, data and bss.
225 * Round down to next 4 kB limit.
228 addr
&= ~(4096UL - 1);
231 /* Reserve memory for malloc() */
232 addr
-= CFG_MALLOC_LEN
;
234 #ifdef CFG_DMA_ALLOC_LEN
235 /* Reserve DMA memory (must be cache aligned) */
236 addr
&= ~(CFG_DCACHE_LINESZ
- 1);
237 addr
-= CFG_DMA_ALLOC_LEN
;
240 /* Allocate a Board Info struct on a word boundary */
241 addr
-= sizeof(bd_t
);
243 gd
->bd
= bd
= (bd_t
*)addr
;
245 /* Allocate a new global data copy on a 8-byte boundary. */
246 addr
-= sizeof(gd_t
);
248 new_gd
= (gd_t
*)addr
;
250 /* And finally, a new, bigger stack. */
251 new_sp
= (unsigned long *)addr
;
252 gd
->stack_end
= addr
;
257 * Initialize the board information struct with the
258 * information we have.
260 bd
->bi_dram
[0].start
= CFG_SDRAM_BASE
;
261 bd
->bi_dram
[0].size
= sdram_size
;
262 bd
->bi_baudrate
= gd
->baudrate
;
264 memcpy(new_gd
, gd
, sizeof(gd_t
));
266 relocate_code((unsigned long)new_sp
, new_gd
, monitor_addr
);
269 void board_init_r(gd_t
*new_gd
, ulong dest_addr
)
271 extern void malloc_bin_reloc (void);
272 #ifndef CFG_ENV_IS_NOWHERE
273 extern char * env_name_spec
;
282 gd
->flags
|= GD_FLG_RELOC
;
283 gd
->reloc_off
= dest_addr
- CFG_MONITOR_BASE
;
285 monitor_flash_len
= _edata
- _text
;
288 * We have to relocate the command table manually
290 for (cmdtp
= &__u_boot_cmd_start
;
291 cmdtp
!= &__u_boot_cmd_end
; cmdtp
++) {
294 addr
= (unsigned long)cmdtp
->cmd
+ gd
->reloc_off
;
295 cmdtp
->cmd
= (typeof(cmdtp
->cmd
))addr
;
297 addr
= (unsigned long)cmdtp
->name
+ gd
->reloc_off
;
298 cmdtp
->name
= (typeof(cmdtp
->name
))addr
;
301 addr
= (unsigned long)cmdtp
->usage
+ gd
->reloc_off
;
302 cmdtp
->usage
= (typeof(cmdtp
->usage
))addr
;
306 addr
= (unsigned long)cmdtp
->help
+ gd
->reloc_off
;
307 cmdtp
->help
= (typeof(cmdtp
->help
))addr
;
312 /* there are some other pointer constants we must deal with */
313 #ifndef CFG_ENV_IS_NOWHERE
314 env_name_spec
+= gd
->reloc_off
;
325 bd
->bi_flashstart
= 0;
326 bd
->bi_flashsize
= 0;
327 bd
->bi_flashoffset
= 0;
330 bd
->bi_flashstart
= CFG_FLASH_BASE
;
331 bd
->bi_flashsize
= flash_init();
332 bd
->bi_flashoffset
= (unsigned long)_edata
- (unsigned long)_text
;
334 if (bd
->bi_flashsize
)
335 display_flash_config();
338 if (bd
->bi_dram
[0].size
)
339 display_dram_config();
341 gd
->bd
->bi_boot_params
= malloc(CFG_BOOTPARAMS_LEN
);
342 if (!gd
->bd
->bi_boot_params
)
343 puts("WARNING: Cannot allocate space for boot parameters\n");
345 /* initialize environment */
348 bd
->bi_ip_addr
= getenv_IPaddr ("ipaddr");
354 s
= getenv("loadaddr");
356 load_addr
= simple_strtoul(s
, NULL
, 16);
358 #if defined(CONFIG_CMD_NET)
359 s
= getenv("bootfile");
361 copy_filename(BootFile
, s
, sizeof(BootFile
));
362 #if defined(CONFIG_NET_MULTI)
365 eth_initialize(gd
->bd
);