blob: 3f25e76fe79ea3c94a85d0306d668233320e2d47 [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 Denk1a459662013-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 Hofstee482f4692014-10-08 22:57:48 +020010#include <iomux.h>
wdenk47d1a6e2002-11-03 00:01:44 +000011#include <malloc.h>
Simon Glass91b136c2013-11-10 10:27:01 -070012#include <os.h>
Joe Hershberger849d5d92012-12-11 22:16:29 -060013#include <serial.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020014#include <stdio_dev.h>
wdenk27b207f2003-07-24 23:38:38 +000015#include <exports.h>
Joe Hershberger849d5d92012-12-11 22:16:29 -060016#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000017
Wolfgang Denkd87080b2006-03-31 18:32:53 +020018DECLARE_GLOBAL_DATA_PTR;
19
Joe Hershberger849d5d92012-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 Hershbergere080d542012-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-VILLARD6d0f6bc2008-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020091#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +010092extern int overwrite_console(void);
93#define OVERWRITE_CONSOLE overwrite_console()
wdenk47d1a6e2002-11-03 00:01:44 +000094#else
wdenk83e40ba2005-03-31 18:42:15 +000095#define OVERWRITE_CONSOLE 0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
wdenk47d1a6e2002-11-03 00:01:44 +000097
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +000099
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-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 Glass709ea542014-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:
Martin Dorwig49cad542015-01-26 15:22:54 -0700128 gd->jt->getc = getc;
129 gd->jt->tstc = tstc;
wdenk47d1a6e2002-11-03 00:01:44 +0000130 break;
131 case stdout:
Martin Dorwig49cad542015-01-26 15:22:54 -0700132 gd->jt->putc = putc;
133 gd->jt->puts = puts;
134 gd->jt->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 Jennejohn16a28ef2008-11-06 15:04:23 +0100145#if defined(CONFIG_CONSOLE_MUX)
146/** Console I/O multiplexing *******************************************/
147
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200148static struct stdio_dev *tstcdev;
149struct stdio_dev **console_devices[MAX_FILES];
Gary Jennejohn16a28ef2008-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-VILLARD5f032012009-02-01 17:07:52 +0100158static int console_getc(int file)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100159{
160 unsigned char ret;
161
162 /* This is never called with testcdev == NULL */
Simon Glass709ea542014-07-23 06:54:59 -0600163 ret = tstcdev->getc(tstcdev);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100164 tstcdev = NULL;
165 return ret;
166}
167
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100168static int console_tstc(int file)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100169{
170 int i, ret;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200171 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-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 Glass709ea542014-07-23 06:54:59 -0600177 ret = dev->tstc(dev);
Gary Jennejohn16a28ef2008-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-VILLARD5f032012009-02-01 17:07:52 +0100190static void console_putc(int file, const char c)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100191{
192 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200193 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-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 Glass709ea542014-07-23 06:54:59 -0600198 dev->putc(dev, c);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100199 }
200}
201
Siarhei Siamashka27669662015-01-08 09:02:31 +0200202#ifdef CONFIG_PRE_CONSOLE_BUFFER
203static void console_putc_noserial(int file, const char c)
204{
205 int i;
206 struct stdio_dev *dev;
207
208 for (i = 0; i < cd_count[file]; i++) {
209 dev = console_devices[file][i];
210 if (dev->putc != NULL && strcmp(dev->name, "serial") != 0)
211 dev->putc(dev, c);
212 }
213}
214#endif
215
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100216static void console_puts(int file, const char *s)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100217{
218 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200219 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100220
221 for (i = 0; i < cd_count[file]; i++) {
222 dev = console_devices[file][i];
223 if (dev->puts != NULL)
Simon Glass709ea542014-07-23 06:54:59 -0600224 dev->puts(dev, s);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100225 }
226}
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100227
228static inline void console_printdevs(int file)
229{
230 iomux_printdevs(file);
231}
232
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200233static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100234{
235 iomux_doenv(file, dev->name);
236}
237#else
238static inline int console_getc(int file)
239{
Simon Glass709ea542014-07-23 06:54:59 -0600240 return stdio_devices[file]->getc(stdio_devices[file]);
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100241}
242
243static inline int console_tstc(int file)
244{
Simon Glass709ea542014-07-23 06:54:59 -0600245 return stdio_devices[file]->tstc(stdio_devices[file]);
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100246}
247
248static inline void console_putc(int file, const char c)
249{
Simon Glass709ea542014-07-23 06:54:59 -0600250 stdio_devices[file]->putc(stdio_devices[file], c);
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100251}
252
Siarhei Siamashka27669662015-01-08 09:02:31 +0200253#ifdef CONFIG_PRE_CONSOLE_BUFFER
254static inline void console_putc_noserial(int file, const char c)
255{
256 if (strcmp(stdio_devices[file]->name, "serial") != 0)
257 stdio_devices[file]->putc(stdio_devices[file], c);
258}
259#endif
260
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100261static inline void console_puts(int file, const char *s)
262{
Simon Glass709ea542014-07-23 06:54:59 -0600263 stdio_devices[file]->puts(stdio_devices[file], s);
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100264}
265
266static inline void console_printdevs(int file)
267{
268 printf("%s\n", stdio_devices[file]->name);
269}
270
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200271static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100272{
273 console_setfile(file, dev);
274}
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100275#endif /* defined(CONFIG_CONSOLE_MUX) */
276
wdenk47d1a6e2002-11-03 00:01:44 +0000277/** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
278
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200279int serial_printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000280{
281 va_list args;
282 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200283 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000284
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100285 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000286
287 /* For this to work, printbuffer must be larger than
288 * anything we ever want to print.
289 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000290 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100291 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000292
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100293 serial_puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200294 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000295}
296
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100297int fgetc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000298{
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100299 if (file < MAX_FILES) {
300#if defined(CONFIG_CONSOLE_MUX)
301 /*
302 * Effectively poll for input wherever it may be available.
303 */
304 for (;;) {
305 /*
306 * Upper layer may have already called tstc() so
307 * check for that first.
308 */
309 if (tstcdev != NULL)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100310 return console_getc(file);
311 console_tstc(file);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100312#ifdef CONFIG_WATCHDOG
313 /*
314 * If the watchdog must be rate-limited then it should
315 * already be handled in board-specific code.
316 */
317 udelay(1);
318#endif
319 }
320#else
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100321 return console_getc(file);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100322#endif
323 }
wdenk47d1a6e2002-11-03 00:01:44 +0000324
325 return -1;
326}
327
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100328int ftstc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000329{
330 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100331 return console_tstc(file);
wdenk47d1a6e2002-11-03 00:01:44 +0000332
333 return -1;
334}
335
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100336void fputc(int file, const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000337{
338 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100339 console_putc(file, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000340}
341
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100342void fputs(int file, const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000343{
344 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100345 console_puts(file, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000346}
347
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200348int fprintf(int file, const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000349{
350 va_list args;
351 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200352 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000353
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100354 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000355
356 /* For this to work, printbuffer must be larger than
357 * anything we ever want to print.
358 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000359 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100360 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000361
362 /* Send to desired file */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100363 fputs(file, printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200364 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000365}
366
367/** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
368
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100369int getc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000370{
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100371#ifdef CONFIG_DISABLE_CONSOLE
372 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
373 return 0;
374#endif
375
Graeme Russe3e454c2011-08-29 02:14:05 +0000376 if (!gd->have_console)
377 return 0;
378
wdenk47d1a6e2002-11-03 00:01:44 +0000379 if (gd->flags & GD_FLG_DEVINIT) {
380 /* Get from the standard input */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100381 return fgetc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000382 }
383
384 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100385 return serial_getc();
wdenk47d1a6e2002-11-03 00:01:44 +0000386}
387
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100388int tstc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000389{
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100390#ifdef CONFIG_DISABLE_CONSOLE
391 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
392 return 0;
393#endif
394
Graeme Russe3e454c2011-08-29 02:14:05 +0000395 if (!gd->have_console)
396 return 0;
397
wdenk47d1a6e2002-11-03 00:01:44 +0000398 if (gd->flags & GD_FLG_DEVINIT) {
399 /* Test the standard input */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100400 return ftstc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000401 }
402
403 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100404 return serial_tstc();
wdenk47d1a6e2002-11-03 00:01:44 +0000405}
406
Siarhei Siamashka27669662015-01-08 09:02:31 +0200407#define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0
408#define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1
409
Simon Glass3fa49772012-03-19 21:59:14 -0700410#ifdef CONFIG_PRE_CONSOLE_BUFFER
Graeme Russ9558b482011-09-01 00:48:27 +0000411#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
412
413static void pre_console_putc(const char c)
414{
415 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
416
417 buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
418}
419
420static void pre_console_puts(const char *s)
421{
422 while (*s)
423 pre_console_putc(*s++);
424}
425
Siarhei Siamashka27669662015-01-08 09:02:31 +0200426static void print_pre_console_buffer(int flushpoint)
Graeme Russ9558b482011-09-01 00:48:27 +0000427{
428 unsigned long i = 0;
429 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
430
431 if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
432 i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
433
434 while (i < gd->precon_buf_idx)
Siarhei Siamashka27669662015-01-08 09:02:31 +0200435 switch (flushpoint) {
436 case PRE_CONSOLE_FLUSHPOINT1_SERIAL:
437 putc(buffer[CIRC_BUF_IDX(i++)]);
438 break;
439 case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL:
440 console_putc_noserial(stdout,
441 buffer[CIRC_BUF_IDX(i++)]);
442 break;
443 }
Graeme Russ9558b482011-09-01 00:48:27 +0000444}
445#else
446static inline void pre_console_putc(const char c) {}
447static inline void pre_console_puts(const char *s) {}
Siarhei Siamashka27669662015-01-08 09:02:31 +0200448static inline void print_pre_console_buffer(int flushpoint) {}
Graeme Russ9558b482011-09-01 00:48:27 +0000449#endif
450
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100451void putc(const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000452{
Simon Glass91b136c2013-11-10 10:27:01 -0700453#ifdef CONFIG_SANDBOX
Simon Glass093f79a2014-07-23 06:55:07 -0600454 if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
Simon Glass91b136c2013-11-10 10:27:01 -0700455 os_putc(c);
456 return;
457 }
458#endif
wdenka6cccae2004-02-06 21:48:22 +0000459#ifdef CONFIG_SILENT_CONSOLE
460 if (gd->flags & GD_FLG_SILENT)
wdenkf6e20fc2004-02-08 19:38:38 +0000461 return;
wdenka6cccae2004-02-06 21:48:22 +0000462#endif
463
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100464#ifdef CONFIG_DISABLE_CONSOLE
465 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
466 return;
467#endif
468
Graeme Russe3e454c2011-08-29 02:14:05 +0000469 if (!gd->have_console)
Graeme Russ9558b482011-09-01 00:48:27 +0000470 return pre_console_putc(c);
Graeme Russe3e454c2011-08-29 02:14:05 +0000471
wdenk47d1a6e2002-11-03 00:01:44 +0000472 if (gd->flags & GD_FLG_DEVINIT) {
473 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100474 fputc(stdout, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000475 } else {
476 /* Send directly to the handler */
Siarhei Siamashka27669662015-01-08 09:02:31 +0200477 pre_console_putc(c);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100478 serial_putc(c);
wdenk47d1a6e2002-11-03 00:01:44 +0000479 }
480}
481
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100482void puts(const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000483{
Simon Glass91b136c2013-11-10 10:27:01 -0700484#ifdef CONFIG_SANDBOX
Simon Glass093f79a2014-07-23 06:55:07 -0600485 if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
Simon Glass91b136c2013-11-10 10:27:01 -0700486 os_puts(s);
487 return;
488 }
489#endif
490
wdenka6cccae2004-02-06 21:48:22 +0000491#ifdef CONFIG_SILENT_CONSOLE
492 if (gd->flags & GD_FLG_SILENT)
493 return;
494#endif
495
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100496#ifdef CONFIG_DISABLE_CONSOLE
497 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
498 return;
499#endif
500
Graeme Russe3e454c2011-08-29 02:14:05 +0000501 if (!gd->have_console)
Graeme Russ9558b482011-09-01 00:48:27 +0000502 return pre_console_puts(s);
Graeme Russe3e454c2011-08-29 02:14:05 +0000503
wdenk47d1a6e2002-11-03 00:01:44 +0000504 if (gd->flags & GD_FLG_DEVINIT) {
505 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100506 fputs(stdout, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000507 } else {
508 /* Send directly to the handler */
Siarhei Siamashka27669662015-01-08 09:02:31 +0200509 pre_console_puts(s);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100510 serial_puts(s);
wdenk47d1a6e2002-11-03 00:01:44 +0000511 }
512}
513
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200514int printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000515{
516 va_list args;
517 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200518 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000519
Simon Glass91b136c2013-11-10 10:27:01 -0700520#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER)
Graeme Russe3e454c2011-08-29 02:14:05 +0000521 if (!gd->have_console)
522 return 0;
Graeme Russ9558b482011-09-01 00:48:27 +0000523#endif
Graeme Russe3e454c2011-08-29 02:14:05 +0000524
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100525 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000526
527 /* For this to work, printbuffer must be larger than
528 * anything we ever want to print.
529 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000530 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100531 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000532
533 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100534 puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200535 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000536}
537
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200538int vprintf(const char *fmt, va_list args)
wdenk6dd652f2003-06-19 23:40:20 +0000539{
540 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200541 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk6dd652f2003-06-19 23:40:20 +0000542
Simon Glass7793ac92014-07-23 06:55:06 -0600543#if defined(CONFIG_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SANDBOX)
Graeme Russe3e454c2011-08-29 02:14:05 +0000544 if (!gd->have_console)
545 return 0;
Graeme Russ9558b482011-09-01 00:48:27 +0000546#endif
Graeme Russe3e454c2011-08-29 02:14:05 +0000547
wdenk6dd652f2003-06-19 23:40:20 +0000548 /* For this to work, printbuffer must be larger than
549 * anything we ever want to print.
550 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000551 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenk6dd652f2003-06-19 23:40:20 +0000552
553 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100554 puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200555 return i;
wdenk6dd652f2003-06-19 23:40:20 +0000556}
557
wdenk47d1a6e2002-11-03 00:01:44 +0000558/* test if ctrl-c was pressed */
559static int ctrlc_disabled = 0; /* see disable_ctrl() */
560static int ctrlc_was_pressed = 0;
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100561int ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000562{
Simon Glass8969ea32014-09-14 12:40:15 -0600563#ifndef CONFIG_SANDBOX
wdenk47d1a6e2002-11-03 00:01:44 +0000564 if (!ctrlc_disabled && gd->have_console) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100565 if (tstc()) {
566 switch (getc()) {
wdenk47d1a6e2002-11-03 00:01:44 +0000567 case 0x03: /* ^C - Control C */
568 ctrlc_was_pressed = 1;
569 return 1;
570 default:
571 break;
572 }
573 }
574 }
Simon Glass8969ea32014-09-14 12:40:15 -0600575#endif
576
wdenk47d1a6e2002-11-03 00:01:44 +0000577 return 0;
578}
Pierre Auberta5dffa42014-04-24 10:30:07 +0200579/* Reads user's confirmation.
580 Returns 1 if user's input is "y", "Y", "yes" or "YES"
581*/
582int confirm_yesno(void)
583{
584 int i;
585 char str_input[5];
wdenk47d1a6e2002-11-03 00:01:44 +0000586
Pierre Auberta5dffa42014-04-24 10:30:07 +0200587 /* Flush input */
588 while (tstc())
589 getc();
590 i = 0;
591 while (i < sizeof(str_input)) {
592 str_input[i] = getc();
593 putc(str_input[i]);
594 if (str_input[i] == '\r')
595 break;
596 i++;
597 }
598 putc('\n');
599 if (strncmp(str_input, "y\r", 2) == 0 ||
600 strncmp(str_input, "Y\r", 2) == 0 ||
601 strncmp(str_input, "yes\r", 4) == 0 ||
602 strncmp(str_input, "YES\r", 4) == 0)
603 return 1;
604 return 0;
605}
wdenk47d1a6e2002-11-03 00:01:44 +0000606/* pass 1 to disable ctrlc() checking, 0 to enable.
607 * returns previous state
608 */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100609int disable_ctrlc(int disable)
wdenk47d1a6e2002-11-03 00:01:44 +0000610{
611 int prev = ctrlc_disabled; /* save previous state */
612
613 ctrlc_disabled = disable;
614 return prev;
615}
616
617int had_ctrlc (void)
618{
619 return ctrlc_was_pressed;
620}
621
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100622void clear_ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000623{
624 ctrlc_was_pressed = 0;
625}
626
627#ifdef CONFIG_MODEM_SUPPORT_DEBUG
628char screen[1024];
629char *cursor = screen;
630int once = 0;
631inline void dbg(const char *fmt, ...)
632{
633 va_list args;
634 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200635 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000636
637 if (!once) {
638 memset(screen, 0, sizeof(screen));
639 once++;
640 }
641
642 va_start(args, fmt);
643
644 /* For this to work, printbuffer must be larger than
645 * anything we ever want to print.
646 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000647 i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenk47d1a6e2002-11-03 00:01:44 +0000648 va_end(args);
649
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100650 if ((screen + sizeof(screen) - 1 - cursor)
651 < strlen(printbuffer) + 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000652 memset(screen, 0, sizeof(screen));
653 cursor = screen;
654 }
655 sprintf(cursor, printbuffer);
656 cursor += strlen(printbuffer);
657
658}
659#else
Jeroen Hofstee482f4692014-10-08 22:57:48 +0200660static inline void dbg(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000661{
662}
663#endif
664
665/** U-Boot INIT FUNCTIONS *************************************************/
666
Mike Frysingerd7be3052010-10-20 07:18:03 -0400667struct stdio_dev *search_device(int flags, const char *name)
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200668{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200669 struct stdio_dev *dev;
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200670
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200671 dev = stdio_get_by_name(name);
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200672
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100673 if (dev && (dev->flags & flags))
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200674 return dev;
675
676 return NULL;
677}
678
Mike Frysingerd7be3052010-10-20 07:18:03 -0400679int console_assign(int file, const char *devname)
wdenk47d1a6e2002-11-03 00:01:44 +0000680{
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200681 int flag;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200682 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000683
684 /* Check for valid file */
685 switch (file) {
686 case stdin:
687 flag = DEV_FLAGS_INPUT;
688 break;
689 case stdout:
690 case stderr:
691 flag = DEV_FLAGS_OUTPUT;
692 break;
693 default:
694 return -1;
695 }
696
697 /* Check for valid device name */
698
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200699 dev = search_device(flag, devname);
wdenk47d1a6e2002-11-03 00:01:44 +0000700
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100701 if (dev)
702 return console_setfile(file, dev);
wdenk47d1a6e2002-11-03 00:01:44 +0000703
704 return -1;
705}
706
707/* Called before relocation - use serial functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100708int console_init_f(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000709{
wdenk47d1a6e2002-11-03 00:01:44 +0000710 gd->have_console = 1;
wdenkf72da342003-10-10 10:05:42 +0000711
712#ifdef CONFIG_SILENT_CONSOLE
713 if (getenv("silent") != NULL)
714 gd->flags |= GD_FLG_SILENT;
715#endif
716
Siarhei Siamashka27669662015-01-08 09:02:31 +0200717 print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL);
Graeme Russ9558b482011-09-01 00:48:27 +0000718
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100719 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000720}
721
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200722void stdio_print_current_devices(void)
723{
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200724 /* Print information */
725 puts("In: ");
726 if (stdio_devices[stdin] == NULL) {
727 puts("No input devices available!\n");
728 } else {
729 printf ("%s\n", stdio_devices[stdin]->name);
730 }
731
732 puts("Out: ");
733 if (stdio_devices[stdout] == NULL) {
734 puts("No output devices available!\n");
735 } else {
736 printf ("%s\n", stdio_devices[stdout]->name);
737 }
738
739 puts("Err: ");
740 if (stdio_devices[stderr] == NULL) {
741 puts("No error devices available!\n");
742 } else {
743 printf ("%s\n", stdio_devices[stderr]->name);
744 }
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200745}
746
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200747#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
wdenk47d1a6e2002-11-03 00:01:44 +0000748/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100749int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000750{
751 char *stdinname, *stdoutname, *stderrname;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200752 struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200753#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk6e592382004-04-18 17:39:38 +0000754 int i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200755#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100756#ifdef CONFIG_CONSOLE_MUX
757 int iomux_err = 0;
758#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000759
760 /* set default handlers at first */
Martin Dorwig49cad542015-01-26 15:22:54 -0700761 gd->jt->getc = serial_getc;
762 gd->jt->tstc = serial_tstc;
763 gd->jt->putc = serial_putc;
764 gd->jt->puts = serial_puts;
765 gd->jt->printf = serial_printf;
wdenk47d1a6e2002-11-03 00:01:44 +0000766
767 /* stdin stdout and stderr are in environment */
768 /* scan for it */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100769 stdinname = getenv("stdin");
770 stdoutname = getenv("stdout");
771 stderrname = getenv("stderr");
wdenk47d1a6e2002-11-03 00:01:44 +0000772
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200773 if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100774 inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
775 outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
776 errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100777#ifdef CONFIG_CONSOLE_MUX
778 iomux_err = iomux_doenv(stdin, stdinname);
779 iomux_err += iomux_doenv(stdout, stdoutname);
780 iomux_err += iomux_doenv(stderr, stderrname);
781 if (!iomux_err)
782 /* Successful, so skip all the code below. */
783 goto done;
784#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000785 }
786 /* if the devices are overwritten or not found, use default device */
787 if (inputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100788 inputdev = search_device(DEV_FLAGS_INPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000789 }
790 if (outputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100791 outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000792 }
793 if (errdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100794 errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000795 }
796 /* Initializes output console first */
797 if (outputdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100798 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100799 console_doenv(stdout, outputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000800 }
801 if (errdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100802 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100803 console_doenv(stderr, errdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000804 }
805 if (inputdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100806 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100807 console_doenv(stdin, inputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000808 }
809
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100810#ifdef CONFIG_CONSOLE_MUX
811done:
812#endif
813
Simon Glass78c112c2012-12-05 14:46:43 +0000814#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200815 stdio_print_current_devices();
Simon Glass78c112c2012-12-05 14:46:43 +0000816#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000817
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200818#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk47d1a6e2002-11-03 00:01:44 +0000819 /* set the environment variables (will overwrite previous env settings) */
820 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100821 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000822 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200823#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
wdenk47d1a6e2002-11-03 00:01:44 +0000824
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600825 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
826
wdenk47d1a6e2002-11-03 00:01:44 +0000827#if 0
828 /* If nothing usable installed, use only the initial console */
829 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100830 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000831#endif
Siarhei Siamashka27669662015-01-08 09:02:31 +0200832 print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100833 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000834}
835
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200836#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +0000837
838/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100839int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000840{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200841 struct stdio_dev *inputdev = NULL, *outputdev = NULL;
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200842 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200843 struct list_head *list = stdio_get_list();
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200844 struct list_head *pos;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200845 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000846
wdenkd791b1d2003-04-20 14:04:18 +0000847#ifdef CONFIG_SPLASH_SCREEN
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100848 /*
849 * suppress all output if splash screen is enabled and we have
Anatolij Gustschina7490812010-03-16 15:29:33 +0100850 * a bmp to display. We redirect the output from frame buffer
851 * console to serial console in this case or suppress it if
852 * "silent" mode was requested.
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100853 */
Anatolij Gustschina7490812010-03-16 15:29:33 +0100854 if (getenv("splashimage") != NULL) {
855 if (!(gd->flags & GD_FLG_SILENT))
856 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
857 }
wdenkf72da342003-10-10 10:05:42 +0000858#endif
859
wdenk47d1a6e2002-11-03 00:01:44 +0000860 /* Scan devices looking for input and output devices */
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200861 list_for_each(pos, list) {
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200862 dev = list_entry(pos, struct stdio_dev, list);
wdenk47d1a6e2002-11-03 00:01:44 +0000863
864 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
865 inputdev = dev;
866 }
867 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
868 outputdev = dev;
869 }
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200870 if(inputdev && outputdev)
871 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000872 }
873
874 /* Initializes output console first */
875 if (outputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100876 console_setfile(stdout, outputdev);
877 console_setfile(stderr, outputdev);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100878#ifdef CONFIG_CONSOLE_MUX
879 console_devices[stdout][0] = outputdev;
880 console_devices[stderr][0] = outputdev;
881#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000882 }
883
884 /* Initializes input console */
885 if (inputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100886 console_setfile(stdin, inputdev);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100887#ifdef CONFIG_CONSOLE_MUX
888 console_devices[stdin][0] = inputdev;
889#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000890 }
891
Simon Glass78c112c2012-12-05 14:46:43 +0000892#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200893 stdio_print_current_devices();
Simon Glass78c112c2012-12-05 14:46:43 +0000894#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000895
896 /* Setting environment variables */
897 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100898 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000899 }
900
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600901 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
902
wdenk47d1a6e2002-11-03 00:01:44 +0000903#if 0
904 /* If nothing usable installed, use only the initial console */
905 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100906 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000907#endif
Siarhei Siamashka27669662015-01-08 09:02:31 +0200908 print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100909 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000910}
911
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200912#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */