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