board.c 26 KB

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