board.c 25 KB

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