console.c 17 KB

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