board.c 27 KB

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