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);
43 int overwrite_console (void)
47 #endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */
49 #endif /* CFG_CONSOLE_IS_IN_ENV */
51 static int console_setfile (int file, device_t * dev)
53 DECLARE_GLOBAL_DATA_PTR;
63 /* Start new device */
65 error = dev->start ();
66 /* If it's not started dont use it */
71 /* Assign the new device (leaving the existing one started) */
72 stdio_devices[file] = dev;
75 * Update monitor functions
76 * (to use the console stuff by other applications)
80 gd->jt[XF_getc] = dev->getc;
81 gd->jt[XF_tstc] = dev->tstc;
84 gd->jt[XF_putc] = dev->putc;
85 gd->jt[XF_puts] = dev->puts;
86 gd->jt[XF_printf] = printf;
91 default: /* Invalid file ID */
97 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
99 void serial_printf (const char *fmt, ...)
103 char printbuffer[CFG_PBSIZE];
105 va_start (args, fmt);
107 /* For this to work, printbuffer must be larger than
108 * anything we ever want to print.
110 i = vsprintf (printbuffer, fmt, args);
113 serial_puts (printbuffer);
118 if (file < MAX_FILES)
119 return stdio_devices[file]->getc ();
126 if (file < MAX_FILES)
127 return stdio_devices[file]->tstc ();
132 void fputc (int file, const char c)
134 if (file < MAX_FILES)
135 stdio_devices[file]->putc (c);
138 void fputs (int file, const char *s)
140 if (file < MAX_FILES)
141 stdio_devices[file]->puts (s);
144 void fprintf (int file, const char *fmt, ...)
148 char printbuffer[CFG_PBSIZE];
150 va_start (args, fmt);
152 /* For this to work, printbuffer must be larger than
153 * anything we ever want to print.
155 i = vsprintf (printbuffer, fmt, args);
158 /* Send to desired file */
159 fputs (file, printbuffer);
162 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
166 DECLARE_GLOBAL_DATA_PTR;
168 if (gd->flags & GD_FLG_DEVINIT) {
169 /* Get from the standard input */
170 return fgetc (stdin);
173 /* Send directly to the handler */
174 return serial_getc ();
179 DECLARE_GLOBAL_DATA_PTR;
181 if (gd->flags & GD_FLG_DEVINIT) {
182 /* Test the standard input */
183 return ftstc (stdin);
186 /* Send directly to the handler */
187 return serial_tstc ();
190 void putc (const char c)
192 DECLARE_GLOBAL_DATA_PTR;
194 #ifdef CONFIG_SILENT_CONSOLE
195 if (gd->flags & GD_FLG_SILENT)
199 if (gd->flags & GD_FLG_DEVINIT) {
200 /* Send to the standard output */
203 /* Send directly to the handler */
208 void puts (const char *s)
210 DECLARE_GLOBAL_DATA_PTR;
212 #ifdef CONFIG_SILENT_CONSOLE
213 if (gd->flags & GD_FLG_SILENT)
217 if (gd->flags & GD_FLG_DEVINIT) {
218 /* Send to the standard output */
221 /* Send directly to the handler */
226 void printf (const char *fmt, ...)
230 char printbuffer[CFG_PBSIZE];
232 va_start (args, fmt);
234 /* For this to work, printbuffer must be larger than
235 * anything we ever want to print.
237 i = vsprintf (printbuffer, fmt, args);
240 /* Print the string */
244 void vprintf (const char *fmt, va_list args)
247 char printbuffer[CFG_PBSIZE];
249 /* For this to work, printbuffer must be larger than
250 * anything we ever want to print.
252 i = vsprintf (printbuffer, fmt, args);
254 /* Print the string */
258 /* test if ctrl-c was pressed */
259 static int ctrlc_disabled = 0; /* see disable_ctrl() */
260 static int ctrlc_was_pressed = 0;
263 DECLARE_GLOBAL_DATA_PTR;
265 if (!ctrlc_disabled && gd->have_console) {
268 case 0x03: /* ^C - Control C */
269 ctrlc_was_pressed = 1;
279 /* pass 1 to disable ctrlc() checking, 0 to enable.
280 * returns previous state
282 int disable_ctrlc (int disable)
284 int prev = ctrlc_disabled; /* save previous state */
286 ctrlc_disabled = disable;
292 return ctrlc_was_pressed;
295 void clear_ctrlc (void)
297 ctrlc_was_pressed = 0;
300 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
302 char *cursor = screen;
304 inline void dbg(const char *fmt, ...)
308 char printbuffer[CFG_PBSIZE];
311 memset(screen, 0, sizeof(screen));
317 /* For this to work, printbuffer must be larger than
318 * anything we ever want to print.
320 i = vsprintf(printbuffer, fmt, args);
323 if ((screen + sizeof(screen) - 1 - cursor) < strlen(printbuffer)+1) {
324 memset(screen, 0, sizeof(screen));
327 sprintf(cursor, printbuffer);
328 cursor += strlen(printbuffer);
332 inline void dbg(const char *fmt, ...)
337 /** U-Boot INIT FUNCTIONS *************************************************/
339 int console_assign (int file, char *devname)
343 /* Check for valid file */
346 flag = DEV_FLAGS_INPUT;
350 flag = DEV_FLAGS_OUTPUT;
356 /* Check for valid device name */
358 for (i = 1; i <= ListNumItems (devlist); i++) {
359 device_t *dev = ListGetPtrToItem (devlist, i);
361 if (strcmp (devname, dev->name) == 0) {
362 if (dev->flags & flag)
363 return console_setfile (file, dev);
372 /* Called before relocation - use serial functions */
373 int console_init_f (void)
375 DECLARE_GLOBAL_DATA_PTR;
377 gd->have_console = 1;
379 #ifdef CONFIG_SILENT_CONSOLE
380 if (getenv("silent") != NULL)
381 gd->flags |= GD_FLG_SILENT;
387 #if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE)
388 /* search a device */
389 device_t *search_device (int flags, char *name)
392 device_t *dev = NULL;
394 items = ListNumItems (devlist);
398 for (i = 1; i <= items; i++) {
399 dev = ListGetPtrToItem (devlist, i);
400 if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
406 #endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */
408 #ifdef CFG_CONSOLE_IS_IN_ENV
409 /* Called after the relocation - use desired console functions */
410 int console_init_r (void)
412 DECLARE_GLOBAL_DATA_PTR;
413 char *stdinname, *stdoutname, *stderrname;
414 device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
416 /* set default handlers at first */
417 gd->jt[XF_getc] = serial_getc;
418 gd->jt[XF_tstc] = serial_tstc;
419 gd->jt[XF_putc] = serial_putc;
420 gd->jt[XF_puts] = serial_puts;
421 gd->jt[XF_printf] = serial_printf;
423 /* stdin stdout and stderr are in environment */
425 stdinname = getenv ("stdin");
426 stdoutname = getenv ("stdout");
427 stderrname = getenv ("stderr");
429 if (overwrite_console () == 0) { /* if not overwritten by config switch */
430 inputdev = search_device (DEV_FLAGS_INPUT, stdinname);
431 outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
432 errdev = search_device (DEV_FLAGS_OUTPUT, stderrname);
434 /* if the devices are overwritten or not found, use default device */
435 if (inputdev == NULL) {
436 inputdev = search_device (DEV_FLAGS_INPUT, "serial");
438 if (outputdev == NULL) {
439 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
441 if (errdev == NULL) {
442 errdev = search_device (DEV_FLAGS_OUTPUT, "serial");
444 /* Initializes output console first */
445 if (outputdev != NULL) {
446 console_setfile (stdout, outputdev);
448 if (errdev != NULL) {
449 console_setfile (stderr, errdev);
451 if (inputdev != NULL) {
452 console_setfile (stdin, inputdev);
455 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
457 #ifndef CFG_CONSOLE_INFO_QUIET
458 /* Print information */
460 if (stdio_devices[stdin] == NULL) {
461 printf ("No input devices available!\n");
463 printf ("%s\n", stdio_devices[stdin]->name);
467 if (stdio_devices[stdout] == NULL) {
468 printf ("No output devices available!\n");
470 printf ("%s\n", stdio_devices[stdout]->name);
474 if (stdio_devices[stderr] == NULL) {
475 printf ("No error devices available!\n");
477 printf ("%s\n", stdio_devices[stderr]->name);
479 #endif /* CFG_CONSOLE_INFO_QUIET */
481 #ifdef CFG_CONSOLE_ENV_OVERWRITE
482 /* set the environment variables (will overwrite previous env settings) */
483 for (i = 0; i < 3; i++) {
484 setenv (stdio_names[i], stdio_devices[i]->name);
486 #endif /* CFG_CONSOLE_ENV_OVERWRITE */
489 /* If nothing usable installed, use only the initial console */
490 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
496 #else /* CFG_CONSOLE_IS_IN_ENV */
498 /* Called after the relocation - use desired console functions */
499 int console_init_r (void)
501 DECLARE_GLOBAL_DATA_PTR;
503 device_t *inputdev = NULL, *outputdev = NULL;
504 int i, items = ListNumItems (devlist);
506 #ifdef CONFIG_SPLASH_SCREEN
507 /* suppress all output if splash screen is enabled and we have
509 if (getenv("splashimage") != NULL)
510 outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev");
513 #ifdef CONFIG_SILENT_CONSOLE
514 /* Suppress all output if "silent" mode requested */
515 if (gd->flags & GD_FLG_SILENT)
516 outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev");
519 /* Scan devices looking for input and output devices */
521 (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
524 device_t *dev = ListGetPtrToItem (devlist, i);
526 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
529 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
534 /* Initializes output console first */
535 if (outputdev != NULL) {
536 console_setfile (stdout, outputdev);
537 console_setfile (stderr, outputdev);
540 /* Initializes input console */
541 if (inputdev != NULL) {
542 console_setfile (stdin, inputdev);
545 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
547 #ifndef CFG_CONSOLE_INFO_QUIET
548 /* Print information */
550 if (stdio_devices[stdin] == NULL) {
551 printf ("No input devices available!\n");
553 printf ("%s\n", stdio_devices[stdin]->name);
557 if (stdio_devices[stdout] == NULL) {
558 printf ("No output devices available!\n");
560 printf ("%s\n", stdio_devices[stdout]->name);
564 if (stdio_devices[stderr] == NULL) {
565 printf ("No error devices available!\n");
567 printf ("%s\n", stdio_devices[stderr]->name);
569 #endif /* CFG_CONSOLE_INFO_QUIET */
571 /* Setting environment variables */
572 for (i = 0; i < 3; i++) {
573 setenv (stdio_names[i], stdio_devices[i]->name);
577 /* If nothing usable installed, use only the initial console */
578 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
585 #endif /* CFG_CONSOLE_IS_IN_ENV */