board.c 25 KB

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