console.c 17 KB

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