board.c 26 KB

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