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