board.c 31 KB

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