board.c 29 KB

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