wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <watchdog.h> |
| 26 | #include <command.h> |
| 27 | #include <malloc.h> |
| 28 | #include <devices.h> |
| 29 | #include <syscall.h> |
| 30 | #ifdef CONFIG_8xx |
| 31 | #include <mpc8xx.h> |
| 32 | #endif |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 33 | #ifdef CONFIG_5xx |
| 34 | #include <mpc5xx.h> |
| 35 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 36 | #if (CONFIG_COMMANDS & CFG_CMD_IDE) |
| 37 | #include <ide.h> |
| 38 | #endif |
| 39 | #if (CONFIG_COMMANDS & CFG_CMD_SCSI) |
| 40 | #include <scsi.h> |
| 41 | #endif |
| 42 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 43 | #include <kgdb.h> |
| 44 | #endif |
| 45 | #ifdef CONFIG_STATUS_LED |
| 46 | #include <status_led.h> |
| 47 | #endif |
| 48 | #include <net.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 49 | #ifdef CFG_ALLOC_DPRAM |
wdenk | 7aa7861 | 2003-05-03 15:50:43 +0000 | [diff] [blame] | 50 | #if !defined(CONFIG_8260) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 51 | #include <commproc.h> |
| 52 | #endif |
wdenk | 7aa7861 | 2003-05-03 15:50:43 +0000 | [diff] [blame] | 53 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 54 | #include <version.h> |
| 55 | #if defined(CONFIG_BAB7xx) |
| 56 | #include <w83c553f.h> |
| 57 | #endif |
| 58 | #include <dtt.h> |
| 59 | #if defined(CONFIG_POST) |
| 60 | #include <post.h> |
| 61 | #endif |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 62 | #if defined(CONFIG_LOGBUFFER) |
| 63 | #include <logbuff.h> |
| 64 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 65 | |
| 66 | #if (CONFIG_COMMANDS & CFG_CMD_DOC) |
| 67 | void doc_init (void); |
| 68 | #endif |
| 69 | #if defined(CONFIG_HARD_I2C) || \ |
| 70 | defined(CONFIG_SOFT_I2C) |
| 71 | #include <i2c.h> |
| 72 | #endif |
stroese | bedc497 | 2003-05-23 11:16:49 +0000 | [diff] [blame] | 73 | #if (CONFIG_COMMANDS & CFG_CMD_NAND) |
| 74 | void nand_init (void); |
| 75 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 76 | |
| 77 | static char *failed = "*** failed ***\n"; |
| 78 | |
| 79 | #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) |
| 80 | extern flash_info_t flash_info[]; |
| 81 | #endif |
| 82 | |
| 83 | #include <environment.h> |
| 84 | |
| 85 | #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \ |
| 86 | (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \ |
| 87 | defined(CFG_ENV_IS_IN_NVRAM) |
| 88 | #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE) |
| 89 | #else |
| 90 | #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN |
| 91 | #endif |
| 92 | |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 93 | extern ulong __init_end; |
| 94 | extern ulong _end; |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 95 | ulong monitor_flash_len; |
| 96 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 97 | #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) |
| 98 | #include <bedbug/type.h> |
| 99 | #endif |
| 100 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 101 | /* |
| 102 | * Begin and End of memory area for malloc(), and current "brk" |
| 103 | */ |
| 104 | static ulong mem_malloc_start = 0; |
| 105 | static ulong mem_malloc_end = 0; |
| 106 | static ulong mem_malloc_brk = 0; |
| 107 | |
| 108 | /************************************************************************ |
| 109 | * Utilities * |
| 110 | ************************************************************************ |
| 111 | */ |
| 112 | |
| 113 | /* |
| 114 | * The Malloc area is immediately below the monitor copy in DRAM |
| 115 | */ |
| 116 | static void mem_malloc_init (void) |
| 117 | { |
| 118 | DECLARE_GLOBAL_DATA_PTR; |
| 119 | |
| 120 | ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off; |
| 121 | |
| 122 | mem_malloc_end = dest_addr; |
| 123 | mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN; |
| 124 | mem_malloc_brk = mem_malloc_start; |
| 125 | |
| 126 | memset ((void *) mem_malloc_start, |
| 127 | 0, |
| 128 | mem_malloc_end - mem_malloc_start); |
| 129 | } |
| 130 | |
| 131 | void *sbrk (ptrdiff_t increment) |
| 132 | { |
| 133 | ulong old = mem_malloc_brk; |
| 134 | ulong new = old + increment; |
| 135 | |
| 136 | if ((new < mem_malloc_start) || (new > mem_malloc_end)) { |
| 137 | return (NULL); |
| 138 | } |
| 139 | mem_malloc_brk = new; |
| 140 | return ((void *) old); |
| 141 | } |
| 142 | |
| 143 | char *strmhz (char *buf, long hz) |
| 144 | { |
| 145 | long l, n; |
| 146 | long m; |
| 147 | |
| 148 | n = hz / 1000000L; |
| 149 | l = sprintf (buf, "%ld", n); |
| 150 | m = (hz % 1000000L) / 1000L; |
| 151 | if (m != 0) |
| 152 | sprintf (buf + l, ".%03ld", m); |
| 153 | return (buf); |
| 154 | } |
| 155 | |
| 156 | static void syscalls_init (void) |
| 157 | { |
| 158 | ulong *addr; |
| 159 | |
| 160 | syscall_tbl[SYSCALL_MALLOC] = (void *) malloc; |
| 161 | syscall_tbl[SYSCALL_FREE] = (void *) free; |
| 162 | |
| 163 | syscall_tbl[SYSCALL_INSTALL_HDLR] = (void *) irq_install_handler; |
| 164 | syscall_tbl[SYSCALL_FREE_HDLR] = (void *) irq_free_handler; |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 165 | syscall_tbl[SYSCALL_GET_TIMER] = (void *)get_timer; |
| 166 | syscall_tbl[SYSCALL_UDELAY] = (void *)udelay; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 167 | |
| 168 | addr = (ulong *) 0xc00; /* syscall ISR addr */ |
| 169 | |
| 170 | /* patch ISR code */ |
| 171 | *addr++ |= (ulong) syscall_tbl >> 16; |
| 172 | *addr++ |= (ulong) syscall_tbl & 0xFFFF; |
| 173 | *addr++ |= NR_SYSCALLS >> 16; |
| 174 | *addr++ |= NR_SYSCALLS & 0xFFFF; |
| 175 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 176 | #ifndef CONFIG_5XX |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 177 | flush_cache (0x0C00, 0x10); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 178 | #endif |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 179 | /* Initialize syscalls stack pointer */ |
| 180 | addr = (ulong *) 0xCFC; |
| 181 | *addr = (ulong)addr; |
stroese | bedc497 | 2003-05-23 11:16:49 +0000 | [diff] [blame] | 182 | #ifndef CONFIG_5xx |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 183 | flush_cache ((ulong)addr, 0x10); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 184 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * All attempts to come up with a "common" initialization sequence |
| 189 | * that works for all boards and architectures failed: some of the |
| 190 | * requirements are just _too_ different. To get rid of the resulting |
| 191 | * mess of board dependend #ifdef'ed code we now make the whole |
| 192 | * initialization sequence configurable to the user. |
| 193 | * |
| 194 | * The requirements for any new initalization function is simple: it |
| 195 | * receives a pointer to the "global data" structure as it's only |
| 196 | * argument, and returns an integer return code, where 0 means |
| 197 | * "continue" and != 0 means "fatal error, hang the system". |
| 198 | */ |
| 199 | typedef int (init_fnc_t) (void); |
| 200 | |
| 201 | /************************************************************************ |
| 202 | * Init Utilities * |
| 203 | ************************************************************************ |
| 204 | * Some of this code should be moved into the core functions, |
| 205 | * but let's get it working (again) first... |
| 206 | */ |
| 207 | |
| 208 | static int init_baudrate (void) |
| 209 | { |
| 210 | DECLARE_GLOBAL_DATA_PTR; |
| 211 | |
| 212 | uchar tmp[64]; /* long enough for environment variables */ |
| 213 | int i = getenv_r ("baudrate", tmp, sizeof (tmp)); |
| 214 | |
| 215 | gd->baudrate = (i > 0) |
| 216 | ? (int) simple_strtoul (tmp, NULL, 10) |
| 217 | : CONFIG_BAUDRATE; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 218 | return (0); |
| 219 | } |
| 220 | |
| 221 | /***********************************************************************/ |
| 222 | |
| 223 | static int init_func_ram (void) |
| 224 | { |
| 225 | DECLARE_GLOBAL_DATA_PTR; |
| 226 | |
| 227 | #ifdef CONFIG_BOARD_TYPES |
| 228 | int board_type = gd->board_type; |
| 229 | #else |
| 230 | int board_type = 0; /* use dummy arg */ |
| 231 | #endif |
| 232 | puts ("DRAM: "); |
| 233 | |
| 234 | if ((gd->ram_size = initdram (board_type)) > 0) { |
| 235 | print_size (gd->ram_size, "\n"); |
| 236 | return (0); |
| 237 | } |
| 238 | puts (failed); |
| 239 | return (1); |
| 240 | } |
| 241 | |
| 242 | /***********************************************************************/ |
| 243 | |
| 244 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| 245 | static int init_func_i2c (void) |
| 246 | { |
| 247 | puts ("I2C: "); |
| 248 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 249 | puts ("ready\n"); |
| 250 | return (0); |
| 251 | } |
| 252 | #endif |
| 253 | |
| 254 | /***********************************************************************/ |
| 255 | |
| 256 | #if defined(CONFIG_WATCHDOG) |
| 257 | static int init_func_watchdog_init (void) |
| 258 | { |
| 259 | puts (" Watchdog enabled\n"); |
| 260 | WATCHDOG_RESET (); |
| 261 | return (0); |
| 262 | } |
| 263 | # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init, |
| 264 | |
| 265 | static int init_func_watchdog_reset (void) |
| 266 | { |
| 267 | WATCHDOG_RESET (); |
| 268 | return (0); |
| 269 | } |
| 270 | # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset, |
| 271 | #else |
| 272 | # define INIT_FUNC_WATCHDOG_INIT /* undef */ |
| 273 | # define INIT_FUNC_WATCHDOG_RESET /* undef */ |
| 274 | #endif /* CONFIG_WATCHDOG */ |
| 275 | |
| 276 | /************************************************************************ |
| 277 | * Initialization sequence * |
| 278 | ************************************************************************ |
| 279 | */ |
| 280 | |
| 281 | init_fnc_t *init_sequence[] = { |
| 282 | |
| 283 | #if defined(CONFIG_BOARD_PRE_INIT) |
| 284 | board_pre_init, /* very early board init code (fpga boot, etc.) */ |
| 285 | #endif |
| 286 | |
| 287 | get_clocks, /* get CPU and bus clocks (etc.) */ |
| 288 | init_timebase, |
| 289 | #ifdef CFG_ALLOC_DPRAM |
wdenk | 7aa7861 | 2003-05-03 15:50:43 +0000 | [diff] [blame] | 290 | #if !defined(CONFIG_8260) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 291 | dpram_init, |
| 292 | #endif |
wdenk | 7aa7861 | 2003-05-03 15:50:43 +0000 | [diff] [blame] | 293 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 294 | #if defined(CONFIG_BOARD_POSTCLK_INIT) |
| 295 | board_postclk_init, |
| 296 | #endif |
| 297 | env_init, |
| 298 | init_baudrate, |
| 299 | serial_init, |
| 300 | console_init_f, |
| 301 | display_options, |
| 302 | #if defined(CONFIG_8260) |
| 303 | prt_8260_rsr, |
| 304 | prt_8260_clks, |
| 305 | #endif /* CONFIG_8260 */ |
| 306 | checkcpu, |
| 307 | checkboard, |
| 308 | INIT_FUNC_WATCHDOG_INIT |
| 309 | #if defined(CONFIG_BMW) || \ |
| 310 | defined(CONFIG_COGENT) || \ |
| 311 | defined(CONFIG_HYMOD) || \ |
| 312 | defined(CONFIG_RSD_PROTO) || \ |
| 313 | defined(CONFIG_W7O) |
| 314 | misc_init_f, |
| 315 | #endif |
| 316 | INIT_FUNC_WATCHDOG_RESET |
| 317 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| 318 | init_func_i2c, |
| 319 | #endif |
| 320 | #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */ |
| 321 | dtt_init, |
| 322 | #endif |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 323 | #ifdef CONFIG_POST |
| 324 | post_init_f, |
| 325 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 326 | INIT_FUNC_WATCHDOG_RESET |
| 327 | init_func_ram, |
| 328 | #if defined(CFG_DRAM_TEST) |
| 329 | testdram, |
| 330 | #endif /* CFG_DRAM_TEST */ |
| 331 | INIT_FUNC_WATCHDOG_RESET |
| 332 | |
| 333 | NULL, /* Terminate this list */ |
| 334 | }; |
| 335 | |
| 336 | /************************************************************************ |
| 337 | * |
| 338 | * This is the first part of the initialization sequence that is |
| 339 | * implemented in C, but still running from ROM. |
| 340 | * |
| 341 | * The main purpose is to provide a (serial) console interface as |
| 342 | * soon as possible (so we can see any error messages), and to |
| 343 | * initialize the RAM so that we can relocate the monitor code to |
| 344 | * RAM. |
| 345 | * |
| 346 | * Be aware of the restrictions: global data is read-only, BSS is not |
| 347 | * initialized, and stack space is limited to a few kB. |
| 348 | * |
| 349 | ************************************************************************ |
| 350 | */ |
| 351 | |
| 352 | void board_init_f (ulong bootflag) |
| 353 | { |
| 354 | DECLARE_GLOBAL_DATA_PTR; |
| 355 | |
| 356 | bd_t *bd; |
| 357 | ulong len, addr, addr_sp; |
| 358 | gd_t *id; |
| 359 | init_fnc_t **init_fnc_ptr; |
| 360 | #ifdef CONFIG_PRAM |
| 361 | int i; |
| 362 | ulong reg; |
| 363 | uchar tmp[64]; /* long enough for environment variables */ |
| 364 | #endif |
| 365 | |
| 366 | /* Pointer is writable since we allocated a register for it */ |
| 367 | gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET); |
| 368 | |
| 369 | #ifndef CONFIG_8260 |
| 370 | /* Clear initial global data */ |
| 371 | memset ((void *) gd, 0, sizeof (gd_t)); |
| 372 | #endif |
| 373 | |
| 374 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
| 375 | if ((*init_fnc_ptr) () != 0) { |
| 376 | hang (); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Now that we have DRAM mapped and working, we can |
| 382 | * relocate the code and continue running from DRAM. |
| 383 | * |
| 384 | * Reserve memory at end of RAM for (top down in that order): |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 385 | * - kernel log buffer |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 386 | * - protected RAM |
| 387 | * - LCD framebuffer |
| 388 | * - monitor code |
| 389 | * - board info struct |
| 390 | */ |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 391 | len = (ulong)&_end - CFG_MONITOR_BASE; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 392 | |
| 393 | #ifndef CONFIG_VERY_BIG_RAM |
| 394 | addr = CFG_SDRAM_BASE + gd->ram_size; |
| 395 | #else |
| 396 | /* only allow stack below 256M */ |
| 397 | addr = CFG_SDRAM_BASE + |
| 398 | (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size; |
| 399 | #endif |
| 400 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 401 | #ifdef CONFIG_LOGBUFFER |
| 402 | /* reserve kernel log buffer */ |
| 403 | addr -= (LOGBUFF_RESERVE); |
| 404 | # ifdef DEBUG |
| 405 | printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr); |
| 406 | # endif |
| 407 | #endif |
| 408 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 409 | #ifdef CONFIG_PRAM |
| 410 | /* |
| 411 | * reserve protected RAM |
| 412 | */ |
| 413 | i = getenv_r ("pram", tmp, sizeof (tmp)); |
| 414 | reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM; |
| 415 | addr -= (reg << 10); /* size is in kB */ |
| 416 | # ifdef DEBUG |
| 417 | printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr); |
| 418 | # endif |
| 419 | #endif /* CONFIG_PRAM */ |
| 420 | |
| 421 | /* round down to next 4 kB limit */ |
| 422 | addr &= ~(4096 - 1); |
| 423 | #ifdef DEBUG |
| 424 | printf ("Top of RAM usable for U-Boot at: %08lx\n", addr); |
| 425 | #endif |
| 426 | |
| 427 | #ifdef CONFIG_LCD |
| 428 | /* reserve memory for LCD display (always full pages) */ |
| 429 | addr = lcd_setmem (addr); |
| 430 | gd->fb_base = addr; |
| 431 | #endif /* CONFIG_LCD */ |
| 432 | |
| 433 | #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx) |
| 434 | /* reserve memory for video display (always full pages) */ |
| 435 | addr = video_setmem (addr); |
| 436 | gd->fb_base = addr; |
| 437 | #endif /* CONFIG_VIDEO */ |
| 438 | |
| 439 | /* |
| 440 | * reserve memory for U-Boot code, data & bss |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 441 | * round down to next 4 kB limit |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 442 | */ |
| 443 | addr -= len; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 444 | addr &= ~(4096 - 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 445 | |
| 446 | #ifdef DEBUG |
| 447 | printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr); |
| 448 | #endif |
| 449 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 450 | #ifdef CONFIG_AMIGAONEG3SE |
| 451 | gd->relocaddr = addr; |
| 452 | #endif |
| 453 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 454 | /* |
| 455 | * reserve memory for malloc() arena |
| 456 | */ |
| 457 | addr_sp = addr - TOTAL_MALLOC_LEN; |
| 458 | #ifdef DEBUG |
| 459 | printf ("Reserving %dk for malloc() at: %08lx\n", |
| 460 | TOTAL_MALLOC_LEN >> 10, addr_sp); |
| 461 | #endif |
| 462 | |
| 463 | /* |
| 464 | * (permanently) allocate a Board Info struct |
| 465 | * and a permanent copy of the "global" data |
| 466 | */ |
| 467 | addr_sp -= sizeof (bd_t); |
| 468 | bd = (bd_t *) addr_sp; |
| 469 | gd->bd = bd; |
| 470 | #ifdef DEBUG |
| 471 | printf ("Reserving %d Bytes for Board Info at: %08lx\n", |
| 472 | sizeof (bd_t), addr_sp); |
| 473 | #endif |
| 474 | addr_sp -= sizeof (gd_t); |
| 475 | id = (gd_t *) addr_sp; |
| 476 | #ifdef DEBUG |
| 477 | printf ("Reserving %d Bytes for Global Data at: %08lx\n", |
| 478 | sizeof (gd_t), addr_sp); |
| 479 | #endif |
| 480 | |
| 481 | /* |
| 482 | * Finally, we set up a new (bigger) stack. |
| 483 | * |
| 484 | * Leave some safety gap for SP, force alignment on 16 byte boundary |
| 485 | * Clear initial stack frame |
| 486 | */ |
| 487 | addr_sp -= 16; |
| 488 | addr_sp &= ~0xF; |
| 489 | *((ulong *) addr_sp)-- = 0; |
| 490 | *((ulong *) addr_sp)-- = 0; |
| 491 | #ifdef DEBUG |
| 492 | printf ("Stack Pointer at: %08lx\n", addr_sp); |
| 493 | #endif |
| 494 | |
| 495 | /* |
| 496 | * Save local variables to board info struct |
| 497 | */ |
| 498 | |
| 499 | bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */ |
| 500 | bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */ |
| 501 | |
| 502 | #ifdef CONFIG_IP860 |
| 503 | bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */ |
| 504 | bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */ |
| 505 | #else |
| 506 | bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */ |
| 507 | bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */ |
| 508 | #endif |
| 509 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 510 | #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 511 | bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */ |
| 512 | #endif |
| 513 | |
| 514 | bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */ |
| 515 | |
| 516 | WATCHDOG_RESET (); |
| 517 | bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ |
| 518 | bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ |
| 519 | #if defined(CONFIG_8260) |
| 520 | bd->bi_cpmfreq = gd->cpm_clk; |
| 521 | bd->bi_brgfreq = gd->brg_clk; |
| 522 | bd->bi_sccfreq = gd->scc_clk; |
| 523 | bd->bi_vco = gd->vco_out; |
| 524 | #endif /* CONFIG_8260 */ |
| 525 | |
| 526 | bd->bi_baudrate = gd->baudrate; /* Console Baudrate */ |
| 527 | |
| 528 | #ifdef CFG_EXTBDINFO |
| 529 | strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version)); |
| 530 | strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version)); |
| 531 | |
| 532 | bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */ |
| 533 | bd->bi_plb_busfreq = gd->bus_clk; |
stroese | bedc497 | 2003-05-23 11:16:49 +0000 | [diff] [blame] | 534 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 535 | bd->bi_pci_busfreq = get_PCI_freq (); |
| 536 | #endif |
| 537 | #endif |
| 538 | |
| 539 | #ifdef DEBUG |
| 540 | printf ("New Stack Pointer is: %08lx\n", addr_sp); |
| 541 | #endif |
| 542 | |
| 543 | WATCHDOG_RESET (); |
| 544 | |
| 545 | #ifdef CONFIG_POST |
| 546 | post_bootmode_init(); |
| 547 | post_run (NULL, POST_ROM | post_bootmode_get(0)); |
| 548 | #endif |
| 549 | |
| 550 | WATCHDOG_RESET(); |
| 551 | |
| 552 | memcpy (id, gd, sizeof (gd_t)); |
| 553 | |
| 554 | relocate_code (addr_sp, id, addr); |
| 555 | |
| 556 | /* NOTREACHED - relocate_code() does not return */ |
| 557 | } |
| 558 | |
| 559 | |
| 560 | /************************************************************************ |
| 561 | * |
| 562 | * This is the next part if the initialization sequence: we are now |
| 563 | * running from RAM and have a "normal" C environment, i. e. global |
| 564 | * data can be written, BSS has been cleared, the stack size in not |
| 565 | * that critical any more, etc. |
| 566 | * |
| 567 | ************************************************************************ |
| 568 | */ |
| 569 | |
| 570 | void board_init_r (gd_t *id, ulong dest_addr) |
| 571 | { |
| 572 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 573 | cmd_tbl_t *cmdtp; |
| 574 | char *s, *e; |
| 575 | bd_t *bd; |
| 576 | int i; |
| 577 | extern void malloc_bin_reloc (void); |
| 578 | #ifndef CFG_ENV_IS_NOWHERE |
| 579 | extern char * env_name_spec; |
| 580 | #endif |
| 581 | |
| 582 | #ifndef CFG_NO_FLASH |
| 583 | ulong flash_size; |
| 584 | #endif |
| 585 | |
| 586 | gd = id; /* initialize RAM version of global data */ |
| 587 | bd = gd->bd; |
| 588 | |
| 589 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 590 | |
| 591 | #ifdef DEBUG |
| 592 | printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); |
| 593 | #endif |
| 594 | |
| 595 | WATCHDOG_RESET (); |
| 596 | |
| 597 | gd->reloc_off = dest_addr - CFG_MONITOR_BASE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 598 | |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 599 | monitor_flash_len = (ulong)&__init_end - dest_addr; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 600 | |
| 601 | /* |
| 602 | * We have to relocate the command table manually |
| 603 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 604 | for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 605 | ulong addr; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 606 | addr = (ulong) (cmdtp->cmd) + gd->reloc_off; |
| 607 | #if 0 |
| 608 | printf ("Command \"%s\": 0x%08lx => 0x%08lx\n", |
| 609 | cmdtp->name, (ulong) (cmdtp->cmd), addr); |
| 610 | #endif |
| 611 | cmdtp->cmd = |
| 612 | (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr; |
| 613 | |
| 614 | addr = (ulong)(cmdtp->name) + gd->reloc_off; |
| 615 | cmdtp->name = (char *)addr; |
| 616 | |
| 617 | if (cmdtp->usage) { |
| 618 | addr = (ulong)(cmdtp->usage) + gd->reloc_off; |
| 619 | cmdtp->usage = (char *)addr; |
| 620 | } |
| 621 | #ifdef CFG_LONGHELP |
| 622 | if (cmdtp->help) { |
| 623 | addr = (ulong)(cmdtp->help) + gd->reloc_off; |
| 624 | cmdtp->help = (char *)addr; |
| 625 | } |
| 626 | #endif |
| 627 | } |
| 628 | /* there are some other pointer constants we must deal with */ |
| 629 | #ifndef CFG_ENV_IS_NOWHERE |
| 630 | env_name_spec += gd->reloc_off; |
| 631 | #endif |
| 632 | |
| 633 | WATCHDOG_RESET (); |
| 634 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 635 | #ifdef CONFIG_LOGBUFFER |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 636 | logbuff_init_ptrs (); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 637 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 638 | #ifdef CONFIG_POST |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 639 | post_output_backlog (); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 640 | post_reloc (); |
| 641 | #endif |
| 642 | |
| 643 | WATCHDOG_RESET(); |
| 644 | |
| 645 | #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM) |
| 646 | icache_enable (); /* it's time to enable the instruction cache */ |
| 647 | #endif |
| 648 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 649 | #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 650 | /* |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 651 | * Do PCI configuration on BAB7xx and CPC45 _before_ the flash |
| 652 | * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus |
| 653 | * bridge there. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 654 | */ |
| 655 | pci_init (); |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 656 | #endif |
| 657 | #if defined(CONFIG_BAB7xx) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 658 | /* |
| 659 | * Initialise the ISA bridge |
| 660 | */ |
| 661 | initialise_w83c553f (); |
| 662 | #endif |
| 663 | |
| 664 | asm ("sync ; isync"); |
| 665 | |
| 666 | /* |
| 667 | * Setup trap handlers |
| 668 | */ |
| 669 | trap_init (dest_addr); |
| 670 | |
| 671 | #if !defined(CFG_NO_FLASH) |
| 672 | puts ("FLASH: "); |
| 673 | |
| 674 | if ((flash_size = flash_init ()) > 0) { |
| 675 | #ifdef CFG_FLASH_CHECKSUM |
| 676 | print_size (flash_size, ""); |
| 677 | /* |
| 678 | * Compute and print flash CRC if flashchecksum is set to 'y' |
| 679 | * |
| 680 | * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX |
| 681 | */ |
| 682 | s = getenv ("flashchecksum"); |
| 683 | if (s && (*s == 'y')) { |
| 684 | printf (" CRC: %08lX", |
| 685 | crc32 (0, |
| 686 | (const unsigned char *) CFG_FLASH_BASE, |
| 687 | flash_size) |
| 688 | ); |
| 689 | } |
| 690 | putc ('\n'); |
| 691 | #else |
| 692 | print_size (flash_size, "\n"); |
| 693 | #endif /* CFG_FLASH_CHECKSUM */ |
| 694 | } else { |
| 695 | puts (failed); |
| 696 | hang (); |
| 697 | } |
| 698 | |
| 699 | bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */ |
| 700 | bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */ |
| 701 | #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) |
| 702 | bd->bi_flashoffset = 0; |
| 703 | #elif CFG_MONITOR_BASE == CFG_FLASH_BASE |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 704 | bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 705 | #else |
| 706 | bd->bi_flashoffset = 0; |
| 707 | #endif |
| 708 | #else |
| 709 | |
| 710 | bd->bi_flashsize = 0; |
| 711 | bd->bi_flashstart = 0; |
| 712 | bd->bi_flashoffset = 0; |
| 713 | #endif /* !CFG_NO_FLASH */ |
| 714 | |
| 715 | WATCHDOG_RESET (); |
| 716 | |
| 717 | /* initialize higher level parts of CPU like time base and timers */ |
| 718 | cpu_init_r (); |
| 719 | |
| 720 | WATCHDOG_RESET (); |
| 721 | |
| 722 | /* initialize malloc() area */ |
| 723 | mem_malloc_init (); |
| 724 | malloc_bin_reloc (); |
| 725 | |
| 726 | #ifdef CONFIG_SPI |
| 727 | # if !defined(CFG_ENV_IS_IN_EEPROM) |
| 728 | spi_init_f (); |
| 729 | # endif |
| 730 | spi_init_r (); |
| 731 | #endif |
| 732 | |
| 733 | /* relocate environment function pointers etc. */ |
| 734 | env_relocate (); |
| 735 | |
| 736 | /* |
| 737 | * Fill in missing fields of bd_info. |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 738 | * We do this here, where we have "normal" access to the |
| 739 | * environment; we used to do this still running from ROM, |
| 740 | * where had to use getenv_r(), which can be pretty slow when |
| 741 | * the environment is in EEPROM. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 742 | */ |
| 743 | s = getenv ("ethaddr"); |
| 744 | #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210) |
| 745 | if (s == NULL) |
| 746 | board_get_enetaddr (bd->bi_enetaddr); |
| 747 | else |
| 748 | #endif |
| 749 | for (i = 0; i < 6; ++i) { |
| 750 | bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; |
| 751 | if (s) |
| 752 | s = (*e) ? e + 1 : e; |
| 753 | } |
| 754 | #ifdef CONFIG_HERMES |
| 755 | if ((gd->board_type >> 16) == 2) |
| 756 | bd->bi_ethspeed = gd->board_type & 0xFFFF; |
| 757 | else |
| 758 | bd->bi_ethspeed = 0xFFFF; |
| 759 | #endif |
| 760 | |
| 761 | #ifdef CONFIG_NX823 |
| 762 | load_sernum_ethaddr (); |
| 763 | #endif |
| 764 | |
| 765 | #if defined(CFG_GT_6426x) || defined(CONFIG_PN62) |
| 766 | /* handle the 2nd ethernet address */ |
| 767 | |
| 768 | s = getenv ("eth1addr"); |
| 769 | |
| 770 | for (i = 0; i < 6; ++i) { |
| 771 | bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0; |
| 772 | if (s) |
| 773 | s = (*e) ? e + 1 : e; |
| 774 | } |
| 775 | #endif |
| 776 | #if defined(CFG_GT_6426x) |
| 777 | /* handle the 3rd ethernet address */ |
| 778 | |
| 779 | s = getenv ("eth2addr"); |
| 780 | |
| 781 | for (i = 0; i < 6; ++i) { |
| 782 | bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0; |
| 783 | if (s) |
| 784 | s = (*e) ? e + 1 : e; |
| 785 | } |
| 786 | #endif |
| 787 | |
| 788 | |
| 789 | #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \ |
| 790 | defined(CONFIG_CCM) |
| 791 | load_sernum_ethaddr (); |
| 792 | #endif |
| 793 | /* IP Address */ |
| 794 | bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); |
| 795 | |
| 796 | WATCHDOG_RESET (); |
| 797 | |
| 798 | #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx) |
| 799 | /* |
| 800 | * Do pci configuration |
| 801 | */ |
| 802 | pci_init (); |
| 803 | #endif |
| 804 | |
| 805 | /** leave this here (after malloc(), environment and PCI are working) **/ |
| 806 | /* Initialize devices */ |
| 807 | devices_init (); |
| 808 | |
| 809 | /* allocate syscalls table (console_init_r will fill it in */ |
| 810 | syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *)); |
| 811 | |
| 812 | /* Initialize the console (after the relocation and devices init) */ |
| 813 | console_init_r (); |
| 814 | /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ |
| 815 | syscalls_init (); |
| 816 | |
| 817 | #if defined(CONFIG_CCM) || \ |
| 818 | defined(CONFIG_COGENT) || \ |
| 819 | defined(CONFIG_CPCI405) || \ |
| 820 | defined(CONFIG_EVB64260) || \ |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 821 | defined(CONFIG_KUP4K) || \ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 822 | defined(CONFIG_LWMON) || \ |
| 823 | defined(CONFIG_PCU_E) || \ |
| 824 | defined(CONFIG_W7O) || \ |
| 825 | defined(CONFIG_MISC_INIT_R) |
| 826 | /* miscellaneous platform dependent initialisations */ |
| 827 | misc_init_r (); |
| 828 | #endif |
| 829 | |
| 830 | #ifdef CONFIG_HERMES |
| 831 | if (bd->bi_ethspeed != 0xFFFF) |
| 832 | hermes_start_lxt980 ((int) bd->bi_ethspeed); |
| 833 | #endif |
| 834 | |
| 835 | #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \ |
| 836 | defined(CONFIG_CCM) || \ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 837 | defined(CONFIG_ELPT860) || \ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 838 | defined(CONFIG_EP8260) || \ |
| 839 | defined(CONFIG_IP860) || \ |
| 840 | defined(CONFIG_IVML24) || \ |
| 841 | defined(CONFIG_IVMS8) || \ |
| 842 | defined(CONFIG_LWMON) || \ |
| 843 | defined(CONFIG_MPC8260ADS) || \ |
wdenk | 5d232d0 | 2003-05-22 22:52:13 +0000 | [diff] [blame] | 844 | defined(CONFIG_MPC8266ADS) || \ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 845 | defined(CONFIG_PCU_E) || \ |
| 846 | defined(CONFIG_RPXSUPER) || \ |
| 847 | defined(CONFIG_SPD823TS) ) |
| 848 | |
| 849 | WATCHDOG_RESET (); |
| 850 | # ifdef DEBUG |
| 851 | puts ("Reset Ethernet PHY\n"); |
| 852 | # endif |
| 853 | reset_phy (); |
| 854 | #endif |
| 855 | |
| 856 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 857 | WATCHDOG_RESET (); |
| 858 | puts ("KGDB: "); |
| 859 | kgdb_init (); |
| 860 | #endif |
| 861 | |
| 862 | #ifdef DEBUG |
| 863 | printf ("U-Boot relocated to %08lx\n", dest_addr); |
| 864 | #endif |
| 865 | |
| 866 | /* |
| 867 | * Enable Interrupts |
| 868 | */ |
| 869 | interrupt_init (); |
| 870 | |
| 871 | /* Must happen after interrupts are initialized since |
| 872 | * an irq handler gets installed |
| 873 | */ |
| 874 | #ifdef CONFIG_SERIAL_SOFTWARE_FIFO |
| 875 | serial_buffered_init(); |
| 876 | #endif |
| 877 | |
| 878 | #ifdef CONFIG_STATUS_LED |
| 879 | status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING); |
| 880 | #endif |
| 881 | |
| 882 | udelay (20); |
| 883 | |
| 884 | set_timer (0); |
| 885 | |
| 886 | /* Insert function pointers now that we have relocated the code */ |
| 887 | |
| 888 | /* Initialize from environment */ |
| 889 | if ((s = getenv ("loadaddr")) != NULL) { |
| 890 | load_addr = simple_strtoul (s, NULL, 16); |
| 891 | } |
| 892 | #if (CONFIG_COMMANDS & CFG_CMD_NET) |
| 893 | if ((s = getenv ("bootfile")) != NULL) { |
| 894 | copy_filename (BootFile, s, sizeof (BootFile)); |
| 895 | } |
| 896 | #endif /* CFG_CMD_NET */ |
| 897 | |
| 898 | WATCHDOG_RESET (); |
| 899 | |
| 900 | #if (CONFIG_COMMANDS & CFG_CMD_SCSI) |
| 901 | WATCHDOG_RESET (); |
| 902 | puts ("SCSI: "); |
| 903 | scsi_init (); |
| 904 | #endif |
| 905 | |
| 906 | #if (CONFIG_COMMANDS & CFG_CMD_DOC) |
| 907 | WATCHDOG_RESET (); |
| 908 | puts ("DOC: "); |
| 909 | doc_init (); |
| 910 | #endif |
| 911 | |
stroese | bedc497 | 2003-05-23 11:16:49 +0000 | [diff] [blame] | 912 | #if (CONFIG_COMMANDS & CFG_CMD_NAND) |
| 913 | WATCHDOG_RESET (); |
| 914 | nand_init(); /* go init the NAND */ |
| 915 | #endif |
| 916 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 917 | #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) |
| 918 | WATCHDOG_RESET (); |
| 919 | puts ("Net: "); |
| 920 | eth_initialize (bd); |
| 921 | #endif |
| 922 | |
| 923 | #ifdef CONFIG_POST |
| 924 | post_run (NULL, POST_RAM | post_bootmode_get(0)); |
| 925 | if (post_bootmode_get(0) & POST_POWERFAIL) { |
| 926 | post_bootmode_clear(); |
| 927 | board_poweroff(); |
| 928 | } |
| 929 | #endif |
| 930 | |
| 931 | #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE) |
| 932 | WATCHDOG_RESET (); |
| 933 | puts ("PCMCIA:"); |
| 934 | pcmcia_init (); |
| 935 | #endif |
| 936 | |
| 937 | #if (CONFIG_COMMANDS & CFG_CMD_IDE) |
| 938 | WATCHDOG_RESET (); |
| 939 | # ifdef CONFIG_IDE_8xx_PCCARD |
| 940 | puts ("PCMCIA:"); |
| 941 | # else |
| 942 | puts ("IDE: "); |
| 943 | #endif |
| 944 | ide_init (); |
| 945 | #endif /* CFG_CMD_IDE */ |
| 946 | |
| 947 | #ifdef CONFIG_LAST_STAGE_INIT |
| 948 | WATCHDOG_RESET (); |
| 949 | /* |
| 950 | * Some parts can be only initialized if all others (like |
| 951 | * Interrupts) are up and running (i.e. the PC-style ISA |
| 952 | * keyboard). |
| 953 | */ |
| 954 | last_stage_init (); |
| 955 | #endif |
| 956 | |
| 957 | #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) |
| 958 | WATCHDOG_RESET (); |
| 959 | bedbug_init (); |
| 960 | #endif |
| 961 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 962 | #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 963 | /* |
| 964 | * Export available size of memory for Linux, |
| 965 | * taking into account the protected RAM at top of memory |
| 966 | */ |
| 967 | { |
| 968 | ulong pram; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 969 | uchar memsz[32]; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 970 | #ifdef CONFIG_PRAM |
| 971 | char *s; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 972 | |
| 973 | if ((s = getenv ("pram")) != NULL) { |
| 974 | pram = simple_strtoul (s, NULL, 10); |
| 975 | } else { |
| 976 | pram = CONFIG_PRAM; |
| 977 | } |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 978 | #else |
| 979 | pram=0; |
| 980 | #endif |
| 981 | #ifdef CONFIG_LOGBUFFER |
| 982 | /* Also take the logbuffer into account (pram is in kB) */ |
| 983 | pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024; |
| 984 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 985 | sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram); |
| 986 | setenv ("mem", memsz); |
| 987 | } |
| 988 | #endif |
| 989 | |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 990 | #ifdef CONFIG_MODEM_SUPPORT |
| 991 | { |
| 992 | extern int do_mdm_init; |
| 993 | do_mdm_init = gd->do_mdm_init; |
| 994 | } |
| 995 | #endif |
| 996 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 997 | /* Initialization complete - start the monitor */ |
| 998 | |
| 999 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
| 1000 | for (;;) { |
| 1001 | WATCHDOG_RESET (); |
| 1002 | main_loop (); |
| 1003 | } |
| 1004 | |
| 1005 | /* NOTREACHED - no way out of command loop except booting */ |
| 1006 | } |
| 1007 | |
| 1008 | void hang (void) |
| 1009 | { |
| 1010 | puts ("### ERROR ### Please RESET the board ###\n"); |
| 1011 | for (;;); |
| 1012 | } |
| 1013 | |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 1014 | #ifdef CONFIG_MODEM_SUPPORT |
| 1015 | /* called from main loop (common/main.c) */ |
| 1016 | extern void dbg(const char *fmt, ...); |
| 1017 | int mdm_init (void) |
| 1018 | { |
| 1019 | char env_str[16]; |
| 1020 | char *init_str; |
| 1021 | int i; |
| 1022 | extern char console_buffer[]; |
| 1023 | static inline void mdm_readline(char *buf, int bufsiz); |
| 1024 | extern void enable_putc(void); |
| 1025 | extern int hwflow_onoff(int); |
| 1026 | |
| 1027 | enable_putc(); /* enable serial_putc() */ |
| 1028 | |
| 1029 | #ifdef CONFIG_HWFLOW |
| 1030 | init_str = getenv("mdm_flow_control"); |
| 1031 | if (init_str && (strcmp(init_str, "rts/cts") == 0)) |
| 1032 | hwflow_onoff (1); |
| 1033 | else |
| 1034 | hwflow_onoff(-1); |
| 1035 | #endif |
| 1036 | |
| 1037 | for (i = 1;;i++) { |
| 1038 | sprintf(env_str, "mdm_init%d", i); |
| 1039 | if ((init_str = getenv(env_str)) != NULL) { |
| 1040 | serial_puts(init_str); |
| 1041 | serial_puts("\n"); |
| 1042 | for(;;) { |
| 1043 | mdm_readline(console_buffer, CFG_CBSIZE); |
| 1044 | dbg("ini%d: [%s]", i, console_buffer); |
| 1045 | |
| 1046 | if ((strcmp(console_buffer, "OK") == 0) || |
| 1047 | (strcmp(console_buffer, "ERROR") == 0)) { |
| 1048 | dbg("ini%d: cmd done", i); |
| 1049 | break; |
| 1050 | } else /* in case we are originating call ... */ |
| 1051 | if (strncmp(console_buffer, "CONNECT", 7) == 0) { |
| 1052 | dbg("ini%d: connect", i); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | } |
| 1056 | } else |
| 1057 | break; /* no init string - stop modem init */ |
| 1058 | |
| 1059 | udelay(100000); |
| 1060 | } |
| 1061 | |
| 1062 | udelay(100000); |
| 1063 | |
| 1064 | /* final stage - wait for connect */ |
| 1065 | for(;i > 1;) { /* if 'i' > 1 - wait for connection |
| 1066 | message from modem */ |
| 1067 | mdm_readline(console_buffer, CFG_CBSIZE); |
| 1068 | dbg("ini_f: [%s]", console_buffer); |
| 1069 | if (strncmp(console_buffer, "CONNECT", 7) == 0) { |
| 1070 | dbg("ini_f: connected"); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | /* 'inline' - We have to do it fast */ |
| 1079 | static inline void mdm_readline(char *buf, int bufsiz) |
| 1080 | { |
| 1081 | char c; |
| 1082 | char *p; |
| 1083 | int n; |
| 1084 | |
| 1085 | n = 0; |
| 1086 | p = buf; |
| 1087 | for(;;) { |
| 1088 | c = serial_getc(); |
| 1089 | |
| 1090 | /* dbg("(%c)", c); */ |
| 1091 | |
| 1092 | switch(c) { |
| 1093 | case '\r': |
| 1094 | break; |
| 1095 | case '\n': |
| 1096 | *p = '\0'; |
| 1097 | return; |
| 1098 | |
| 1099 | default: |
| 1100 | if(n++ > bufsiz) { |
| 1101 | *p = '\0'; |
| 1102 | return; /* sanity check */ |
| 1103 | } |
| 1104 | *p = c; |
| 1105 | p++; |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | #endif |
| 1111 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1112 | #if 0 /* We could use plain global data, but the resulting code is bigger */ |
| 1113 | /* |
| 1114 | * Pointer to initial global data area |
| 1115 | * |
| 1116 | * Here we initialize it. |
| 1117 | */ |
| 1118 | #undef XTRN_DECLARE_GLOBAL_DATA_PTR |
| 1119 | #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ |
| 1120 | DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET); |
| 1121 | #endif /* 0 */ |
| 1122 | |
| 1123 | /************************************************************************/ |