Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - board.c First C file to be called contains init routines |
| 3 | * |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 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 |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 25 | * MA 02110-1301 USA |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 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> |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 35 | #include <i2c.h> |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 36 | #include "blackfin_board.h" |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 37 | #include <asm/cplb.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2439e4b | 2007-11-21 21:19:24 +0100 | [diff] [blame] | 38 | #include "../drivers/net/smc91111.h" |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 39 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 40 | #if defined(CONFIG_BF537)&&defined(CONFIG_POST) |
| 41 | #include <post.h> |
| 42 | int post_flag; |
| 43 | #endif |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 44 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 45 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 47 | #ifndef CFG_NO_FLASH |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 48 | extern flash_info_t flash_info[]; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 49 | #endif |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 50 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 51 | static inline u_long get_vco(void) |
| 52 | { |
| 53 | u_long msel; |
| 54 | u_long vco; |
| 55 | |
| 56 | msel = (*pPLL_CTL >> 9) & 0x3F; |
| 57 | if (0 == msel) |
| 58 | msel = 64; |
| 59 | |
| 60 | vco = CONFIG_CLKIN_HZ; |
| 61 | vco >>= (1 & *pPLL_CTL); /* DF bit */ |
| 62 | vco = msel * vco; |
| 63 | return vco; |
| 64 | } |
| 65 | |
| 66 | /*Get the Core clock*/ |
| 67 | u_long get_cclk(void) |
| 68 | { |
| 69 | u_long csel, ssel; |
| 70 | if (*pPLL_STAT & 0x1) |
| 71 | return CONFIG_CLKIN_HZ; |
| 72 | |
| 73 | ssel = *pPLL_DIV; |
| 74 | csel = ((ssel >> 4) & 0x03); |
| 75 | ssel &= 0xf; |
| 76 | if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */ |
| 77 | return get_vco() / ssel; |
| 78 | return get_vco() >> csel; |
| 79 | } |
| 80 | |
| 81 | /* Get the System clock */ |
| 82 | u_long get_sclk(void) |
| 83 | { |
| 84 | u_long ssel; |
| 85 | |
| 86 | if (*pPLL_STAT & 0x1) |
| 87 | return CONFIG_CLKIN_HZ; |
| 88 | |
| 89 | ssel = (*pPLL_DIV & 0xf); |
| 90 | |
| 91 | return get_vco() / ssel; |
| 92 | } |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 93 | |
| 94 | static void mem_malloc_init(void) |
| 95 | { |
| 96 | mem_malloc_start = CFG_MALLOC_BASE; |
| 97 | mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN); |
| 98 | mem_malloc_brk = mem_malloc_start; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 99 | memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void *sbrk(ptrdiff_t increment) |
| 103 | { |
| 104 | ulong old = mem_malloc_brk; |
| 105 | ulong new = old + increment; |
| 106 | |
| 107 | if ((new < mem_malloc_start) || (new > mem_malloc_end)) { |
| 108 | return (NULL); |
| 109 | } |
| 110 | mem_malloc_brk = new; |
| 111 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 112 | return ((void *)old); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static int display_banner(void) |
| 116 | { |
| 117 | sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING); |
| 118 | printf("%s\n", version_string); |
Mike Frysinger | f7ce12c | 2008-02-18 05:26:48 -0500 | [diff] [blame] | 119 | printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid()); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 120 | return (0); |
| 121 | } |
| 122 | |
| 123 | static void display_flash_config(ulong size) |
| 124 | { |
| 125 | puts("FLASH: "); |
| 126 | print_size(size, "\n"); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | static int init_baudrate(void) |
| 131 | { |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 132 | char tmp[64]; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 133 | int i = getenv_r("baudrate", tmp, sizeof(tmp)); |
| 134 | gd->bd->bi_baudrate = gd->baudrate = (i > 0) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 135 | ? (int)simple_strtoul(tmp, NULL, 10) |
| 136 | : CONFIG_BAUDRATE; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 137 | return (0); |
| 138 | } |
| 139 | |
| 140 | #ifdef DEBUG |
| 141 | static void display_global_data(void) |
| 142 | { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 143 | bd_t *bd; |
| 144 | bd = gd->bd; |
| 145 | printf("--flags:%x\n", gd->flags); |
| 146 | printf("--board_type:%x\n", gd->board_type); |
| 147 | printf("--baudrate:%x\n", gd->baudrate); |
| 148 | printf("--have_console:%x\n", gd->have_console); |
| 149 | printf("--ram_size:%x\n", gd->ram_size); |
| 150 | printf("--reloc_off:%x\n", gd->reloc_off); |
| 151 | printf("--env_addr:%x\n", gd->env_addr); |
| 152 | printf("--env_valid:%x\n", gd->env_valid); |
| 153 | printf("--bd:%x %x\n", gd->bd, bd); |
| 154 | printf("---bi_baudrate:%x\n", bd->bi_baudrate); |
| 155 | printf("---bi_ip_addr:%x\n", bd->bi_ip_addr); |
| 156 | printf("---bi_enetaddr:%x %x %x %x %x %x\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 157 | bd->bi_enetaddr[0], |
| 158 | bd->bi_enetaddr[1], |
| 159 | bd->bi_enetaddr[2], |
| 160 | bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 161 | printf("---bi_arch_number:%x\n", bd->bi_arch_number); |
| 162 | printf("---bi_boot_params:%x\n", bd->bi_boot_params); |
| 163 | printf("---bi_memstart:%x\n", bd->bi_memstart); |
| 164 | printf("---bi_memsize:%x\n", bd->bi_memsize); |
| 165 | printf("---bi_flashstart:%x\n", bd->bi_flashstart); |
| 166 | printf("---bi_flashsize:%x\n", bd->bi_flashsize); |
| 167 | printf("---bi_flashoffset:%x\n", bd->bi_flashoffset); |
| 168 | printf("--jt:%x *:%x\n", gd->jt, *(gd->jt)); |
| 169 | } |
| 170 | #endif |
| 171 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 172 | /* we cover everything with 4 meg pages, and need an extra for L1 */ |
| 173 | unsigned int icplb_table[page_descriptor_table_size][2]; |
| 174 | unsigned int dcplb_table[page_descriptor_table_size][2]; |
| 175 | |
| 176 | void init_cplbtables(void) |
| 177 | { |
| 178 | int i, j; |
| 179 | |
| 180 | j = 0; |
| 181 | icplb_table[j][0] = 0xFFA00000; |
| 182 | icplb_table[j][1] = L1_IMEMORY; |
| 183 | j++; |
| 184 | |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 185 | for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) { |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 186 | icplb_table[j][0] = (i * 4 * 1024 * 1024); |
| 187 | if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE |
| 188 | && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) { |
| 189 | icplb_table[j][1] = SDRAM_IKERNEL; |
| 190 | } else { |
| 191 | icplb_table[j][1] = SDRAM_IGENERIC; |
| 192 | } |
| 193 | j++; |
| 194 | } |
| 195 | #if defined(CONFIG_BF561) |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 196 | /* MAC space */ |
| 197 | icplb_table[j][0] = 0x2C000000; |
| 198 | icplb_table[j][1] = SDRAM_INON_CHBL; |
| 199 | j++; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 200 | /* Async Memory space */ |
| 201 | for (i = 0; i < 3; i++) { |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 202 | icplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024; |
| 203 | icplb_table[j][1] = SDRAM_INON_CHBL; |
| 204 | j++; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 205 | } |
| 206 | #else |
| 207 | icplb_table[j][0] = 0x20000000; |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 208 | icplb_table[j][1] = SDRAM_INON_CHBL; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 209 | #endif |
| 210 | j = 0; |
| 211 | dcplb_table[j][0] = 0xFF800000; |
| 212 | dcplb_table[j][1] = L1_DMEMORY; |
| 213 | j++; |
| 214 | |
| 215 | for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) { |
| 216 | dcplb_table[j][0] = (i * 4 * 1024 * 1024); |
| 217 | if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE |
| 218 | && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) { |
| 219 | dcplb_table[j][1] = SDRAM_DKERNEL; |
| 220 | } else { |
| 221 | dcplb_table[j][1] = SDRAM_DGENERIC; |
| 222 | } |
| 223 | j++; |
| 224 | } |
| 225 | |
| 226 | #if defined(CONFIG_BF561) |
| 227 | /* MAC space */ |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 228 | dcplb_table[j][0] = 0x2C000000; |
| 229 | dcplb_table[j][1] = SDRAM_EBIU; |
| 230 | j++; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 231 | |
| 232 | /* Flash space */ |
Aubrey Li | 7b7e30a | 2007-04-05 18:33:04 +0800 | [diff] [blame] | 233 | for (i = 0; i < 3; i++) { |
| 234 | dcplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024; |
| 235 | dcplb_table[j][1] = SDRAM_EBIU; |
| 236 | j++; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 237 | } |
| 238 | #else |
| 239 | dcplb_table[j][0] = 0x20000000; |
| 240 | dcplb_table[j][1] = SDRAM_EBIU; |
| 241 | #endif |
| 242 | } |
| 243 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 244 | /* |
| 245 | * All attempts to come up with a "common" initialization sequence |
| 246 | * that works for all boards and architectures failed: some of the |
| 247 | * requirements are just _too_ different. To get rid of the resulting |
| 248 | * mess of board dependend #ifdef'ed code we now make the whole |
| 249 | * initialization sequence configurable to the user. |
| 250 | * |
| 251 | * The requirements for any new initalization function is simple: it |
| 252 | * receives a pointer to the "global data" structure as it's only |
| 253 | * argument, and returns an integer return code, where 0 means |
| 254 | * "continue" and != 0 means "fatal error, hang the system". |
| 255 | */ |
| 256 | |
| 257 | void board_init_f(ulong bootflag) |
| 258 | { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 259 | ulong addr; |
| 260 | bd_t *bd; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 261 | int i; |
| 262 | |
| 263 | init_cplbtables(); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 264 | |
| 265 | gd = (gd_t *) (CFG_GBL_DATA_ADDR); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 266 | memset((void *)gd, 0, sizeof(gd_t)); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 267 | |
| 268 | /* Board data initialization */ |
| 269 | addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t)); |
| 270 | |
| 271 | /* Align to 4 byte boundary */ |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 272 | addr &= ~(4 - 1); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 273 | bd = (bd_t *) addr; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 274 | gd->bd = bd; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 275 | memset((void *)bd, 0, sizeof(bd_t)); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 276 | |
| 277 | /* Initialize */ |
| 278 | init_IRQ(); |
| 279 | env_init(); /* initialize environment */ |
| 280 | init_baudrate(); /* initialze baudrate settings */ |
| 281 | serial_init(); /* serial communications setup */ |
| 282 | console_init_f(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 283 | #ifdef CONFIG_ICACHE_ON |
| 284 | icache_enable(); |
| 285 | #endif |
| 286 | #ifdef CONFIG_DCACHE_ON |
| 287 | dcache_enable(); |
| 288 | #endif |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 289 | display_banner(); /* say that we are here */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 290 | |
| 291 | for (i = 0; i < page_descriptor_table_size; i++) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 292 | debug |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 293 | ("data (%02i)= 0x%08x : 0x%08x intr = 0x%08x : 0x%08x\n", |
| 294 | i, dcplb_table[i][0], dcplb_table[i][1], icplb_table[i][0], |
| 295 | icplb_table[i][1]); |
| 296 | } |
| 297 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 298 | checkboard(); |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 299 | #if defined(CONFIG_RTC_BF533) && defined(CONFIG_CMD_DATE) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 300 | rtc_init(); |
| 301 | #endif |
| 302 | timer_init(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 303 | printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", |
| 304 | get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 305 | printf("SDRAM: "); |
| 306 | print_size(initdram(0), "\n"); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 307 | #if defined(CONFIG_BF537)&&defined(CONFIG_POST) |
| 308 | post_init_f(); |
| 309 | post_bootmode_init(); |
| 310 | post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| 311 | #endif |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 312 | board_init_r((gd_t *) gd, 0x20000010); |
| 313 | } |
| 314 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 315 | #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) |
| 316 | static int init_func_i2c(void) |
| 317 | { |
| 318 | puts("I2C: "); |
| 319 | i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 320 | puts("ready\n"); |
| 321 | return (0); |
| 322 | } |
| 323 | #endif |
| 324 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 325 | void board_init_r(gd_t * id, ulong dest_addr) |
| 326 | { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 327 | ulong size; |
| 328 | extern void malloc_bin_reloc(void); |
| 329 | char *s, *e; |
| 330 | bd_t *bd; |
| 331 | int i; |
| 332 | gd = id; |
| 333 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 334 | bd = gd->bd; |
| 335 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 336 | #if defined(CONFIG_BF537) && defined(CONFIG_POST) |
| 337 | post_output_backlog(); |
| 338 | post_reloc(); |
| 339 | #endif |
| 340 | |
| 341 | #if (CONFIG_STAMP || CONFIG_BF537 || CONFIG_EZKIT561) && !defined(CFG_NO_FLASH) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 342 | /* There are some other pointer constants we must deal with */ |
| 343 | /* configure available FLASH banks */ |
| 344 | size = flash_init(); |
| 345 | display_flash_config(size); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 346 | flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, |
| 347 | CFG_FLASH_BASE + 0x1ffff, &flash_info[0]); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 348 | bd->bi_flashstart = CFG_FLASH_BASE; |
| 349 | bd->bi_flashsize = size; |
| 350 | bd->bi_flashoffset = 0; |
| 351 | #else |
| 352 | bd->bi_flashstart = 0; |
| 353 | bd->bi_flashsize = 0; |
| 354 | bd->bi_flashoffset = 0; |
| 355 | #endif |
| 356 | /* initialize malloc() area */ |
| 357 | mem_malloc_init(); |
| 358 | malloc_bin_reloc(); |
| 359 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 360 | #ifdef CONFIG_SPI |
| 361 | # if ! defined(CFG_ENV_IS_IN_EEPROM) |
| 362 | spi_init_f(); |
| 363 | # endif |
| 364 | spi_init_r(); |
| 365 | #endif |
| 366 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 367 | /* relocate environment function pointers etc. */ |
| 368 | env_relocate(); |
| 369 | |
| 370 | /* board MAC address */ |
| 371 | s = getenv("ethaddr"); |
| 372 | for (i = 0; i < 6; ++i) { |
| 373 | bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; |
| 374 | if (s) |
| 375 | s = (*e) ? e + 1 : e; |
| 376 | } |
| 377 | |
| 378 | /* IP Address */ |
| 379 | bd->bi_ip_addr = getenv_IPaddr("ipaddr"); |
| 380 | |
| 381 | /* Initialize devices */ |
| 382 | devices_init(); |
| 383 | jumptable_init(); |
| 384 | |
| 385 | /* Initialize the console (after the relocation and devices init) */ |
| 386 | console_init_r(); |
| 387 | |
| 388 | /* Initialize from environment */ |
| 389 | if ((s = getenv("loadaddr")) != NULL) { |
| 390 | load_addr = simple_strtoul(s, NULL, 16); |
| 391 | } |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 392 | #if defined(CONFIG_CMD_NET) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 393 | if ((s = getenv("bootfile")) != NULL) { |
| 394 | copy_filename(BootFile, s, sizeof(BootFile)); |
| 395 | } |
| 396 | #endif |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 397 | |
Jon Loeliger | 6735056 | 2007-07-09 18:05:38 -0500 | [diff] [blame] | 398 | #if defined(CONFIG_CMD_NAND) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 399 | puts("NAND: "); |
| 400 | nand_init(); /* go init the NAND */ |
| 401 | #endif |
| 402 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 403 | #if defined(CONFIG_MISC_INIT_R) |
| 404 | /* miscellaneous platform dependent initialisations */ |
| 405 | misc_init_r(); |
| 406 | #endif |
| 407 | |
Mike Frysinger | f7ce12c | 2008-02-18 05:26:48 -0500 | [diff] [blame] | 408 | #ifdef CONFIG_CMD_NET |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 409 | printf("Net: "); |
| 410 | eth_initialize(bd); |
| 411 | #endif |
| 412 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 413 | #ifdef CONFIG_DRIVER_SMC91111 |
| 414 | #ifdef SHARED_RESOURCES |
| 415 | /* Switch to Ethernet */ |
| 416 | swap_to(ETHERNET); |
| 417 | #endif |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 418 | if ((SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT) { |
| 419 | printf("ERROR: Can't find SMC91111 at address %x\n", |
| 420 | SMC_BASE_ADDRESS); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 421 | } else { |
| 422 | printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS); |
| 423 | } |
| 424 | |
| 425 | #ifdef SHARED_RESOURCES |
| 426 | swap_to(FLASH); |
| 427 | #endif |
| 428 | #endif |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 429 | #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 430 | init_func_i2c(); |
| 431 | #endif |
| 432 | |
| 433 | #ifdef DEBUG |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 434 | display_global_data(); |
| 435 | #endif |
| 436 | |
| 437 | #if defined(CONFIG_BF537) && defined(CONFIG_POST) |
| 438 | if (post_flag) |
| 439 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 440 | #endif |
| 441 | |
| 442 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
| 443 | for (;;) { |
| 444 | main_loop(); |
| 445 | } |
| 446 | } |
| 447 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 448 | void hang(void) |
| 449 | { |
| 450 | puts("### ERROR ### Please RESET the board ###\n"); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 451 | for (;;) ; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 452 | } |