]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/console.c
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 DECLARE_GLOBAL_DATA_PTR
;
32 #ifdef CONFIG_AMIGAONEG3SE
33 int console_changed
= 0;
36 #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
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
42 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
43 extern int overwrite_console (void);
44 #define OVERWRITE_CONSOLE overwrite_console ()
46 #define OVERWRITE_CONSOLE 0
47 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
49 #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
51 static int console_setfile (int file
, device_t
* dev
)
62 /* Start new device */
64 error
= dev
->start ();
65 /* If it's not started dont use it */
70 /* Assign the new device (leaving the existing one started) */
71 stdio_devices
[file
] = dev
;
74 * Update monitor functions
75 * (to use the console stuff by other applications)
79 gd
->jt
[XF_getc
] = dev
->getc
;
80 gd
->jt
[XF_tstc
] = dev
->tstc
;
83 gd
->jt
[XF_putc
] = dev
->putc
;
84 gd
->jt
[XF_puts
] = dev
->puts
;
85 gd
->jt
[XF_printf
] = printf
;
90 default: /* Invalid file ID */
96 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
98 void serial_printf (const char *fmt
, ...)
102 char printbuffer
[CONFIG_SYS_PBSIZE
];
104 va_start (args
, fmt
);
106 /* For this to work, printbuffer must be larger than
107 * anything we ever want to print.
109 i
= vsprintf (printbuffer
, fmt
, args
);
112 serial_puts (printbuffer
);
117 if (file
< MAX_FILES
)
118 return stdio_devices
[file
]->getc ();
125 if (file
< MAX_FILES
)
126 return stdio_devices
[file
]->tstc ();
131 void fputc (int file
, const char c
)
133 if (file
< MAX_FILES
)
134 stdio_devices
[file
]->putc (c
);
137 void fputs (int file
, const char *s
)
139 if (file
< MAX_FILES
)
140 stdio_devices
[file
]->puts (s
);
143 void fprintf (int file
, const char *fmt
, ...)
147 char printbuffer
[CONFIG_SYS_PBSIZE
];
149 va_start (args
, fmt
);
151 /* For this to work, printbuffer must be larger than
152 * anything we ever want to print.
154 i
= vsprintf (printbuffer
, fmt
, args
);
157 /* Send to desired file */
158 fputs (file
, printbuffer
);
161 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
165 #ifdef CONFIG_DISABLE_CONSOLE
166 if (gd
->flags
& GD_FLG_DISABLE_CONSOLE
)
170 if (gd
->flags
& GD_FLG_DEVINIT
) {
171 /* Get from the standard input */
172 return fgetc (stdin
);
175 /* Send directly to the handler */
176 return serial_getc ();
181 #ifdef CONFIG_DISABLE_CONSOLE
182 if (gd
->flags
& GD_FLG_DISABLE_CONSOLE
)
186 if (gd
->flags
& GD_FLG_DEVINIT
) {
187 /* Test the standard input */
188 return ftstc (stdin
);
191 /* Send directly to the handler */
192 return serial_tstc ();
195 void putc (const char c
)
197 #ifdef CONFIG_SILENT_CONSOLE
198 if (gd
->flags
& GD_FLG_SILENT
)
202 #ifdef CONFIG_DISABLE_CONSOLE
203 if (gd
->flags
& GD_FLG_DISABLE_CONSOLE
)
207 if (gd
->flags
& GD_FLG_DEVINIT
) {
208 /* Send to the standard output */
211 /* Send directly to the handler */
216 void puts (const char *s
)
218 #ifdef CONFIG_SILENT_CONSOLE
219 if (gd
->flags
& GD_FLG_SILENT
)
223 #ifdef CONFIG_DISABLE_CONSOLE
224 if (gd
->flags
& GD_FLG_DISABLE_CONSOLE
)
228 if (gd
->flags
& GD_FLG_DEVINIT
) {
229 /* Send to the standard output */
232 /* Send directly to the handler */
237 void printf (const char *fmt
, ...)
241 char printbuffer
[CONFIG_SYS_PBSIZE
];
243 va_start (args
, fmt
);
245 /* For this to work, printbuffer must be larger than
246 * anything we ever want to print.
248 i
= vsprintf (printbuffer
, fmt
, args
);
251 /* Print the string */
255 void vprintf (const char *fmt
, va_list args
)
258 char printbuffer
[CONFIG_SYS_PBSIZE
];
260 /* For this to work, printbuffer must be larger than
261 * anything we ever want to print.
263 i
= vsprintf (printbuffer
, fmt
, args
);
265 /* Print the string */
269 /* test if ctrl-c was pressed */
270 static int ctrlc_disabled
= 0; /* see disable_ctrl() */
271 static int ctrlc_was_pressed
= 0;
274 if (!ctrlc_disabled
&& gd
->have_console
) {
277 case 0x03: /* ^C - Control C */
278 ctrlc_was_pressed
= 1;
288 /* pass 1 to disable ctrlc() checking, 0 to enable.
289 * returns previous state
291 int disable_ctrlc (int disable
)
293 int prev
= ctrlc_disabled
; /* save previous state */
295 ctrlc_disabled
= disable
;
301 return ctrlc_was_pressed
;
304 void clear_ctrlc (void)
306 ctrlc_was_pressed
= 0;
309 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
311 char *cursor
= screen
;
313 inline void dbg(const char *fmt
, ...)
317 char printbuffer
[CONFIG_SYS_PBSIZE
];
320 memset(screen
, 0, sizeof(screen
));
326 /* For this to work, printbuffer must be larger than
327 * anything we ever want to print.
329 i
= vsprintf(printbuffer
, fmt
, args
);
332 if ((screen
+ sizeof(screen
) - 1 - cursor
) < strlen(printbuffer
)+1) {
333 memset(screen
, 0, sizeof(screen
));
336 sprintf(cursor
, printbuffer
);
337 cursor
+= strlen(printbuffer
);
341 inline void dbg(const char *fmt
, ...)
346 /** U-Boot INIT FUNCTIONS *************************************************/
348 device_t
*search_device (int flags
, char *name
)
352 dev
= device_get_by_name(name
);
354 if(dev
&& (dev
->flags
& flags
))
360 int console_assign (int file
, char *devname
)
365 /* Check for valid file */
368 flag
= DEV_FLAGS_INPUT
;
372 flag
= DEV_FLAGS_OUTPUT
;
378 /* Check for valid device name */
380 dev
= search_device(flag
, devname
);
383 return console_setfile (file
, dev
);
388 /* Called before relocation - use serial functions */
389 int console_init_f (void)
391 gd
->have_console
= 1;
393 #ifdef CONFIG_SILENT_CONSOLE
394 if (getenv("silent") != NULL
)
395 gd
->flags
|= GD_FLG_SILENT
;
401 #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
402 /* Called after the relocation - use desired console functions */
403 int console_init_r (void)
405 char *stdinname
, *stdoutname
, *stderrname
;
406 device_t
*inputdev
= NULL
, *outputdev
= NULL
, *errdev
= NULL
;
407 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
409 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
411 /* set default handlers at first */
412 gd
->jt
[XF_getc
] = serial_getc
;
413 gd
->jt
[XF_tstc
] = serial_tstc
;
414 gd
->jt
[XF_putc
] = serial_putc
;
415 gd
->jt
[XF_puts
] = serial_puts
;
416 gd
->jt
[XF_printf
] = serial_printf
;
418 /* stdin stdout and stderr are in environment */
420 stdinname
= getenv ("stdin");
421 stdoutname
= getenv ("stdout");
422 stderrname
= getenv ("stderr");
424 if (OVERWRITE_CONSOLE
== 0) { /* if not overwritten by config switch */
425 inputdev
= search_device (DEV_FLAGS_INPUT
, stdinname
);
426 outputdev
= search_device (DEV_FLAGS_OUTPUT
, stdoutname
);
427 errdev
= search_device (DEV_FLAGS_OUTPUT
, stderrname
);
429 /* if the devices are overwritten or not found, use default device */
430 if (inputdev
== NULL
) {
431 inputdev
= search_device (DEV_FLAGS_INPUT
, "serial");
433 if (outputdev
== NULL
) {
434 outputdev
= search_device (DEV_FLAGS_OUTPUT
, "serial");
436 if (errdev
== NULL
) {
437 errdev
= search_device (DEV_FLAGS_OUTPUT
, "serial");
439 /* Initializes output console first */
440 if (outputdev
!= NULL
) {
441 console_setfile (stdout
, outputdev
);
443 if (errdev
!= NULL
) {
444 console_setfile (stderr
, errdev
);
446 if (inputdev
!= NULL
) {
447 console_setfile (stdin
, inputdev
);
450 gd
->flags
|= GD_FLG_DEVINIT
; /* device initialization completed */
452 #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
453 /* Print information */
455 if (stdio_devices
[stdin
] == NULL
) {
456 puts ("No input devices available!\n");
458 printf ("%s\n", stdio_devices
[stdin
]->name
);
462 if (stdio_devices
[stdout
] == NULL
) {
463 puts ("No output devices available!\n");
465 printf ("%s\n", stdio_devices
[stdout
]->name
);
469 if (stdio_devices
[stderr
] == NULL
) {
470 puts ("No error devices available!\n");
472 printf ("%s\n", stdio_devices
[stderr
]->name
);
474 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
476 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
477 /* set the environment variables (will overwrite previous env settings) */
478 for (i
= 0; i
< 3; i
++) {
479 setenv (stdio_names
[i
], stdio_devices
[i
]->name
);
481 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
484 /* If nothing usable installed, use only the initial console */
485 if ((stdio_devices
[stdin
] == NULL
) && (stdio_devices
[stdout
] == NULL
))
491 #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
493 /* Called after the relocation - use desired console functions */
494 int console_init_r (void)
496 device_t
*inputdev
= NULL
, *outputdev
= NULL
;
498 struct list_head
*list
= device_get_list();
499 struct list_head
*pos
;
502 #ifdef CONFIG_SPLASH_SCREEN
503 /* suppress all output if splash screen is enabled and we have
505 if (getenv("splashimage") != NULL
)
506 gd
->flags
|= GD_FLG_SILENT
;
509 /* Scan devices looking for input and output devices */
510 list_for_each(pos
, list
) {
511 dev
= list_entry(pos
, device_t
, list
);
513 if ((dev
->flags
& DEV_FLAGS_INPUT
) && (inputdev
== NULL
)) {
516 if ((dev
->flags
& DEV_FLAGS_OUTPUT
) && (outputdev
== NULL
)) {
519 if(inputdev
&& outputdev
)
523 /* Initializes output console first */
524 if (outputdev
!= NULL
) {
525 console_setfile (stdout
, outputdev
);
526 console_setfile (stderr
, outputdev
);
529 /* Initializes input console */
530 if (inputdev
!= NULL
) {
531 console_setfile (stdin
, inputdev
);
534 gd
->flags
|= GD_FLG_DEVINIT
; /* device initialization completed */
536 #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
537 /* Print information */
539 if (stdio_devices
[stdin
] == NULL
) {
540 puts ("No input devices available!\n");
542 printf ("%s\n", stdio_devices
[stdin
]->name
);
546 if (stdio_devices
[stdout
] == NULL
) {
547 puts ("No output devices available!\n");
549 printf ("%s\n", stdio_devices
[stdout
]->name
);
553 if (stdio_devices
[stderr
] == NULL
) {
554 puts ("No error devices available!\n");
556 printf ("%s\n", stdio_devices
[stderr
]->name
);
558 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
560 /* Setting environment variables */
561 for (i
= 0; i
< 3; i
++) {
562 setenv (stdio_names
[i
], stdio_devices
[i
]->name
);
566 /* If nothing usable installed, use only the initial console */
567 if ((stdio_devices
[stdin
] == NULL
) && (stdio_devices
[stdout
] == NULL
))
574 #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */