board.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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 <devices.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. #include <serial.h>
  51. #ifdef CFG_ALLOC_DPRAM
  52. #if !defined(CONFIG_CPM2)
  53. #include <commproc.h>
  54. #endif
  55. #endif
  56. #include <version.h>
  57. #if defined(CONFIG_BAB7xx)
  58. #include <w83c553f.h>
  59. #endif
  60. #include <dtt.h>
  61. #if defined(CONFIG_POST)
  62. #include <post.h>
  63. #endif
  64. #if defined(CONFIG_LOGBUFFER)
  65. #include <logbuff.h>
  66. #endif
  67. #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
  68. #include <asm/cache.h>
  69. #endif
  70. #ifdef CONFIG_PS2KBD
  71. #include <keyboard.h>
  72. #endif
  73. #ifdef CFG_UPDATE_FLASH_SIZE
  74. extern int update_flash_size (int flash_size);
  75. #endif
  76. #if defined(CONFIG_SC3)
  77. extern void sc3_read_eeprom(void);
  78. #endif
  79. #if defined(CONFIG_CMD_DOC)
  80. void doc_init (void);
  81. #endif
  82. #if defined(CONFIG_HARD_I2C) || \
  83. defined(CONFIG_SOFT_I2C)
  84. #include <i2c.h>
  85. #endif
  86. #if defined(CONFIG_CMD_NAND)
  87. void nand_init (void);
  88. #endif
  89. static char *failed = "*** failed ***\n";
  90. #if defined(CONFIG_OXC) || defined(CONFIG_PCU_E) || defined(CONFIG_RMU)
  91. extern flash_info_t flash_info[];
  92. #endif
  93. #if defined(CONFIG_START_IDE)
  94. extern int board_start_ide(void);
  95. #endif
  96. #include <environment.h>
  97. DECLARE_GLOBAL_DATA_PTR;
  98. #if defined(CFG_ENV_IS_EMBEDDED)
  99. #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
  100. #elif ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
  101. (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
  102. defined(CFG_ENV_IS_IN_NVRAM)
  103. #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
  104. #else
  105. #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
  106. #endif
  107. extern ulong __init_end;
  108. extern ulong _end;
  109. ulong monitor_flash_len;
  110. #if defined(CONFIG_CMD_BEDBUG)
  111. #include <bedbug/type.h>
  112. #endif
  113. /*
  114. * Begin and End of memory area for malloc(), and current "brk"
  115. */
  116. static ulong mem_malloc_start = 0;
  117. static ulong mem_malloc_end = 0;
  118. static ulong mem_malloc_brk = 0;
  119. /************************************************************************
  120. * Utilities *
  121. ************************************************************************
  122. */
  123. /*
  124. * The Malloc area is immediately below the monitor copy in DRAM
  125. */
  126. static void mem_malloc_init (void)
  127. {
  128. #if !defined(CONFIG_RELOC_FIXUP_WORKS)
  129. mem_malloc_end = CFG_MONITOR_BASE + gd->reloc_off;
  130. #endif
  131. mem_malloc_start = mem_malloc_end - TOTAL_MALLOC_LEN;
  132. mem_malloc_brk = mem_malloc_start;
  133. memset ((void *) mem_malloc_start,
  134. 0,
  135. mem_malloc_end - mem_malloc_start);
  136. }
  137. void *sbrk (ptrdiff_t increment)
  138. {
  139. ulong old = mem_malloc_brk;
  140. ulong new = old + increment;
  141. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  142. return (NULL);
  143. }
  144. mem_malloc_brk = new;
  145. return ((void *) old);
  146. }
  147. char *strmhz (char *buf, long hz)
  148. {
  149. long l, n;
  150. long m;
  151. n = hz / 1000000L;
  152. l = sprintf (buf, "%ld", n);
  153. m = (hz % 1000000L) / 1000L;
  154. if (m != 0)
  155. sprintf (buf + l, ".%03ld", m);
  156. return (buf);
  157. }
  158. /*
  159. * All attempts to come up with a "common" initialization sequence
  160. * that works for all boards and architectures failed: some of the
  161. * requirements are just _too_ different. To get rid of the resulting
  162. * mess of board dependend #ifdef'ed code we now make the whole
  163. * initialization sequence configurable to the user.
  164. *
  165. * The requirements for any new initalization function is simple: it
  166. * receives a pointer to the "global data" structure as it's only
  167. * argument, and returns an integer return code, where 0 means
  168. * "continue" and != 0 means "fatal error, hang the system".
  169. */
  170. typedef int (init_fnc_t) (void);
  171. /************************************************************************
  172. * Init Utilities *
  173. ************************************************************************
  174. * Some of this code should be moved into the core functions,
  175. * but let's get it working (again) first...
  176. */
  177. static int init_baudrate (void)
  178. {
  179. char tmp[64]; /* long enough for environment variables */
  180. int i = getenv_r ("baudrate", tmp, sizeof (tmp));
  181. gd->baudrate = (i > 0)
  182. ? (int) simple_strtoul (tmp, NULL, 10)
  183. : CONFIG_BAUDRATE;
  184. return (0);
  185. }
  186. /***********************************************************************/
  187. #ifdef CONFIG_ADD_RAM_INFO
  188. void board_add_ram_info(int);
  189. #endif
  190. static int init_func_ram (void)
  191. {
  192. #ifdef CONFIG_BOARD_TYPES
  193. int board_type = gd->board_type;
  194. #else
  195. int board_type = 0; /* use dummy arg */
  196. #endif
  197. puts ("DRAM: ");
  198. if ((gd->ram_size = initdram (board_type)) > 0) {
  199. print_size (gd->ram_size, "");
  200. #ifdef CONFIG_ADD_RAM_INFO
  201. board_add_ram_info(0);
  202. #endif
  203. putc('\n');
  204. return (0);
  205. }
  206. puts (failed);
  207. return (1);
  208. }
  209. /***********************************************************************/
  210. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  211. static int init_func_i2c (void)
  212. {
  213. puts ("I2C: ");
  214. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  215. puts ("ready\n");
  216. return (0);
  217. }
  218. #endif
  219. /***********************************************************************/
  220. #if defined(CONFIG_WATCHDOG)
  221. static int init_func_watchdog_init (void)
  222. {
  223. puts (" Watchdog enabled\n");
  224. WATCHDOG_RESET ();
  225. return (0);
  226. }
  227. # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
  228. static int init_func_watchdog_reset (void)
  229. {
  230. WATCHDOG_RESET ();
  231. return (0);
  232. }
  233. # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
  234. #else
  235. # define INIT_FUNC_WATCHDOG_INIT /* undef */
  236. # define INIT_FUNC_WATCHDOG_RESET /* undef */
  237. #endif /* CONFIG_WATCHDOG */
  238. /************************************************************************
  239. * Initialization sequence *
  240. ************************************************************************
  241. */
  242. init_fnc_t *init_sequence[] = {
  243. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  244. board_early_init_f,
  245. #endif
  246. #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  247. get_clocks, /* get CPU and bus clocks (etc.) */
  248. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  249. && !defined(CONFIG_TQM885D)
  250. adjust_sdram_tbs_8xx,
  251. #endif
  252. init_timebase,
  253. #endif
  254. #ifdef CFG_ALLOC_DPRAM
  255. #if !defined(CONFIG_CPM2)
  256. dpram_init,
  257. #endif
  258. #endif
  259. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  260. board_postclk_init,
  261. #endif
  262. env_init,
  263. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  264. get_clocks_866, /* get CPU and bus clocks according to the environment variable */
  265. sdram_adjust_866, /* adjust sdram refresh rate according to the new clock */
  266. init_timebase,
  267. #endif
  268. init_baudrate,
  269. serial_init,
  270. console_init_f,
  271. display_options,
  272. #if defined(CONFIG_8260)
  273. prt_8260_rsr,
  274. prt_8260_clks,
  275. #endif /* CONFIG_8260 */
  276. checkcpu,
  277. #if defined(CONFIG_MPC5xxx)
  278. prt_mpc5xxx_clks,
  279. #endif /* CONFIG_MPC5xxx */
  280. #if defined(CONFIG_MPC8220)
  281. prt_mpc8220_clks,
  282. #endif
  283. checkboard,
  284. INIT_FUNC_WATCHDOG_INIT
  285. #if defined(CONFIG_MISC_INIT_F)
  286. misc_init_f,
  287. #endif
  288. INIT_FUNC_WATCHDOG_RESET
  289. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  290. init_func_i2c,
  291. #endif
  292. #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
  293. dtt_init,
  294. #endif
  295. #ifdef CONFIG_POST
  296. post_init_f,
  297. #endif
  298. INIT_FUNC_WATCHDOG_RESET
  299. init_func_ram,
  300. #if defined(CFG_DRAM_TEST)
  301. testdram,
  302. #endif /* CFG_DRAM_TEST */
  303. INIT_FUNC_WATCHDOG_RESET
  304. NULL, /* Terminate this list */
  305. };
  306. /************************************************************************
  307. *
  308. * This is the first part of the initialization sequence that is
  309. * implemented in C, but still running from ROM.
  310. *
  311. * The main purpose is to provide a (serial) console interface as
  312. * soon as possible (so we can see any error messages), and to
  313. * initialize the RAM so that we can relocate the monitor code to
  314. * RAM.
  315. *
  316. * Be aware of the restrictions: global data is read-only, BSS is not
  317. * initialized, and stack space is limited to a few kB.
  318. *
  319. ************************************************************************
  320. */
  321. void board_init_f (ulong bootflag)
  322. {
  323. bd_t *bd;
  324. ulong len, addr, addr_sp;
  325. ulong *s;
  326. gd_t *id;
  327. init_fnc_t **init_fnc_ptr;
  328. #ifdef CONFIG_PRAM
  329. int i;
  330. ulong reg;
  331. uchar tmp[64]; /* long enough for environment variables */
  332. #endif
  333. /* Pointer is writable since we allocated a register for it */
  334. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  335. /* compiler optimization barrier needed for GCC >= 3.4 */
  336. __asm__ __volatile__("": : :"memory");
  337. #if !defined(CONFIG_CPM2)
  338. /* Clear initial global data */
  339. memset ((void *) gd, 0, sizeof (gd_t));
  340. #endif
  341. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  342. if ((*init_fnc_ptr) () != 0) {
  343. hang ();
  344. }
  345. }
  346. /*
  347. * Now that we have DRAM mapped and working, we can
  348. * relocate the code and continue running from DRAM.
  349. *
  350. * Reserve memory at end of RAM for (top down in that order):
  351. * - kernel log buffer
  352. * - protected RAM
  353. * - LCD framebuffer
  354. * - monitor code
  355. * - board info struct
  356. */
  357. len = (ulong)&_end - CFG_MONITOR_BASE;
  358. #ifndef CONFIG_VERY_BIG_RAM
  359. addr = CFG_SDRAM_BASE + gd->ram_size;
  360. #else
  361. /* only allow stack below 256M */
  362. addr = CFG_SDRAM_BASE +
  363. (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
  364. #endif
  365. #ifdef CONFIG_LOGBUFFER
  366. /* reserve kernel log buffer */
  367. addr -= (LOGBUFF_RESERVE);
  368. debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  369. #endif
  370. #ifdef CONFIG_PRAM
  371. /*
  372. * reserve protected RAM
  373. */
  374. i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
  375. reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
  376. addr -= (reg << 10); /* size is in kB */
  377. debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  378. #endif /* CONFIG_PRAM */
  379. /* round down to next 4 kB limit */
  380. addr &= ~(4096 - 1);
  381. debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  382. #ifdef CONFIG_LCD
  383. /* reserve memory for LCD display (always full pages) */
  384. addr = lcd_setmem (addr);
  385. gd->fb_base = addr;
  386. #endif /* CONFIG_LCD */
  387. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  388. /* reserve memory for video display (always full pages) */
  389. addr = video_setmem (addr);
  390. gd->fb_base = addr;
  391. #endif /* CONFIG_VIDEO */
  392. /*
  393. * reserve memory for U-Boot code, data & bss
  394. * round down to next 4 kB limit
  395. */
  396. addr -= len;
  397. addr &= ~(4096 - 1);
  398. #ifdef CONFIG_E500
  399. /* round down to next 64 kB limit so that IVPR stays aligned */
  400. addr &= ~(65536 - 1);
  401. #endif
  402. debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  403. #ifdef CONFIG_AMIGAONEG3SE
  404. gd->relocaddr = addr;
  405. #endif
  406. /*
  407. * reserve memory for malloc() arena
  408. */
  409. addr_sp = addr - TOTAL_MALLOC_LEN;
  410. debug ("Reserving %dk for malloc() at: %08lx\n",
  411. TOTAL_MALLOC_LEN >> 10, addr_sp);
  412. /*
  413. * (permanently) allocate a Board Info struct
  414. * and a permanent copy of the "global" data
  415. */
  416. addr_sp -= sizeof (bd_t);
  417. bd = (bd_t *) addr_sp;
  418. gd->bd = bd;
  419. debug ("Reserving %d Bytes for Board Info at: %08lx\n",
  420. sizeof (bd_t), addr_sp);
  421. addr_sp -= sizeof (gd_t);
  422. id = (gd_t *) addr_sp;
  423. debug ("Reserving %d Bytes for Global Data at: %08lx\n",
  424. sizeof (gd_t), addr_sp);
  425. /*
  426. * Finally, we set up a new (bigger) stack.
  427. *
  428. * Leave some safety gap for SP, force alignment on 16 byte boundary
  429. * Clear initial stack frame
  430. */
  431. addr_sp -= 16;
  432. addr_sp &= ~0xF;
  433. s = (ulong *)addr_sp;
  434. *s-- = 0;
  435. *s-- = 0;
  436. addr_sp = (ulong)s;
  437. debug ("Stack Pointer at: %08lx\n", addr_sp);
  438. /*
  439. * Save local variables to board info struct
  440. */
  441. bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
  442. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  443. #ifdef CONFIG_IP860
  444. bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
  445. bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
  446. #elif defined CONFIG_MPC8220
  447. bd->bi_sramstart = CFG_SRAM_BASE; /* start of SRAM memory */
  448. bd->bi_sramsize = CFG_SRAM_SIZE; /* size of SRAM memory */
  449. #else
  450. bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
  451. bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
  452. #endif
  453. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
  454. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  455. bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
  456. #endif
  457. #if defined(CONFIG_MPC5xxx)
  458. bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
  459. #endif
  460. #if defined(CONFIG_MPC83XX)
  461. bd->bi_immrbar = CFG_IMMR;
  462. #endif
  463. #if defined(CONFIG_MPC8220)
  464. bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
  465. bd->bi_inpfreq = gd->inp_clk;
  466. bd->bi_pcifreq = gd->pci_clk;
  467. bd->bi_vcofreq = gd->vco_clk;
  468. bd->bi_pevfreq = gd->pev_clk;
  469. bd->bi_flbfreq = gd->flb_clk;
  470. /* store bootparam to sram (backward compatible), here? */
  471. {
  472. u32 *sram = (u32 *)CFG_SRAM_BASE;
  473. *sram++ = gd->ram_size;
  474. *sram++ = gd->bus_clk;
  475. *sram++ = gd->inp_clk;
  476. *sram++ = gd->cpu_clk;
  477. *sram++ = gd->vco_clk;
  478. *sram++ = gd->flb_clk;
  479. *sram++ = 0xb8c3ba11; /* boot signature */
  480. }
  481. #endif
  482. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  483. WATCHDOG_RESET ();
  484. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  485. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  486. #if defined(CONFIG_CPM2)
  487. bd->bi_cpmfreq = gd->cpm_clk;
  488. bd->bi_brgfreq = gd->brg_clk;
  489. bd->bi_sccfreq = gd->scc_clk;
  490. bd->bi_vco = gd->vco_out;
  491. #endif /* CONFIG_CPM2 */
  492. #if defined(CONFIG_MPC5xxx)
  493. bd->bi_ipbfreq = gd->ipb_clk;
  494. bd->bi_pcifreq = gd->pci_clk;
  495. #endif /* CONFIG_MPC5xxx */
  496. bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
  497. #ifdef CFG_EXTBDINFO
  498. strncpy ((char *)bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
  499. strncpy ((char *)bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
  500. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  501. bd->bi_plb_busfreq = gd->bus_clk;
  502. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  503. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  504. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  505. bd->bi_pci_busfreq = get_PCI_freq ();
  506. bd->bi_opbfreq = get_OPB_freq ();
  507. #elif defined(CONFIG_XILINX_ML300)
  508. bd->bi_pci_busfreq = get_PCI_freq ();
  509. #endif
  510. #endif
  511. debug ("New Stack Pointer is: %08lx\n", addr_sp);
  512. WATCHDOG_RESET ();
  513. #ifdef CONFIG_POST
  514. post_bootmode_init();
  515. post_run (NULL, POST_ROM | post_bootmode_get(0));
  516. #endif
  517. WATCHDOG_RESET();
  518. memcpy (id, (void *)gd, sizeof (gd_t));
  519. relocate_code (addr_sp, id, addr);
  520. /* NOTREACHED - relocate_code() does not return */
  521. }
  522. /************************************************************************
  523. *
  524. * This is the next part if the initialization sequence: we are now
  525. * running from RAM and have a "normal" C environment, i. e. global
  526. * data can be written, BSS has been cleared, the stack size in not
  527. * that critical any more, etc.
  528. *
  529. ************************************************************************
  530. */
  531. void board_init_r (gd_t *id, ulong dest_addr)
  532. {
  533. cmd_tbl_t *cmdtp;
  534. char *s, *e;
  535. bd_t *bd;
  536. int i;
  537. extern void malloc_bin_reloc (void);
  538. #ifndef CFG_ENV_IS_NOWHERE
  539. extern char * env_name_spec;
  540. #endif
  541. #ifndef CFG_NO_FLASH
  542. ulong flash_size;
  543. #endif
  544. gd = id; /* initialize RAM version of global data */
  545. bd = gd->bd;
  546. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  547. #if defined(CONFIG_RELOC_FIXUP_WORKS)
  548. gd->reloc_off = 0;
  549. mem_malloc_end = dest_addr;
  550. #else
  551. gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
  552. #endif
  553. #ifdef CONFIG_SERIAL_MULTI
  554. serial_initialize();
  555. #endif
  556. debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  557. WATCHDOG_RESET ();
  558. #if defined(CONFIG_BOARD_EARLY_INIT_R)
  559. board_early_init_r ();
  560. #endif
  561. monitor_flash_len = (ulong)&__init_end - dest_addr;
  562. /*
  563. * We have to relocate the command table manually
  564. */
  565. for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
  566. ulong addr;
  567. addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
  568. #if 0
  569. printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
  570. cmdtp->name, (ulong) (cmdtp->cmd), addr);
  571. #endif
  572. cmdtp->cmd =
  573. (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  574. addr = (ulong)(cmdtp->name) + gd->reloc_off;
  575. cmdtp->name = (char *)addr;
  576. if (cmdtp->usage) {
  577. addr = (ulong)(cmdtp->usage) + gd->reloc_off;
  578. cmdtp->usage = (char *)addr;
  579. }
  580. #ifdef CFG_LONGHELP
  581. if (cmdtp->help) {
  582. addr = (ulong)(cmdtp->help) + gd->reloc_off;
  583. cmdtp->help = (char *)addr;
  584. }
  585. #endif
  586. }
  587. /* there are some other pointer constants we must deal with */
  588. #ifndef CFG_ENV_IS_NOWHERE
  589. env_name_spec += gd->reloc_off;
  590. #endif
  591. WATCHDOG_RESET ();
  592. #ifdef CONFIG_LOGBUFFER
  593. logbuff_init_ptrs ();
  594. #endif
  595. #ifdef CONFIG_POST
  596. post_output_backlog ();
  597. post_reloc ();
  598. #endif
  599. WATCHDOG_RESET();
  600. #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || \
  601. defined (CONFIG_FLAGADM) || defined(CONFIG_MPC83XX)
  602. icache_enable (); /* it's time to enable the instruction cache */
  603. #endif
  604. #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
  605. unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
  606. #endif
  607. #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
  608. /*
  609. * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
  610. * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
  611. * bridge there.
  612. */
  613. pci_init ();
  614. #endif
  615. #if defined(CONFIG_BAB7xx)
  616. /*
  617. * Initialise the ISA bridge
  618. */
  619. initialise_w83c553f ();
  620. #endif
  621. asm ("sync ; isync");
  622. /*
  623. * Setup trap handlers
  624. */
  625. trap_init (dest_addr);
  626. #if !defined(CFG_NO_FLASH)
  627. puts ("FLASH: ");
  628. if ((flash_size = flash_init ()) > 0) {
  629. # ifdef CFG_FLASH_CHECKSUM
  630. print_size (flash_size, "");
  631. /*
  632. * Compute and print flash CRC if flashchecksum is set to 'y'
  633. *
  634. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  635. */
  636. s = getenv ("flashchecksum");
  637. if (s && (*s == 'y')) {
  638. printf (" CRC: %08lX",
  639. crc32 (0, (const unsigned char *) CFG_FLASH_BASE, flash_size)
  640. );
  641. }
  642. putc ('\n');
  643. # else /* !CFG_FLASH_CHECKSUM */
  644. print_size (flash_size, "\n");
  645. # endif /* CFG_FLASH_CHECKSUM */
  646. } else {
  647. puts (failed);
  648. hang ();
  649. }
  650. bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
  651. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  652. #if defined(CFG_UPDATE_FLASH_SIZE)
  653. /* Make a update of the Memctrl. */
  654. update_flash_size (flash_size);
  655. #endif
  656. # if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) || defined(CONFIG_RMU)
  657. /* flash mapped at end of memory map */
  658. bd->bi_flashoffset = TEXT_BASE + flash_size;
  659. # elif CFG_MONITOR_BASE == CFG_FLASH_BASE
  660. bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
  661. # else
  662. bd->bi_flashoffset = 0;
  663. # endif
  664. #else /* CFG_NO_FLASH */
  665. bd->bi_flashsize = 0;
  666. bd->bi_flashstart = 0;
  667. bd->bi_flashoffset = 0;
  668. #endif /* !CFG_NO_FLASH */
  669. WATCHDOG_RESET ();
  670. /* initialize higher level parts of CPU like time base and timers */
  671. cpu_init_r ();
  672. WATCHDOG_RESET ();
  673. /* initialize malloc() area */
  674. mem_malloc_init ();
  675. malloc_bin_reloc ();
  676. #ifdef CONFIG_SPI
  677. # if !defined(CFG_ENV_IS_IN_EEPROM)
  678. spi_init_f ();
  679. # endif
  680. spi_init_r ();
  681. #endif
  682. #if defined(CONFIG_CMD_NAND)
  683. WATCHDOG_RESET ();
  684. puts ("NAND: ");
  685. nand_init(); /* go init the NAND */
  686. #endif
  687. /* relocate environment function pointers etc. */
  688. env_relocate ();
  689. /*
  690. * Fill in missing fields of bd_info.
  691. * We do this here, where we have "normal" access to the
  692. * environment; we used to do this still running from ROM,
  693. * where had to use getenv_r(), which can be pretty slow when
  694. * the environment is in EEPROM.
  695. */
  696. #if defined(CFG_EXTBDINFO)
  697. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  698. #if defined(CONFIG_I2CFAST)
  699. /*
  700. * set bi_iic_fast for linux taking environment variable
  701. * "i2cfast" into account
  702. */
  703. {
  704. char *s = getenv ("i2cfast");
  705. if (s && ((*s == 'y') || (*s == 'Y'))) {
  706. bd->bi_iic_fast[0] = 1;
  707. bd->bi_iic_fast[1] = 1;
  708. } else {
  709. bd->bi_iic_fast[0] = 0;
  710. bd->bi_iic_fast[1] = 0;
  711. }
  712. }
  713. #else
  714. bd->bi_iic_fast[0] = 0;
  715. bd->bi_iic_fast[1] = 0;
  716. #endif /* CONFIG_I2CFAST */
  717. #endif /* CONFIG_405GP, CONFIG_405EP */
  718. #endif /* CFG_EXTBDINFO */
  719. #if defined(CONFIG_SC3)
  720. sc3_read_eeprom();
  721. #endif
  722. s = getenv ("ethaddr");
  723. #if defined (CONFIG_MBX) || \
  724. defined (CONFIG_RPXCLASSIC) || \
  725. defined(CONFIG_IAD210) || \
  726. defined(CONFIG_V38B)
  727. if (s == NULL)
  728. board_get_enetaddr (bd->bi_enetaddr);
  729. else
  730. #endif
  731. for (i = 0; i < 6; ++i) {
  732. bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  733. if (s)
  734. s = (*e) ? e + 1 : e;
  735. }
  736. #ifdef CONFIG_HERMES
  737. if ((gd->board_type >> 16) == 2)
  738. bd->bi_ethspeed = gd->board_type & 0xFFFF;
  739. else
  740. bd->bi_ethspeed = 0xFFFF;
  741. #endif
  742. #ifdef CONFIG_NX823
  743. load_sernum_ethaddr ();
  744. #endif
  745. #ifdef CONFIG_HAS_ETH1
  746. /* handle the 2nd ethernet address */
  747. s = getenv ("eth1addr");
  748. for (i = 0; i < 6; ++i) {
  749. bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  750. if (s)
  751. s = (*e) ? e + 1 : e;
  752. }
  753. #endif
  754. #ifdef CONFIG_HAS_ETH2
  755. /* handle the 3rd ethernet address */
  756. s = getenv ("eth2addr");
  757. #if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
  758. if (s == NULL)
  759. board_get_enetaddr(bd->bi_enet2addr);
  760. else
  761. #endif
  762. for (i = 0; i < 6; ++i) {
  763. bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  764. if (s)
  765. s = (*e) ? e + 1 : e;
  766. }
  767. #endif
  768. #ifdef CONFIG_HAS_ETH3
  769. /* handle 4th ethernet address */
  770. s = getenv("eth3addr");
  771. #if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
  772. if (s == NULL)
  773. board_get_enetaddr(bd->bi_enet3addr);
  774. else
  775. #endif
  776. for (i = 0; i < 6; ++i) {
  777. bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  778. if (s)
  779. s = (*e) ? e + 1 : e;
  780. }
  781. #endif
  782. #ifdef CFG_ID_EEPROM
  783. mac_read_from_eeprom();
  784. #endif
  785. #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
  786. defined(CONFIG_TQM8272) || \
  787. defined(CONFIG_CCM) || defined(CONFIG_KUP4K) || \
  788. defined(CONFIG_KUP4X) || defined(CONFIG_PCS440EP)
  789. load_sernum_ethaddr ();
  790. #endif
  791. /* IP Address */
  792. bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  793. WATCHDOG_RESET ();
  794. #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx) && !defined(CONFIG_CPC45)
  795. /*
  796. * Do pci configuration
  797. */
  798. pci_init ();
  799. #endif
  800. /** leave this here (after malloc(), environment and PCI are working) **/
  801. /* Initialize devices */
  802. devices_init ();
  803. /* Initialize the jump table for applications */
  804. jumptable_init ();
  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_CMD_SCSI)
  857. WATCHDOG_RESET ();
  858. puts ("SCSI: ");
  859. scsi_init ();
  860. #endif
  861. #if defined(CONFIG_CMD_DOC)
  862. WATCHDOG_RESET ();
  863. puts ("DOC: ");
  864. doc_init ();
  865. #endif
  866. #if defined(CONFIG_CMD_NET)
  867. #if defined(CONFIG_NET_MULTI)
  868. WATCHDOG_RESET ();
  869. puts ("Net: ");
  870. #endif
  871. eth_initialize (bd);
  872. #endif
  873. #if defined(CONFIG_CMD_NET) && ( \
  874. defined(CONFIG_CCM) || \
  875. defined(CONFIG_ELPT860) || \
  876. defined(CONFIG_EP8260) || \
  877. defined(CONFIG_IP860) || \
  878. defined(CONFIG_IVML24) || \
  879. defined(CONFIG_IVMS8) || \
  880. defined(CONFIG_MPC8260ADS) || \
  881. defined(CONFIG_MPC8266ADS) || \
  882. defined(CONFIG_MPC8560ADS) || \
  883. defined(CONFIG_PCU_E) || \
  884. defined(CONFIG_RPXSUPER) || \
  885. defined(CONFIG_STXGP3) || \
  886. defined(CONFIG_SPD823TS) || \
  887. defined(CONFIG_RESET_PHY_R) )
  888. WATCHDOG_RESET ();
  889. debug ("Reset Ethernet PHY\n");
  890. reset_phy ();
  891. #endif
  892. #ifdef CONFIG_POST
  893. post_run (NULL, POST_RAM | post_bootmode_get(0));
  894. #endif
  895. #if defined(CONFIG_CMD_PCMCIA) \
  896. && !defined(CONFIG_CMD_IDE)
  897. WATCHDOG_RESET ();
  898. puts ("PCMCIA:");
  899. pcmcia_init ();
  900. #endif
  901. #if defined(CONFIG_CMD_IDE)
  902. WATCHDOG_RESET ();
  903. # ifdef CONFIG_IDE_8xx_PCCARD
  904. puts ("PCMCIA:");
  905. # else
  906. puts ("IDE: ");
  907. #endif
  908. #if defined(CONFIG_START_IDE)
  909. if (board_start_ide())
  910. ide_init ();
  911. #else
  912. ide_init ();
  913. #endif
  914. #endif
  915. #ifdef CONFIG_LAST_STAGE_INIT
  916. WATCHDOG_RESET ();
  917. /*
  918. * Some parts can be only initialized if all others (like
  919. * Interrupts) are up and running (i.e. the PC-style ISA
  920. * keyboard).
  921. */
  922. last_stage_init ();
  923. #endif
  924. #if defined(CONFIG_CMD_BEDBUG)
  925. WATCHDOG_RESET ();
  926. bedbug_init ();
  927. #endif
  928. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  929. /*
  930. * Export available size of memory for Linux,
  931. * taking into account the protected RAM at top of memory
  932. */
  933. {
  934. ulong pram;
  935. uchar memsz[32];
  936. #ifdef CONFIG_PRAM
  937. char *s;
  938. if ((s = getenv ("pram")) != NULL) {
  939. pram = simple_strtoul (s, NULL, 10);
  940. } else {
  941. pram = CONFIG_PRAM;
  942. }
  943. #else
  944. pram=0;
  945. #endif
  946. #ifdef CONFIG_LOGBUFFER
  947. /* Also take the logbuffer into account (pram is in kB) */
  948. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  949. #endif
  950. sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  951. setenv ("mem", (char *)memsz);
  952. }
  953. #endif
  954. #ifdef CONFIG_PS2KBD
  955. puts ("PS/2: ");
  956. kbd_init();
  957. #endif
  958. #ifdef CONFIG_MODEM_SUPPORT
  959. {
  960. extern int do_mdm_init;
  961. do_mdm_init = gd->do_mdm_init;
  962. }
  963. #endif
  964. /* Initialization complete - start the monitor */
  965. /* main_loop() can return to retry autoboot, if so just run it again. */
  966. for (;;) {
  967. WATCHDOG_RESET ();
  968. main_loop ();
  969. }
  970. /* NOTREACHED - no way out of command loop except booting */
  971. }
  972. void hang (void)
  973. {
  974. puts ("### ERROR ### Please RESET the board ###\n");
  975. show_boot_progress(-30);
  976. for (;;);
  977. }
  978. #ifdef CONFIG_MODEM_SUPPORT
  979. /* called from main loop (common/main.c) */
  980. /* 'inline' - We have to do it fast */
  981. static inline void mdm_readline(char *buf, int bufsiz)
  982. {
  983. char c;
  984. char *p;
  985. int n;
  986. n = 0;
  987. p = buf;
  988. for(;;) {
  989. c = serial_getc();
  990. /* dbg("(%c)", c); */
  991. switch(c) {
  992. case '\r':
  993. break;
  994. case '\n':
  995. *p = '\0';
  996. return;
  997. default:
  998. if(n++ > bufsiz) {
  999. *p = '\0';
  1000. return; /* sanity check */
  1001. }
  1002. *p = c;
  1003. p++;
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. extern void dbg(const char *fmt, ...);
  1009. int mdm_init (void)
  1010. {
  1011. char env_str[16];
  1012. char *init_str;
  1013. int i;
  1014. extern char console_buffer[];
  1015. extern void enable_putc(void);
  1016. extern int hwflow_onoff(int);
  1017. enable_putc(); /* enable serial_putc() */
  1018. #ifdef CONFIG_HWFLOW
  1019. init_str = getenv("mdm_flow_control");
  1020. if (init_str && (strcmp(init_str, "rts/cts") == 0))
  1021. hwflow_onoff (1);
  1022. else
  1023. hwflow_onoff(-1);
  1024. #endif
  1025. for (i = 1;;i++) {
  1026. sprintf(env_str, "mdm_init%d", i);
  1027. if ((init_str = getenv(env_str)) != NULL) {
  1028. serial_puts(init_str);
  1029. serial_puts("\n");
  1030. for(;;) {
  1031. mdm_readline(console_buffer, CFG_CBSIZE);
  1032. dbg("ini%d: [%s]", i, console_buffer);
  1033. if ((strcmp(console_buffer, "OK") == 0) ||
  1034. (strcmp(console_buffer, "ERROR") == 0)) {
  1035. dbg("ini%d: cmd done", i);
  1036. break;
  1037. } else /* in case we are originating call ... */
  1038. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  1039. dbg("ini%d: connect", i);
  1040. return 0;
  1041. }
  1042. }
  1043. } else
  1044. break; /* no init string - stop modem init */
  1045. udelay(100000);
  1046. }
  1047. udelay(100000);
  1048. /* final stage - wait for connect */
  1049. for(;i > 1;) { /* if 'i' > 1 - wait for connection
  1050. message from modem */
  1051. mdm_readline(console_buffer, CFG_CBSIZE);
  1052. dbg("ini_f: [%s]", console_buffer);
  1053. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  1054. dbg("ini_f: connected");
  1055. return 0;
  1056. }
  1057. }
  1058. return 0;
  1059. }
  1060. #endif
  1061. #if 0 /* We could use plain global data, but the resulting code is bigger */
  1062. /*
  1063. * Pointer to initial global data area
  1064. *
  1065. * Here we initialize it.
  1066. */
  1067. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  1068. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  1069. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  1070. #endif /* 0 */
  1071. /************************************************************************/