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