console.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. /*
  2. * (C) Copyright 2000
  3. * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
  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 <stdarg.h>
  25. #include <malloc.h>
  26. #include <stdio_dev.h>
  27. #include <exports.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
  30. /*
  31. * if overwrite_console returns 1, the stdin, stderr and stdout
  32. * are switched to the serial port, else the settings in the
  33. * environment are used
  34. */
  35. #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
  36. extern int overwrite_console(void);
  37. #define OVERWRITE_CONSOLE overwrite_console()
  38. #else
  39. #define OVERWRITE_CONSOLE 0
  40. #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
  41. #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
  42. static int console_setfile(int file, struct stdio_dev * dev)
  43. {
  44. int error = 0;
  45. if (dev == NULL)
  46. return -1;
  47. switch (file) {
  48. case stdin:
  49. case stdout:
  50. case stderr:
  51. /* Start new device */
  52. if (dev->start) {
  53. error = dev->start();
  54. /* If it's not started dont use it */
  55. if (error < 0)
  56. break;
  57. }
  58. /* Assign the new device (leaving the existing one started) */
  59. stdio_devices[file] = dev;
  60. /*
  61. * Update monitor functions
  62. * (to use the console stuff by other applications)
  63. */
  64. switch (file) {
  65. case stdin:
  66. gd->jt[XF_getc] = dev->getc;
  67. gd->jt[XF_tstc] = dev->tstc;
  68. break;
  69. case stdout:
  70. gd->jt[XF_putc] = dev->putc;
  71. gd->jt[XF_puts] = dev->puts;
  72. gd->jt[XF_printf] = printf;
  73. break;
  74. }
  75. break;
  76. default: /* Invalid file ID */
  77. error = -1;
  78. }
  79. return error;
  80. }
  81. #if defined(CONFIG_CONSOLE_MUX)
  82. /** Console I/O multiplexing *******************************************/
  83. static struct stdio_dev *tstcdev;
  84. struct stdio_dev **console_devices[MAX_FILES];
  85. int cd_count[MAX_FILES];
  86. /*
  87. * This depends on tstc() always being called before getc().
  88. * This is guaranteed to be true because this routine is called
  89. * only from fgetc() which assures it.
  90. * No attempt is made to demultiplex multiple input sources.
  91. */
  92. static int console_getc(int file)
  93. {
  94. unsigned char ret;
  95. /* This is never called with testcdev == NULL */
  96. ret = tstcdev->getc();
  97. tstcdev = NULL;
  98. return ret;
  99. }
  100. static int console_tstc(int file)
  101. {
  102. int i, ret;
  103. struct stdio_dev *dev;
  104. disable_ctrlc(1);
  105. for (i = 0; i < cd_count[file]; i++) {
  106. dev = console_devices[file][i];
  107. if (dev->tstc != NULL) {
  108. ret = dev->tstc();
  109. if (ret > 0) {
  110. tstcdev = dev;
  111. disable_ctrlc(0);
  112. return ret;
  113. }
  114. }
  115. }
  116. disable_ctrlc(0);
  117. return 0;
  118. }
  119. static void console_putc(int file, const char c)
  120. {
  121. int i;
  122. struct stdio_dev *dev;
  123. for (i = 0; i < cd_count[file]; i++) {
  124. dev = console_devices[file][i];
  125. if (dev->putc != NULL)
  126. dev->putc(c);
  127. }
  128. }
  129. static void console_puts(int file, const char *s)
  130. {
  131. int i;
  132. struct stdio_dev *dev;
  133. for (i = 0; i < cd_count[file]; i++) {
  134. dev = console_devices[file][i];
  135. if (dev->puts != NULL)
  136. dev->puts(s);
  137. }
  138. }
  139. static inline void console_printdevs(int file)
  140. {
  141. iomux_printdevs(file);
  142. }
  143. static inline void console_doenv(int file, struct stdio_dev *dev)
  144. {
  145. iomux_doenv(file, dev->name);
  146. }
  147. #else
  148. static inline int console_getc(int file)
  149. {
  150. return stdio_devices[file]->getc();
  151. }
  152. static inline int console_tstc(int file)
  153. {
  154. return stdio_devices[file]->tstc();
  155. }
  156. static inline void console_putc(int file, const char c)
  157. {
  158. stdio_devices[file]->putc(c);
  159. }
  160. static inline void console_puts(int file, const char *s)
  161. {
  162. stdio_devices[file]->puts(s);
  163. }
  164. static inline void console_printdevs(int file)
  165. {
  166. printf("%s\n", stdio_devices[file]->name);
  167. }
  168. static inline void console_doenv(int file, struct stdio_dev *dev)
  169. {
  170. console_setfile(file, dev);
  171. }
  172. #endif /* defined(CONFIG_CONSOLE_MUX) */
  173. /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
  174. int serial_printf(const char *fmt, ...)
  175. {
  176. va_list args;
  177. uint i;
  178. char printbuffer[CONFIG_SYS_PBSIZE];
  179. va_start(args, fmt);
  180. /* For this to work, printbuffer must be larger than
  181. * anything we ever want to print.
  182. */
  183. i = vsprintf(printbuffer, fmt, args);
  184. va_end(args);
  185. serial_puts(printbuffer);
  186. return i;
  187. }
  188. int fgetc(int file)
  189. {
  190. if (file < MAX_FILES) {
  191. #if defined(CONFIG_CONSOLE_MUX)
  192. /*
  193. * Effectively poll for input wherever it may be available.
  194. */
  195. for (;;) {
  196. /*
  197. * Upper layer may have already called tstc() so
  198. * check for that first.
  199. */
  200. if (tstcdev != NULL)
  201. return console_getc(file);
  202. console_tstc(file);
  203. #ifdef CONFIG_WATCHDOG
  204. /*
  205. * If the watchdog must be rate-limited then it should
  206. * already be handled in board-specific code.
  207. */
  208. udelay(1);
  209. #endif
  210. }
  211. #else
  212. return console_getc(file);
  213. #endif
  214. }
  215. return -1;
  216. }
  217. int ftstc(int file)
  218. {
  219. if (file < MAX_FILES)
  220. return console_tstc(file);
  221. return -1;
  222. }
  223. void fputc(int file, const char c)
  224. {
  225. if (file < MAX_FILES)
  226. console_putc(file, c);
  227. }
  228. void fputs(int file, const char *s)
  229. {
  230. if (file < MAX_FILES)
  231. console_puts(file, s);
  232. }
  233. int fprintf(int file, const char *fmt, ...)
  234. {
  235. va_list args;
  236. uint i;
  237. char printbuffer[CONFIG_SYS_PBSIZE];
  238. va_start(args, fmt);
  239. /* For this to work, printbuffer must be larger than
  240. * anything we ever want to print.
  241. */
  242. i = vsprintf(printbuffer, fmt, args);
  243. va_end(args);
  244. /* Send to desired file */
  245. fputs(file, printbuffer);
  246. return i;
  247. }
  248. /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
  249. int getc(void)
  250. {
  251. #ifdef CONFIG_DISABLE_CONSOLE
  252. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  253. return 0;
  254. #endif
  255. if (!gd->have_console)
  256. return 0;
  257. if (gd->flags & GD_FLG_DEVINIT) {
  258. /* Get from the standard input */
  259. return fgetc(stdin);
  260. }
  261. /* Send directly to the handler */
  262. return serial_getc();
  263. }
  264. int tstc(void)
  265. {
  266. #ifdef CONFIG_DISABLE_CONSOLE
  267. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  268. return 0;
  269. #endif
  270. if (!gd->have_console)
  271. return 0;
  272. if (gd->flags & GD_FLG_DEVINIT) {
  273. /* Test the standard input */
  274. return ftstc(stdin);
  275. }
  276. /* Send directly to the handler */
  277. return serial_tstc();
  278. }
  279. #ifdef CONFIG_PRE_CONSOLE_BUFFER
  280. #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
  281. static void pre_console_putc(const char c)
  282. {
  283. char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
  284. buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
  285. }
  286. static void pre_console_puts(const char *s)
  287. {
  288. while (*s)
  289. pre_console_putc(*s++);
  290. }
  291. static void print_pre_console_buffer(void)
  292. {
  293. unsigned long i = 0;
  294. char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
  295. if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
  296. i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
  297. while (i < gd->precon_buf_idx)
  298. putc(buffer[CIRC_BUF_IDX(i++)]);
  299. }
  300. #else
  301. static inline void pre_console_putc(const char c) {}
  302. static inline void pre_console_puts(const char *s) {}
  303. static inline void print_pre_console_buffer(void) {}
  304. #endif
  305. void putc(const char c)
  306. {
  307. #ifdef CONFIG_SILENT_CONSOLE
  308. if (gd->flags & GD_FLG_SILENT)
  309. return;
  310. #endif
  311. #ifdef CONFIG_DISABLE_CONSOLE
  312. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  313. return;
  314. #endif
  315. if (!gd->have_console)
  316. return pre_console_putc(c);
  317. if (gd->flags & GD_FLG_DEVINIT) {
  318. /* Send to the standard output */
  319. fputc(stdout, c);
  320. } else {
  321. /* Send directly to the handler */
  322. serial_putc(c);
  323. }
  324. }
  325. void puts(const char *s)
  326. {
  327. #ifdef CONFIG_SILENT_CONSOLE
  328. if (gd->flags & GD_FLG_SILENT)
  329. return;
  330. #endif
  331. #ifdef CONFIG_DISABLE_CONSOLE
  332. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  333. return;
  334. #endif
  335. if (!gd->have_console)
  336. return pre_console_puts(s);
  337. if (gd->flags & GD_FLG_DEVINIT) {
  338. /* Send to the standard output */
  339. fputs(stdout, s);
  340. } else {
  341. /* Send directly to the handler */
  342. serial_puts(s);
  343. }
  344. }
  345. int printf(const char *fmt, ...)
  346. {
  347. va_list args;
  348. uint i;
  349. char printbuffer[CONFIG_SYS_PBSIZE];
  350. #ifndef CONFIG_PRE_CONSOLE_BUFFER
  351. if (!gd->have_console)
  352. return 0;
  353. #endif
  354. va_start(args, fmt);
  355. /* For this to work, printbuffer must be larger than
  356. * anything we ever want to print.
  357. */
  358. i = vsprintf(printbuffer, fmt, args);
  359. va_end(args);
  360. /* Print the string */
  361. puts(printbuffer);
  362. return i;
  363. }
  364. int vprintf(const char *fmt, va_list args)
  365. {
  366. uint i;
  367. char printbuffer[CONFIG_SYS_PBSIZE];
  368. #ifndef CONFIG_PRE_CONSOLE_BUFFER
  369. if (!gd->have_console)
  370. return 0;
  371. #endif
  372. /* For this to work, printbuffer must be larger than
  373. * anything we ever want to print.
  374. */
  375. i = vsprintf(printbuffer, fmt, args);
  376. /* Print the string */
  377. puts(printbuffer);
  378. return i;
  379. }
  380. /* test if ctrl-c was pressed */
  381. static int ctrlc_disabled = 0; /* see disable_ctrl() */
  382. static int ctrlc_was_pressed = 0;
  383. int ctrlc(void)
  384. {
  385. if (!ctrlc_disabled && gd->have_console) {
  386. if (tstc()) {
  387. switch (getc()) {
  388. case 0x03: /* ^C - Control C */
  389. ctrlc_was_pressed = 1;
  390. return 1;
  391. default:
  392. break;
  393. }
  394. }
  395. }
  396. return 0;
  397. }
  398. /* pass 1 to disable ctrlc() checking, 0 to enable.
  399. * returns previous state
  400. */
  401. int disable_ctrlc(int disable)
  402. {
  403. int prev = ctrlc_disabled; /* save previous state */
  404. ctrlc_disabled = disable;
  405. return prev;
  406. }
  407. int had_ctrlc (void)
  408. {
  409. return ctrlc_was_pressed;
  410. }
  411. void clear_ctrlc(void)
  412. {
  413. ctrlc_was_pressed = 0;
  414. }
  415. #ifdef CONFIG_MODEM_SUPPORT_DEBUG
  416. char screen[1024];
  417. char *cursor = screen;
  418. int once = 0;
  419. inline void dbg(const char *fmt, ...)
  420. {
  421. va_list args;
  422. uint i;
  423. char printbuffer[CONFIG_SYS_PBSIZE];
  424. if (!once) {
  425. memset(screen, 0, sizeof(screen));
  426. once++;
  427. }
  428. va_start(args, fmt);
  429. /* For this to work, printbuffer must be larger than
  430. * anything we ever want to print.
  431. */
  432. i = vsprintf(printbuffer, fmt, args);
  433. va_end(args);
  434. if ((screen + sizeof(screen) - 1 - cursor)
  435. < strlen(printbuffer) + 1) {
  436. memset(screen, 0, sizeof(screen));
  437. cursor = screen;
  438. }
  439. sprintf(cursor, printbuffer);
  440. cursor += strlen(printbuffer);
  441. }
  442. #else
  443. inline void dbg(const char *fmt, ...)
  444. {
  445. }
  446. #endif
  447. /** U-Boot INIT FUNCTIONS *************************************************/
  448. struct stdio_dev *search_device(int flags, const char *name)
  449. {
  450. struct stdio_dev *dev;
  451. dev = stdio_get_by_name(name);
  452. if (dev && (dev->flags & flags))
  453. return dev;
  454. return NULL;
  455. }
  456. int console_assign(int file, const char *devname)
  457. {
  458. int flag;
  459. struct stdio_dev *dev;
  460. /* Check for valid file */
  461. switch (file) {
  462. case stdin:
  463. flag = DEV_FLAGS_INPUT;
  464. break;
  465. case stdout:
  466. case stderr:
  467. flag = DEV_FLAGS_OUTPUT;
  468. break;
  469. default:
  470. return -1;
  471. }
  472. /* Check for valid device name */
  473. dev = search_device(flag, devname);
  474. if (dev)
  475. return console_setfile(file, dev);
  476. return -1;
  477. }
  478. /* Called before relocation - use serial functions */
  479. int console_init_f(void)
  480. {
  481. gd->have_console = 1;
  482. #ifdef CONFIG_SILENT_CONSOLE
  483. if (getenv("silent") != NULL)
  484. gd->flags |= GD_FLG_SILENT;
  485. #endif
  486. print_pre_console_buffer();
  487. return 0;
  488. }
  489. void stdio_print_current_devices(void)
  490. {
  491. #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
  492. /* Print information */
  493. puts("In: ");
  494. if (stdio_devices[stdin] == NULL) {
  495. puts("No input devices available!\n");
  496. } else {
  497. printf ("%s\n", stdio_devices[stdin]->name);
  498. }
  499. puts("Out: ");
  500. if (stdio_devices[stdout] == NULL) {
  501. puts("No output devices available!\n");
  502. } else {
  503. printf ("%s\n", stdio_devices[stdout]->name);
  504. }
  505. puts("Err: ");
  506. if (stdio_devices[stderr] == NULL) {
  507. puts("No error devices available!\n");
  508. } else {
  509. printf ("%s\n", stdio_devices[stderr]->name);
  510. }
  511. #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
  512. }
  513. #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
  514. /* Called after the relocation - use desired console functions */
  515. int console_init_r(void)
  516. {
  517. char *stdinname, *stdoutname, *stderrname;
  518. struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
  519. #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  520. int i;
  521. #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
  522. #ifdef CONFIG_CONSOLE_MUX
  523. int iomux_err = 0;
  524. #endif
  525. /* set default handlers at first */
  526. gd->jt[XF_getc] = serial_getc;
  527. gd->jt[XF_tstc] = serial_tstc;
  528. gd->jt[XF_putc] = serial_putc;
  529. gd->jt[XF_puts] = serial_puts;
  530. gd->jt[XF_printf] = serial_printf;
  531. /* stdin stdout and stderr are in environment */
  532. /* scan for it */
  533. stdinname = getenv("stdin");
  534. stdoutname = getenv("stdout");
  535. stderrname = getenv("stderr");
  536. if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
  537. inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
  538. outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
  539. errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
  540. #ifdef CONFIG_CONSOLE_MUX
  541. iomux_err = iomux_doenv(stdin, stdinname);
  542. iomux_err += iomux_doenv(stdout, stdoutname);
  543. iomux_err += iomux_doenv(stderr, stderrname);
  544. if (!iomux_err)
  545. /* Successful, so skip all the code below. */
  546. goto done;
  547. #endif
  548. }
  549. /* if the devices are overwritten or not found, use default device */
  550. if (inputdev == NULL) {
  551. inputdev = search_device(DEV_FLAGS_INPUT, "serial");
  552. }
  553. if (outputdev == NULL) {
  554. outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
  555. }
  556. if (errdev == NULL) {
  557. errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
  558. }
  559. /* Initializes output console first */
  560. if (outputdev != NULL) {
  561. /* need to set a console if not done above. */
  562. console_doenv(stdout, outputdev);
  563. }
  564. if (errdev != NULL) {
  565. /* need to set a console if not done above. */
  566. console_doenv(stderr, errdev);
  567. }
  568. if (inputdev != NULL) {
  569. /* need to set a console if not done above. */
  570. console_doenv(stdin, inputdev);
  571. }
  572. #ifdef CONFIG_CONSOLE_MUX
  573. done:
  574. #endif
  575. gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
  576. stdio_print_current_devices();
  577. #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  578. /* set the environment variables (will overwrite previous env settings) */
  579. for (i = 0; i < 3; i++) {
  580. setenv(stdio_names[i], stdio_devices[i]->name);
  581. }
  582. #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
  583. #if 0
  584. /* If nothing usable installed, use only the initial console */
  585. if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
  586. return 0;
  587. #endif
  588. return 0;
  589. }
  590. #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
  591. /* Called after the relocation - use desired console functions */
  592. int console_init_r(void)
  593. {
  594. struct stdio_dev *inputdev = NULL, *outputdev = NULL;
  595. int i;
  596. struct list_head *list = stdio_get_list();
  597. struct list_head *pos;
  598. struct stdio_dev *dev;
  599. #ifdef CONFIG_SPLASH_SCREEN
  600. /*
  601. * suppress all output if splash screen is enabled and we have
  602. * a bmp to display. We redirect the output from frame buffer
  603. * console to serial console in this case or suppress it if
  604. * "silent" mode was requested.
  605. */
  606. if (getenv("splashimage") != NULL) {
  607. if (!(gd->flags & GD_FLG_SILENT))
  608. outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
  609. }
  610. #endif
  611. /* Scan devices looking for input and output devices */
  612. list_for_each(pos, list) {
  613. dev = list_entry(pos, struct stdio_dev, list);
  614. if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
  615. inputdev = dev;
  616. }
  617. if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
  618. outputdev = dev;
  619. }
  620. if(inputdev && outputdev)
  621. break;
  622. }
  623. /* Initializes output console first */
  624. if (outputdev != NULL) {
  625. console_setfile(stdout, outputdev);
  626. console_setfile(stderr, outputdev);
  627. #ifdef CONFIG_CONSOLE_MUX
  628. console_devices[stdout][0] = outputdev;
  629. console_devices[stderr][0] = outputdev;
  630. #endif
  631. }
  632. /* Initializes input console */
  633. if (inputdev != NULL) {
  634. console_setfile(stdin, inputdev);
  635. #ifdef CONFIG_CONSOLE_MUX
  636. console_devices[stdin][0] = inputdev;
  637. #endif
  638. }
  639. gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
  640. stdio_print_current_devices();
  641. /* Setting environment variables */
  642. for (i = 0; i < 3; i++) {
  643. setenv(stdio_names[i], stdio_devices[i]->name);
  644. }
  645. #if 0
  646. /* If nothing usable installed, use only the initial console */
  647. if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
  648. return 0;
  649. #endif
  650. return 0;
  651. }
  652. #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */