wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 28 | #include <exports.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 29 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_AMIGAONEG3SE |
| 31 | int console_changed = 0; |
| 32 | #endif |
| 33 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 34 | #ifdef CFG_CONSOLE_IS_IN_ENV |
| 35 | /* |
| 36 | * if overwrite_console returns 1, the stdin, stderr and stdout |
| 37 | * are switched to the serial port, else the settings in the |
| 38 | * environment are used |
| 39 | */ |
| 40 | #ifdef CFG_CONSOLE_OVERWRITE_ROUTINE |
| 41 | extern int overwrite_console (void); |
wdenk | 83e40ba | 2005-03-31 18:42:15 +0000 | [diff] [blame^] | 42 | #define OVERWRITE_CONSOLE overwrite_console () |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 43 | #else |
wdenk | 83e40ba | 2005-03-31 18:42:15 +0000 | [diff] [blame^] | 44 | #define OVERWRITE_CONSOLE 0 |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 45 | #endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */ |
| 46 | |
| 47 | #endif /* CFG_CONSOLE_IS_IN_ENV */ |
| 48 | |
| 49 | static int console_setfile (int file, device_t * dev) |
| 50 | { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 51 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 52 | int error = 0; |
| 53 | |
| 54 | if (dev == NULL) |
| 55 | return -1; |
| 56 | |
| 57 | switch (file) { |
| 58 | case stdin: |
| 59 | case stdout: |
| 60 | case stderr: |
| 61 | /* Start new device */ |
| 62 | if (dev->start) { |
| 63 | error = dev->start (); |
| 64 | /* If it's not started dont use it */ |
| 65 | if (error < 0) |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | /* Assign the new device (leaving the existing one started) */ |
| 70 | stdio_devices[file] = dev; |
| 71 | |
| 72 | /* |
| 73 | * Update monitor functions |
| 74 | * (to use the console stuff by other applications) |
| 75 | */ |
| 76 | switch (file) { |
| 77 | case stdin: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 78 | gd->jt[XF_getc] = dev->getc; |
| 79 | gd->jt[XF_tstc] = dev->tstc; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 80 | break; |
| 81 | case stdout: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 82 | gd->jt[XF_putc] = dev->putc; |
| 83 | gd->jt[XF_puts] = dev->puts; |
| 84 | gd->jt[XF_printf] = printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 85 | break; |
| 86 | } |
| 87 | break; |
| 88 | |
| 89 | default: /* Invalid file ID */ |
| 90 | error = -1; |
| 91 | } |
| 92 | return error; |
| 93 | } |
| 94 | |
| 95 | /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
| 96 | |
| 97 | void serial_printf (const char *fmt, ...) |
| 98 | { |
| 99 | va_list args; |
| 100 | uint i; |
| 101 | char printbuffer[CFG_PBSIZE]; |
| 102 | |
| 103 | va_start (args, fmt); |
| 104 | |
| 105 | /* For this to work, printbuffer must be larger than |
| 106 | * anything we ever want to print. |
| 107 | */ |
| 108 | i = vsprintf (printbuffer, fmt, args); |
| 109 | va_end (args); |
| 110 | |
| 111 | serial_puts (printbuffer); |
| 112 | } |
| 113 | |
| 114 | int fgetc (int file) |
| 115 | { |
| 116 | if (file < MAX_FILES) |
| 117 | return stdio_devices[file]->getc (); |
| 118 | |
| 119 | return -1; |
| 120 | } |
| 121 | |
| 122 | int ftstc (int file) |
| 123 | { |
| 124 | if (file < MAX_FILES) |
| 125 | return stdio_devices[file]->tstc (); |
| 126 | |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | void fputc (int file, const char c) |
| 131 | { |
| 132 | if (file < MAX_FILES) |
| 133 | stdio_devices[file]->putc (c); |
| 134 | } |
| 135 | |
| 136 | void fputs (int file, const char *s) |
| 137 | { |
| 138 | if (file < MAX_FILES) |
| 139 | stdio_devices[file]->puts (s); |
| 140 | } |
| 141 | |
| 142 | void fprintf (int file, const char *fmt, ...) |
| 143 | { |
| 144 | va_list args; |
| 145 | uint i; |
| 146 | char printbuffer[CFG_PBSIZE]; |
| 147 | |
| 148 | va_start (args, fmt); |
| 149 | |
| 150 | /* For this to work, printbuffer must be larger than |
| 151 | * anything we ever want to print. |
| 152 | */ |
| 153 | i = vsprintf (printbuffer, fmt, args); |
| 154 | va_end (args); |
| 155 | |
| 156 | /* Send to desired file */ |
| 157 | fputs (file, printbuffer); |
| 158 | } |
| 159 | |
| 160 | /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
| 161 | |
| 162 | int getc (void) |
| 163 | { |
| 164 | DECLARE_GLOBAL_DATA_PTR; |
| 165 | |
| 166 | if (gd->flags & GD_FLG_DEVINIT) { |
| 167 | /* Get from the standard input */ |
| 168 | return fgetc (stdin); |
| 169 | } |
| 170 | |
| 171 | /* Send directly to the handler */ |
| 172 | return serial_getc (); |
| 173 | } |
| 174 | |
| 175 | int tstc (void) |
| 176 | { |
| 177 | DECLARE_GLOBAL_DATA_PTR; |
| 178 | |
| 179 | if (gd->flags & GD_FLG_DEVINIT) { |
| 180 | /* Test the standard input */ |
| 181 | return ftstc (stdin); |
| 182 | } |
| 183 | |
| 184 | /* Send directly to the handler */ |
| 185 | return serial_tstc (); |
| 186 | } |
| 187 | |
| 188 | void putc (const char c) |
| 189 | { |
| 190 | DECLARE_GLOBAL_DATA_PTR; |
| 191 | |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 192 | #ifdef CONFIG_SILENT_CONSOLE |
| 193 | if (gd->flags & GD_FLG_SILENT) |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 194 | return; |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 197 | if (gd->flags & GD_FLG_DEVINIT) { |
| 198 | /* Send to the standard output */ |
| 199 | fputc (stdout, c); |
| 200 | } else { |
| 201 | /* Send directly to the handler */ |
| 202 | serial_putc (c); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void puts (const char *s) |
| 207 | { |
| 208 | DECLARE_GLOBAL_DATA_PTR; |
| 209 | |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 210 | #ifdef CONFIG_SILENT_CONSOLE |
| 211 | if (gd->flags & GD_FLG_SILENT) |
| 212 | return; |
| 213 | #endif |
| 214 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 215 | if (gd->flags & GD_FLG_DEVINIT) { |
| 216 | /* Send to the standard output */ |
| 217 | fputs (stdout, s); |
| 218 | } else { |
| 219 | /* Send directly to the handler */ |
| 220 | serial_puts (s); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void printf (const char *fmt, ...) |
| 225 | { |
| 226 | va_list args; |
| 227 | uint i; |
| 228 | char printbuffer[CFG_PBSIZE]; |
| 229 | |
| 230 | va_start (args, fmt); |
| 231 | |
| 232 | /* For this to work, printbuffer must be larger than |
| 233 | * anything we ever want to print. |
| 234 | */ |
| 235 | i = vsprintf (printbuffer, fmt, args); |
| 236 | va_end (args); |
| 237 | |
| 238 | /* Print the string */ |
| 239 | puts (printbuffer); |
| 240 | } |
| 241 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 242 | void vprintf (const char *fmt, va_list args) |
| 243 | { |
| 244 | uint i; |
| 245 | char printbuffer[CFG_PBSIZE]; |
| 246 | |
| 247 | /* For this to work, printbuffer must be larger than |
| 248 | * anything we ever want to print. |
| 249 | */ |
| 250 | i = vsprintf (printbuffer, fmt, args); |
| 251 | |
| 252 | /* Print the string */ |
| 253 | puts (printbuffer); |
| 254 | } |
| 255 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 256 | /* test if ctrl-c was pressed */ |
| 257 | static int ctrlc_disabled = 0; /* see disable_ctrl() */ |
| 258 | static int ctrlc_was_pressed = 0; |
| 259 | int ctrlc (void) |
| 260 | { |
| 261 | DECLARE_GLOBAL_DATA_PTR; |
| 262 | |
| 263 | if (!ctrlc_disabled && gd->have_console) { |
| 264 | if (tstc ()) { |
| 265 | switch (getc ()) { |
| 266 | case 0x03: /* ^C - Control C */ |
| 267 | ctrlc_was_pressed = 1; |
| 268 | return 1; |
| 269 | default: |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | /* pass 1 to disable ctrlc() checking, 0 to enable. |
| 278 | * returns previous state |
| 279 | */ |
| 280 | int disable_ctrlc (int disable) |
| 281 | { |
| 282 | int prev = ctrlc_disabled; /* save previous state */ |
| 283 | |
| 284 | ctrlc_disabled = disable; |
| 285 | return prev; |
| 286 | } |
| 287 | |
| 288 | int had_ctrlc (void) |
| 289 | { |
| 290 | return ctrlc_was_pressed; |
| 291 | } |
| 292 | |
| 293 | void clear_ctrlc (void) |
| 294 | { |
| 295 | ctrlc_was_pressed = 0; |
| 296 | } |
| 297 | |
| 298 | #ifdef CONFIG_MODEM_SUPPORT_DEBUG |
| 299 | char screen[1024]; |
| 300 | char *cursor = screen; |
| 301 | int once = 0; |
| 302 | inline void dbg(const char *fmt, ...) |
| 303 | { |
| 304 | va_list args; |
| 305 | uint i; |
| 306 | char printbuffer[CFG_PBSIZE]; |
| 307 | |
| 308 | if (!once) { |
| 309 | memset(screen, 0, sizeof(screen)); |
| 310 | once++; |
| 311 | } |
| 312 | |
| 313 | va_start(args, fmt); |
| 314 | |
| 315 | /* For this to work, printbuffer must be larger than |
| 316 | * anything we ever want to print. |
| 317 | */ |
| 318 | i = vsprintf(printbuffer, fmt, args); |
| 319 | va_end(args); |
| 320 | |
| 321 | if ((screen + sizeof(screen) - 1 - cursor) < strlen(printbuffer)+1) { |
| 322 | memset(screen, 0, sizeof(screen)); |
| 323 | cursor = screen; |
| 324 | } |
| 325 | sprintf(cursor, printbuffer); |
| 326 | cursor += strlen(printbuffer); |
| 327 | |
| 328 | } |
| 329 | #else |
| 330 | inline void dbg(const char *fmt, ...) |
| 331 | { |
| 332 | } |
| 333 | #endif |
| 334 | |
| 335 | /** U-Boot INIT FUNCTIONS *************************************************/ |
| 336 | |
| 337 | int console_assign (int file, char *devname) |
| 338 | { |
| 339 | int flag, i; |
| 340 | |
| 341 | /* Check for valid file */ |
| 342 | switch (file) { |
| 343 | case stdin: |
| 344 | flag = DEV_FLAGS_INPUT; |
| 345 | break; |
| 346 | case stdout: |
| 347 | case stderr: |
| 348 | flag = DEV_FLAGS_OUTPUT; |
| 349 | break; |
| 350 | default: |
| 351 | return -1; |
| 352 | } |
| 353 | |
| 354 | /* Check for valid device name */ |
| 355 | |
| 356 | for (i = 1; i <= ListNumItems (devlist); i++) { |
| 357 | device_t *dev = ListGetPtrToItem (devlist, i); |
| 358 | |
| 359 | if (strcmp (devname, dev->name) == 0) { |
| 360 | if (dev->flags & flag) |
| 361 | return console_setfile (file, dev); |
| 362 | |
| 363 | return -1; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | /* Called before relocation - use serial functions */ |
| 371 | int console_init_f (void) |
| 372 | { |
| 373 | DECLARE_GLOBAL_DATA_PTR; |
| 374 | |
| 375 | gd->have_console = 1; |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 376 | |
| 377 | #ifdef CONFIG_SILENT_CONSOLE |
| 378 | if (getenv("silent") != NULL) |
| 379 | gd->flags |= GD_FLG_SILENT; |
| 380 | #endif |
| 381 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 382 | return (0); |
| 383 | } |
| 384 | |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 385 | #if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 386 | /* search a device */ |
| 387 | device_t *search_device (int flags, char *name) |
| 388 | { |
| 389 | int i, items; |
| 390 | device_t *dev = NULL; |
| 391 | |
| 392 | items = ListNumItems (devlist); |
| 393 | if (name == NULL) |
| 394 | return dev; |
| 395 | |
| 396 | for (i = 1; i <= items; i++) { |
| 397 | dev = ListGetPtrToItem (devlist, i); |
| 398 | if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | return dev; |
| 403 | } |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 404 | #endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 405 | |
| 406 | #ifdef CFG_CONSOLE_IS_IN_ENV |
| 407 | /* Called after the relocation - use desired console functions */ |
| 408 | int console_init_r (void) |
| 409 | { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 410 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 411 | char *stdinname, *stdoutname, *stderrname; |
| 412 | device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 413 | #ifdef CFG_CONSOLE_ENV_OVERWRITE |
| 414 | int i; |
| 415 | #endif /* CFG_CONSOLE_ENV_OVERWRITE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 416 | |
| 417 | /* set default handlers at first */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 418 | gd->jt[XF_getc] = serial_getc; |
| 419 | gd->jt[XF_tstc] = serial_tstc; |
| 420 | gd->jt[XF_putc] = serial_putc; |
| 421 | gd->jt[XF_puts] = serial_puts; |
| 422 | gd->jt[XF_printf] = serial_printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 423 | |
| 424 | /* stdin stdout and stderr are in environment */ |
| 425 | /* scan for it */ |
| 426 | stdinname = getenv ("stdin"); |
| 427 | stdoutname = getenv ("stdout"); |
| 428 | stderrname = getenv ("stderr"); |
| 429 | |
wdenk | 83e40ba | 2005-03-31 18:42:15 +0000 | [diff] [blame^] | 430 | if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 431 | inputdev = search_device (DEV_FLAGS_INPUT, stdinname); |
| 432 | outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname); |
| 433 | errdev = search_device (DEV_FLAGS_OUTPUT, stderrname); |
| 434 | } |
| 435 | /* if the devices are overwritten or not found, use default device */ |
| 436 | if (inputdev == NULL) { |
| 437 | inputdev = search_device (DEV_FLAGS_INPUT, "serial"); |
| 438 | } |
| 439 | if (outputdev == NULL) { |
| 440 | outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); |
| 441 | } |
| 442 | if (errdev == NULL) { |
| 443 | errdev = search_device (DEV_FLAGS_OUTPUT, "serial"); |
| 444 | } |
| 445 | /* Initializes output console first */ |
| 446 | if (outputdev != NULL) { |
| 447 | console_setfile (stdout, outputdev); |
| 448 | } |
| 449 | if (errdev != NULL) { |
| 450 | console_setfile (stderr, errdev); |
| 451 | } |
| 452 | if (inputdev != NULL) { |
| 453 | console_setfile (stdin, inputdev); |
| 454 | } |
| 455 | |
wdenk | 5f535fe | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 456 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 457 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 458 | #ifndef CFG_CONSOLE_INFO_QUIET |
| 459 | /* Print information */ |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 460 | puts ("In: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 461 | if (stdio_devices[stdin] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 462 | puts ("No input devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 463 | } else { |
| 464 | printf ("%s\n", stdio_devices[stdin]->name); |
| 465 | } |
| 466 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 467 | puts ("Out: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 468 | if (stdio_devices[stdout] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 469 | puts ("No output devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 470 | } else { |
| 471 | printf ("%s\n", stdio_devices[stdout]->name); |
| 472 | } |
| 473 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 474 | puts ("Err: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 475 | if (stdio_devices[stderr] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 476 | puts ("No error devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 477 | } else { |
| 478 | printf ("%s\n", stdio_devices[stderr]->name); |
| 479 | } |
| 480 | #endif /* CFG_CONSOLE_INFO_QUIET */ |
| 481 | |
| 482 | #ifdef CFG_CONSOLE_ENV_OVERWRITE |
| 483 | /* set the environment variables (will overwrite previous env settings) */ |
| 484 | for (i = 0; i < 3; i++) { |
| 485 | setenv (stdio_names[i], stdio_devices[i]->name); |
| 486 | } |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 487 | #endif /* CFG_CONSOLE_ENV_OVERWRITE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 488 | |
| 489 | #if 0 |
| 490 | /* If nothing usable installed, use only the initial console */ |
| 491 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
| 492 | return (0); |
| 493 | #endif |
| 494 | return (0); |
| 495 | } |
| 496 | |
| 497 | #else /* CFG_CONSOLE_IS_IN_ENV */ |
| 498 | |
| 499 | /* Called after the relocation - use desired console functions */ |
| 500 | int console_init_r (void) |
| 501 | { |
wdenk | 5f535fe | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 502 | DECLARE_GLOBAL_DATA_PTR; |
| 503 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 504 | device_t *inputdev = NULL, *outputdev = NULL; |
| 505 | int i, items = ListNumItems (devlist); |
| 506 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 507 | #ifdef CONFIG_SPLASH_SCREEN |
dzu | 87970eb | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 508 | /* suppress all output if splash screen is enabled and we have |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 509 | a bmp to display */ |
dzu | 87970eb | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 510 | if (getenv("splashimage") != NULL) |
| 511 | outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev"); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 512 | #endif |
| 513 | |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 514 | #ifdef CONFIG_SILENT_CONSOLE |
| 515 | /* Suppress all output if "silent" mode requested */ |
| 516 | if (gd->flags & GD_FLG_SILENT) |
| 517 | outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev"); |
| 518 | #endif |
| 519 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 520 | /* Scan devices looking for input and output devices */ |
| 521 | for (i = 1; |
| 522 | (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); |
| 523 | i++ |
| 524 | ) { |
| 525 | device_t *dev = ListGetPtrToItem (devlist, i); |
| 526 | |
| 527 | if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { |
| 528 | inputdev = dev; |
| 529 | } |
| 530 | if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { |
| 531 | outputdev = dev; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /* Initializes output console first */ |
| 536 | if (outputdev != NULL) { |
| 537 | console_setfile (stdout, outputdev); |
| 538 | console_setfile (stderr, outputdev); |
| 539 | } |
| 540 | |
| 541 | /* Initializes input console */ |
| 542 | if (inputdev != NULL) { |
| 543 | console_setfile (stdin, inputdev); |
| 544 | } |
| 545 | |
wdenk | 5f535fe | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 546 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 547 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 548 | #ifndef CFG_CONSOLE_INFO_QUIET |
wdenk | 47cd00f | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 549 | /* Print information */ |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 550 | puts ("In: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 551 | if (stdio_devices[stdin] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 552 | puts ("No input devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 553 | } else { |
| 554 | printf ("%s\n", stdio_devices[stdin]->name); |
| 555 | } |
| 556 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 557 | puts ("Out: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 558 | if (stdio_devices[stdout] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 559 | puts ("No output devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 560 | } else { |
| 561 | printf ("%s\n", stdio_devices[stdout]->name); |
| 562 | } |
| 563 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 564 | puts ("Err: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 565 | if (stdio_devices[stderr] == NULL) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 566 | puts ("No error devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 567 | } else { |
| 568 | printf ("%s\n", stdio_devices[stderr]->name); |
| 569 | } |
| 570 | #endif /* CFG_CONSOLE_INFO_QUIET */ |
| 571 | |
| 572 | /* Setting environment variables */ |
| 573 | for (i = 0; i < 3; i++) { |
| 574 | setenv (stdio_names[i], stdio_devices[i]->name); |
| 575 | } |
| 576 | |
| 577 | #if 0 |
| 578 | /* If nothing usable installed, use only the initial console */ |
| 579 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
| 580 | return (0); |
| 581 | #endif |
| 582 | |
| 583 | return (0); |
| 584 | } |
| 585 | |
| 586 | #endif /* CFG_CONSOLE_IS_IN_ENV */ |