board.c 26 KB

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