console.c 18 KB

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