Blame view

common/console.c 20.1 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
47d1a6e1e   wdenk   Initial revision
2
3
4
  /*
   * (C) Copyright 2000
   * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
47d1a6e1e   wdenk   Initial revision
5
6
7
   */
  
  #include <common.h>
24b852a7a   Simon Glass   Move console defi...
8
  #include <console.h>
d6ea5307d   Simon Glass   dm: Allow debug U...
9
  #include <debug_uart.h>
7b3c4c3a5   Simon Glass   dm: console: Chec...
10
  #include <dm.h>
47d1a6e1e   wdenk   Initial revision
11
  #include <stdarg.h>
482f4691a   Jeroen Hofstee   common:console: a...
12
  #include <iomux.h>
47d1a6e1e   wdenk   Initial revision
13
  #include <malloc.h>
4e6bafa56   Simon Glass   console: Use map_...
14
  #include <mapmem.h>
91b136c79   Simon Glass   sandbox: Allow th...
15
  #include <os.h>
849d5d9cd   Joe Hershberger   env: Add a consol...
16
  #include <serial.h>
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
17
  #include <stdio_dev.h>
27b207fd0   wdenk   * Implement new m...
18
  #include <exports.h>
849d5d9cd   Joe Hershberger   env: Add a consol...
19
  #include <environment.h>
644074671   Andreas J. Reichel   watchdog: Fix Wat...
20
  #include <watchdog.h>
47d1a6e1e   wdenk   Initial revision
21

d87080b72   Wolfgang Denk   GCC-4.x fixes: cl...
22
  DECLARE_GLOBAL_DATA_PTR;
849d5d9cd   Joe Hershberger   env: Add a consol...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  static int on_console(const char *name, const char *value, enum env_op op,
  	int flags)
  {
  	int console = -1;
  
  	/* Check for console redirection */
  	if (strcmp(name, "stdin") == 0)
  		console = stdin;
  	else if (strcmp(name, "stdout") == 0)
  		console = stdout;
  	else if (strcmp(name, "stderr") == 0)
  		console = stderr;
  
  	/* if not actually setting a console variable, we don't care */
  	if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0)
  		return 0;
  
  	switch (op) {
  	case env_op_create:
  	case env_op_overwrite:
b02654294   Simon Glass   console: Don't en...
43
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
849d5d9cd   Joe Hershberger   env: Add a consol...
44
45
46
47
48
49
  		if (iomux_doenv(console, value))
  			return 1;
  #else
  		/* Try assigning specified device */
  		if (console_assign(console, value) < 0)
  			return 1;
b02654294   Simon Glass   console: Don't en...
50
  #endif
849d5d9cd   Joe Hershberger   env: Add a consol...
51
52
53
54
55
56
57
58
59
60
61
62
63
  		return 0;
  
  	case env_op_delete:
  		if ((flags & H_FORCE) == 0)
  			printf("Can't delete \"%s\"
  ", name);
  		return 1;
  
  	default:
  		return 0;
  	}
  }
  U_BOOT_ENV_CALLBACK(console, on_console);
e080d545f   Joe Hershberger   env: Add a silent...
64
65
66
67
  #ifdef CONFIG_SILENT_CONSOLE
  static int on_silent(const char *name, const char *value, enum env_op op,
  	int flags)
  {
5daf6e56d   Wilson Lee   common: console: ...
68
  #if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)
e080d545f   Joe Hershberger   env: Add a silent...
69
70
71
  	if (flags & H_INTERACTIVE)
  		return 0;
  #endif
5daf6e56d   Wilson Lee   common: console: ...
72
  #if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)
e080d545f   Joe Hershberger   env: Add a silent...
73
74
75
76
77
78
79
80
81
82
83
84
85
  	if ((flags & H_INTERACTIVE) == 0)
  		return 0;
  #endif
  
  	if (value != NULL)
  		gd->flags |= GD_FLG_SILENT;
  	else
  		gd->flags &= ~GD_FLG_SILENT;
  
  	return 0;
  }
  U_BOOT_ENV_CALLBACK(silent, on_silent);
  #endif
b02654294   Simon Glass   console: Don't en...
86
  #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
47d1a6e1e   wdenk   Initial revision
87
88
89
90
91
  /*
   * if overwrite_console returns 1, the stdin, stderr and stdout
   * are switched to the serial port, else the settings in the
   * environment are used
   */
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
92
  #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
93
94
  extern int overwrite_console(void);
  #define OVERWRITE_CONSOLE overwrite_console()
47d1a6e1e   wdenk   Initial revision
95
  #else
83e40ba75   wdenk   * Patch by Detlev...
96
  #define OVERWRITE_CONSOLE 0
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
97
  #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
47d1a6e1e   wdenk   Initial revision
98

b02654294   Simon Glass   console: Don't en...
99
  #endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */
47d1a6e1e   wdenk   Initial revision
100

52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
101
  static int console_setfile(int file, struct stdio_dev * dev)
47d1a6e1e   wdenk   Initial revision
102
103
104
105
106
107
108
109
110
111
112
113
  {
  	int error = 0;
  
  	if (dev == NULL)
  		return -1;
  
  	switch (file) {
  	case stdin:
  	case stdout:
  	case stderr:
  		/* Start new device */
  		if (dev->start) {
709ea543b   Simon Glass   stdio: Pass devic...
114
  			error = dev->start(dev);
47d1a6e1e   wdenk   Initial revision
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  			/* If it's not started dont use it */
  			if (error < 0)
  				break;
  		}
  
  		/* Assign the new device (leaving the existing one started) */
  		stdio_devices[file] = dev;
  
  		/*
  		 * Update monitor functions
  		 * (to use the console stuff by other applications)
  		 */
  		switch (file) {
  		case stdin:
49cad5478   Martin Dorwig   Export redesign
129
130
  			gd->jt->getc = getc;
  			gd->jt->tstc = tstc;
47d1a6e1e   wdenk   Initial revision
131
132
  			break;
  		case stdout:
49cad5478   Martin Dorwig   Export redesign
133
134
135
  			gd->jt->putc  = putc;
  			gd->jt->puts  = puts;
  			gd->jt->printf = printf;
47d1a6e1e   wdenk   Initial revision
136
137
138
139
140
141
142
143
144
  			break;
  		}
  		break;
  
  	default:		/* Invalid file ID */
  		error = -1;
  	}
  	return error;
  }
42f9f915c   Simon Glass   console: Unify th...
145
146
147
148
  /**
   * console_dev_is_serial() - Check if a stdio device is a serial device
   *
   * @sdev: Device to check
7b3c4c3a5   Simon Glass   dm: console: Chec...
149
150
   * @return true if this device is in the serial uclass (or for pre-driver-model,
   * whether it is called "serial".
42f9f915c   Simon Glass   console: Unify th...
151
152
153
154
   */
  static bool console_dev_is_serial(struct stdio_dev *sdev)
  {
  	bool is_serial;
7b3c4c3a5   Simon Glass   dm: console: Chec...
155
156
157
158
159
160
161
  #ifdef CONFIG_DM_SERIAL
  	if (sdev->flags & DEV_FLAGS_DM) {
  		struct udevice *dev = sdev->priv;
  
  		is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL;
  	} else
  #endif
42f9f915c   Simon Glass   console: Unify th...
162
163
164
165
  	is_serial = !strcmp(sdev->name, "serial");
  
  	return is_serial;
  }
b02654294   Simon Glass   console: Don't en...
166
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
167
  /** Console I/O multiplexing *******************************************/
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
168
169
  static struct stdio_dev *tstcdev;
  struct stdio_dev **console_devices[MAX_FILES];
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
170
171
172
173
174
175
176
177
  int cd_count[MAX_FILES];
  
  /*
   * This depends on tstc() always being called before getc().
   * This is guaranteed to be true because this routine is called
   * only from fgetc() which assures it.
   * No attempt is made to demultiplex multiple input sources.
   */
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
178
  static int console_getc(int file)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
179
180
181
182
  {
  	unsigned char ret;
  
  	/* This is never called with testcdev == NULL */
709ea543b   Simon Glass   stdio: Pass devic...
183
  	ret = tstcdev->getc(tstcdev);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
184
185
186
  	tstcdev = NULL;
  	return ret;
  }
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
187
  static int console_tstc(int file)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
188
189
  {
  	int i, ret;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
190
  	struct stdio_dev *dev;
b2f58d8ee   Joe Hershberger   console: Remember...
191
  	int prev;
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
192

b2f58d8ee   Joe Hershberger   console: Remember...
193
  	prev = disable_ctrlc(1);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
194
195
196
  	for (i = 0; i < cd_count[file]; i++) {
  		dev = console_devices[file][i];
  		if (dev->tstc != NULL) {
709ea543b   Simon Glass   stdio: Pass devic...
197
  			ret = dev->tstc(dev);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
198
199
  			if (ret > 0) {
  				tstcdev = dev;
b2f58d8ee   Joe Hershberger   console: Remember...
200
  				disable_ctrlc(prev);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
201
202
203
204
  				return ret;
  			}
  		}
  	}
b2f58d8ee   Joe Hershberger   console: Remember...
205
  	disable_ctrlc(prev);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
206
207
208
  
  	return 0;
  }
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
209
  static void console_putc(int file, const char c)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
210
211
  {
  	int i;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
212
  	struct stdio_dev *dev;
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
213
214
215
216
  
  	for (i = 0; i < cd_count[file]; i++) {
  		dev = console_devices[file][i];
  		if (dev->putc != NULL)
709ea543b   Simon Glass   stdio: Pass devic...
217
  			dev->putc(dev, c);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
218
219
  	}
  }
a8552c7c9   Hans de Goede   console: Fix pre-...
220
  static void console_puts_noserial(int file, const char *s)
276696675   Siarhei Siamashka   console: Use pre-...
221
222
223
224
225
226
  {
  	int i;
  	struct stdio_dev *dev;
  
  	for (i = 0; i < cd_count[file]; i++) {
  		dev = console_devices[file][i];
42f9f915c   Simon Glass   console: Unify th...
227
  		if (dev->puts != NULL && !console_dev_is_serial(dev))
a8552c7c9   Hans de Goede   console: Fix pre-...
228
  			dev->puts(dev, s);
276696675   Siarhei Siamashka   console: Use pre-...
229
230
  	}
  }
276696675   Siarhei Siamashka   console: Use pre-...
231

5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
232
  static void console_puts(int file, const char *s)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
233
234
  {
  	int i;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
235
  	struct stdio_dev *dev;
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
236
237
238
239
  
  	for (i = 0; i < cd_count[file]; i++) {
  		dev = console_devices[file][i];
  		if (dev->puts != NULL)
709ea543b   Simon Glass   stdio: Pass devic...
240
  			dev->puts(dev, s);
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
241
242
  	}
  }
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
243

52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
244
  static inline void console_doenv(int file, struct stdio_dev *dev)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
245
246
247
248
249
250
  {
  	iomux_doenv(file, dev->name);
  }
  #else
  static inline int console_getc(int file)
  {
709ea543b   Simon Glass   stdio: Pass devic...
251
  	return stdio_devices[file]->getc(stdio_devices[file]);
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
252
253
254
255
  }
  
  static inline int console_tstc(int file)
  {
709ea543b   Simon Glass   stdio: Pass devic...
256
  	return stdio_devices[file]->tstc(stdio_devices[file]);
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
257
258
259
260
  }
  
  static inline void console_putc(int file, const char c)
  {
709ea543b   Simon Glass   stdio: Pass devic...
261
  	stdio_devices[file]->putc(stdio_devices[file], c);
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
262
  }
a8552c7c9   Hans de Goede   console: Fix pre-...
263
  static inline void console_puts_noserial(int file, const char *s)
276696675   Siarhei Siamashka   console: Use pre-...
264
  {
42f9f915c   Simon Glass   console: Unify th...
265
  	if (!console_dev_is_serial(stdio_devices[file]))
a8552c7c9   Hans de Goede   console: Fix pre-...
266
  		stdio_devices[file]->puts(stdio_devices[file], s);
276696675   Siarhei Siamashka   console: Use pre-...
267
  }
276696675   Siarhei Siamashka   console: Use pre-...
268

5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
269
270
  static inline void console_puts(int file, const char *s)
  {
709ea543b   Simon Glass   stdio: Pass devic...
271
  	stdio_devices[file]->puts(stdio_devices[file], s);
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
272
  }
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
273
  static inline void console_doenv(int file, struct stdio_dev *dev)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
274
275
276
  {
  	console_setfile(file, dev);
  }
b02654294   Simon Glass   console: Don't en...
277
  #endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
278

47d1a6e1e   wdenk   Initial revision
279
  /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
d9c27253c   Wolfgang Denk   Make *printf() re...
280
  int serial_printf(const char *fmt, ...)
47d1a6e1e   wdenk   Initial revision
281
282
283
  {
  	va_list args;
  	uint i;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
284
  	char printbuffer[CONFIG_SYS_PBSIZE];
47d1a6e1e   wdenk   Initial revision
285

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
286
  	va_start(args, fmt);
47d1a6e1e   wdenk   Initial revision
287
288
289
290
  
  	/* For this to work, printbuffer must be larger than
  	 * anything we ever want to print.
  	 */
068af6f84   Sonny Rao   Make printf and v...
291
  	i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
292
  	va_end(args);
47d1a6e1e   wdenk   Initial revision
293

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
294
  	serial_puts(printbuffer);
d9c27253c   Wolfgang Denk   Make *printf() re...
295
  	return i;
47d1a6e1e   wdenk   Initial revision
296
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
297
  int fgetc(int file)
47d1a6e1e   wdenk   Initial revision
298
  {
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
299
  	if (file < MAX_FILES) {
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
300
301
302
303
  		/*
  		 * Effectively poll for input wherever it may be available.
  		 */
  		for (;;) {
644074671   Andreas J. Reichel   watchdog: Fix Wat...
304
  			WATCHDOG_RESET();
273a12526   Patrick Delaunay   console: unify fg...
305
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
306
307
308
309
310
  			/*
  			 * Upper layer may have already called tstc() so
  			 * check for that first.
  			 */
  			if (tstcdev != NULL)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
311
312
  				return console_getc(file);
  			console_tstc(file);
273a12526   Patrick Delaunay   console: unify fg...
313
314
315
316
  #else
  			if (console_tstc(file))
  				return console_getc(file);
  #endif
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
317
318
319
320
321
322
323
324
  #ifdef CONFIG_WATCHDOG
  			/*
  			 * If the watchdog must be rate-limited then it should
  			 * already be handled in board-specific code.
  			 */
  			 udelay(1);
  #endif
  		}
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
325
  	}
47d1a6e1e   wdenk   Initial revision
326
327
328
  
  	return -1;
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
329
  int ftstc(int file)
47d1a6e1e   wdenk   Initial revision
330
331
  {
  	if (file < MAX_FILES)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
332
  		return console_tstc(file);
47d1a6e1e   wdenk   Initial revision
333
334
335
  
  	return -1;
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
336
  void fputc(int file, const char c)
47d1a6e1e   wdenk   Initial revision
337
338
  {
  	if (file < MAX_FILES)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
339
  		console_putc(file, c);
47d1a6e1e   wdenk   Initial revision
340
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
341
  void fputs(int file, const char *s)
47d1a6e1e   wdenk   Initial revision
342
343
  {
  	if (file < MAX_FILES)
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
344
  		console_puts(file, s);
47d1a6e1e   wdenk   Initial revision
345
  }
d9c27253c   Wolfgang Denk   Make *printf() re...
346
  int fprintf(int file, const char *fmt, ...)
47d1a6e1e   wdenk   Initial revision
347
348
349
  {
  	va_list args;
  	uint i;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
350
  	char printbuffer[CONFIG_SYS_PBSIZE];
47d1a6e1e   wdenk   Initial revision
351

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
352
  	va_start(args, fmt);
47d1a6e1e   wdenk   Initial revision
353
354
355
356
  
  	/* For this to work, printbuffer must be larger than
  	 * anything we ever want to print.
  	 */
068af6f84   Sonny Rao   Make printf and v...
357
  	i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
358
  	va_end(args);
47d1a6e1e   wdenk   Initial revision
359
360
  
  	/* Send to desired file */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
361
  	fputs(file, printbuffer);
d9c27253c   Wolfgang Denk   Make *printf() re...
362
  	return i;
47d1a6e1e   wdenk   Initial revision
363
364
365
  }
  
  /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
366
  int getc(void)
47d1a6e1e   wdenk   Initial revision
367
  {
f5c3ba797   Mark Jackson   Allow console inp...
368
369
370
371
  #ifdef CONFIG_DISABLE_CONSOLE
  	if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  		return 0;
  #endif
e3e454cd7   Graeme Russ   console: Squelch ...
372
373
  	if (!gd->have_console)
  		return 0;
9854a8748   Simon Glass   console: Add a co...
374
375
376
377
378
379
380
381
382
  #ifdef CONFIG_CONSOLE_RECORD
  	if (gd->console_in.start) {
  		int ch;
  
  		ch = membuff_getbyte(&gd->console_in);
  		if (ch != -1)
  			return 1;
  	}
  #endif
47d1a6e1e   wdenk   Initial revision
383
384
  	if (gd->flags & GD_FLG_DEVINIT) {
  		/* Get from the standard input */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
385
  		return fgetc(stdin);
47d1a6e1e   wdenk   Initial revision
386
387
388
  	}
  
  	/* Send directly to the handler */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
389
  	return serial_getc();
47d1a6e1e   wdenk   Initial revision
390
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
391
  int tstc(void)
47d1a6e1e   wdenk   Initial revision
392
  {
f5c3ba797   Mark Jackson   Allow console inp...
393
394
395
396
  #ifdef CONFIG_DISABLE_CONSOLE
  	if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  		return 0;
  #endif
e3e454cd7   Graeme Russ   console: Squelch ...
397
398
  	if (!gd->have_console)
  		return 0;
9854a8748   Simon Glass   console: Add a co...
399
400
401
402
403
404
  #ifdef CONFIG_CONSOLE_RECORD
  	if (gd->console_in.start) {
  		if (membuff_peekbyte(&gd->console_in) != -1)
  			return 1;
  	}
  #endif
47d1a6e1e   wdenk   Initial revision
405
406
  	if (gd->flags & GD_FLG_DEVINIT) {
  		/* Test the standard input */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
407
  		return ftstc(stdin);
47d1a6e1e   wdenk   Initial revision
408
409
410
  	}
  
  	/* Send directly to the handler */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
411
  	return serial_tstc();
47d1a6e1e   wdenk   Initial revision
412
  }
276696675   Siarhei Siamashka   console: Use pre-...
413
414
  #define PRE_CONSOLE_FLUSHPOINT1_SERIAL			0
  #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL	1
8f9255841   Simon Glass   Convert CONSOLE_P...
415
  #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
9558b48af   Graeme Russ   console: Implemen...
416
417
418
419
  #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
  
  static void pre_console_putc(const char c)
  {
4e6bafa56   Simon Glass   console: Use map_...
420
421
422
  	char *buffer;
  
  	buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
9558b48af   Graeme Russ   console: Implemen...
423
424
  
  	buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
4e6bafa56   Simon Glass   console: Use map_...
425
426
  
  	unmap_sysmem(buffer);
9558b48af   Graeme Russ   console: Implemen...
427
  }
be135cc5e   Soeren Moch   Revert "console: ...
428
429
430
431
432
  static void pre_console_puts(const char *s)
  {
  	while (*s)
  		pre_console_putc(*s++);
  }
276696675   Siarhei Siamashka   console: Use pre-...
433
  static void print_pre_console_buffer(int flushpoint)
9558b48af   Graeme Russ   console: Implemen...
434
  {
a8552c7c9   Hans de Goede   console: Fix pre-...
435
  	unsigned long in = 0, out = 0;
a8552c7c9   Hans de Goede   console: Fix pre-...
436
  	char buf_out[CONFIG_PRE_CON_BUF_SZ + 1];
4e6bafa56   Simon Glass   console: Use map_...
437
  	char *buf_in;
9558b48af   Graeme Russ   console: Implemen...
438

4e6bafa56   Simon Glass   console: Use map_...
439
  	buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
9558b48af   Graeme Russ   console: Implemen...
440
  	if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
a8552c7c9   Hans de Goede   console: Fix pre-...
441
  		in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
9558b48af   Graeme Russ   console: Implemen...
442

a8552c7c9   Hans de Goede   console: Fix pre-...
443
444
  	while (in < gd->precon_buf_idx)
  		buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)];
4e6bafa56   Simon Glass   console: Use map_...
445
  	unmap_sysmem(buf_in);
a8552c7c9   Hans de Goede   console: Fix pre-...
446
447
448
449
450
451
452
453
454
455
456
  
  	buf_out[out] = 0;
  
  	switch (flushpoint) {
  	case PRE_CONSOLE_FLUSHPOINT1_SERIAL:
  		puts(buf_out);
  		break;
  	case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL:
  		console_puts_noserial(stdout, buf_out);
  		break;
  	}
9558b48af   Graeme Russ   console: Implemen...
457
458
459
  }
  #else
  static inline void pre_console_putc(const char c) {}
be135cc5e   Soeren Moch   Revert "console: ...
460
  static inline void pre_console_puts(const char *s) {}
276696675   Siarhei Siamashka   console: Use pre-...
461
  static inline void print_pre_console_buffer(int flushpoint) {}
9558b48af   Graeme Russ   console: Implemen...
462
  #endif
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
463
  void putc(const char c)
47d1a6e1e   wdenk   Initial revision
464
  {
64e9b4f34   Simon Glass   Revert "sandbox: ...
465
466
467
468
469
470
471
  #ifdef CONFIG_SANDBOX
  	/* sandbox can send characters to stdout before it has a console */
  	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
  		os_putc(c);
  		return;
  	}
  #endif
d6ea5307d   Simon Glass   dm: Allow debug U...
472
473
474
475
476
477
478
  #ifdef CONFIG_DEBUG_UART
  	/* if we don't have a console yet, use the debug UART */
  	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
  		printch(c);
  		return;
  	}
  #endif
af880e247   Simon Glass   console: Fix hand...
479
480
  	if (!gd)
  		return;
9854a8748   Simon Glass   console: Add a co...
481
  #ifdef CONFIG_CONSOLE_RECORD
af880e247   Simon Glass   console: Fix hand...
482
  	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
9854a8748   Simon Glass   console: Add a co...
483
484
  		membuff_putbyte(&gd->console_out, c);
  #endif
a6cccaea5   wdenk   * Patch by Wolter...
485
486
  #ifdef CONFIG_SILENT_CONSOLE
  	if (gd->flags & GD_FLG_SILENT)
f6e20fc6c   wdenk   Patch by Anders L...
487
  		return;
a6cccaea5   wdenk   * Patch by Wolter...
488
  #endif
f5c3ba797   Mark Jackson   Allow console inp...
489
490
491
492
  #ifdef CONFIG_DISABLE_CONSOLE
  	if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  		return;
  #endif
e3e454cd7   Graeme Russ   console: Squelch ...
493
  	if (!gd->have_console)
9558b48af   Graeme Russ   console: Implemen...
494
  		return pre_console_putc(c);
e3e454cd7   Graeme Russ   console: Squelch ...
495

47d1a6e1e   wdenk   Initial revision
496
497
  	if (gd->flags & GD_FLG_DEVINIT) {
  		/* Send to the standard output */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
498
  		fputc(stdout, c);
47d1a6e1e   wdenk   Initial revision
499
500
  	} else {
  		/* Send directly to the handler */
276696675   Siarhei Siamashka   console: Use pre-...
501
  		pre_console_putc(c);
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
502
  		serial_putc(c);
47d1a6e1e   wdenk   Initial revision
503
504
  	}
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
505
  void puts(const char *s)
47d1a6e1e   wdenk   Initial revision
506
  {
36bcea62a   Simon Glass   sandbox: Allow pu...
507
508
509
510
511
512
513
  #ifdef CONFIG_SANDBOX
  	/* sandbox can send characters to stdout before it has a console */
  	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
  		os_puts(s);
  		return;
  	}
  #endif
be135cc5e   Soeren Moch   Revert "console: ...
514
515
516
517
518
519
520
521
522
523
  #ifdef CONFIG_DEBUG_UART
  	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
  		while (*s) {
  			int ch = *s++;
  
  			printch(ch);
  		}
  		return;
  	}
  #endif
af880e247   Simon Glass   console: Fix hand...
524
525
  	if (!gd)
  		return;
be135cc5e   Soeren Moch   Revert "console: ...
526
  #ifdef CONFIG_CONSOLE_RECORD
af880e247   Simon Glass   console: Fix hand...
527
  	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
be135cc5e   Soeren Moch   Revert "console: ...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  		membuff_put(&gd->console_out, s, strlen(s));
  #endif
  #ifdef CONFIG_SILENT_CONSOLE
  	if (gd->flags & GD_FLG_SILENT)
  		return;
  #endif
  
  #ifdef CONFIG_DISABLE_CONSOLE
  	if (gd->flags & GD_FLG_DISABLE_CONSOLE)
  		return;
  #endif
  
  	if (!gd->have_console)
  		return pre_console_puts(s);
  
  	if (gd->flags & GD_FLG_DEVINIT) {
  		/* Send to the standard output */
  		fputs(stdout, s);
  	} else {
  		/* Send directly to the handler */
  		pre_console_puts(s);
  		serial_puts(s);
  	}
47d1a6e1e   wdenk   Initial revision
551
  }
9854a8748   Simon Glass   console: Add a co...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
  #ifdef CONFIG_CONSOLE_RECORD
  int console_record_init(void)
  {
  	int ret;
  
  	ret = membuff_new(&gd->console_out, CONFIG_CONSOLE_RECORD_OUT_SIZE);
  	if (ret)
  		return ret;
  	ret = membuff_new(&gd->console_in, CONFIG_CONSOLE_RECORD_IN_SIZE);
  
  	return ret;
  }
  
  void console_record_reset(void)
  {
  	membuff_purge(&gd->console_out);
  	membuff_purge(&gd->console_in);
  }
  
  void console_record_reset_enable(void)
  {
  	console_record_reset();
  	gd->flags |= GD_FLG_RECORD;
  }
  #endif
47d1a6e1e   wdenk   Initial revision
577
578
579
  /* test if ctrl-c was pressed */
  static int ctrlc_disabled = 0;	/* see disable_ctrl() */
  static int ctrlc_was_pressed = 0;
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
580
  int ctrlc(void)
47d1a6e1e   wdenk   Initial revision
581
  {
47d1a6e1e   wdenk   Initial revision
582
  	if (!ctrlc_disabled && gd->have_console) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
583
584
  		if (tstc()) {
  			switch (getc()) {
47d1a6e1e   wdenk   Initial revision
585
586
587
588
589
590
591
592
  			case 0x03:		/* ^C - Control C */
  				ctrlc_was_pressed = 1;
  				return 1;
  			default:
  				break;
  			}
  		}
  	}
8969ea3e9   Simon Glass   sandbox: Disable ...
593

47d1a6e1e   wdenk   Initial revision
594
595
  	return 0;
  }
a5dffa4b6   Pierre Aubert   Add the function ...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  /* Reads user's confirmation.
     Returns 1 if user's input is "y", "Y", "yes" or "YES"
  */
  int confirm_yesno(void)
  {
  	int i;
  	char str_input[5];
  
  	/* Flush input */
  	while (tstc())
  		getc();
  	i = 0;
  	while (i < sizeof(str_input)) {
  		str_input[i] = getc();
  		putc(str_input[i]);
  		if (str_input[i] == '\r')
  			break;
  		i++;
  	}
  	putc('
  ');
  	if (strncmp(str_input, "y\r", 2) == 0 ||
  	    strncmp(str_input, "Y\r", 2) == 0 ||
  	    strncmp(str_input, "yes\r", 4) == 0 ||
  	    strncmp(str_input, "YES\r", 4) == 0)
  		return 1;
  	return 0;
  }
47d1a6e1e   wdenk   Initial revision
624
625
626
  /* pass 1 to disable ctrlc() checking, 0 to enable.
   * returns previous state
   */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
627
  int disable_ctrlc(int disable)
47d1a6e1e   wdenk   Initial revision
628
629
630
631
632
633
634
635
636
637
638
  {
  	int prev = ctrlc_disabled;	/* save previous state */
  
  	ctrlc_disabled = disable;
  	return prev;
  }
  
  int had_ctrlc (void)
  {
  	return ctrlc_was_pressed;
  }
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
639
  void clear_ctrlc(void)
47d1a6e1e   wdenk   Initial revision
640
641
642
  {
  	ctrlc_was_pressed = 0;
  }
47d1a6e1e   wdenk   Initial revision
643
  /** U-Boot INIT FUNCTIONS *************************************************/
d7be3056d   Mike Frysinger   stdio: constify "...
644
  struct stdio_dev *search_device(int flags, const char *name)
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
645
  {
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
646
  	struct stdio_dev *dev;
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
647

52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
648
  	dev = stdio_get_by_name(name);
a2931b30d   Simon Glass   dm: video: Add a ...
649
650
651
652
  #ifdef CONFIG_VIDCONSOLE_AS_LCD
  	if (!dev && !strcmp(name, "lcd"))
  		dev = stdio_get_by_name("vidconsole");
  #endif
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
653

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
654
  	if (dev && (dev->flags & flags))
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
655
656
657
658
  		return dev;
  
  	return NULL;
  }
d7be3056d   Mike Frysinger   stdio: constify "...
659
  int console_assign(int file, const char *devname)
47d1a6e1e   wdenk   Initial revision
660
  {
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
661
  	int flag;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
662
  	struct stdio_dev *dev;
47d1a6e1e   wdenk   Initial revision
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  
  	/* Check for valid file */
  	switch (file) {
  	case stdin:
  		flag = DEV_FLAGS_INPUT;
  		break;
  	case stdout:
  	case stderr:
  		flag = DEV_FLAGS_OUTPUT;
  		break;
  	default:
  		return -1;
  	}
  
  	/* Check for valid device name */
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
678
  	dev = search_device(flag, devname);
47d1a6e1e   wdenk   Initial revision
679

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
680
681
  	if (dev)
  		return console_setfile(file, dev);
47d1a6e1e   wdenk   Initial revision
682
683
684
  
  	return -1;
  }
43e0a3dec   Chris Packham   common/console.c:...
685
  static void console_update_silent(void)
47d1a6e1e   wdenk   Initial revision
686
  {
f72da3406   wdenk   Added config opti...
687
  #ifdef CONFIG_SILENT_CONSOLE
00caae6d4   Simon Glass   env: Rename geten...
688
  	if (env_get("silent") != NULL)
f72da3406   wdenk   Added config opti...
689
  		gd->flags |= GD_FLG_SILENT;
43e0a3dec   Chris Packham   common/console.c:...
690
691
  	else
  		gd->flags &= ~GD_FLG_SILENT;
f72da3406   wdenk   Added config opti...
692
  #endif
43e0a3dec   Chris Packham   common/console.c:...
693
  }
b0895384b   Simon Glass   Allow displaying ...
694
695
696
697
698
699
700
701
702
703
704
705
  int console_announce_r(void)
  {
  #if !CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
  	char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
  
  	display_options_get_banner(false, buf, sizeof(buf));
  
  	console_puts_noserial(stdout, buf);
  #endif
  
  	return 0;
  }
43e0a3dec   Chris Packham   common/console.c:...
706
707
708
709
710
711
  /* Called before relocation - use serial functions */
  int console_init_f(void)
  {
  	gd->have_console = 1;
  
  	console_update_silent();
f72da3406   wdenk   Added config opti...
712

276696675   Siarhei Siamashka   console: Use pre-...
713
  	print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL);
9558b48af   Graeme Russ   console: Implemen...
714

ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
715
  	return 0;
47d1a6e1e   wdenk   Initial revision
716
  }
7e3be7cf3   Jean-Christophe PLAGNIOL-VILLARD   console: unify pr...
717
718
  void stdio_print_current_devices(void)
  {
7e3be7cf3   Jean-Christophe PLAGNIOL-VILLARD   console: unify pr...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
  	/* Print information */
  	puts("In:    ");
  	if (stdio_devices[stdin] == NULL) {
  		puts("No input devices available!
  ");
  	} else {
  		printf ("%s
  ", stdio_devices[stdin]->name);
  	}
  
  	puts("Out:   ");
  	if (stdio_devices[stdout] == NULL) {
  		puts("No output devices available!
  ");
  	} else {
  		printf ("%s
  ", stdio_devices[stdout]->name);
  	}
  
  	puts("Err:   ");
  	if (stdio_devices[stderr] == NULL) {
  		puts("No error devices available!
  ");
  	} else {
  		printf ("%s
  ", stdio_devices[stderr]->name);
  	}
7e3be7cf3   Jean-Christophe PLAGNIOL-VILLARD   console: unify pr...
746
  }
b02654294   Simon Glass   console: Don't en...
747
  #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
47d1a6e1e   wdenk   Initial revision
748
  /* Called after the relocation - use desired console functions */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
749
  int console_init_r(void)
47d1a6e1e   wdenk   Initial revision
750
751
  {
  	char *stdinname, *stdoutname, *stderrname;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
752
  	struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
753
  #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
6e5923851   wdenk   * Cleanup, minor ...
754
  	int i;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
755
  #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
b02654294   Simon Glass   console: Don't en...
756
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
757
758
  	int iomux_err = 0;
  #endif
47d1a6e1e   wdenk   Initial revision
759
760
  
  	/* set default handlers at first */
49cad5478   Martin Dorwig   Export redesign
761
762
763
764
765
  	gd->jt->getc  = serial_getc;
  	gd->jt->tstc  = serial_tstc;
  	gd->jt->putc  = serial_putc;
  	gd->jt->puts  = serial_puts;
  	gd->jt->printf = serial_printf;
47d1a6e1e   wdenk   Initial revision
766
767
768
  
  	/* stdin stdout and stderr are in environment */
  	/* scan for it */
00caae6d4   Simon Glass   env: Rename geten...
769
770
771
  	stdinname  = env_get("stdin");
  	stdoutname = env_get("stdout");
  	stderrname = env_get("stderr");
47d1a6e1e   wdenk   Initial revision
772

53677ef18   Wolfgang Denk   Big white-space c...
773
  	if (OVERWRITE_CONSOLE == 0) {	/* if not overwritten by config switch */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
774
775
776
  		inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
  		outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
  		errdev    = search_device(DEV_FLAGS_OUTPUT, stderrname);
b02654294   Simon Glass   console: Don't en...
777
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
778
779
780
781
782
783
784
  		iomux_err = iomux_doenv(stdin, stdinname);
  		iomux_err += iomux_doenv(stdout, stdoutname);
  		iomux_err += iomux_doenv(stderr, stderrname);
  		if (!iomux_err)
  			/* Successful, so skip all the code below. */
  			goto done;
  #endif
47d1a6e1e   wdenk   Initial revision
785
786
787
  	}
  	/* if the devices are overwritten or not found, use default device */
  	if (inputdev == NULL) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
788
  		inputdev  = search_device(DEV_FLAGS_INPUT,  "serial");
47d1a6e1e   wdenk   Initial revision
789
790
  	}
  	if (outputdev == NULL) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
791
  		outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
47d1a6e1e   wdenk   Initial revision
792
793
  	}
  	if (errdev == NULL) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
794
  		errdev    = search_device(DEV_FLAGS_OUTPUT, "serial");
47d1a6e1e   wdenk   Initial revision
795
796
797
  	}
  	/* Initializes output console first */
  	if (outputdev != NULL) {
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
798
  		/* need to set a console if not done above. */
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
799
  		console_doenv(stdout, outputdev);
47d1a6e1e   wdenk   Initial revision
800
801
  	}
  	if (errdev != NULL) {
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
802
  		/* need to set a console if not done above. */
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
803
  		console_doenv(stderr, errdev);
47d1a6e1e   wdenk   Initial revision
804
805
  	}
  	if (inputdev != NULL) {
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
806
  		/* need to set a console if not done above. */
5f0320108   Jean-Christophe PLAGNIOL-VILLARD   common/console: a...
807
  		console_doenv(stdin, inputdev);
47d1a6e1e   wdenk   Initial revision
808
  	}
b02654294   Simon Glass   console: Don't en...
809
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
810
811
  done:
  #endif
78c112c9f   Simon Glass   console: Enable f...
812
  #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
7e3be7cf3   Jean-Christophe PLAGNIOL-VILLARD   console: unify pr...
813
  	stdio_print_current_devices();
78c112c9f   Simon Glass   console: Enable f...
814
  #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
a2931b30d   Simon Glass   dm: video: Add a ...
815
816
817
818
819
  #ifdef CONFIG_VIDCONSOLE_AS_LCD
  	if (strstr(stdoutname, "lcd"))
  		printf("Warning: Please change 'lcd' to 'vidconsole' in stdout/stderr environment vars
  ");
  #endif
47d1a6e1e   wdenk   Initial revision
820

6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
821
  #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
47d1a6e1e   wdenk   Initial revision
822
  	/* set the environment variables (will overwrite previous env settings) */
27b4225b3   Tom Rini   stdio_names: Ensu...
823
  	for (i = 0; i < MAX_FILES; i++) {
382bee57f   Simon Glass   env: Rename seten...
824
  		env_set(stdio_names[i], stdio_devices[i]->name);
47d1a6e1e   wdenk   Initial revision
825
  	}
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
826
  #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
47d1a6e1e   wdenk   Initial revision
827

c4e0057fa   Joe Hershberger   env: Refactor do_...
828
  	gd->flags |= GD_FLG_DEVINIT;	/* device initialization completed */
47d1a6e1e   wdenk   Initial revision
829
830
831
  #if 0
  	/* If nothing usable installed, use only the initial console */
  	if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
832
  		return 0;
47d1a6e1e   wdenk   Initial revision
833
  #endif
276696675   Siarhei Siamashka   console: Use pre-...
834
  	print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
835
  	return 0;
47d1a6e1e   wdenk   Initial revision
836
  }
b02654294   Simon Glass   console: Don't en...
837
  #else /* !CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */
47d1a6e1e   wdenk   Initial revision
838
839
  
  /* Called after the relocation - use desired console functions */
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
840
  int console_init_r(void)
47d1a6e1e   wdenk   Initial revision
841
  {
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
842
  	struct stdio_dev *inputdev = NULL, *outputdev = NULL;
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
843
  	int i;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
844
  	struct list_head *list = stdio_get_list();
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
845
  	struct list_head *pos;
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
846
  	struct stdio_dev *dev;
47d1a6e1e   wdenk   Initial revision
847

43e0a3dec   Chris Packham   common/console.c:...
848
  	console_update_silent();
d791b1dc3   wdenk   * Make sure Block...
849
  #ifdef CONFIG_SPLASH_SCREEN
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
850
851
  	/*
  	 * suppress all output if splash screen is enabled and we have
a74908161   Anatolij Gustschin   console.c: fix pr...
852
853
854
  	 * a bmp to display. We redirect the output from frame buffer
  	 * console to serial console in this case or suppress it if
  	 * "silent" mode was requested.
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
855
  	 */
00caae6d4   Simon Glass   env: Rename geten...
856
  	if (env_get("splashimage") != NULL) {
a74908161   Anatolij Gustschin   console.c: fix pr...
857
858
859
  		if (!(gd->flags & GD_FLG_SILENT))
  			outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
  	}
f72da3406   wdenk   Added config opti...
860
  #endif
47d1a6e1e   wdenk   Initial revision
861
  	/* Scan devices looking for input and output devices */
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
862
  	list_for_each(pos, list) {
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
863
  		dev = list_entry(pos, struct stdio_dev, list);
47d1a6e1e   wdenk   Initial revision
864
865
866
867
868
869
870
  
  		if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
  			inputdev = dev;
  		}
  		if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
  			outputdev = dev;
  		}
c1de7a6da   Jean-Christophe PLAGNIOL-VILLARD   devices: merge to...
871
872
  		if(inputdev && outputdev)
  			break;
47d1a6e1e   wdenk   Initial revision
873
874
875
876
  	}
  
  	/* Initializes output console first */
  	if (outputdev != NULL) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
877
878
  		console_setfile(stdout, outputdev);
  		console_setfile(stderr, outputdev);
b02654294   Simon Glass   console: Don't en...
879
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
880
881
882
  		console_devices[stdout][0] = outputdev;
  		console_devices[stderr][0] = outputdev;
  #endif
47d1a6e1e   wdenk   Initial revision
883
884
885
886
  	}
  
  	/* Initializes input console */
  	if (inputdev != NULL) {
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
887
  		console_setfile(stdin, inputdev);
b02654294   Simon Glass   console: Don't en...
888
  #if CONFIG_IS_ENABLED(CONSOLE_MUX)
16a28ef21   Gary Jennejohn   IOMUX: Add consol...
889
890
  		console_devices[stdin][0] = inputdev;
  #endif
47d1a6e1e   wdenk   Initial revision
891
  	}
78c112c9f   Simon Glass   console: Enable f...
892
  #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
7e3be7cf3   Jean-Christophe PLAGNIOL-VILLARD   console: unify pr...
893
  	stdio_print_current_devices();
78c112c9f   Simon Glass   console: Enable f...
894
  #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
47d1a6e1e   wdenk   Initial revision
895
896
  
  	/* Setting environment variables */
27b4225b3   Tom Rini   stdio_names: Ensu...
897
  	for (i = 0; i < MAX_FILES; i++) {
382bee57f   Simon Glass   env: Rename seten...
898
  		env_set(stdio_names[i], stdio_devices[i]->name);
47d1a6e1e   wdenk   Initial revision
899
  	}
c4e0057fa   Joe Hershberger   env: Refactor do_...
900
  	gd->flags |= GD_FLG_DEVINIT;	/* device initialization completed */
47d1a6e1e   wdenk   Initial revision
901
902
903
  #if 0
  	/* If nothing usable installed, use only the initial console */
  	if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
904
  		return 0;
47d1a6e1e   wdenk   Initial revision
905
  #endif
276696675   Siarhei Siamashka   console: Use pre-...
906
  	print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
ec6f14994   Jean-Christophe PLAGNIOL-VILLARD   common/console: c...
907
  	return 0;
47d1a6e1e   wdenk   Initial revision
908
  }
b02654294   Simon Glass   console: Don't en...
909
  #endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */