board.c 32 KB

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