board.c 28 KB

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