board.c 32 KB

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