board.c 28 KB

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