board.c 29 KB

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