blob: 29560c3ebecbf595f813a5dde9fb102afe4dfa55 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * (C) Copyright 2000
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk47d1a6e2002-11-03 00:01:44 +00006 */
7
8#include <common.h>
9#include <stdarg.h>
Jeroen Hofstee3b46b3b2014-10-08 22:57:48 +020010#include <iomux.h>
wdenk47d1a6e2002-11-03 00:01:44 +000011#include <malloc.h>
Simon Glass3e9fd242013-11-10 10:27:01 -070012#include <os.h>
Joe Hershberger5c89d6d2012-12-11 22:16:29 -060013#include <serial.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020014#include <stdio_dev.h>
wdenk874ac262003-07-24 23:38:38 +000015#include <exports.h>
Joe Hershberger5c89d6d2012-12-11 22:16:29 -060016#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000017
Wolfgang Denk6405a152006-03-31 18:32:53 +020018DECLARE_GLOBAL_DATA_PTR;
19
Joe Hershberger5c89d6d2012-12-11 22:16:29 -060020static int on_console(const char *name, const char *value, enum env_op op,
21 int flags)
22{
23 int console = -1;
24
25 /* Check for console redirection */
26 if (strcmp(name, "stdin") == 0)
27 console = stdin;
28 else if (strcmp(name, "stdout") == 0)
29 console = stdout;
30 else if (strcmp(name, "stderr") == 0)
31 console = stderr;
32
33 /* if not actually setting a console variable, we don't care */
34 if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0)
35 return 0;
36
37 switch (op) {
38 case env_op_create:
39 case env_op_overwrite:
40
41#ifdef CONFIG_CONSOLE_MUX
42 if (iomux_doenv(console, value))
43 return 1;
44#else
45 /* Try assigning specified device */
46 if (console_assign(console, value) < 0)
47 return 1;
48#endif /* CONFIG_CONSOLE_MUX */
49 return 0;
50
51 case env_op_delete:
52 if ((flags & H_FORCE) == 0)
53 printf("Can't delete \"%s\"\n", name);
54 return 1;
55
56 default:
57 return 0;
58 }
59}
60U_BOOT_ENV_CALLBACK(console, on_console);
61
Joe Hershberger03ddaba2012-12-11 22:16:30 -060062#ifdef CONFIG_SILENT_CONSOLE
63static int on_silent(const char *name, const char *value, enum env_op op,
64 int flags)
65{
66#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_SET
67 if (flags & H_INTERACTIVE)
68 return 0;
69#endif
70#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC
71 if ((flags & H_INTERACTIVE) == 0)
72 return 0;
73#endif
74
75 if (value != NULL)
76 gd->flags |= GD_FLG_SILENT;
77 else
78 gd->flags &= ~GD_FLG_SILENT;
79
80 return 0;
81}
82U_BOOT_ENV_CALLBACK(silent, on_silent);
83#endif
84
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
wdenk47d1a6e2002-11-03 00:01:44 +000086/*
87 * if overwrite_console returns 1, the stdin, stderr and stdout
88 * are switched to the serial port, else the settings in the
89 * environment are used
90 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020091#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +010092extern int overwrite_console(void);
93#define OVERWRITE_CONSOLE overwrite_console()
wdenk47d1a6e2002-11-03 00:01:44 +000094#else
wdenk61c636e2005-03-31 18:42:15 +000095#define OVERWRITE_CONSOLE 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020096#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
wdenk47d1a6e2002-11-03 00:01:44 +000097
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +000099
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200100static int console_setfile(int file, struct stdio_dev * dev)
wdenk47d1a6e2002-11-03 00:01:44 +0000101{
102 int error = 0;
103
104 if (dev == NULL)
105 return -1;
106
107 switch (file) {
108 case stdin:
109 case stdout:
110 case stderr:
111 /* Start new device */
112 if (dev->start) {
Simon Glass0d1e1f72014-07-23 06:54:59 -0600113 error = dev->start(dev);
wdenk47d1a6e2002-11-03 00:01:44 +0000114 /* If it's not started dont use it */
115 if (error < 0)
116 break;
117 }
118
119 /* Assign the new device (leaving the existing one started) */
120 stdio_devices[file] = dev;
121
122 /*
123 * Update monitor functions
124 * (to use the console stuff by other applications)
125 */
126 switch (file) {
127 case stdin:
Simon Glass379bcd62014-11-13 20:51:12 -0700128 gd->jt[XF_getc] = getc;
129 gd->jt[XF_tstc] = tstc;
wdenk47d1a6e2002-11-03 00:01:44 +0000130 break;
131 case stdout:
Simon Glass379bcd62014-11-13 20:51:12 -0700132 gd->jt[XF_putc] = putc;
133 gd->jt[XF_puts] = puts;
wdenk874ac262003-07-24 23:38:38 +0000134 gd->jt[XF_printf] = printf;
wdenk47d1a6e2002-11-03 00:01:44 +0000135 break;
136 }
137 break;
138
139 default: /* Invalid file ID */
140 error = -1;
141 }
142 return error;
143}
144
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100145#if defined(CONFIG_CONSOLE_MUX)
146/** Console I/O multiplexing *******************************************/
147
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200148static struct stdio_dev *tstcdev;
149struct stdio_dev **console_devices[MAX_FILES];
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100150int cd_count[MAX_FILES];
151
152/*
153 * This depends on tstc() always being called before getc().
154 * This is guaranteed to be true because this routine is called
155 * only from fgetc() which assures it.
156 * No attempt is made to demultiplex multiple input sources.
157 */
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100158static int console_getc(int file)
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100159{
160 unsigned char ret;
161
162 /* This is never called with testcdev == NULL */
Simon Glass0d1e1f72014-07-23 06:54:59 -0600163 ret = tstcdev->getc(tstcdev);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100164 tstcdev = NULL;
165 return ret;
166}
167
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100168static int console_tstc(int file)
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100169{
170 int i, ret;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200171 struct stdio_dev *dev;
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100172
173 disable_ctrlc(1);
174 for (i = 0; i < cd_count[file]; i++) {
175 dev = console_devices[file][i];
176 if (dev->tstc != NULL) {
Simon Glass0d1e1f72014-07-23 06:54:59 -0600177 ret = dev->tstc(dev);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100178 if (ret > 0) {
179 tstcdev = dev;
180 disable_ctrlc(0);
181 return ret;
182 }
183 }
184 }
185 disable_ctrlc(0);
186
187 return 0;
188}
189
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100190static void console_putc(int file, const char c)
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100191{
192 int i;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200193 struct stdio_dev *dev;
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100194
195 for (i = 0; i < cd_count[file]; i++) {
196 dev = console_devices[file][i];
197 if (dev->putc != NULL)
Simon Glass0d1e1f72014-07-23 06:54:59 -0600198 dev->putc(dev, c);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100199 }
200}
201
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100202static void console_puts(int file, const char *s)
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100203{
204 int i;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200205 struct stdio_dev *dev;
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100206
207 for (i = 0; i < cd_count[file]; i++) {
208 dev = console_devices[file][i];
209 if (dev->puts != NULL)
Simon Glass0d1e1f72014-07-23 06:54:59 -0600210 dev->puts(dev, s);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100211 }
212}
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100213
214static inline void console_printdevs(int file)
215{
216 iomux_printdevs(file);
217}
218
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200219static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100220{
221 iomux_doenv(file, dev->name);
222}
223#else
224static inline int console_getc(int file)
225{
Simon Glass0d1e1f72014-07-23 06:54:59 -0600226 return stdio_devices[file]->getc(stdio_devices[file]);
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100227}
228
229static inline int console_tstc(int file)
230{
Simon Glass0d1e1f72014-07-23 06:54:59 -0600231 return stdio_devices[file]->tstc(stdio_devices[file]);
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100232}
233
234static inline void console_putc(int file, const char c)
235{
Simon Glass0d1e1f72014-07-23 06:54:59 -0600236 stdio_devices[file]->putc(stdio_devices[file], c);
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100237}
238
239static inline void console_puts(int file, const char *s)
240{
Simon Glass0d1e1f72014-07-23 06:54:59 -0600241 stdio_devices[file]->puts(stdio_devices[file], s);
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100242}
243
244static inline void console_printdevs(int file)
245{
246 printf("%s\n", stdio_devices[file]->name);
247}
248
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200249static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100250{
251 console_setfile(file, dev);
252}
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100253#endif /* defined(CONFIG_CONSOLE_MUX) */
254
wdenk47d1a6e2002-11-03 00:01:44 +0000255/** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
256
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200257int serial_printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000258{
259 va_list args;
260 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200261 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000262
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100263 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000264
265 /* For this to work, printbuffer must be larger than
266 * anything we ever want to print.
267 */
Sonny Rao2813a212011-10-10 09:22:31 +0000268 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100269 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000270
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100271 serial_puts(printbuffer);
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200272 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000273}
274
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100275int fgetc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000276{
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100277 if (file < MAX_FILES) {
278#if defined(CONFIG_CONSOLE_MUX)
279 /*
280 * Effectively poll for input wherever it may be available.
281 */
282 for (;;) {
283 /*
284 * Upper layer may have already called tstc() so
285 * check for that first.
286 */
287 if (tstcdev != NULL)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100288 return console_getc(file);
289 console_tstc(file);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100290#ifdef CONFIG_WATCHDOG
291 /*
292 * If the watchdog must be rate-limited then it should
293 * already be handled in board-specific code.
294 */
295 udelay(1);
296#endif
297 }
298#else
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100299 return console_getc(file);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100300#endif
301 }
wdenk47d1a6e2002-11-03 00:01:44 +0000302
303 return -1;
304}
305
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100306int ftstc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000307{
308 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100309 return console_tstc(file);
wdenk47d1a6e2002-11-03 00:01:44 +0000310
311 return -1;
312}
313
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100314void fputc(int file, const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000315{
316 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100317 console_putc(file, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000318}
319
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100320void fputs(int file, const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000321{
322 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100323 console_puts(file, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000324}
325
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200326int fprintf(int file, const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000327{
328 va_list args;
329 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200330 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000331
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100332 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000333
334 /* For this to work, printbuffer must be larger than
335 * anything we ever want to print.
336 */
Sonny Rao2813a212011-10-10 09:22:31 +0000337 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100338 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000339
340 /* Send to desired file */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100341 fputs(file, printbuffer);
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200342 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000343}
344
345/** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
346
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100347int getc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000348{
Mark Jackson5de56212008-08-25 19:21:30 +0100349#ifdef CONFIG_DISABLE_CONSOLE
350 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
351 return 0;
352#endif
353
Graeme Russ70600b02011-08-29 02:14:05 +0000354 if (!gd->have_console)
355 return 0;
356
wdenk47d1a6e2002-11-03 00:01:44 +0000357 if (gd->flags & GD_FLG_DEVINIT) {
358 /* Get from the standard input */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100359 return fgetc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000360 }
361
362 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100363 return serial_getc();
wdenk47d1a6e2002-11-03 00:01:44 +0000364}
365
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100366int tstc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000367{
Mark Jackson5de56212008-08-25 19:21:30 +0100368#ifdef CONFIG_DISABLE_CONSOLE
369 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
370 return 0;
371#endif
372
Graeme Russ70600b02011-08-29 02:14:05 +0000373 if (!gd->have_console)
374 return 0;
375
wdenk47d1a6e2002-11-03 00:01:44 +0000376 if (gd->flags & GD_FLG_DEVINIT) {
377 /* Test the standard input */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100378 return ftstc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000379 }
380
381 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100382 return serial_tstc();
wdenk47d1a6e2002-11-03 00:01:44 +0000383}
384
Simon Glass89aa5c92012-03-19 21:59:14 -0700385#ifdef CONFIG_PRE_CONSOLE_BUFFER
Graeme Russ3c28f482011-09-01 00:48:27 +0000386#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
387
388static void pre_console_putc(const char c)
389{
390 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
391
392 buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
393}
394
395static void pre_console_puts(const char *s)
396{
397 while (*s)
398 pre_console_putc(*s++);
399}
400
401static void print_pre_console_buffer(void)
402{
403 unsigned long i = 0;
404 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
405
406 if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
407 i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
408
409 while (i < gd->precon_buf_idx)
410 putc(buffer[CIRC_BUF_IDX(i++)]);
411}
412#else
413static inline void pre_console_putc(const char c) {}
414static inline void pre_console_puts(const char *s) {}
415static inline void print_pre_console_buffer(void) {}
416#endif
417
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100418void putc(const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000419{
Simon Glass3e9fd242013-11-10 10:27:01 -0700420#ifdef CONFIG_SANDBOX
Simon Glassb9d5f6b2014-07-23 06:55:07 -0600421 if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
Simon Glass3e9fd242013-11-10 10:27:01 -0700422 os_putc(c);
423 return;
424 }
425#endif
wdenk4b6e9052004-02-06 21:48:22 +0000426#ifdef CONFIG_SILENT_CONSOLE
427 if (gd->flags & GD_FLG_SILENT)
wdenk927034e2004-02-08 19:38:38 +0000428 return;
wdenk4b6e9052004-02-06 21:48:22 +0000429#endif
430
Mark Jackson5de56212008-08-25 19:21:30 +0100431#ifdef CONFIG_DISABLE_CONSOLE
432 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
433 return;
434#endif
435
Graeme Russ70600b02011-08-29 02:14:05 +0000436 if (!gd->have_console)
Graeme Russ3c28f482011-09-01 00:48:27 +0000437 return pre_console_putc(c);
Graeme Russ70600b02011-08-29 02:14:05 +0000438
wdenk47d1a6e2002-11-03 00:01:44 +0000439 if (gd->flags & GD_FLG_DEVINIT) {
440 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100441 fputc(stdout, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000442 } else {
443 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100444 serial_putc(c);
wdenk47d1a6e2002-11-03 00:01:44 +0000445 }
446}
447
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100448void puts(const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000449{
Simon Glass3e9fd242013-11-10 10:27:01 -0700450#ifdef CONFIG_SANDBOX
Simon Glassb9d5f6b2014-07-23 06:55:07 -0600451 if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
Simon Glass3e9fd242013-11-10 10:27:01 -0700452 os_puts(s);
453 return;
454 }
455#endif
456
wdenk4b6e9052004-02-06 21:48:22 +0000457#ifdef CONFIG_SILENT_CONSOLE
458 if (gd->flags & GD_FLG_SILENT)
459 return;
460#endif
461
Mark Jackson5de56212008-08-25 19:21:30 +0100462#ifdef CONFIG_DISABLE_CONSOLE
463 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
464 return;
465#endif
466
Graeme Russ70600b02011-08-29 02:14:05 +0000467 if (!gd->have_console)
Graeme Russ3c28f482011-09-01 00:48:27 +0000468 return pre_console_puts(s);
Graeme Russ70600b02011-08-29 02:14:05 +0000469
wdenk47d1a6e2002-11-03 00:01:44 +0000470 if (gd->flags & GD_FLG_DEVINIT) {
471 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100472 fputs(stdout, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000473 } else {
474 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100475 serial_puts(s);
wdenk47d1a6e2002-11-03 00:01:44 +0000476 }
477}
478
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200479int printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000480{
481 va_list args;
482 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200483 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000484
Simon Glass3e9fd242013-11-10 10:27:01 -0700485#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER)
Graeme Russ70600b02011-08-29 02:14:05 +0000486 if (!gd->have_console)
487 return 0;
Graeme Russ3c28f482011-09-01 00:48:27 +0000488#endif
Graeme Russ70600b02011-08-29 02:14:05 +0000489
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100490 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000491
492 /* For this to work, printbuffer must be larger than
493 * anything we ever want to print.
494 */
Sonny Rao2813a212011-10-10 09:22:31 +0000495 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100496 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000497
498 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100499 puts(printbuffer);
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200500 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000501}
502
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200503int vprintf(const char *fmt, va_list args)
wdenkb00ec162003-06-19 23:40:20 +0000504{
505 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200506 char printbuffer[CONFIG_SYS_PBSIZE];
wdenkb00ec162003-06-19 23:40:20 +0000507
Simon Glassa9d808b2014-07-23 06:55:06 -0600508#if defined(CONFIG_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SANDBOX)
Graeme Russ70600b02011-08-29 02:14:05 +0000509 if (!gd->have_console)
510 return 0;
Graeme Russ3c28f482011-09-01 00:48:27 +0000511#endif
Graeme Russ70600b02011-08-29 02:14:05 +0000512
wdenkb00ec162003-06-19 23:40:20 +0000513 /* For this to work, printbuffer must be larger than
514 * anything we ever want to print.
515 */
Sonny Rao2813a212011-10-10 09:22:31 +0000516 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenkb00ec162003-06-19 23:40:20 +0000517
518 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100519 puts(printbuffer);
Wolfgang Denk318ef5c2010-06-20 17:14:14 +0200520 return i;
wdenkb00ec162003-06-19 23:40:20 +0000521}
522
wdenk47d1a6e2002-11-03 00:01:44 +0000523/* test if ctrl-c was pressed */
524static int ctrlc_disabled = 0; /* see disable_ctrl() */
525static int ctrlc_was_pressed = 0;
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100526int ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000527{
Simon Glass28c5ce72014-09-14 12:40:15 -0600528#ifndef CONFIG_SANDBOX
wdenk47d1a6e2002-11-03 00:01:44 +0000529 if (!ctrlc_disabled && gd->have_console) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100530 if (tstc()) {
531 switch (getc()) {
wdenk47d1a6e2002-11-03 00:01:44 +0000532 case 0x03: /* ^C - Control C */
533 ctrlc_was_pressed = 1;
534 return 1;
535 default:
536 break;
537 }
538 }
539 }
Simon Glass28c5ce72014-09-14 12:40:15 -0600540#endif
541
wdenk47d1a6e2002-11-03 00:01:44 +0000542 return 0;
543}
Pierre Aubert5fef9d32014-04-24 10:30:07 +0200544/* Reads user's confirmation.
545 Returns 1 if user's input is "y", "Y", "yes" or "YES"
546*/
547int confirm_yesno(void)
548{
549 int i;
550 char str_input[5];
wdenk47d1a6e2002-11-03 00:01:44 +0000551
Pierre Aubert5fef9d32014-04-24 10:30:07 +0200552 /* Flush input */
553 while (tstc())
554 getc();
555 i = 0;
556 while (i < sizeof(str_input)) {
557 str_input[i] = getc();
558 putc(str_input[i]);
559 if (str_input[i] == '\r')
560 break;
561 i++;
562 }
563 putc('\n');
564 if (strncmp(str_input, "y\r", 2) == 0 ||
565 strncmp(str_input, "Y\r", 2) == 0 ||
566 strncmp(str_input, "yes\r", 4) == 0 ||
567 strncmp(str_input, "YES\r", 4) == 0)
568 return 1;
569 return 0;
570}
wdenk47d1a6e2002-11-03 00:01:44 +0000571/* pass 1 to disable ctrlc() checking, 0 to enable.
572 * returns previous state
573 */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100574int disable_ctrlc(int disable)
wdenk47d1a6e2002-11-03 00:01:44 +0000575{
576 int prev = ctrlc_disabled; /* save previous state */
577
578 ctrlc_disabled = disable;
579 return prev;
580}
581
582int had_ctrlc (void)
583{
584 return ctrlc_was_pressed;
585}
586
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100587void clear_ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000588{
589 ctrlc_was_pressed = 0;
590}
591
592#ifdef CONFIG_MODEM_SUPPORT_DEBUG
593char screen[1024];
594char *cursor = screen;
595int once = 0;
596inline void dbg(const char *fmt, ...)
597{
598 va_list args;
599 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200600 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000601
602 if (!once) {
603 memset(screen, 0, sizeof(screen));
604 once++;
605 }
606
607 va_start(args, fmt);
608
609 /* For this to work, printbuffer must be larger than
610 * anything we ever want to print.
611 */
Sonny Rao2813a212011-10-10 09:22:31 +0000612 i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenk47d1a6e2002-11-03 00:01:44 +0000613 va_end(args);
614
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100615 if ((screen + sizeof(screen) - 1 - cursor)
616 < strlen(printbuffer) + 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000617 memset(screen, 0, sizeof(screen));
618 cursor = screen;
619 }
620 sprintf(cursor, printbuffer);
621 cursor += strlen(printbuffer);
622
623}
624#else
Jeroen Hofstee3b46b3b2014-10-08 22:57:48 +0200625static inline void dbg(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000626{
627}
628#endif
629
630/** U-Boot INIT FUNCTIONS *************************************************/
631
Mike Frysingere3d55722010-10-20 07:18:03 -0400632struct stdio_dev *search_device(int flags, const char *name)
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200633{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200634 struct stdio_dev *dev;
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200635
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200636 dev = stdio_get_by_name(name);
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200637
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100638 if (dev && (dev->flags & flags))
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200639 return dev;
640
641 return NULL;
642}
643
Mike Frysingere3d55722010-10-20 07:18:03 -0400644int console_assign(int file, const char *devname)
wdenk47d1a6e2002-11-03 00:01:44 +0000645{
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200646 int flag;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200647 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000648
649 /* Check for valid file */
650 switch (file) {
651 case stdin:
652 flag = DEV_FLAGS_INPUT;
653 break;
654 case stdout:
655 case stderr:
656 flag = DEV_FLAGS_OUTPUT;
657 break;
658 default:
659 return -1;
660 }
661
662 /* Check for valid device name */
663
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200664 dev = search_device(flag, devname);
wdenk47d1a6e2002-11-03 00:01:44 +0000665
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100666 if (dev)
667 return console_setfile(file, dev);
wdenk47d1a6e2002-11-03 00:01:44 +0000668
669 return -1;
670}
671
672/* Called before relocation - use serial functions */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100673int console_init_f(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000674{
wdenk47d1a6e2002-11-03 00:01:44 +0000675 gd->have_console = 1;
wdenk808532a2003-10-10 10:05:42 +0000676
677#ifdef CONFIG_SILENT_CONSOLE
678 if (getenv("silent") != NULL)
679 gd->flags |= GD_FLG_SILENT;
680#endif
681
Graeme Russ3c28f482011-09-01 00:48:27 +0000682 print_pre_console_buffer();
683
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100684 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000685}
686
Jean-Christophe PLAGNIOL-VILLARD5a309362009-05-16 12:14:55 +0200687void stdio_print_current_devices(void)
688{
Jean-Christophe PLAGNIOL-VILLARD5a309362009-05-16 12:14:55 +0200689 /* Print information */
690 puts("In: ");
691 if (stdio_devices[stdin] == NULL) {
692 puts("No input devices available!\n");
693 } else {
694 printf ("%s\n", stdio_devices[stdin]->name);
695 }
696
697 puts("Out: ");
698 if (stdio_devices[stdout] == NULL) {
699 puts("No output devices available!\n");
700 } else {
701 printf ("%s\n", stdio_devices[stdout]->name);
702 }
703
704 puts("Err: ");
705 if (stdio_devices[stderr] == NULL) {
706 puts("No error devices available!\n");
707 } else {
708 printf ("%s\n", stdio_devices[stderr]->name);
709 }
Jean-Christophe PLAGNIOL-VILLARD5a309362009-05-16 12:14:55 +0200710}
711
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200712#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
wdenk47d1a6e2002-11-03 00:01:44 +0000713/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100714int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000715{
716 char *stdinname, *stdoutname, *stderrname;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200717 struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200718#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk05939202004-04-18 17:39:38 +0000719 int i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200720#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100721#ifdef CONFIG_CONSOLE_MUX
722 int iomux_err = 0;
723#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000724
725 /* set default handlers at first */
wdenk874ac262003-07-24 23:38:38 +0000726 gd->jt[XF_getc] = serial_getc;
727 gd->jt[XF_tstc] = serial_tstc;
728 gd->jt[XF_putc] = serial_putc;
729 gd->jt[XF_puts] = serial_puts;
730 gd->jt[XF_printf] = serial_printf;
wdenk47d1a6e2002-11-03 00:01:44 +0000731
732 /* stdin stdout and stderr are in environment */
733 /* scan for it */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100734 stdinname = getenv("stdin");
735 stdoutname = getenv("stdout");
736 stderrname = getenv("stderr");
wdenk47d1a6e2002-11-03 00:01:44 +0000737
Wolfgang Denka1be4762008-05-20 16:00:29 +0200738 if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100739 inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
740 outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
741 errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100742#ifdef CONFIG_CONSOLE_MUX
743 iomux_err = iomux_doenv(stdin, stdinname);
744 iomux_err += iomux_doenv(stdout, stdoutname);
745 iomux_err += iomux_doenv(stderr, stderrname);
746 if (!iomux_err)
747 /* Successful, so skip all the code below. */
748 goto done;
749#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000750 }
751 /* if the devices are overwritten or not found, use default device */
752 if (inputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100753 inputdev = search_device(DEV_FLAGS_INPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000754 }
755 if (outputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100756 outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000757 }
758 if (errdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100759 errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000760 }
761 /* Initializes output console first */
762 if (outputdev != NULL) {
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100763 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100764 console_doenv(stdout, outputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000765 }
766 if (errdev != NULL) {
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100767 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100768 console_doenv(stderr, errdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000769 }
770 if (inputdev != NULL) {
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100771 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD63331a02009-02-01 17:07:52 +0100772 console_doenv(stdin, inputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000773 }
774
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100775#ifdef CONFIG_CONSOLE_MUX
776done:
777#endif
778
Simon Glassa2cc8552012-12-05 14:46:43 +0000779#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD5a309362009-05-16 12:14:55 +0200780 stdio_print_current_devices();
Simon Glassa2cc8552012-12-05 14:46:43 +0000781#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000782
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200783#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk47d1a6e2002-11-03 00:01:44 +0000784 /* set the environment variables (will overwrite previous env settings) */
785 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100786 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000787 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200788#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
wdenk47d1a6e2002-11-03 00:01:44 +0000789
Joe Hershbergera46f7702012-12-11 22:16:19 -0600790 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
791
wdenk47d1a6e2002-11-03 00:01:44 +0000792#if 0
793 /* If nothing usable installed, use only the initial console */
794 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100795 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000796#endif
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100797 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000798}
799
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200800#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +0000801
802/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100803int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000804{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200805 struct stdio_dev *inputdev = NULL, *outputdev = NULL;
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200806 int i;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200807 struct list_head *list = stdio_get_list();
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200808 struct list_head *pos;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200809 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000810
wdenk92bbe3f2003-04-20 14:04:18 +0000811#ifdef CONFIG_SPLASH_SCREEN
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100812 /*
813 * suppress all output if splash screen is enabled and we have
Anatolij Gustschinec8744a2010-03-16 15:29:33 +0100814 * a bmp to display. We redirect the output from frame buffer
815 * console to serial console in this case or suppress it if
816 * "silent" mode was requested.
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100817 */
Anatolij Gustschinec8744a2010-03-16 15:29:33 +0100818 if (getenv("splashimage") != NULL) {
819 if (!(gd->flags & GD_FLG_SILENT))
820 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
821 }
wdenk808532a2003-10-10 10:05:42 +0000822#endif
823
wdenk47d1a6e2002-11-03 00:01:44 +0000824 /* Scan devices looking for input and output devices */
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200825 list_for_each(pos, list) {
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200826 dev = list_entry(pos, struct stdio_dev, list);
wdenk47d1a6e2002-11-03 00:01:44 +0000827
828 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
829 inputdev = dev;
830 }
831 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
832 outputdev = dev;
833 }
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +0200834 if(inputdev && outputdev)
835 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000836 }
837
838 /* Initializes output console first */
839 if (outputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100840 console_setfile(stdout, outputdev);
841 console_setfile(stderr, outputdev);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100842#ifdef CONFIG_CONSOLE_MUX
843 console_devices[stdout][0] = outputdev;
844 console_devices[stderr][0] = outputdev;
845#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000846 }
847
848 /* Initializes input console */
849 if (inputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100850 console_setfile(stdin, inputdev);
Gary Jennejohnc6dc7552008-11-06 15:04:23 +0100851#ifdef CONFIG_CONSOLE_MUX
852 console_devices[stdin][0] = inputdev;
853#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000854 }
855
Simon Glassa2cc8552012-12-05 14:46:43 +0000856#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD5a309362009-05-16 12:14:55 +0200857 stdio_print_current_devices();
Simon Glassa2cc8552012-12-05 14:46:43 +0000858#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000859
860 /* Setting environment variables */
861 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100862 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000863 }
864
Joe Hershbergera46f7702012-12-11 22:16:19 -0600865 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
866
wdenk47d1a6e2002-11-03 00:01:44 +0000867#if 0
868 /* If nothing usable installed, use only the initial console */
869 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100870 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000871#endif
872
Jean-Christophe PLAGNIOL-VILLARDc7dc6722009-02-01 17:07:51 +0100873 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000874}
875
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200876#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */