board.c 28 KB

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