board.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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
  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
  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)
  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. nand_init(); /* go init the NAND */
  737. #endif
  738. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
  739. WATCHDOG_RESET ();
  740. puts ("Net: ");
  741. eth_initialize (bd);
  742. #endif
  743. #ifdef CONFIG_POST
  744. post_run (NULL, POST_RAM | post_bootmode_get(0));
  745. #endif
  746. #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
  747. WATCHDOG_RESET ();
  748. puts ("PCMCIA:");
  749. pcmcia_init ();
  750. #endif
  751. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  752. WATCHDOG_RESET ();
  753. # ifdef CONFIG_IDE_8xx_PCCARD
  754. puts ("PCMCIA:");
  755. # else
  756. puts ("IDE: ");
  757. #endif
  758. ide_init ();
  759. #endif /* CFG_CMD_IDE */
  760. #ifdef CONFIG_LAST_STAGE_INIT
  761. WATCHDOG_RESET ();
  762. /*
  763. * Some parts can be only initialized if all others (like
  764. * Interrupts) are up and running (i.e. the PC-style ISA
  765. * keyboard).
  766. */
  767. last_stage_init ();
  768. #endif
  769. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  770. WATCHDOG_RESET ();
  771. bedbug_init ();
  772. #endif
  773. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  774. /*
  775. * Export available size of memory for Linux,
  776. * taking into account the protected RAM at top of memory
  777. */
  778. {
  779. ulong pram;
  780. uchar memsz[32];
  781. #ifdef CONFIG_PRAM
  782. char *s;
  783. if ((s = getenv ("pram")) != NULL) {
  784. pram = simple_strtoul (s, NULL, 10);
  785. } else {
  786. pram = CONFIG_PRAM;
  787. }
  788. #else
  789. pram=0;
  790. #endif
  791. #ifdef CONFIG_LOGBUFFER
  792. /* Also take the logbuffer into account (pram is in kB) */
  793. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  794. #endif
  795. sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  796. setenv ("mem", memsz);
  797. }
  798. #endif
  799. #ifdef CONFIG_MODEM_SUPPORT
  800. {
  801. extern int do_mdm_init;
  802. do_mdm_init = gd->do_mdm_init;
  803. }
  804. #endif
  805. /* Initialization complete - start the monitor */
  806. /* main_loop() can return to retry autoboot, if so just run it again. */
  807. for (;;) {
  808. WATCHDOG_RESET ();
  809. main_loop ();
  810. }
  811. /* NOTREACHED - no way out of command loop except booting */
  812. }
  813. void hang (void)
  814. {
  815. puts ("### ERROR ### Please RESET the board ###\n");
  816. for (;;);
  817. }
  818. #ifdef CONFIG_MODEM_SUPPORT
  819. /* called from main loop (common/main.c) */
  820. extern void dbg(const char *fmt, ...);
  821. int mdm_init (void)
  822. {
  823. char env_str[16];
  824. char *init_str;
  825. int i;
  826. extern char console_buffer[];
  827. static inline void mdm_readline(char *buf, int bufsiz);
  828. extern void enable_putc(void);
  829. extern int hwflow_onoff(int);
  830. enable_putc(); /* enable serial_putc() */
  831. #ifdef CONFIG_HWFLOW
  832. init_str = getenv("mdm_flow_control");
  833. if (init_str && (strcmp(init_str, "rts/cts") == 0))
  834. hwflow_onoff (1);
  835. else
  836. hwflow_onoff(-1);
  837. #endif
  838. for (i = 1;;i++) {
  839. sprintf(env_str, "mdm_init%d", i);
  840. if ((init_str = getenv(env_str)) != NULL) {
  841. serial_puts(init_str);
  842. serial_puts("\n");
  843. for(;;) {
  844. mdm_readline(console_buffer, CFG_CBSIZE);
  845. dbg("ini%d: [%s]", i, console_buffer);
  846. if ((strcmp(console_buffer, "OK") == 0) ||
  847. (strcmp(console_buffer, "ERROR") == 0)) {
  848. dbg("ini%d: cmd done", i);
  849. break;
  850. } else /* in case we are originating call ... */
  851. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  852. dbg("ini%d: connect", i);
  853. return 0;
  854. }
  855. }
  856. } else
  857. break; /* no init string - stop modem init */
  858. udelay(100000);
  859. }
  860. udelay(100000);
  861. /* final stage - wait for connect */
  862. for(;i > 1;) { /* if 'i' > 1 - wait for connection
  863. message from modem */
  864. mdm_readline(console_buffer, CFG_CBSIZE);
  865. dbg("ini_f: [%s]", console_buffer);
  866. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  867. dbg("ini_f: connected");
  868. return 0;
  869. }
  870. }
  871. return 0;
  872. }
  873. /* 'inline' - We have to do it fast */
  874. static inline void mdm_readline(char *buf, int bufsiz)
  875. {
  876. char c;
  877. char *p;
  878. int n;
  879. n = 0;
  880. p = buf;
  881. for(;;) {
  882. c = serial_getc();
  883. /* dbg("(%c)", c); */
  884. switch(c) {
  885. case '\r':
  886. break;
  887. case '\n':
  888. *p = '\0';
  889. return;
  890. default:
  891. if(n++ > bufsiz) {
  892. *p = '\0';
  893. return; /* sanity check */
  894. }
  895. *p = c;
  896. p++;
  897. break;
  898. }
  899. }
  900. }
  901. #endif
  902. #if 0 /* We could use plain global data, but the resulting code is bigger */
  903. /*
  904. * Pointer to initial global data area
  905. *
  906. * Here we initialize it.
  907. */
  908. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  909. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  910. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  911. #endif /* 0 */
  912. /************************************************************************/