board.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /*
  2. * (C) Copyright 2000-2011
  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. * All attempts to come up with a "common" initialization sequence
  123. * that works for all boards and architectures failed: some of the
  124. * requirements are just _too_ different. To get rid of the resulting
  125. * mess of board dependend #ifdef'ed code we now make the whole
  126. * initialization sequence configurable to the user.
  127. *
  128. * The requirements for any new initalization function is simple: it
  129. * receives a pointer to the "global data" structure as it's only
  130. * argument, and returns an integer return code, where 0 means
  131. * "continue" and != 0 means "fatal error, hang the system".
  132. */
  133. typedef int (init_fnc_t)(void);
  134. /*
  135. * Init Utilities
  136. *
  137. * Some of this code should be moved into the core functions,
  138. * but let's get it working (again) first...
  139. */
  140. static int init_baudrate(void)
  141. {
  142. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  143. return 0;
  144. }
  145. /***********************************************************************/
  146. void __board_add_ram_info(int use_default)
  147. {
  148. /* please define platform specific board_add_ram_info() */
  149. }
  150. void board_add_ram_info(int)
  151. __attribute__ ((weak, alias("__board_add_ram_info")));
  152. int __board_flash_wp_on(void)
  153. {
  154. /*
  155. * Most flashes can't be detected when write protection is enabled,
  156. * so provide a way to let U-Boot gracefully ignore write protected
  157. * devices.
  158. */
  159. return 0;
  160. }
  161. int board_flash_wp_on(void)
  162. __attribute__ ((weak, alias("__board_flash_wp_on")));
  163. void __cpu_secondary_init_r(void)
  164. {
  165. }
  166. void cpu_secondary_init_r(void)
  167. __attribute__ ((weak, alias("__cpu_secondary_init_r")));
  168. static int init_func_ram(void)
  169. {
  170. #ifdef CONFIG_BOARD_TYPES
  171. int board_type = gd->board_type;
  172. #else
  173. int board_type = 0; /* use dummy arg */
  174. #endif
  175. puts("DRAM: ");
  176. gd->ram_size = initdram(board_type);
  177. if (gd->ram_size > 0) {
  178. print_size(gd->ram_size, "");
  179. board_add_ram_info(0);
  180. putc('\n');
  181. return 0;
  182. }
  183. puts(failed);
  184. return 1;
  185. }
  186. /***********************************************************************/
  187. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  188. static int init_func_i2c(void)
  189. {
  190. puts("I2C: ");
  191. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  192. puts("ready\n");
  193. return 0;
  194. }
  195. #endif
  196. #if defined(CONFIG_HARD_SPI)
  197. static int init_func_spi(void)
  198. {
  199. puts("SPI: ");
  200. spi_init();
  201. puts("ready\n");
  202. return 0;
  203. }
  204. #endif
  205. /***********************************************************************/
  206. #if defined(CONFIG_WATCHDOG)
  207. static int init_func_watchdog_init(void)
  208. {
  209. puts(" Watchdog enabled\n");
  210. WATCHDOG_RESET();
  211. return 0;
  212. }
  213. #define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
  214. static int init_func_watchdog_reset(void)
  215. {
  216. WATCHDOG_RESET();
  217. return 0;
  218. }
  219. #define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
  220. #else
  221. #define INIT_FUNC_WATCHDOG_INIT /* undef */
  222. #define INIT_FUNC_WATCHDOG_RESET /* undef */
  223. #endif /* CONFIG_WATCHDOG */
  224. /*
  225. * Initialization sequence
  226. */
  227. init_fnc_t *init_sequence[] = {
  228. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  229. probecpu,
  230. #endif
  231. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  232. board_early_init_f,
  233. #endif
  234. #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  235. get_clocks, /* get CPU and bus clocks (etc.) */
  236. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  237. && !defined(CONFIG_TQM885D)
  238. adjust_sdram_tbs_8xx,
  239. #endif
  240. init_timebase,
  241. #endif
  242. #ifdef CONFIG_SYS_ALLOC_DPRAM
  243. #if !defined(CONFIG_CPM2)
  244. dpram_init,
  245. #endif
  246. #endif
  247. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  248. board_postclk_init,
  249. #endif
  250. env_init,
  251. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  252. /* get CPU and bus clocks according to the environment variable */
  253. get_clocks_866,
  254. /* adjust sdram refresh rate according to the new clock */
  255. sdram_adjust_866,
  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. prt_83xx_rsr,
  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_HARD_SPI)
  286. init_func_spi,
  287. #endif
  288. #ifdef CONFIG_POST
  289. post_init_f,
  290. #endif
  291. INIT_FUNC_WATCHDOG_RESET init_func_ram,
  292. #if defined(CONFIG_SYS_DRAM_TEST)
  293. testdram,
  294. #endif /* CONFIG_SYS_DRAM_TEST */
  295. INIT_FUNC_WATCHDOG_RESET
  296. NULL, /* Terminate this list */
  297. };
  298. ulong get_effective_memsize(void)
  299. {
  300. #ifndef CONFIG_VERY_BIG_RAM
  301. return gd->ram_size;
  302. #else
  303. /* limit stack to what we can reasonable map */
  304. return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
  305. CONFIG_MAX_MEM_MAPPED : gd->ram_size);
  306. #endif
  307. }
  308. int __fixup_cpu(void)
  309. {
  310. return 0;
  311. }
  312. int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
  313. /*
  314. * This is the first part of the initialization sequence that is
  315. * implemented in C, but still running from ROM.
  316. *
  317. * The main purpose is to provide a (serial) console interface as
  318. * soon as possible (so we can see any error messages), and to
  319. * initialize the RAM so that we can relocate the monitor code to
  320. * RAM.
  321. *
  322. * Be aware of the restrictions: global data is read-only, BSS is not
  323. * initialized, and stack space is limited to a few kB.
  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. ulong reg;
  340. #endif
  341. /* Pointer is writable since we allocated a register for it */
  342. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  343. /* compiler optimization barrier needed for GCC >= 3.4 */
  344. __asm__ __volatile__("":::"memory");
  345. #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
  346. !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
  347. !defined(CONFIG_MPC86xx)
  348. /* Clear initial global data */
  349. memset((void *) gd, 0, sizeof(gd_t));
  350. #endif
  351. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
  352. if ((*init_fnc_ptr) () != 0)
  353. hang();
  354. #ifdef CONFIG_POST
  355. post_bootmode_init();
  356. post_run(NULL, POST_ROM | post_bootmode_get(0));
  357. #endif
  358. WATCHDOG_RESET();
  359. /*
  360. * Now that we have DRAM mapped and working, we can
  361. * relocate the code and continue running from DRAM.
  362. *
  363. * Reserve memory at end of RAM for (top down in that order):
  364. * - area that won't get touched by U-Boot and Linux (optional)
  365. * - kernel log buffer
  366. * - protected RAM
  367. * - LCD framebuffer
  368. * - monitor code
  369. * - board info struct
  370. */
  371. len = (ulong)&__bss_end__ - CONFIG_SYS_MONITOR_BASE;
  372. /*
  373. * Subtract specified amount of memory to hide so that it won't
  374. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  375. * the Linux kernel should now get passed the now "corrected"
  376. * memory size and won't touch it either. This should work
  377. * for arch/ppc and arch/powerpc. Only Linux board ports in
  378. * arch/powerpc with bootwrapper support, that recalculate the
  379. * memory size from the SDRAM controller setup will have to
  380. * get fixed.
  381. */
  382. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  383. addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
  384. #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
  385. /*
  386. * We need to make sure the location we intend to put secondary core
  387. * boot code is reserved and not used by any part of u-boot
  388. */
  389. if (addr > determine_mp_bootpg()) {
  390. addr = determine_mp_bootpg();
  391. debug("Reserving MP boot page to %08lx\n", addr);
  392. }
  393. #endif
  394. #ifdef CONFIG_LOGBUFFER
  395. #ifndef CONFIG_ALT_LB_ADDR
  396. /* reserve kernel log buffer */
  397. addr -= (LOGBUFF_RESERVE);
  398. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  399. addr);
  400. #endif
  401. #endif
  402. #ifdef CONFIG_PRAM
  403. /*
  404. * reserve protected RAM
  405. */
  406. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  407. addr -= (reg << 10); /* size is in kB */
  408. debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  409. #endif /* CONFIG_PRAM */
  410. /* round down to next 4 kB limit */
  411. addr &= ~(4096 - 1);
  412. debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
  413. #ifdef CONFIG_LCD
  414. #ifdef CONFIG_FB_ADDR
  415. gd->fb_base = CONFIG_FB_ADDR;
  416. #else
  417. /* reserve memory for LCD display (always full pages) */
  418. addr = lcd_setmem(addr);
  419. gd->fb_base = addr;
  420. #endif /* CONFIG_FB_ADDR */
  421. #endif /* CONFIG_LCD */
  422. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  423. /* reserve memory for video display (always full pages) */
  424. addr = video_setmem(addr);
  425. gd->fb_base = addr;
  426. #endif /* CONFIG_VIDEO */
  427. /*
  428. * reserve memory for U-Boot code, data & bss
  429. * round down to next 4 kB limit
  430. */
  431. addr -= len;
  432. addr &= ~(4096 - 1);
  433. #ifdef CONFIG_E500
  434. /* round down to next 64 kB limit so that IVPR stays aligned */
  435. addr &= ~(65536 - 1);
  436. #endif
  437. debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  438. /*
  439. * reserve memory for malloc() arena
  440. */
  441. addr_sp = addr - TOTAL_MALLOC_LEN;
  442. debug("Reserving %dk for malloc() at: %08lx\n",
  443. TOTAL_MALLOC_LEN >> 10, addr_sp);
  444. /*
  445. * (permanently) allocate a Board Info struct
  446. * and a permanent copy of the "global" data
  447. */
  448. addr_sp -= sizeof(bd_t);
  449. bd = (bd_t *) addr_sp;
  450. memset(bd, 0, sizeof(bd_t));
  451. gd->bd = bd;
  452. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  453. sizeof(bd_t), addr_sp);
  454. addr_sp -= sizeof(gd_t);
  455. id = (gd_t *) addr_sp;
  456. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  457. sizeof(gd_t), addr_sp);
  458. /*
  459. * Finally, we set up a new (bigger) stack.
  460. *
  461. * Leave some safety gap for SP, force alignment on 16 byte boundary
  462. * Clear initial stack frame
  463. */
  464. addr_sp -= 16;
  465. addr_sp &= ~0xF;
  466. s = (ulong *) addr_sp;
  467. *s = 0; /* Terminate back chain */
  468. *++s = 0; /* NULL return address */
  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 memory */
  474. bd->bi_memsize = gd->ram_size; /* size in bytes */
  475. #ifdef CONFIG_SYS_SRAM_BASE
  476. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
  477. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
  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,
  528. sizeof(bd->bi_r_version));
  529. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  530. bd->bi_plb_busfreq = gd->bus_clk;
  531. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  532. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  533. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  534. bd->bi_pci_busfreq = get_PCI_freq();
  535. bd->bi_opbfreq = get_OPB_freq();
  536. #elif defined(CONFIG_XILINX_405)
  537. bd->bi_pci_busfreq = get_PCI_freq();
  538. #endif
  539. #endif
  540. debug("New Stack Pointer is: %08lx\n", addr_sp);
  541. WATCHDOG_RESET();
  542. gd->relocaddr = addr; /* Store relocation addr, useful for debug */
  543. memcpy(id, (void *) gd, sizeof(gd_t));
  544. relocate_code(addr_sp, id, addr);
  545. /* NOTREACHED - relocate_code() does not return */
  546. }
  547. /*
  548. * This is the next part if the initialization sequence: we are now
  549. * running from RAM and have a "normal" C environment, i. e. global
  550. * data can be written, BSS has been cleared, the stack size in not
  551. * that critical any more, etc.
  552. */
  553. void board_init_r(gd_t *id, ulong dest_addr)
  554. {
  555. bd_t *bd;
  556. ulong malloc_start;
  557. #ifndef CONFIG_SYS_NO_FLASH
  558. ulong flash_size;
  559. #endif
  560. gd = id; /* initialize RAM version of global data */
  561. bd = gd->bd;
  562. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  563. /* The Malloc area is immediately below the monitor copy in DRAM */
  564. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  565. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  566. /*
  567. * The gd->cpu pointer is set to an address in flash before relocation.
  568. * We need to update it to point to the same CPU entry in RAM.
  569. */
  570. gd->cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
  571. /*
  572. * If we didn't know the cpu mask & # cores, we can save them of
  573. * now rather than 'computing' them constantly
  574. */
  575. fixup_cpu();
  576. #endif
  577. #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
  578. /*
  579. * Some systems need to relocate the env_addr pointer early because the
  580. * location it points to will get invalidated before env_relocate is
  581. * called. One example is on systems that might use a L2 or L3 cache
  582. * in SRAM mode and initialize that cache from SRAM mode back to being
  583. * a cache in cpu_init_r.
  584. */
  585. gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
  586. #endif
  587. #ifdef CONFIG_SERIAL_MULTI
  588. serial_initialize();
  589. #endif
  590. debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  591. WATCHDOG_RESET();
  592. /*
  593. * Setup trap handlers
  594. */
  595. trap_init(dest_addr);
  596. #ifdef CONFIG_ADDR_MAP
  597. init_addr_map();
  598. #endif
  599. #if defined(CONFIG_BOARD_EARLY_INIT_R)
  600. board_early_init_r();
  601. #endif
  602. monitor_flash_len = (ulong)&__init_end - dest_addr;
  603. WATCHDOG_RESET();
  604. #ifdef CONFIG_LOGBUFFER
  605. logbuff_init_ptrs();
  606. #endif
  607. #ifdef CONFIG_POST
  608. post_output_backlog();
  609. #endif
  610. WATCHDOG_RESET();
  611. #if defined(CONFIG_SYS_DELAYED_ICACHE)
  612. icache_enable(); /* it's time to enable the instruction cache */
  613. #endif
  614. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  615. unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
  616. #endif
  617. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
  618. /*
  619. * Do early PCI configuration _before_ the flash gets initialised,
  620. * because PCU ressources are crucial for flash access on some boards.
  621. */
  622. pci_init();
  623. #endif
  624. #if defined(CONFIG_WINBOND_83C553)
  625. /*
  626. * Initialise the ISA bridge
  627. */
  628. initialise_w83c553f();
  629. #endif
  630. asm("sync ; isync");
  631. mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
  632. #if !defined(CONFIG_SYS_NO_FLASH)
  633. puts("Flash: ");
  634. if (board_flash_wp_on()) {
  635. printf("Uninitialized - Write Protect On\n");
  636. /* Since WP is on, we can't find real size. Set to 0 */
  637. flash_size = 0;
  638. } else if ((flash_size = flash_init()) > 0) {
  639. #ifdef CONFIG_SYS_FLASH_CHECKSUM
  640. char *s;
  641. print_size(flash_size, "");
  642. /*
  643. * Compute and print flash CRC if flashchecksum is set to 'y'
  644. *
  645. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  646. */
  647. s = getenv("flashchecksum");
  648. if (s && (*s == 'y')) {
  649. printf(" CRC: %08X",
  650. crc32(0,
  651. (const unsigned char *)
  652. 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. /* update start of FLASH memory */
  664. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  665. /* size of FLASH memory (final value) */
  666. bd->bi_flashsize = flash_size;
  667. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  668. /* Make a update of the Memctrl. */
  669. update_flash_size(flash_size);
  670. #endif
  671. #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  672. /* flash mapped at end of memory map */
  673. bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
  674. #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
  675. bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
  676. #endif
  677. #endif /* !CONFIG_SYS_NO_FLASH */
  678. WATCHDOG_RESET();
  679. /* initialize higher level parts of CPU like time base and timers */
  680. cpu_init_r();
  681. WATCHDOG_RESET();
  682. #ifdef CONFIG_SPI
  683. #if !defined(CONFIG_ENV_IS_IN_EEPROM)
  684. spi_init_f();
  685. #endif
  686. spi_init_r();
  687. #endif
  688. #if defined(CONFIG_CMD_NAND)
  689. WATCHDOG_RESET();
  690. puts("NAND: ");
  691. nand_init(); /* go init the NAND */
  692. #endif
  693. #ifdef CONFIG_GENERIC_MMC
  694. /*
  695. * MMC initialization is called before relocating env.
  696. * Thus It is required that operations like pin multiplexer
  697. * be put in board_init.
  698. */
  699. WATCHDOG_RESET();
  700. puts("MMC: ");
  701. mmc_initialize(bd);
  702. #endif
  703. /* relocate environment function pointers etc. */
  704. env_relocate();
  705. /*
  706. * after non-volatile devices & environment is setup and cpu code have
  707. * another round to deal with any initialization that might require
  708. * full access to the environment or loading of some image (firmware)
  709. * from a non-volatile device
  710. */
  711. cpu_secondary_init_r();
  712. /*
  713. * Fill in missing fields of bd_info.
  714. * We do this here, where we have "normal" access to the
  715. * environment; we used to do this still running from ROM,
  716. * where had to use getenv_f(), which can be pretty slow when
  717. * the environment is in EEPROM.
  718. */
  719. #if defined(CONFIG_SYS_EXTBDINFO)
  720. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  721. #if defined(CONFIG_I2CFAST)
  722. /*
  723. * set bi_iic_fast for linux taking environment variable
  724. * "i2cfast" into account
  725. */
  726. {
  727. char *s = getenv("i2cfast");
  728. if (s && ((*s == 'y') || (*s == 'Y'))) {
  729. bd->bi_iic_fast[0] = 1;
  730. bd->bi_iic_fast[1] = 1;
  731. }
  732. }
  733. #endif /* CONFIG_I2CFAST */
  734. #endif /* CONFIG_405GP, CONFIG_405EP */
  735. #endif /* CONFIG_SYS_EXTBDINFO */
  736. #if defined(CONFIG_SC3)
  737. sc3_read_eeprom();
  738. #endif
  739. #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
  740. mac_read_from_eeprom();
  741. #endif
  742. #ifdef CONFIG_HERMES
  743. if ((gd->board_type >> 16) == 2)
  744. bd->bi_ethspeed = gd->board_type & 0xFFFF;
  745. else
  746. bd->bi_ethspeed = 0xFFFF;
  747. #endif
  748. #ifdef CONFIG_CMD_NET
  749. /* kept around for legacy kernels only ... ignore the next section */
  750. eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
  751. #ifdef CONFIG_HAS_ETH1
  752. eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
  753. #endif
  754. #ifdef CONFIG_HAS_ETH2
  755. eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
  756. #endif
  757. #ifdef CONFIG_HAS_ETH3
  758. eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
  759. #endif
  760. #ifdef CONFIG_HAS_ETH4
  761. eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
  762. #endif
  763. #ifdef CONFIG_HAS_ETH5
  764. eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
  765. #endif
  766. #endif /* CONFIG_CMD_NET */
  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. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  809. WATCHDOG_RESET();
  810. #if defined(CONFIG_CMD_SCSI)
  811. WATCHDOG_RESET();
  812. puts("SCSI: ");
  813. scsi_init();
  814. #endif
  815. #if defined(CONFIG_CMD_DOC)
  816. WATCHDOG_RESET();
  817. puts("DOC: ");
  818. doc_init();
  819. #endif
  820. #ifdef CONFIG_BITBANGMII
  821. bb_miiphy_init();
  822. #endif
  823. #if defined(CONFIG_CMD_NET)
  824. WATCHDOG_RESET();
  825. puts("Net: ");
  826. eth_initialize(bd);
  827. #endif
  828. #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
  829. WATCHDOG_RESET();
  830. debug("Reset Ethernet PHY\n");
  831. reset_phy();
  832. #endif
  833. #ifdef CONFIG_POST
  834. post_run(NULL, POST_RAM | post_bootmode_get(0));
  835. #endif
  836. #if defined(CONFIG_CMD_PCMCIA) \
  837. && !defined(CONFIG_CMD_IDE)
  838. WATCHDOG_RESET();
  839. puts("PCMCIA:");
  840. pcmcia_init();
  841. #endif
  842. #if defined(CONFIG_CMD_IDE)
  843. WATCHDOG_RESET();
  844. #ifdef CONFIG_IDE_8xx_PCCARD
  845. puts("PCMCIA:");
  846. #else
  847. puts("IDE: ");
  848. #endif
  849. #if defined(CONFIG_START_IDE)
  850. if (board_start_ide())
  851. ide_init();
  852. #else
  853. ide_init();
  854. #endif
  855. #endif
  856. #ifdef CONFIG_LAST_STAGE_INIT
  857. WATCHDOG_RESET();
  858. /*
  859. * Some parts can be only initialized if all others (like
  860. * Interrupts) are up and running (i.e. the PC-style ISA
  861. * keyboard).
  862. */
  863. last_stage_init();
  864. #endif
  865. #if defined(CONFIG_CMD_BEDBUG)
  866. WATCHDOG_RESET();
  867. bedbug_init();
  868. #endif
  869. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  870. /*
  871. * Export available size of memory for Linux,
  872. * taking into account the protected RAM at top of memory
  873. */
  874. {
  875. ulong pram = 0;
  876. char memsz[32];
  877. #ifdef CONFIG_PRAM
  878. pram = getenv_ulong("pram", 10, CONFIG_PRAM);
  879. #endif
  880. #ifdef CONFIG_LOGBUFFER
  881. #ifndef CONFIG_ALT_LB_ADDR
  882. /* Also take the logbuffer into account (pram is in kB) */
  883. pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
  884. #endif
  885. #endif
  886. sprintf(memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  887. setenv("mem", memsz);
  888. }
  889. #endif
  890. #ifdef CONFIG_PS2KBD
  891. puts("PS/2: ");
  892. kbd_init();
  893. #endif
  894. #ifdef CONFIG_MODEM_SUPPORT
  895. {
  896. extern int do_mdm_init;
  897. do_mdm_init = gd->do_mdm_init;
  898. }
  899. #endif
  900. /* Initialization complete - start the monitor */
  901. /* main_loop() can return to retry autoboot, if so just run it again. */
  902. for (;;) {
  903. WATCHDOG_RESET();
  904. main_loop();
  905. }
  906. /* NOTREACHED - no way out of command loop except booting */
  907. }
  908. void hang(void)
  909. {
  910. puts("### ERROR ### Please RESET the board ###\n");
  911. bootstage_error(BOOTSTAGE_ID_NEED_RESET);
  912. for (;;)
  913. ;
  914. }
  915. #if 0 /* We could use plain global data, but the resulting code is bigger */
  916. /*
  917. * Pointer to initial global data area
  918. *
  919. * Here we initialize it.
  920. */
  921. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  922. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  923. DECLARE_GLOBAL_DATA_PTR =
  924. (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  925. #endif /* 0 */
  926. /************************************************************************/