board.c 28 KB

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