board.c 27 KB

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