board.c 26 KB

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