board.c 26 KB

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