board.c 28 KB

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