board.c 29 KB

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