board.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /*
  2. * (C) Copyright 2000-2010
  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 <stdio_dev.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 defined(CONFIG_CMD_IDE)
  38. #include <ide.h>
  39. #endif
  40. #if defined(CONFIG_CMD_SCSI)
  41. #include <scsi.h>
  42. #endif
  43. #if defined(CONFIG_CMD_KGDB)
  44. #include <kgdb.h>
  45. #endif
  46. #ifdef CONFIG_STATUS_LED
  47. #include <status_led.h>
  48. #endif
  49. #include <net.h>
  50. #ifdef CONFIG_GENERIC_MMC
  51. #include <mmc.h>
  52. #endif
  53. #include <serial.h>
  54. #ifdef CONFIG_SYS_ALLOC_DPRAM
  55. #if !defined(CONFIG_CPM2)
  56. #include <commproc.h>
  57. #endif
  58. #endif
  59. #include <version.h>
  60. #if defined(CONFIG_BAB7xx)
  61. #include <w83c553f.h>
  62. #endif
  63. #include <dtt.h>
  64. #if defined(CONFIG_POST)
  65. #include <post.h>
  66. #endif
  67. #if defined(CONFIG_LOGBUFFER)
  68. #include <logbuff.h>
  69. #endif
  70. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  71. #include <asm/cache.h>
  72. #endif
  73. #ifdef CONFIG_PS2KBD
  74. #include <keyboard.h>
  75. #endif
  76. #ifdef CONFIG_ADDR_MAP
  77. #include <asm/mmu.h>
  78. #endif
  79. #ifdef CONFIG_MP
  80. #include <asm/mp.h>
  81. #endif
  82. #ifdef CONFIG_BITBANGMII
  83. #include <miiphy.h>
  84. #endif
  85. #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
  86. extern int update_flash_size (int flash_size);
  87. #endif
  88. #if defined(CONFIG_SC3)
  89. extern void sc3_read_eeprom(void);
  90. #endif
  91. #if defined(CONFIG_CMD_DOC)
  92. void doc_init (void);
  93. #endif
  94. #if defined(CONFIG_HARD_I2C) || \
  95. defined(CONFIG_SOFT_I2C)
  96. #include <i2c.h>
  97. #endif
  98. #include <spi.h>
  99. #include <nand.h>
  100. static char *failed = "*** failed ***\n";
  101. #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  102. extern flash_info_t flash_info[];
  103. #endif
  104. #if defined(CONFIG_START_IDE)
  105. extern int board_start_ide(void);
  106. #endif
  107. #include <environment.h>
  108. DECLARE_GLOBAL_DATA_PTR;
  109. #if !defined(CONFIG_SYS_MEM_TOP_HIDE)
  110. #define CONFIG_SYS_MEM_TOP_HIDE 0
  111. #endif
  112. extern ulong __init_end;
  113. extern ulong __bss_end__;
  114. ulong monitor_flash_len;
  115. #if defined(CONFIG_CMD_BEDBUG)
  116. #include <bedbug/type.h>
  117. #endif
  118. /************************************************************************
  119. * Utilities *
  120. ************************************************************************
  121. */
  122. /*
  123. * All attempts to come up with a "common" initialization sequence
  124. * that works for all boards and architectures failed: some of the
  125. * requirements are just _too_ different. To get rid of the resulting
  126. * mess of board dependend #ifdef'ed code we now make the whole
  127. * initialization sequence configurable to the user.
  128. *
  129. * The requirements for any new initalization function is simple: it
  130. * receives a pointer to the "global data" structure as it's only
  131. * argument, and returns an integer return code, where 0 means
  132. * "continue" and != 0 means "fatal error, hang the system".
  133. */
  134. typedef int (init_fnc_t) (void);
  135. /************************************************************************
  136. * Init Utilities *
  137. ************************************************************************
  138. * Some of this code should be moved into the core functions,
  139. * but let's get it working (again) first...
  140. */
  141. static int init_baudrate (void)
  142. {
  143. char tmp[64]; /* long enough for environment variables */
  144. int i = getenv_f("baudrate", tmp, sizeof (tmp));
  145. gd->baudrate = (i > 0)
  146. ? (int) simple_strtoul (tmp, NULL, 10)
  147. : CONFIG_BAUDRATE;
  148. return (0);
  149. }
  150. /***********************************************************************/
  151. void __board_add_ram_info(int use_default)
  152. {
  153. /* please define platform specific board_add_ram_info() */
  154. }
  155. void board_add_ram_info(int) __attribute__((weak, alias("__board_add_ram_info")));
  156. int __board_flash_wp_on(void)
  157. {
  158. /*
  159. * Most flashes can't be detected when write protection is enabled,
  160. * so provide a way to let U-Boot gracefully ignore write protected
  161. * devices.
  162. */
  163. return 0;
  164. }
  165. int board_flash_wp_on(void) __attribute__((weak, alias("__board_flash_wp_on")));
  166. void __cpu_secondary_init_r(void)
  167. {
  168. }
  169. void cpu_secondary_init_r(void)
  170. __attribute__((weak, alias("__cpu_secondary_init_r")));
  171. static int init_func_ram (void)
  172. {
  173. #ifdef CONFIG_BOARD_TYPES
  174. int board_type = gd->board_type;
  175. #else
  176. int board_type = 0; /* use dummy arg */
  177. #endif
  178. puts ("DRAM: ");
  179. if ((gd->ram_size = initdram (board_type)) > 0) {
  180. print_size (gd->ram_size, "");
  181. board_add_ram_info(0);
  182. putc('\n');
  183. return (0);
  184. }
  185. puts (failed);
  186. return (1);
  187. }
  188. /***********************************************************************/
  189. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  190. static int init_func_i2c (void)
  191. {
  192. puts ("I2C: ");
  193. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  194. puts ("ready\n");
  195. return (0);
  196. }
  197. #endif
  198. #if defined(CONFIG_HARD_SPI)
  199. static int init_func_spi (void)
  200. {
  201. puts ("SPI: ");
  202. spi_init ();
  203. puts ("ready\n");
  204. return (0);
  205. }
  206. #endif
  207. /***********************************************************************/
  208. #if defined(CONFIG_WATCHDOG)
  209. static int init_func_watchdog_init (void)
  210. {
  211. puts (" Watchdog enabled\n");
  212. WATCHDOG_RESET ();
  213. return (0);
  214. }
  215. # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
  216. static int init_func_watchdog_reset (void)
  217. {
  218. WATCHDOG_RESET ();
  219. return (0);
  220. }
  221. # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
  222. #else
  223. # define INIT_FUNC_WATCHDOG_INIT /* undef */
  224. # define INIT_FUNC_WATCHDOG_RESET /* undef */
  225. #endif /* CONFIG_WATCHDOG */
  226. /************************************************************************
  227. * Initialization sequence *
  228. ************************************************************************
  229. */
  230. init_fnc_t *init_sequence[] = {
  231. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  232. probecpu,
  233. #endif
  234. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  235. board_early_init_f,
  236. #endif
  237. #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  238. get_clocks, /* get CPU and bus clocks (etc.) */
  239. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  240. && !defined(CONFIG_TQM885D)
  241. adjust_sdram_tbs_8xx,
  242. #endif
  243. init_timebase,
  244. #endif
  245. #ifdef CONFIG_SYS_ALLOC_DPRAM
  246. #if !defined(CONFIG_CPM2)
  247. dpram_init,
  248. #endif
  249. #endif
  250. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  251. board_postclk_init,
  252. #endif
  253. env_init,
  254. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  255. get_clocks_866, /* get CPU and bus clocks according to the environment variable */
  256. sdram_adjust_866, /* adjust sdram refresh rate according to the new clock */
  257. init_timebase,
  258. #endif
  259. init_baudrate,
  260. serial_init,
  261. console_init_f,
  262. display_options,
  263. #if defined(CONFIG_8260)
  264. prt_8260_rsr,
  265. prt_8260_clks,
  266. #endif /* CONFIG_8260 */
  267. #if defined(CONFIG_MPC83xx)
  268. prt_83xx_rsr,
  269. #endif
  270. checkcpu,
  271. #if defined(CONFIG_MPC5xxx)
  272. prt_mpc5xxx_clks,
  273. #endif /* CONFIG_MPC5xxx */
  274. #if defined(CONFIG_MPC8220)
  275. prt_mpc8220_clks,
  276. #endif
  277. checkboard,
  278. INIT_FUNC_WATCHDOG_INIT
  279. #if defined(CONFIG_MISC_INIT_F)
  280. misc_init_f,
  281. #endif
  282. INIT_FUNC_WATCHDOG_RESET
  283. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  284. init_func_i2c,
  285. #endif
  286. #if defined(CONFIG_HARD_SPI)
  287. init_func_spi,
  288. #endif
  289. #ifdef CONFIG_POST
  290. post_init_f,
  291. #endif
  292. INIT_FUNC_WATCHDOG_RESET
  293. init_func_ram,
  294. #if defined(CONFIG_SYS_DRAM_TEST)
  295. testdram,
  296. #endif /* CONFIG_SYS_DRAM_TEST */
  297. INIT_FUNC_WATCHDOG_RESET
  298. NULL, /* Terminate this list */
  299. };
  300. ulong get_effective_memsize(void)
  301. {
  302. #ifndef CONFIG_VERY_BIG_RAM
  303. return gd->ram_size;
  304. #else
  305. /* limit stack to what we can reasonable map */
  306. return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
  307. CONFIG_MAX_MEM_MAPPED : gd->ram_size);
  308. #endif
  309. }
  310. /************************************************************************
  311. *
  312. * This is the first part of the initialization sequence that is
  313. * implemented in C, but still running from ROM.
  314. *
  315. * The main purpose is to provide a (serial) console interface as
  316. * soon as possible (so we can see any error messages), and to
  317. * initialize the RAM so that we can relocate the monitor code to
  318. * RAM.
  319. *
  320. * Be aware of the restrictions: global data is read-only, BSS is not
  321. * initialized, and stack space is limited to a few kB.
  322. *
  323. ************************************************************************
  324. */
  325. #ifdef CONFIG_LOGBUFFER
  326. unsigned long logbuffer_base(void)
  327. {
  328. return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
  329. }
  330. #endif
  331. void board_init_f (ulong bootflag)
  332. {
  333. bd_t *bd;
  334. ulong len, addr, addr_sp;
  335. ulong *s;
  336. gd_t *id;
  337. init_fnc_t **init_fnc_ptr;
  338. #ifdef CONFIG_PRAM
  339. int i;
  340. ulong reg;
  341. uchar tmp[64]; /* long enough for environment variables */
  342. #endif
  343. /* Pointer is writable since we allocated a register for it */
  344. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  345. /* compiler optimization barrier needed for GCC >= 3.4 */
  346. __asm__ __volatile__("": : :"memory");
  347. #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
  348. !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
  349. !defined(CONFIG_MPC86xx)
  350. /* Clear initial global data */
  351. memset ((void *) gd, 0, sizeof (gd_t));
  352. #endif
  353. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  354. if ((*init_fnc_ptr) () != 0) {
  355. hang ();
  356. }
  357. }
  358. /*
  359. * Now that we have DRAM mapped and working, we can
  360. * relocate the code and continue running from DRAM.
  361. *
  362. * Reserve memory at end of RAM for (top down in that order):
  363. * - area that won't get touched by U-Boot and Linux (optional)
  364. * - kernel log buffer
  365. * - protected RAM
  366. * - LCD framebuffer
  367. * - monitor code
  368. * - board info struct
  369. */
  370. len = (ulong)&__bss_end__ - CONFIG_SYS_MONITOR_BASE;
  371. /*
  372. * Subtract specified amount of memory to hide so that it won't
  373. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  374. * the Linux kernel should now get passed the now "corrected"
  375. * memory size and won't touch it either. This should work
  376. * for arch/ppc and arch/powerpc. Only Linux board ports in
  377. * arch/powerpc with bootwrapper support, that recalculate the
  378. * memory size from the SDRAM controller setup will have to
  379. * get fixed.
  380. */
  381. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  382. addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
  383. #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
  384. /*
  385. * We need to make sure the location we intend to put secondary core
  386. * boot code is reserved and not used by any part of u-boot
  387. */
  388. if (addr > determine_mp_bootpg()) {
  389. addr = determine_mp_bootpg();
  390. debug ("Reserving MP boot page to %08lx\n", addr);
  391. }
  392. #endif
  393. #ifdef CONFIG_LOGBUFFER
  394. #ifndef CONFIG_ALT_LB_ADDR
  395. /* reserve kernel log buffer */
  396. addr -= (LOGBUFF_RESERVE);
  397. debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  398. #endif
  399. #endif
  400. #ifdef CONFIG_PRAM
  401. /*
  402. * reserve protected RAM
  403. */
  404. i = getenv_f("pram", (char *)tmp, sizeof (tmp));
  405. reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
  406. addr -= (reg << 10); /* size is in kB */
  407. debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  408. #endif /* CONFIG_PRAM */
  409. /* round down to next 4 kB limit */
  410. addr &= ~(4096 - 1);
  411. debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  412. #ifdef CONFIG_LCD
  413. #ifdef CONFIG_FB_ADDR
  414. gd->fb_base = CONFIG_FB_ADDR;
  415. #else
  416. /* reserve memory for LCD display (always full pages) */
  417. addr = lcd_setmem (addr);
  418. gd->fb_base = addr;
  419. #endif /* CONFIG_FB_ADDR */
  420. #endif /* CONFIG_LCD */
  421. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  422. /* reserve memory for video display (always full pages) */
  423. addr = video_setmem (addr);
  424. gd->fb_base = addr;
  425. #endif /* CONFIG_VIDEO */
  426. /*
  427. * reserve memory for U-Boot code, data & bss
  428. * round down to next 4 kB limit
  429. */
  430. addr -= len;
  431. addr &= ~(4096 - 1);
  432. #ifdef CONFIG_E500
  433. /* round down to next 64 kB limit so that IVPR stays aligned */
  434. addr &= ~(65536 - 1);
  435. #endif
  436. debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  437. /*
  438. * reserve memory for malloc() arena
  439. */
  440. addr_sp = addr - TOTAL_MALLOC_LEN;
  441. debug ("Reserving %dk for malloc() at: %08lx\n",
  442. TOTAL_MALLOC_LEN >> 10, addr_sp);
  443. /*
  444. * (permanently) allocate a Board Info struct
  445. * and a permanent copy of the "global" data
  446. */
  447. addr_sp -= sizeof (bd_t);
  448. bd = (bd_t *) addr_sp;
  449. memset(bd, 0, sizeof(bd_t));
  450. gd->bd = bd;
  451. debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
  452. sizeof (bd_t), addr_sp);
  453. addr_sp -= sizeof (gd_t);
  454. id = (gd_t *) addr_sp;
  455. debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
  456. sizeof (gd_t), addr_sp);
  457. /*
  458. * Finally, we set up a new (bigger) stack.
  459. *
  460. * Leave some safety gap for SP, force alignment on 16 byte boundary
  461. * Clear initial stack frame
  462. */
  463. addr_sp -= 16;
  464. addr_sp &= ~0xF;
  465. s = (ulong *)addr_sp;
  466. *s-- = 0;
  467. *s-- = 0;
  468. addr_sp = (ulong)s;
  469. debug ("Stack Pointer at: %08lx\n", addr_sp);
  470. /*
  471. * Save local variables to board info struct
  472. */
  473. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM memory */
  474. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  475. #ifdef CONFIG_SYS_SRAM_BASE
  476. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM memory */
  477. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM memory */
  478. #endif
  479. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
  480. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  481. bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
  482. #endif
  483. #if defined(CONFIG_MPC5xxx)
  484. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  485. #endif
  486. #if defined(CONFIG_MPC83xx)
  487. bd->bi_immrbar = CONFIG_SYS_IMMR;
  488. #endif
  489. #if defined(CONFIG_MPC8220)
  490. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  491. bd->bi_inpfreq = gd->inp_clk;
  492. bd->bi_pcifreq = gd->pci_clk;
  493. bd->bi_vcofreq = gd->vco_clk;
  494. bd->bi_pevfreq = gd->pev_clk;
  495. bd->bi_flbfreq = gd->flb_clk;
  496. /* store bootparam to sram (backward compatible), here? */
  497. {
  498. u32 *sram = (u32 *)CONFIG_SYS_SRAM_BASE;
  499. *sram++ = gd->ram_size;
  500. *sram++ = gd->bus_clk;
  501. *sram++ = gd->inp_clk;
  502. *sram++ = gd->cpu_clk;
  503. *sram++ = gd->vco_clk;
  504. *sram++ = gd->flb_clk;
  505. *sram++ = 0xb8c3ba11; /* boot signature */
  506. }
  507. #endif
  508. WATCHDOG_RESET ();
  509. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  510. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  511. #if defined(CONFIG_CPM2)
  512. bd->bi_cpmfreq = gd->cpm_clk;
  513. bd->bi_brgfreq = gd->brg_clk;
  514. bd->bi_sccfreq = gd->scc_clk;
  515. bd->bi_vco = gd->vco_out;
  516. #endif /* CONFIG_CPM2 */
  517. #if defined(CONFIG_MPC512X)
  518. bd->bi_ipsfreq = gd->ips_clk;
  519. #endif /* CONFIG_MPC512X */
  520. #if defined(CONFIG_MPC5xxx)
  521. bd->bi_ipbfreq = gd->ipb_clk;
  522. bd->bi_pcifreq = gd->pci_clk;
  523. #endif /* CONFIG_MPC5xxx */
  524. bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
  525. #ifdef CONFIG_SYS_EXTBDINFO
  526. strncpy ((char *)bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
  527. strncpy ((char *)bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
  528. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  529. bd->bi_plb_busfreq = gd->bus_clk;
  530. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  531. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  532. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  533. bd->bi_pci_busfreq = get_PCI_freq ();
  534. bd->bi_opbfreq = get_OPB_freq ();
  535. #elif defined(CONFIG_XILINX_405)
  536. bd->bi_pci_busfreq = get_PCI_freq ();
  537. #endif
  538. #endif
  539. debug ("New Stack Pointer is: %08lx\n", addr_sp);
  540. WATCHDOG_RESET ();
  541. #ifdef CONFIG_POST
  542. post_bootmode_init();
  543. post_run (NULL, POST_ROM | post_bootmode_get(0));
  544. #endif
  545. WATCHDOG_RESET();
  546. gd->relocaddr = addr; /* Record relocation address, useful for debug */
  547. memcpy (id, (void *)gd, sizeof (gd_t));
  548. relocate_code (addr_sp, id, addr);
  549. /* NOTREACHED - relocate_code() does not return */
  550. }
  551. /************************************************************************
  552. *
  553. * This is the next part if the initialization sequence: we are now
  554. * running from RAM and have a "normal" C environment, i. e. global
  555. * data can be written, BSS has been cleared, the stack size in not
  556. * that critical any more, etc.
  557. *
  558. ************************************************************************
  559. */
  560. void board_init_r (gd_t *id, ulong dest_addr)
  561. {
  562. char *s;
  563. bd_t *bd;
  564. ulong malloc_start;
  565. #ifndef CONFIG_SYS_NO_FLASH
  566. ulong flash_size;
  567. #endif
  568. gd = id; /* initialize RAM version of global data */
  569. bd = gd->bd;
  570. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  571. /* The Malloc area is immediately below the monitor copy in DRAM */
  572. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  573. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  574. /*
  575. * The gd->cpu pointer is set to an address in flash before relocation.
  576. * We need to update it to point to the same CPU entry in RAM.
  577. */
  578. gd->cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
  579. #endif
  580. #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
  581. /*
  582. * Some systems need to relocate the env_addr pointer early because the
  583. * location it points to will get invalidated before env_relocate is
  584. * called. One example is on systems that might use a L2 or L3 cache
  585. * in SRAM mode and initialize that cache from SRAM mode back to being
  586. * a cache in cpu_init_r.
  587. */
  588. gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
  589. #endif
  590. #ifdef CONFIG_SERIAL_MULTI
  591. serial_initialize();
  592. #endif
  593. debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  594. WATCHDOG_RESET ();
  595. /*
  596. * Setup trap handlers
  597. */
  598. trap_init (dest_addr);
  599. #ifdef CONFIG_ADDR_MAP
  600. init_addr_map();
  601. #endif
  602. #if defined(CONFIG_BOARD_EARLY_INIT_R)
  603. board_early_init_r ();
  604. #endif
  605. monitor_flash_len = (ulong)&__init_end - dest_addr;
  606. WATCHDOG_RESET ();
  607. #ifdef CONFIG_LOGBUFFER
  608. logbuff_init_ptrs ();
  609. #endif
  610. #ifdef CONFIG_POST
  611. post_output_backlog ();
  612. #endif
  613. WATCHDOG_RESET();
  614. #if defined(CONFIG_SYS_DELAYED_ICACHE)
  615. icache_enable (); /* it's time to enable the instruction cache */
  616. #endif
  617. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  618. unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
  619. #endif
  620. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
  621. /*
  622. * Do early PCI configuration _before_ the flash gets initialised,
  623. * because PCU ressources are crucial for flash access on some boards.
  624. */
  625. pci_init ();
  626. #endif
  627. #if defined(CONFIG_WINBOND_83C553)
  628. /*
  629. * Initialise the ISA bridge
  630. */
  631. initialise_w83c553f ();
  632. #endif
  633. asm ("sync ; isync");
  634. mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
  635. #if !defined(CONFIG_SYS_NO_FLASH)
  636. puts ("Flash: ");
  637. if (board_flash_wp_on()) {
  638. printf("Uninitialized - Write Protect On\n");
  639. /* Since WP is on, we can't find real size. Set to 0 */
  640. flash_size = 0;
  641. } else if ((flash_size = flash_init ()) > 0) {
  642. # ifdef CONFIG_SYS_FLASH_CHECKSUM
  643. print_size (flash_size, "");
  644. /*
  645. * Compute and print flash CRC if flashchecksum is set to 'y'
  646. *
  647. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  648. */
  649. s = getenv ("flashchecksum");
  650. if (s && (*s == 'y')) {
  651. printf (" CRC: %08X",
  652. crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
  653. );
  654. }
  655. putc ('\n');
  656. # else /* !CONFIG_SYS_FLASH_CHECKSUM */
  657. print_size (flash_size, "\n");
  658. # endif /* CONFIG_SYS_FLASH_CHECKSUM */
  659. } else {
  660. puts (failed);
  661. hang ();
  662. }
  663. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
  664. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  665. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  666. /* Make a update of the Memctrl. */
  667. update_flash_size (flash_size);
  668. #endif
  669. # if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  670. /* flash mapped at end of memory map */
  671. bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
  672. # elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
  673. bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
  674. # endif
  675. #endif /* !CONFIG_SYS_NO_FLASH */
  676. WATCHDOG_RESET ();
  677. /* initialize higher level parts of CPU like time base and timers */
  678. cpu_init_r ();
  679. WATCHDOG_RESET ();
  680. #ifdef CONFIG_SPI
  681. # if !defined(CONFIG_ENV_IS_IN_EEPROM)
  682. spi_init_f ();
  683. # endif
  684. spi_init_r ();
  685. #endif
  686. #if defined(CONFIG_CMD_NAND)
  687. WATCHDOG_RESET ();
  688. puts ("NAND: ");
  689. nand_init(); /* go init the NAND */
  690. #endif
  691. #ifdef CONFIG_GENERIC_MMC
  692. /*
  693. * MMC initialization is called before relocating env.
  694. * Thus It is required that operations like pin multiplexer
  695. * be put in board_init.
  696. */
  697. WATCHDOG_RESET ();
  698. puts ("MMC: ");
  699. mmc_initialize (bd);
  700. #endif
  701. /* relocate environment function pointers etc. */
  702. env_relocate ();
  703. /*
  704. * after non-volatile devices & environment is setup and cpu code have
  705. * another round to deal with any initialization that might require
  706. * full access to the environment or loading of some image (firmware)
  707. * from a non-volatile device
  708. */
  709. cpu_secondary_init_r();
  710. /*
  711. * Fill in missing fields of bd_info.
  712. * We do this here, where we have "normal" access to the
  713. * environment; we used to do this still running from ROM,
  714. * where had to use getenv_f(), which can be pretty slow when
  715. * the environment is in EEPROM.
  716. */
  717. #if defined(CONFIG_SYS_EXTBDINFO)
  718. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  719. #if defined(CONFIG_I2CFAST)
  720. /*
  721. * set bi_iic_fast for linux taking environment variable
  722. * "i2cfast" into account
  723. */
  724. {
  725. char *s = getenv ("i2cfast");
  726. if (s && ((*s == 'y') || (*s == 'Y'))) {
  727. bd->bi_iic_fast[0] = 1;
  728. bd->bi_iic_fast[1] = 1;
  729. }
  730. }
  731. #endif /* CONFIG_I2CFAST */
  732. #endif /* CONFIG_405GP, CONFIG_405EP */
  733. #endif /* CONFIG_SYS_EXTBDINFO */
  734. #if defined(CONFIG_SC3)
  735. sc3_read_eeprom();
  736. #endif
  737. #if defined (CONFIG_ID_EEPROM) || defined (CONFIG_SYS_I2C_MAC_OFFSET)
  738. mac_read_from_eeprom();
  739. #endif
  740. #ifdef CONFIG_HERMES
  741. if ((gd->board_type >> 16) == 2)
  742. bd->bi_ethspeed = gd->board_type & 0xFFFF;
  743. else
  744. bd->bi_ethspeed = 0xFFFF;
  745. #endif
  746. #ifdef CONFIG_CMD_NET
  747. /* kept around for legacy kernels only ... ignore the next section */
  748. eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
  749. #ifdef CONFIG_HAS_ETH1
  750. eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
  751. #endif
  752. #ifdef CONFIG_HAS_ETH2
  753. eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
  754. #endif
  755. #ifdef CONFIG_HAS_ETH3
  756. eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
  757. #endif
  758. #ifdef CONFIG_HAS_ETH4
  759. eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
  760. #endif
  761. #ifdef CONFIG_HAS_ETH5
  762. eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
  763. #endif
  764. #endif /* CONFIG_CMD_NET */
  765. /* IP Address */
  766. bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  767. WATCHDOG_RESET ();
  768. #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
  769. /*
  770. * Do pci configuration
  771. */
  772. pci_init ();
  773. #endif
  774. /** leave this here (after malloc(), environment and PCI are working) **/
  775. /* Initialize stdio devices */
  776. stdio_init ();
  777. /* Initialize the jump table for applications */
  778. jumptable_init ();
  779. #if defined(CONFIG_API)
  780. /* Initialize API */
  781. api_init ();
  782. #endif
  783. /* Initialize the console (after the relocation and devices init) */
  784. console_init_r ();
  785. #if defined(CONFIG_MISC_INIT_R)
  786. /* miscellaneous platform dependent initialisations */
  787. misc_init_r ();
  788. #endif
  789. #ifdef CONFIG_HERMES
  790. if (bd->bi_ethspeed != 0xFFFF)
  791. hermes_start_lxt980 ((int) bd->bi_ethspeed);
  792. #endif
  793. #if defined(CONFIG_CMD_KGDB)
  794. WATCHDOG_RESET ();
  795. puts ("KGDB: ");
  796. kgdb_init ();
  797. #endif
  798. debug ("U-Boot relocated to %08lx\n", dest_addr);
  799. /*
  800. * Enable Interrupts
  801. */
  802. interrupt_init ();
  803. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  804. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  805. #endif
  806. udelay (20);
  807. /* Initialize from environment */
  808. if ((s = getenv ("loadaddr")) != NULL) {
  809. load_addr = simple_strtoul (s, NULL, 16);
  810. }
  811. #if defined(CONFIG_CMD_NET)
  812. if ((s = getenv ("bootfile")) != NULL) {
  813. copy_filename (BootFile, s, sizeof (BootFile));
  814. }
  815. #endif
  816. WATCHDOG_RESET ();
  817. #if defined(CONFIG_CMD_SCSI)
  818. WATCHDOG_RESET ();
  819. puts ("SCSI: ");
  820. scsi_init ();
  821. #endif
  822. #if defined(CONFIG_CMD_DOC)
  823. WATCHDOG_RESET ();
  824. puts ("DOC: ");
  825. doc_init ();
  826. #endif
  827. #ifdef CONFIG_BITBANGMII
  828. bb_miiphy_init();
  829. #endif
  830. #if defined(CONFIG_CMD_NET)
  831. WATCHDOG_RESET ();
  832. puts ("Net: ");
  833. eth_initialize (bd);
  834. #endif
  835. #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
  836. WATCHDOG_RESET ();
  837. debug ("Reset Ethernet PHY\n");
  838. reset_phy ();
  839. #endif
  840. #ifdef CONFIG_POST
  841. post_run (NULL, POST_RAM | post_bootmode_get(0));
  842. #endif
  843. #if defined(CONFIG_CMD_PCMCIA) \
  844. && !defined(CONFIG_CMD_IDE)
  845. WATCHDOG_RESET ();
  846. puts ("PCMCIA:");
  847. pcmcia_init ();
  848. #endif
  849. #if defined(CONFIG_CMD_IDE)
  850. WATCHDOG_RESET ();
  851. # ifdef CONFIG_IDE_8xx_PCCARD
  852. puts ("PCMCIA:");
  853. # else
  854. puts ("IDE: ");
  855. #endif
  856. #if defined(CONFIG_START_IDE)
  857. if (board_start_ide())
  858. ide_init ();
  859. #else
  860. ide_init ();
  861. #endif
  862. #endif
  863. #ifdef CONFIG_LAST_STAGE_INIT
  864. WATCHDOG_RESET ();
  865. /*
  866. * Some parts can be only initialized if all others (like
  867. * Interrupts) are up and running (i.e. the PC-style ISA
  868. * keyboard).
  869. */
  870. last_stage_init ();
  871. #endif
  872. #if defined(CONFIG_CMD_BEDBUG)
  873. WATCHDOG_RESET ();
  874. bedbug_init ();
  875. #endif
  876. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  877. /*
  878. * Export available size of memory for Linux,
  879. * taking into account the protected RAM at top of memory
  880. */
  881. {
  882. ulong pram;
  883. uchar memsz[32];
  884. #ifdef CONFIG_PRAM
  885. char *s;
  886. if ((s = getenv ("pram")) != NULL) {
  887. pram = simple_strtoul (s, NULL, 10);
  888. } else {
  889. pram = CONFIG_PRAM;
  890. }
  891. #else
  892. pram=0;
  893. #endif
  894. #ifdef CONFIG_LOGBUFFER
  895. #ifndef CONFIG_ALT_LB_ADDR
  896. /* Also take the logbuffer into account (pram is in kB) */
  897. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  898. #endif
  899. #endif
  900. sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  901. setenv ("mem", (char *)memsz);
  902. }
  903. #endif
  904. #ifdef CONFIG_PS2KBD
  905. puts ("PS/2: ");
  906. kbd_init();
  907. #endif
  908. #ifdef CONFIG_MODEM_SUPPORT
  909. {
  910. extern int do_mdm_init;
  911. do_mdm_init = gd->do_mdm_init;
  912. }
  913. #endif
  914. /* Initialization complete - start the monitor */
  915. /* main_loop() can return to retry autoboot, if so just run it again. */
  916. for (;;) {
  917. WATCHDOG_RESET ();
  918. main_loop ();
  919. }
  920. /* NOTREACHED - no way out of command loop except booting */
  921. }
  922. void hang (void)
  923. {
  924. puts ("### ERROR ### Please RESET the board ###\n");
  925. show_boot_progress(-30);
  926. for (;;);
  927. }
  928. #if 0 /* We could use plain global data, but the resulting code is bigger */
  929. /*
  930. * Pointer to initial global data area
  931. *
  932. * Here we initialize it.
  933. */
  934. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  935. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  936. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  937. #endif /* 0 */
  938. /************************************************************************/