2 * U-boot - board.c First C file to be called contains init routines
4 * Copyright (c) 2005 blackfin.uclinux.org
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
34 #include <environment.h>
35 #include "blackfin_board.h"
36 #include "../drivers/smc91111.h"
38 extern flash_info_t flash_info[];
41 static void mem_malloc_init(void)
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);
50 void *sbrk(ptrdiff_t increment)
52 ulong old = mem_malloc_brk;
53 ulong new = old + increment;
55 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
60 return ((void *) old);
63 static int display_banner(void)
65 sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
66 printf("%s\n", version_string);
70 static void display_flash_config(ulong size)
73 print_size(size, "\n");
77 static int init_baudrate(void)
79 DECLARE_GLOBAL_DATA_PTR;
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)
90 static void display_global_data(void)
92 DECLARE_GLOBAL_DATA_PTR;
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",
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));
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.
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".
137 void board_init_f(ulong bootflag)
139 DECLARE_GLOBAL_DATA_PTR;
143 gd = (gd_t *) (CFG_GBL_DATA_ADDR);
144 memset((void *) gd, 0, sizeof(gd_t));
146 /* Board data initialization */
147 addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
149 /* Align to 4 byte boundary */
153 memset((void *) bd, 0, sizeof(bd_t));
157 env_init(); /* initialize environment */
158 init_baudrate(); /* initialze baudrate settings */
159 serial_init(); /* serial communications setup */
161 display_banner(); /* say that we are here */
163 #if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
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);
170 print_size(initdram(0), "\n");
171 board_init_r((gd_t *) gd, 0x20000010);
174 void board_init_r(gd_t * id, ulong dest_addr)
176 DECLARE_GLOBAL_DATA_PTR;
178 extern void malloc_bin_reloc(void);
183 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
187 /* There are some other pointer constants we must deal with */
188 /* configure available FLASH banks */
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;
196 bd->bi_flashstart = 0;
197 bd->bi_flashsize = 0;
198 bd->bi_flashoffset = 0;
200 /* initialize malloc() area */
204 /* relocate environment function pointers etc. */
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;
212 s = (*e) ? e + 1 : e;
216 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
218 /* Initialize devices */
222 /* Initialize the console (after the relocation and devices init) */
225 /* Initialize from environment */
226 if ((s = getenv("loadaddr")) != NULL) {
227 load_addr = simple_strtoul(s, NULL, 16);
229 #if (CONFIG_COMMANDS & CFG_CMD_NET)
230 if ((s = getenv("bootfile")) != NULL) {
231 copy_filename(BootFile, s, sizeof(BootFile));
234 #if defined(CONFIG_MISC_INIT_R)
235 /* miscellaneous platform dependent initialisations */
239 #ifdef CONFIG_DRIVER_SMC91111
240 #ifdef SHARED_RESOURCES
241 /* Switch to Ethernet */
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);
247 printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
250 #ifdef SHARED_RESOURCES
254 #ifdef CONFIG_SOFT_I2C
259 display_global_data(void);
262 /* main_loop() can return to retry autoboot, if so just run it again. */
268 #ifdef CONFIG_SOFT_I2C
269 static int init_func_i2c (void)
272 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
280 puts("### ERROR ### Please RESET the board ###\n");