board.c 29 KB

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