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