board.c 28 KB

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