]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_blackfin/board.c
Coding Style cleanup
[karo-tx-uboot.git] / lib_blackfin / board.c
1 /*
2  * U-boot - board.c First C file to be called contains init routines
3  *
4  * Copyright (c) 2005 blackfin.uclinux.org
5  *
6  * (C) Copyright 2000-2004
7  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <command.h>
30 #include <malloc.h>
31 #include <devices.h>
32 #include <version.h>
33 #include <net.h>
34 #include <environment.h>
35 #include "blackfin_board.h"
36 #include "../drivers/smc91111.h"
37
38 extern flash_info_t flash_info[];
39
40
41 static void mem_malloc_init(void)
42 {
43         mem_malloc_start = CFG_MALLOC_BASE;
44         mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
45         mem_malloc_brk = mem_malloc_start;
46         memset((void *) mem_malloc_start, 0,
47         mem_malloc_end - mem_malloc_start);
48 }
49
50 void *sbrk(ptrdiff_t increment)
51 {
52         ulong old = mem_malloc_brk;
53         ulong new = old + increment;
54
55         if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
56                 return (NULL);
57         }
58         mem_malloc_brk = new;
59
60         return ((void *) old);
61 }
62
63 static int display_banner(void)
64 {
65         sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
66         printf("%s\n", version_string);
67         return (0);
68 }
69
70 static void display_flash_config(ulong size)
71 {
72         puts("FLASH:  ");
73         print_size(size, "\n");
74         return;
75 }
76
77 static int init_baudrate(void)
78 {
79         DECLARE_GLOBAL_DATA_PTR;
80
81         uchar tmp[64];
82         int i = getenv_r("baudrate", tmp, sizeof(tmp));
83         gd->bd->bi_baudrate = gd->baudrate = (i > 0)
84                 ? (int) simple_strtoul(tmp, NULL, 10)
85                 : CONFIG_BAUDRATE;
86         return (0);
87 }
88
89 #ifdef DEBUG
90 static void display_global_data(void)
91 {
92         DECLARE_GLOBAL_DATA_PTR;
93         bd_t *bd;
94         bd = gd->bd;
95         printf("--flags:%x\n", gd->flags);
96         printf("--board_type:%x\n", gd->board_type);
97         printf("--baudrate:%x\n", gd->baudrate);
98         printf("--have_console:%x\n", gd->have_console);
99         printf("--ram_size:%x\n", gd->ram_size);
100         printf("--reloc_off:%x\n", gd->reloc_off);
101         printf("--env_addr:%x\n", gd->env_addr);
102         printf("--env_valid:%x\n", gd->env_valid);
103         printf("--bd:%x %x\n", gd->bd, bd);
104         printf("---bi_baudrate:%x\n", bd->bi_baudrate);
105         printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
106         printf("---bi_enetaddr:%x %x %x %x %x %x\n",
107                                 bd->bi_enetaddr[0],
108                                 bd->bi_enetaddr[1],
109                                 bd->bi_enetaddr[2],
110                                 bd->bi_enetaddr[3],
111                                 bd->bi_enetaddr[4],
112                                 bd->bi_enetaddr[5]);
113         printf("---bi_arch_number:%x\n", bd->bi_arch_number);
114         printf("---bi_boot_params:%x\n", bd->bi_boot_params);
115         printf("---bi_memstart:%x\n", bd->bi_memstart);
116         printf("---bi_memsize:%x\n", bd->bi_memsize);
117         printf("---bi_flashstart:%x\n", bd->bi_flashstart);
118         printf("---bi_flashsize:%x\n", bd->bi_flashsize);
119         printf("---bi_flashoffset:%x\n", bd->bi_flashoffset);
120         printf("--jt:%x *:%x\n", gd->jt, *(gd->jt));
121 }
122 #endif
123
124 /*
125  * All attempts to come up with a "common" initialization sequence
126  * that works for all boards and architectures failed: some of the
127  * requirements are just _too_ different. To get rid of the resulting
128  * mess of board dependend #ifdef'ed code we now make the whole
129  * initialization sequence configurable to the user.
130  *
131  * The requirements for any new initalization function is simple: it
132  * receives a pointer to the "global data" structure as it's only
133  * argument, and returns an integer return code, where 0 means
134  * "continue" and != 0 means "fatal error, hang the system".
135  */
136
137 void board_init_f(ulong bootflag)
138 {
139         DECLARE_GLOBAL_DATA_PTR;
140         ulong addr;
141         bd_t *bd;
142
143         gd = (gd_t *) (CFG_GBL_DATA_ADDR);
144         memset((void *) gd, 0, sizeof(gd_t));
145
146         /* Board data initialization */
147         addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
148
149         /* Align to 4 byte boundary */
150         addr &= ~(4 - 1);
151         bd = (bd_t*)addr;
152         gd->bd = bd;
153         memset((void *) bd, 0, sizeof(bd_t));
154
155         /* Initialize */
156         init_IRQ();
157         env_init();             /* initialize environment */
158         init_baudrate();        /* initialze baudrate settings */
159         serial_init();          /* serial communications setup */
160         console_init_f();
161         display_banner();       /* say that we are here */
162         checkboard();
163 #if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
164         rtc_init();
165 #endif
166         timer_init();
167         printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \
168         CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000);
169         printf("SDRAM: ");
170         print_size(initdram(0), "\n");
171         board_init_r((gd_t *) gd, 0x20000010);
172 }
173
174 void board_init_r(gd_t * id, ulong dest_addr)
175 {
176         DECLARE_GLOBAL_DATA_PTR;
177         ulong size;
178         extern void malloc_bin_reloc(void);
179         char *s, *e;
180         bd_t *bd;
181         int i;
182         gd = id;
183         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
184         bd = gd->bd;
185
186 #if     CONFIG_STAMP
187         /* There are some other pointer constants we must deal with */
188         /* configure available FLASH banks */
189         size = flash_init();
190         display_flash_config(size);
191         flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
192         bd->bi_flashstart = CFG_FLASH_BASE;
193         bd->bi_flashsize = size;
194         bd->bi_flashoffset = 0;
195 #else
196         bd->bi_flashstart = 0;
197         bd->bi_flashsize = 0;
198         bd->bi_flashoffset = 0;
199 #endif
200         /* initialize malloc() area */
201         mem_malloc_init();
202         malloc_bin_reloc();
203
204         /* relocate environment function pointers etc. */
205         env_relocate();
206
207         /* board MAC address */
208         s = getenv("ethaddr");
209         for (i = 0; i < 6; ++i) {
210                 bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
211                 if (s)
212                         s = (*e) ? e + 1 : e;
213         }
214
215         /* IP Address */
216         bd->bi_ip_addr = getenv_IPaddr("ipaddr");
217
218         /* Initialize devices */
219         devices_init();
220         jumptable_init();
221
222         /* Initialize the console (after the relocation and devices init) */
223         console_init_r();
224
225         /* Initialize from environment */
226         if ((s = getenv("loadaddr")) != NULL) {
227                 load_addr = simple_strtoul(s, NULL, 16);
228         }
229 #if (CONFIG_COMMANDS & CFG_CMD_NET)
230         if ((s = getenv("bootfile")) != NULL) {
231                 copy_filename(BootFile, s, sizeof(BootFile));
232         }
233 #endif
234 #if defined(CONFIG_MISC_INIT_R)
235         /* miscellaneous platform dependent initialisations */
236         misc_init_r();
237 #endif
238
239 #ifdef CONFIG_DRIVER_SMC91111
240 #ifdef SHARED_RESOURCES
241         /* Switch to Ethernet */
242         swap_to(ETHERNET);
243 #endif
244         if  ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) {
245                 printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS);
246         } else {
247                 printf("Net:   SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
248         }
249
250 #ifdef SHARED_RESOURCES
251         swap_to(FLASH);
252 #endif
253 #endif
254 #ifdef CONFIG_SOFT_I2C
255         init_func_i2c();
256 #endif
257
258 #ifdef DEBUG
259         display_global_data(void);
260 #endif
261
262         /* main_loop() can return to retry autoboot, if so just run it again. */
263         for (;;) {
264                 main_loop();
265         }
266 }
267
268 #ifdef CONFIG_SOFT_I2C
269 static int init_func_i2c (void)
270 {
271         puts ("I2C:   ");
272         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
273         puts ("ready\n");
274         return (0);
275 }
276 #endif
277
278 void hang(void)
279 {
280         puts("### ERROR ### Please RESET the board ###\n");
281         for (;;);
282 }