]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_avr32/board.c
Merge with /home/mk/git/u-boot-generic_ohci#generic_ohci
[karo-tx-uboot.git] / lib_avr32 / board.c
1 /*
2  * Copyright (C) 2004-2006 Atmel Corporation
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
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.
11  *
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.
16  *
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,
20  * MA 02111-1307 USA
21  */
22 #include <common.h>
23 #include <command.h>
24 #include <malloc.h>
25 #include <devices.h>
26 #include <version.h>
27 #include <net.h>
28
29 #include <asm/initcalls.h>
30 #include <asm/sections.h>
31
32 #ifndef CONFIG_IDENT_STRING
33 #define CONFIG_IDENT_STRING ""
34 #endif
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 const char version_string[] =
39         U_BOOT_VERSION " (" __DATE__ " - " __TIME__ ") " CONFIG_IDENT_STRING;
40
41 unsigned long monitor_flash_len;
42
43 /*
44  * Begin and end of memory area for malloc(), and current "brk"
45  */
46 static unsigned long mem_malloc_start = 0;
47 static unsigned long mem_malloc_end = 0;
48 static unsigned long mem_malloc_brk = 0;
49
50 /* The malloc area is wherever the board wants it to be */
51 static void mem_malloc_init(void)
52 {
53         mem_malloc_start = CFG_MALLOC_START;
54         mem_malloc_end = CFG_MALLOC_END;
55         mem_malloc_brk = mem_malloc_start;
56
57         printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
58                mem_malloc_start, mem_malloc_end);
59
60         memset ((void *)mem_malloc_start, 0,
61                 mem_malloc_end - mem_malloc_start);
62 }
63
64 void *sbrk(ptrdiff_t increment)
65 {
66         unsigned long old = mem_malloc_brk;
67         unsigned long new = old + increment;
68
69         if ((new < mem_malloc_start) || (new > mem_malloc_end))
70                 return NULL;
71
72         mem_malloc_brk = new;
73         return ((void *)old);
74 }
75
76 static int init_baudrate(void)
77 {
78         char tmp[64];
79         int i;
80
81         i = getenv_r("baudrate", tmp, sizeof(tmp));
82         if (i > 0) {
83                 gd->baudrate = simple_strtoul(tmp, NULL, 10);
84         } else {
85                 gd->baudrate = CONFIG_BAUDRATE;
86         }
87         return 0;
88 }
89
90
91 static int display_banner (void)
92 {
93         printf ("\n\n%s\n\n", version_string);
94         printf ("U-Boot code: %p -> %p  data: %p -> %p\n",
95                 _text, _etext, _data, _end);
96         return 0;
97 }
98
99 void hang(void)
100 {
101         for (;;) ;
102 }
103
104 static int display_dram_config (void)
105 {
106         int i;
107
108         puts ("DRAM Configuration:\n");
109
110         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
111                 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
112                 print_size (gd->bd->bi_dram[i].size, "\n");
113         }
114
115         return 0;
116 }
117
118 static void display_flash_config (void)
119 {
120         puts ("Flash: ");
121         print_size(gd->bd->bi_flashsize, " ");
122         printf("at address 0x%08lx\n", gd->bd->bi_flashstart);
123 }
124
125 void start_u_boot (void)
126 {
127         gd_t gd_data;
128
129         /* Initialize the global data pointer */
130         memset(&gd_data, 0, sizeof(gd_data));
131         gd = &gd_data;
132
133         monitor_flash_len = _edata - _text;
134
135         /* Perform initialization sequence */
136         cpu_init();
137         timer_init();
138         env_init();
139         init_baudrate();
140         serial_init();
141         console_init_f();
142         display_banner();
143
144         board_init_memories();
145         mem_malloc_init();
146
147         gd->bd = malloc(sizeof(bd_t));
148         memset(gd->bd, 0, sizeof(bd_t));
149         gd->bd->bi_baudrate = gd->baudrate;
150         gd->bd->bi_dram[0].start = CFG_SDRAM_BASE;
151         gd->bd->bi_dram[0].size = gd->sdram_size;
152
153         board_init_info();
154         flash_init();
155
156         if (gd->bd->bi_flashsize)
157                 display_flash_config();
158         if (gd->bd->bi_dram[0].size)
159                 display_dram_config();
160
161         gd->bd->bi_boot_params = malloc(CFG_BOOTPARAMS_LEN);
162         if (!gd->bd->bi_boot_params)
163                 puts("WARNING: Cannot allocate space for boot parameters\n");
164
165         /* initialize environment */
166         env_relocate();
167
168         devices_init();
169         jumptable_init();
170         console_init_r();
171
172         for (;;) {
173                 main_loop();
174         }
175 }