3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 #ifdef CONFIG_AMIGAONEG3SE
31 int console_changed = 0;
34 #ifdef CFG_CONSOLE_IS_IN_ENV
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
40 #ifdef CFG_CONSOLE_OVERWRITE_ROUTINE
41 extern int overwrite_console (void);
42 #define OVERWRITE_CONSOLE overwrite_console ()
44 #define OVERWRITE_CONSOLE 0
45 #endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */
47 #endif /* CFG_CONSOLE_IS_IN_ENV */
49 static int console_setfile (int file, device_t * dev)
51 DECLARE_GLOBAL_DATA_PTR;
61 /* Start new device */
63 error = dev->start ();
64 /* If it's not started dont use it */
69 /* Assign the new device (leaving the existing one started) */
70 stdio_devices[file] = dev;
73 * Update monitor functions
74 * (to use the console stuff by other applications)
78 gd->jt[XF_getc] = dev->getc;
79 gd->jt[XF_tstc] = dev->tstc;
82 gd->jt[XF_putc] = dev->putc;
83 gd->jt[XF_puts] = dev->puts;
84 gd->jt[XF_printf] = printf;
89 default: /* Invalid file ID */
95 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
97 void serial_printf (const char *fmt, ...)
101 char printbuffer[CFG_PBSIZE];
103 va_start (args, fmt);
105 /* For this to work, printbuffer must be larger than
106 * anything we ever want to print.
108 i = vsprintf (printbuffer, fmt, args);
111 serial_puts (printbuffer);
116 if (file < MAX_FILES)
117 return stdio_devices[file]->getc ();
124 if (file < MAX_FILES)
125 return stdio_devices[file]->tstc ();
130 void fputc (int file, const char c)
132 if (file < MAX_FILES)
133 stdio_devices[file]->putc (c);
136 void fputs (int file, const char *s)
138 if (file < MAX_FILES)
139 stdio_devices[file]->puts (s);
142 void fprintf (int file, const char *fmt, ...)
146 char printbuffer[CFG_PBSIZE];
148 va_start (args, fmt);
150 /* For this to work, printbuffer must be larger than
151 * anything we ever want to print.
153 i = vsprintf (printbuffer, fmt, args);
156 /* Send to desired file */
157 fputs (file, printbuffer);
160 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
164 DECLARE_GLOBAL_DATA_PTR;
166 if (gd->flags & GD_FLG_DEVINIT) {
167 /* Get from the standard input */
168 return fgetc (stdin);
171 /* Send directly to the handler */
172 return serial_getc ();
177 DECLARE_GLOBAL_DATA_PTR;
179 if (gd->flags & GD_FLG_DEVINIT) {
180 /* Test the standard input */
181 return ftstc (stdin);
184 /* Send directly to the handler */
185 return serial_tstc ();
188 void putc (const char c)
190 DECLARE_GLOBAL_DATA_PTR;
192 #ifdef CONFIG_SILENT_CONSOLE
193 if (gd->flags & GD_FLG_SILENT)
197 if (gd->flags & GD_FLG_DEVINIT) {
198 /* Send to the standard output */
201 /* Send directly to the handler */
206 void puts (const char *s)
208 DECLARE_GLOBAL_DATA_PTR;
210 #ifdef CONFIG_SILENT_CONSOLE
211 if (gd->flags & GD_FLG_SILENT)
215 if (gd->flags & GD_FLG_DEVINIT) {
216 /* Send to the standard output */
219 /* Send directly to the handler */
224 void printf (const char *fmt, ...)
228 char printbuffer[CFG_PBSIZE];
230 va_start (args, fmt);
232 /* For this to work, printbuffer must be larger than
233 * anything we ever want to print.
235 i = vsprintf (printbuffer, fmt, args);
238 /* Print the string */
242 void vprintf (const char *fmt, va_list args)
245 char printbuffer[CFG_PBSIZE];
247 /* For this to work, printbuffer must be larger than
248 * anything we ever want to print.
250 i = vsprintf (printbuffer, fmt, args);
252 /* Print the string */
256 /* test if ctrl-c was pressed */
257 static int ctrlc_disabled = 0; /* see disable_ctrl() */
258 static int ctrlc_was_pressed = 0;
261 DECLARE_GLOBAL_DATA_PTR;
263 if (!ctrlc_disabled && gd->have_console) {
266 case 0x03: /* ^C - Control C */
267 ctrlc_was_pressed = 1;
277 /* pass 1 to disable ctrlc() checking, 0 to enable.
278 * returns previous state
280 int disable_ctrlc (int disable)
282 int prev = ctrlc_disabled; /* save previous state */
284 ctrlc_disabled = disable;
290 return ctrlc_was_pressed;
293 void clear_ctrlc (void)
295 ctrlc_was_pressed = 0;
298 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
300 char *cursor = screen;
302 inline void dbg(const char *fmt, ...)
306 char printbuffer[CFG_PBSIZE];
309 memset(screen, 0, sizeof(screen));
315 /* For this to work, printbuffer must be larger than
316 * anything we ever want to print.
318 i = vsprintf(printbuffer, fmt, args);
321 if ((screen + sizeof(screen) - 1 - cursor) < strlen(printbuffer)+1) {
322 memset(screen, 0, sizeof(screen));
325 sprintf(cursor, printbuffer);
326 cursor += strlen(printbuffer);
330 inline void dbg(const char *fmt, ...)
335 /** U-Boot INIT FUNCTIONS *************************************************/
337 int console_assign (int file, char *devname)
341 /* Check for valid file */
344 flag = DEV_FLAGS_INPUT;
348 flag = DEV_FLAGS_OUTPUT;
354 /* Check for valid device name */
356 for (i = 1; i <= ListNumItems (devlist); i++) {
357 device_t *dev = ListGetPtrToItem (devlist, i);
359 if (strcmp (devname, dev->name) == 0) {
360 if (dev->flags & flag)
361 return console_setfile (file, dev);
370 /* Called before relocation - use serial functions */
371 int console_init_f (void)
373 DECLARE_GLOBAL_DATA_PTR;
375 gd->have_console = 1;
377 #ifdef CONFIG_SILENT_CONSOLE
378 if (getenv("silent") != NULL)
379 gd->flags |= GD_FLG_SILENT;
385 #if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE)
386 /* search a device */
387 device_t *search_device (int flags, char *name)
390 device_t *dev = NULL;
392 items = ListNumItems (devlist);
396 for (i = 1; i <= items; i++) {
397 dev = ListGetPtrToItem (devlist, i);
398 if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
404 #endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */
406 #ifdef CFG_CONSOLE_IS_IN_ENV
407 /* Called after the relocation - use desired console functions */
408 int console_init_r (void)
410 DECLARE_GLOBAL_DATA_PTR;
411 char *stdinname, *stdoutname, *stderrname;
412 device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
413 #ifdef CFG_CONSOLE_ENV_OVERWRITE
415 #endif /* CFG_CONSOLE_ENV_OVERWRITE */
417 /* set default handlers at first */
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;
424 /* stdin stdout and stderr are in environment */
426 stdinname = getenv ("stdin");
427 stdoutname = getenv ("stdout");
428 stderrname = getenv ("stderr");
430 if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
431 inputdev = search_device (DEV_FLAGS_INPUT, stdinname);
432 outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
433 errdev = search_device (DEV_FLAGS_OUTPUT, stderrname);
435 /* if the devices are overwritten or not found, use default device */
436 if (inputdev == NULL) {
437 inputdev = search_device (DEV_FLAGS_INPUT, "serial");
439 if (outputdev == NULL) {
440 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
442 if (errdev == NULL) {
443 errdev = search_device (DEV_FLAGS_OUTPUT, "serial");
445 /* Initializes output console first */
446 if (outputdev != NULL) {
447 console_setfile (stdout, outputdev);
449 if (errdev != NULL) {
450 console_setfile (stderr, errdev);
452 if (inputdev != NULL) {
453 console_setfile (stdin, inputdev);
456 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
458 #ifndef CFG_CONSOLE_INFO_QUIET
459 /* Print information */
461 if (stdio_devices[stdin] == NULL) {
462 puts ("No input devices available!\n");
464 printf ("%s\n", stdio_devices[stdin]->name);
468 if (stdio_devices[stdout] == NULL) {
469 puts ("No output devices available!\n");
471 printf ("%s\n", stdio_devices[stdout]->name);
475 if (stdio_devices[stderr] == NULL) {
476 puts ("No error devices available!\n");
478 printf ("%s\n", stdio_devices[stderr]->name);
480 #endif /* CFG_CONSOLE_INFO_QUIET */
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);
487 #endif /* CFG_CONSOLE_ENV_OVERWRITE */
490 /* If nothing usable installed, use only the initial console */
491 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
497 #else /* CFG_CONSOLE_IS_IN_ENV */
499 /* Called after the relocation - use desired console functions */
500 int console_init_r (void)
502 DECLARE_GLOBAL_DATA_PTR;
504 device_t *inputdev = NULL, *outputdev = NULL;
505 int i, items = ListNumItems (devlist);
507 #ifdef CONFIG_SPLASH_SCREEN
508 /* suppress all output if splash screen is enabled and we have
510 if (getenv("splashimage") != NULL)
511 outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev");
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");
520 /* Scan devices looking for input and output devices */
522 (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
525 device_t *dev = ListGetPtrToItem (devlist, i);
527 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
530 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
535 /* Initializes output console first */
536 if (outputdev != NULL) {
537 console_setfile (stdout, outputdev);
538 console_setfile (stderr, outputdev);
541 /* Initializes input console */
542 if (inputdev != NULL) {
543 console_setfile (stdin, inputdev);
546 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
548 #ifndef CFG_CONSOLE_INFO_QUIET
549 /* Print information */
551 if (stdio_devices[stdin] == NULL) {
552 puts ("No input devices available!\n");
554 printf ("%s\n", stdio_devices[stdin]->name);
558 if (stdio_devices[stdout] == NULL) {
559 puts ("No output devices available!\n");
561 printf ("%s\n", stdio_devices[stdout]->name);
565 if (stdio_devices[stderr] == NULL) {
566 puts ("No error devices available!\n");
568 printf ("%s\n", stdio_devices[stderr]->name);
570 #endif /* CFG_CONSOLE_INFO_QUIET */
572 /* Setting environment variables */
573 for (i = 0; i < 3; i++) {
574 setenv (stdio_names[i], stdio_devices[i]->name);
578 /* If nothing usable installed, use only the initial console */
579 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
586 #endif /* CFG_CONSOLE_IS_IN_ENV */