board.c 27 KB

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