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 if (gd->flags & GD_FLG_DEVINIT) {
195 /* Send to the standard output */
198 /* Send directly to the handler */
203 void puts (const char *s)
205 DECLARE_GLOBAL_DATA_PTR;
207 if (gd->flags & GD_FLG_DEVINIT) {
208 /* Send to the standard output */
211 /* Send directly to the handler */
216 void printf (const char *fmt, ...)
220 char printbuffer[CFG_PBSIZE];
222 va_start (args, fmt);
224 /* For this to work, printbuffer must be larger than
225 * anything we ever want to print.
227 i = vsprintf (printbuffer, fmt, args);
230 /* Print the string */
234 void vprintf (const char *fmt, va_list args)
237 char printbuffer[CFG_PBSIZE];
239 /* For this to work, printbuffer must be larger than
240 * anything we ever want to print.
242 i = vsprintf (printbuffer, fmt, args);
244 /* Print the string */
248 /* test if ctrl-c was pressed */
249 static int ctrlc_disabled = 0; /* see disable_ctrl() */
250 static int ctrlc_was_pressed = 0;
253 DECLARE_GLOBAL_DATA_PTR;
255 if (!ctrlc_disabled && gd->have_console) {
258 case 0x03: /* ^C - Control C */
259 ctrlc_was_pressed = 1;
269 /* pass 1 to disable ctrlc() checking, 0 to enable.
270 * returns previous state
272 int disable_ctrlc (int disable)
274 int prev = ctrlc_disabled; /* save previous state */
276 ctrlc_disabled = disable;
282 return ctrlc_was_pressed;
285 void clear_ctrlc (void)
287 ctrlc_was_pressed = 0;
290 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
292 char *cursor = screen;
294 inline void dbg(const char *fmt, ...)
298 char printbuffer[CFG_PBSIZE];
301 memset(screen, 0, sizeof(screen));
307 /* For this to work, printbuffer must be larger than
308 * anything we ever want to print.
310 i = vsprintf(printbuffer, fmt, args);
313 if ((screen + sizeof(screen) - 1 - cursor) < strlen(printbuffer)+1) {
314 memset(screen, 0, sizeof(screen));
317 sprintf(cursor, printbuffer);
318 cursor += strlen(printbuffer);
322 inline void dbg(const char *fmt, ...)
327 /** U-Boot INIT FUNCTIONS *************************************************/
329 int console_assign (int file, char *devname)
333 /* Check for valid file */
336 flag = DEV_FLAGS_INPUT;
340 flag = DEV_FLAGS_OUTPUT;
346 /* Check for valid device name */
348 for (i = 1; i <= ListNumItems (devlist); i++) {
349 device_t *dev = ListGetPtrToItem (devlist, i);
351 if (strcmp (devname, dev->name) == 0) {
352 if (dev->flags & flag)
353 return console_setfile (file, dev);
362 /* Called before relocation - use serial functions */
363 int console_init_f (void)
365 DECLARE_GLOBAL_DATA_PTR;
367 gd->have_console = 1;
371 #if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN)
372 /* search a device */
373 device_t *search_device (int flags, char *name)
376 device_t *dev = NULL;
378 items = ListNumItems (devlist);
382 for (i = 1; i <= items; i++) {
383 dev = ListGetPtrToItem (devlist, i);
384 if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
390 #endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */
392 #ifdef CFG_CONSOLE_IS_IN_ENV
393 /* Called after the relocation - use desired console functions */
394 int console_init_r (void)
396 DECLARE_GLOBAL_DATA_PTR;
397 char *stdinname, *stdoutname, *stderrname;
398 device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
400 /* set default handlers at first */
401 gd->jt[XF_getc] = serial_getc;
402 gd->jt[XF_tstc] = serial_tstc;
403 gd->jt[XF_putc] = serial_putc;
404 gd->jt[XF_puts] = serial_puts;
405 gd->jt[XF_printf] = serial_printf;
407 /* stdin stdout and stderr are in environment */
409 stdinname = getenv ("stdin");
410 stdoutname = getenv ("stdout");
411 stderrname = getenv ("stderr");
413 if (overwrite_console () == 0) { /* if not overwritten by config switch */
414 inputdev = search_device (DEV_FLAGS_INPUT, stdinname);
415 outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
416 errdev = search_device (DEV_FLAGS_OUTPUT, stderrname);
418 /* if the devices are overwritten or not found, use default device */
419 if (inputdev == NULL) {
420 inputdev = search_device (DEV_FLAGS_INPUT, "serial");
422 if (outputdev == NULL) {
423 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
425 if (errdev == NULL) {
426 errdev = search_device (DEV_FLAGS_OUTPUT, "serial");
428 /* Initializes output console first */
429 if (outputdev != NULL) {
430 console_setfile (stdout, outputdev);
432 if (errdev != NULL) {
433 console_setfile (stderr, errdev);
435 if (inputdev != NULL) {
436 console_setfile (stdin, inputdev);
439 #ifndef CFG_CONSOLE_INFO_QUIET
440 /* Print information */
442 if (stdio_devices[stdin] == NULL) {
443 printf ("No input devices available!\n");
445 printf ("%s\n", stdio_devices[stdin]->name);
449 if (stdio_devices[stdout] == NULL) {
450 printf ("No output devices available!\n");
452 printf ("%s\n", stdio_devices[stdout]->name);
456 if (stdio_devices[stderr] == NULL) {
457 printf ("No error devices available!\n");
459 printf ("%s\n", stdio_devices[stderr]->name);
461 #endif /* CFG_CONSOLE_INFO_QUIET */
463 #ifdef CFG_CONSOLE_ENV_OVERWRITE
464 /* set the environment variables (will overwrite previous env settings) */
465 for (i = 0; i < 3; i++) {
466 setenv (stdio_names[i], stdio_devices[i]->name);
468 #endif /* CFG_CONSOLE_ENV_OVERWRITE */
471 /* If nothing usable installed, use only the initial console */
472 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
478 #else /* CFG_CONSOLE_IS_IN_ENV */
480 /* Called after the relocation - use desired console functions */
481 int console_init_r (void)
483 device_t *inputdev = NULL, *outputdev = NULL;
484 int i, items = ListNumItems (devlist);
486 #ifdef CONFIG_SPLASH_SCREEN
487 /* suppress all output if splash screen is enabled */
488 outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev");
491 /* Scan devices looking for input and output devices */
493 (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
496 device_t *dev = ListGetPtrToItem (devlist, i);
498 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
501 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
506 /* Initializes output console first */
507 if (outputdev != NULL) {
508 console_setfile (stdout, outputdev);
509 console_setfile (stderr, outputdev);
512 /* Initializes input console */
513 if (inputdev != NULL) {
514 console_setfile (stdin, inputdev);
517 #ifndef CFG_CONSOLE_INFO_QUIET
518 /* Print information */
520 if (stdio_devices[stdin] == NULL) {
521 printf ("No input devices available!\n");
523 printf ("%s\n", stdio_devices[stdin]->name);
527 if (stdio_devices[stdout] == NULL) {
528 printf ("No output devices available!\n");
530 printf ("%s\n", stdio_devices[stdout]->name);
534 if (stdio_devices[stderr] == NULL) {
535 printf ("No error devices available!\n");
537 printf ("%s\n", stdio_devices[stderr]->name);
539 #endif /* CFG_CONSOLE_INFO_QUIET */
541 /* Setting environment variables */
542 for (i = 0; i < 3; i++) {
543 setenv (stdio_names[i], stdio_devices[i]->name);
547 /* If nothing usable installed, use only the initial console */
548 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
555 #endif /* CFG_CONSOLE_IS_IN_ENV */