blob: d9dc2b6d0cf9a254bf422b7375cfe256c65eae2f [file] [log] [blame]
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01001/*
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
Wolfgang Denkd87080b2006-03-31 18:32:53 +020038DECLARE_GLOBAL_DATA_PTR;
39
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010040extern flash_info_t flash_info[];
41
42
43static void mem_malloc_init(void)
44{
45 mem_malloc_start = CFG_MALLOC_BASE;
46 mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
47 mem_malloc_brk = mem_malloc_start;
48 memset((void *) mem_malloc_start, 0,
49 mem_malloc_end - mem_malloc_start);
50}
51
52void *sbrk(ptrdiff_t increment)
53{
54 ulong old = mem_malloc_brk;
55 ulong new = old + increment;
56
57 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
58 return (NULL);
59 }
60 mem_malloc_brk = new;
61
62 return ((void *) old);
63}
64
65static int display_banner(void)
66{
67 sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
68 printf("%s\n", version_string);
69 return (0);
70}
71
72static void display_flash_config(ulong size)
73{
74 puts("FLASH: ");
75 print_size(size, "\n");
76 return;
77}
78
79static int init_baudrate(void)
80{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010081 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
90static void display_global_data(void)
91{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010092 bd_t *bd;
93 bd = gd->bd;
94 printf("--flags:%x\n", gd->flags);
95 printf("--board_type:%x\n", gd->board_type);
96 printf("--baudrate:%x\n", gd->baudrate);
97 printf("--have_console:%x\n", gd->have_console);
98 printf("--ram_size:%x\n", gd->ram_size);
99 printf("--reloc_off:%x\n", gd->reloc_off);
100 printf("--env_addr:%x\n", gd->env_addr);
101 printf("--env_valid:%x\n", gd->env_valid);
102 printf("--bd:%x %x\n", gd->bd, bd);
103 printf("---bi_baudrate:%x\n", bd->bi_baudrate);
104 printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
105 printf("---bi_enetaddr:%x %x %x %x %x %x\n",
106 bd->bi_enetaddr[0],
107 bd->bi_enetaddr[1],
108 bd->bi_enetaddr[2],
109 bd->bi_enetaddr[3],
110 bd->bi_enetaddr[4],
111 bd->bi_enetaddr[5]);
112 printf("---bi_arch_number:%x\n", bd->bi_arch_number);
113 printf("---bi_boot_params:%x\n", bd->bi_boot_params);
114 printf("---bi_memstart:%x\n", bd->bi_memstart);
115 printf("---bi_memsize:%x\n", bd->bi_memsize);
116 printf("---bi_flashstart:%x\n", bd->bi_flashstart);
117 printf("---bi_flashsize:%x\n", bd->bi_flashsize);
118 printf("---bi_flashoffset:%x\n", bd->bi_flashoffset);
119 printf("--jt:%x *:%x\n", gd->jt, *(gd->jt));
120}
121#endif
122
123/*
124 * All attempts to come up with a "common" initialization sequence
125 * that works for all boards and architectures failed: some of the
126 * requirements are just _too_ different. To get rid of the resulting
127 * mess of board dependend #ifdef'ed code we now make the whole
128 * initialization sequence configurable to the user.
129 *
130 * The requirements for any new initalization function is simple: it
131 * receives a pointer to the "global data" structure as it's only
132 * argument, and returns an integer return code, where 0 means
133 * "continue" and != 0 means "fatal error, hang the system".
134 */
135
136void board_init_f(ulong bootflag)
137{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100138 ulong addr;
139 bd_t *bd;
140
141 gd = (gd_t *) (CFG_GBL_DATA_ADDR);
142 memset((void *) gd, 0, sizeof(gd_t));
143
144 /* Board data initialization */
145 addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
146
147 /* Align to 4 byte boundary */
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100148 addr &= ~(4 - 1);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100149 bd = (bd_t*)addr;
150 gd->bd = bd;
151 memset((void *) bd, 0, sizeof(bd_t));
152
153 /* Initialize */
154 init_IRQ();
155 env_init(); /* initialize environment */
156 init_baudrate(); /* initialze baudrate settings */
157 serial_init(); /* serial communications setup */
158 console_init_f();
159 display_banner(); /* say that we are here */
160 checkboard();
161#if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
162 rtc_init();
163#endif
164 timer_init();
165 printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \
166 CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000);
167 printf("SDRAM: ");
168 print_size(initdram(0), "\n");
169 board_init_r((gd_t *) gd, 0x20000010);
170}
171
172void board_init_r(gd_t * id, ulong dest_addr)
173{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100174 ulong size;
175 extern void malloc_bin_reloc(void);
176 char *s, *e;
177 bd_t *bd;
178 int i;
179 gd = id;
180 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
181 bd = gd->bd;
182
183#if CONFIG_STAMP
184 /* There are some other pointer constants we must deal with */
185 /* configure available FLASH banks */
186 size = flash_init();
187 display_flash_config(size);
188 flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
189 bd->bi_flashstart = CFG_FLASH_BASE;
190 bd->bi_flashsize = size;
191 bd->bi_flashoffset = 0;
192#else
193 bd->bi_flashstart = 0;
194 bd->bi_flashsize = 0;
195 bd->bi_flashoffset = 0;
196#endif
197 /* initialize malloc() area */
198 mem_malloc_init();
199 malloc_bin_reloc();
200
201 /* relocate environment function pointers etc. */
202 env_relocate();
203
204 /* board MAC address */
205 s = getenv("ethaddr");
206 for (i = 0; i < 6; ++i) {
207 bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
208 if (s)
209 s = (*e) ? e + 1 : e;
210 }
211
212 /* IP Address */
213 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
214
215 /* Initialize devices */
216 devices_init();
217 jumptable_init();
218
219 /* Initialize the console (after the relocation and devices init) */
220 console_init_r();
221
222 /* Initialize from environment */
223 if ((s = getenv("loadaddr")) != NULL) {
224 load_addr = simple_strtoul(s, NULL, 16);
225 }
226#if (CONFIG_COMMANDS & CFG_CMD_NET)
227 if ((s = getenv("bootfile")) != NULL) {
228 copy_filename(BootFile, s, sizeof(BootFile));
229 }
230#endif
231#if defined(CONFIG_MISC_INIT_R)
232 /* miscellaneous platform dependent initialisations */
233 misc_init_r();
234#endif
235
236#ifdef CONFIG_DRIVER_SMC91111
237#ifdef SHARED_RESOURCES
238 /* Switch to Ethernet */
239 swap_to(ETHERNET);
240#endif
241 if ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) {
242 printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS);
243 } else {
244 printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
245 }
246
247#ifdef SHARED_RESOURCES
248 swap_to(FLASH);
249#endif
250#endif
251#ifdef CONFIG_SOFT_I2C
252 init_func_i2c();
253#endif
254
255#ifdef DEBUG
256 display_global_data(void);
257#endif
258
259 /* main_loop() can return to retry autoboot, if so just run it again. */
260 for (;;) {
261 main_loop();
262 }
263}
264
265#ifdef CONFIG_SOFT_I2C
266static int init_func_i2c (void)
267{
268 puts ("I2C: ");
269 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
270 puts ("ready\n");
271 return (0);
272}
273#endif
274
275void hang(void)
276{
277 puts("### ERROR ### Please RESET the board ###\n");
278 for (;;);
279}