console.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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 = vscnprintf(printbuffer, sizeof(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 = vscnprintf(printbuffer, sizeof(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. #if defined(CONFIG_PRE_CONSOLE_BUFFER) || defined(CONFIG_PRE_CONSOLE_PUTC)
  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. #ifdef CONFIG_PRE_CONSOLE_BUFFER
  284. char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
  285. buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
  286. #endif
  287. #ifdef CONFIG_PRE_CONSOLE_PUTC
  288. board_pre_console_putc(c);
  289. #endif
  290. }
  291. static void pre_console_puts(const char *s)
  292. {
  293. while (*s)
  294. pre_console_putc(*s++);
  295. }
  296. static void print_pre_console_buffer(void)
  297. {
  298. #ifdef CONFIG_PRE_CONSOLE_BUFFER
  299. unsigned long i = 0;
  300. char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
  301. if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
  302. i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
  303. while (i < gd->precon_buf_idx)
  304. putc(buffer[CIRC_BUF_IDX(i++)]);
  305. #endif
  306. }
  307. #else
  308. static inline void pre_console_putc(const char c) {}
  309. static inline void pre_console_puts(const char *s) {}
  310. static inline void print_pre_console_buffer(void) {}
  311. #endif
  312. void putc(const char c)
  313. {
  314. #ifdef CONFIG_SILENT_CONSOLE
  315. if (gd->flags & GD_FLG_SILENT)
  316. return;
  317. #endif
  318. #ifdef CONFIG_DISABLE_CONSOLE
  319. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  320. return;
  321. #endif
  322. if (!gd->have_console)
  323. return pre_console_putc(c);
  324. if (gd->flags & GD_FLG_DEVINIT) {
  325. /* Send to the standard output */
  326. fputc(stdout, c);
  327. } else {
  328. /* Send directly to the handler */
  329. serial_putc(c);
  330. }
  331. }
  332. void puts(const char *s)
  333. {
  334. #ifdef CONFIG_SILENT_CONSOLE
  335. if (gd->flags & GD_FLG_SILENT)
  336. return;
  337. #endif
  338. #ifdef CONFIG_DISABLE_CONSOLE
  339. if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  340. return;
  341. #endif
  342. if (!gd->have_console)
  343. return pre_console_puts(s);
  344. if (gd->flags & GD_FLG_DEVINIT) {
  345. /* Send to the standard output */
  346. fputs(stdout, s);
  347. } else {
  348. /* Send directly to the handler */
  349. serial_puts(s);
  350. }
  351. }
  352. int printf(const char *fmt, ...)
  353. {
  354. va_list args;
  355. uint i;
  356. char printbuffer[CONFIG_SYS_PBSIZE];
  357. #ifndef CONFIG_PRE_CONSOLE_BUFFER
  358. if (!gd->have_console)
  359. return 0;
  360. #endif
  361. va_start(args, fmt);
  362. /* For this to work, printbuffer must be larger than
  363. * anything we ever want to print.
  364. */
  365. i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
  366. va_end(args);
  367. /* Print the string */
  368. puts(printbuffer);
  369. return i;
  370. }
  371. int vprintf(const char *fmt, va_list args)
  372. {
  373. uint i;
  374. char printbuffer[CONFIG_SYS_PBSIZE];
  375. #ifndef CONFIG_PRE_CONSOLE_BUFFER
  376. if (!gd->have_console)
  377. return 0;
  378. #endif
  379. /* For this to work, printbuffer must be larger than
  380. * anything we ever want to print.
  381. */
  382. i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
  383. /* Print the string */
  384. puts(printbuffer);
  385. return i;
  386. }
  387. /* test if ctrl-c was pressed */
  388. static int ctrlc_disabled = 0; /* see disable_ctrl() */
  389. static int ctrlc_was_pressed = 0;
  390. int ctrlc(void)
  391. {
  392. if (!ctrlc_disabled && gd->have_console) {
  393. if (tstc()) {
  394. switch (getc()) {
  395. case 0x03: /* ^C - Control C */
  396. ctrlc_was_pressed = 1;
  397. return 1;
  398. default:
  399. break;
  400. }
  401. }
  402. }
  403. return 0;
  404. }
  405. /* pass 1 to disable ctrlc() checking, 0 to enable.
  406. * returns previous state
  407. */
  408. int disable_ctrlc(int disable)
  409. {
  410. int prev = ctrlc_disabled; /* save previous state */
  411. ctrlc_disabled = disable;
  412. return prev;
  413. }
  414. int had_ctrlc (void)
  415. {
  416. return ctrlc_was_pressed;
  417. }
  418. void clear_ctrlc(void)
  419. {
  420. ctrlc_was_pressed = 0;
  421. }
  422. #ifdef CONFIG_MODEM_SUPPORT_DEBUG
  423. char screen[1024];
  424. char *cursor = screen;
  425. int once = 0;
  426. inline void dbg(const char *fmt, ...)
  427. {
  428. va_list args;
  429. uint i;
  430. char printbuffer[CONFIG_SYS_PBSIZE];
  431. if (!once) {
  432. memset(screen, 0, sizeof(screen));
  433. once++;
  434. }
  435. va_start(args, fmt);
  436. /* For this to work, printbuffer must be larger than
  437. * anything we ever want to print.
  438. */
  439. i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
  440. va_end(args);
  441. if ((screen + sizeof(screen) - 1 - cursor)
  442. < strlen(printbuffer) + 1) {
  443. memset(screen, 0, sizeof(screen));
  444. cursor = screen;
  445. }
  446. sprintf(cursor, printbuffer);
  447. cursor += strlen(printbuffer);
  448. }
  449. #else
  450. inline void dbg(const char *fmt, ...)
  451. {
  452. }
  453. #endif
  454. /** U-Boot INIT FUNCTIONS *************************************************/
  455. struct stdio_dev *search_device(int flags, const char *name)
  456. {
  457. struct stdio_dev *dev;
  458. dev = stdio_get_by_name(name);
  459. if (dev && (dev->flags & flags))
  460. return dev;
  461. return NULL;
  462. }
  463. int console_assign(int file, const char *devname)
  464. {
  465. int flag;
  466. struct stdio_dev *dev;
  467. /* Check for valid file */
  468. switch (file) {
  469. case stdin:
  470. flag = DEV_FLAGS_INPUT;
  471. break;
  472. case stdout:
  473. case stderr:
  474. flag = DEV_FLAGS_OUTPUT;
  475. break;
  476. default:
  477. return -1;
  478. }
  479. /* Check for valid device name */
  480. dev = search_device(flag, devname);
  481. if (dev)
  482. return console_setfile(file, dev);
  483. return -1;
  484. }
  485. /* Called before relocation - use serial functions */
  486. int console_init_f(void)
  487. {
  488. gd->have_console = 1;
  489. #ifdef CONFIG_SILENT_CONSOLE
  490. if (getenv("silent") != NULL)
  491. gd->flags |= GD_FLG_SILENT;
  492. #endif
  493. print_pre_console_buffer();
  494. return 0;
  495. }
  496. void stdio_print_current_devices(void)
  497. {
  498. #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
  499. /* Print information */
  500. puts("In: ");
  501. if (stdio_devices[stdin] == NULL) {
  502. puts("No input devices available!\n");
  503. } else {
  504. printf ("%s\n", stdio_devices[stdin]->name);
  505. }
  506. puts("Out: ");
  507. if (stdio_devices[stdout] == NULL) {
  508. puts("No output devices available!\n");
  509. } else {
  510. printf ("%s\n", stdio_devices[stdout]->name);
  511. }
  512. puts("Err: ");
  513. if (stdio_devices[stderr] == NULL) {
  514. puts("No error devices available!\n");
  515. } else {
  516. printf ("%s\n", stdio_devices[stderr]->name);
  517. }
  518. #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
  519. }
  520. #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
  521. /* Called after the relocation - use desired console functions */
  522. int console_init_r(void)
  523. {
  524. char *stdinname, *stdoutname, *stderrname;
  525. struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
  526. #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  527. int i;
  528. #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
  529. #ifdef CONFIG_CONSOLE_MUX
  530. int iomux_err = 0;
  531. #endif
  532. /* set default handlers at first */
  533. gd->jt[XF_getc] = serial_getc;
  534. gd->jt[XF_tstc] = serial_tstc;
  535. gd->jt[XF_putc] = serial_putc;
  536. gd->jt[XF_puts] = serial_puts;
  537. gd->jt[XF_printf] = serial_printf;
  538. /* stdin stdout and stderr are in environment */
  539. /* scan for it */
  540. stdinname = getenv("stdin");
  541. stdoutname = getenv("stdout");
  542. stderrname = getenv("stderr");
  543. if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
  544. inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
  545. outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
  546. errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
  547. #ifdef CONFIG_CONSOLE_MUX
  548. iomux_err = iomux_doenv(stdin, stdinname);
  549. iomux_err += iomux_doenv(stdout, stdoutname);
  550. iomux_err += iomux_doenv(stderr, stderrname);
  551. if (!iomux_err)
  552. /* Successful, so skip all the code below. */
  553. goto done;
  554. #endif
  555. }
  556. /* if the devices are overwritten or not found, use default device */
  557. if (inputdev == NULL) {
  558. inputdev = search_device(DEV_FLAGS_INPUT, "serial");
  559. }
  560. if (outputdev == NULL) {
  561. outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
  562. }
  563. if (errdev == NULL) {
  564. errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
  565. }
  566. /* Initializes output console first */
  567. if (outputdev != NULL) {
  568. /* need to set a console if not done above. */
  569. console_doenv(stdout, outputdev);
  570. }
  571. if (errdev != NULL) {
  572. /* need to set a console if not done above. */
  573. console_doenv(stderr, errdev);
  574. }
  575. if (inputdev != NULL) {
  576. /* need to set a console if not done above. */
  577. console_doenv(stdin, inputdev);
  578. }
  579. #ifdef CONFIG_CONSOLE_MUX
  580. done:
  581. #endif
  582. gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
  583. stdio_print_current_devices();
  584. #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  585. /* set the environment variables (will overwrite previous env settings) */
  586. for (i = 0; i < 3; i++) {
  587. setenv(stdio_names[i], stdio_devices[i]->name);
  588. }
  589. #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
  590. #if 0
  591. /* If nothing usable installed, use only the initial console */
  592. if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
  593. return 0;
  594. #endif
  595. return 0;
  596. }
  597. #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
  598. /* Called after the relocation - use desired console functions */
  599. int console_init_r(void)
  600. {
  601. struct stdio_dev *inputdev = NULL, *outputdev = NULL;
  602. int i;
  603. struct list_head *list = stdio_get_list();
  604. struct list_head *pos;
  605. struct stdio_dev *dev;
  606. #ifdef CONFIG_SPLASH_SCREEN
  607. /*
  608. * suppress all output if splash screen is enabled and we have
  609. * a bmp to display. We redirect the output from frame buffer
  610. * console to serial console in this case or suppress it if
  611. * "silent" mode was requested.
  612. */
  613. if (getenv("splashimage") != NULL) {
  614. if (!(gd->flags & GD_FLG_SILENT))
  615. outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
  616. }
  617. #endif
  618. /* Scan devices looking for input and output devices */
  619. list_for_each(pos, list) {
  620. dev = list_entry(pos, struct stdio_dev, list);
  621. if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
  622. inputdev = dev;
  623. }
  624. if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
  625. outputdev = dev;
  626. }
  627. if(inputdev && outputdev)
  628. break;
  629. }
  630. /* Initializes output console first */
  631. if (outputdev != NULL) {
  632. console_setfile(stdout, outputdev);
  633. console_setfile(stderr, outputdev);
  634. #ifdef CONFIG_CONSOLE_MUX
  635. console_devices[stdout][0] = outputdev;
  636. console_devices[stderr][0] = outputdev;
  637. #endif
  638. }
  639. /* Initializes input console */
  640. if (inputdev != NULL) {
  641. console_setfile(stdin, inputdev);
  642. #ifdef CONFIG_CONSOLE_MUX
  643. console_devices[stdin][0] = inputdev;
  644. #endif
  645. }
  646. gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
  647. stdio_print_current_devices();
  648. /* Setting environment variables */
  649. for (i = 0; i < 3; i++) {
  650. setenv(stdio_names[i], stdio_devices[i]->name);
  651. }
  652. #if 0
  653. /* If nothing usable installed, use only the initial console */
  654. if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
  655. return 0;
  656. #endif
  657. return 0;
  658. }
  659. #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */