X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fconsole.c;h=6f0846f5ee5db302b7cd486caaea9528cf0cc57d;hb=29a4c24de99d8cb4ac32991c04cab87ed94ca1f9;hp=86ed5842115177a696340d6b32e907c64cac0e85;hpb=d791b1dc3e64a6a6317293245d884589bc5c6277;p=u-boot diff --git a/common/console.c b/common/console.c index 86ed584211..6f0846f5ee 100644 --- a/common/console.c +++ b/common/console.c @@ -25,30 +25,28 @@ #include #include #include -#include +#include -void **syscall_tbl; +DECLARE_GLOBAL_DATA_PTR; #ifdef CONFIG_AMIGAONEG3SE int console_changed = 0; #endif -#ifdef CFG_CONSOLE_IS_IN_ENV +#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV /* * if overwrite_console returns 1, the stdin, stderr and stdout * are switched to the serial port, else the settings in the * environment are used */ -#ifdef CFG_CONSOLE_OVERWRITE_ROUTINE +#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE extern int overwrite_console (void); +#define OVERWRITE_CONSOLE overwrite_console () #else -int overwrite_console (void) -{ - return (0); -} -#endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */ +#define OVERWRITE_CONSOLE 0 +#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ -#endif /* CFG_CONSOLE_IS_IN_ENV */ +#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ static int console_setfile (int file, device_t * dev) { @@ -78,13 +76,13 @@ static int console_setfile (int file, device_t * dev) */ switch (file) { case stdin: - syscall_tbl[SYSCALL_GETC] = dev->getc; - syscall_tbl[SYSCALL_TSTC] = dev->tstc; + gd->jt[XF_getc] = dev->getc; + gd->jt[XF_tstc] = dev->tstc; break; case stdout: - syscall_tbl[SYSCALL_PUTC] = dev->putc; - syscall_tbl[SYSCALL_PUTS] = dev->puts; - syscall_tbl[SYSCALL_PRINTF] = printf; + gd->jt[XF_putc] = dev->putc; + gd->jt[XF_puts] = dev->puts; + gd->jt[XF_printf] = printf; break; } break; @@ -101,7 +99,7 @@ void serial_printf (const char *fmt, ...) { va_list args; uint i; - char printbuffer[CFG_PBSIZE]; + char printbuffer[CONFIG_SYS_PBSIZE]; va_start (args, fmt); @@ -146,7 +144,7 @@ void fprintf (int file, const char *fmt, ...) { va_list args; uint i; - char printbuffer[CFG_PBSIZE]; + char printbuffer[CONFIG_SYS_PBSIZE]; va_start (args, fmt); @@ -164,7 +162,10 @@ void fprintf (int file, const char *fmt, ...) int getc (void) { - DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_DISABLE_CONSOLE + if (gd->flags & GD_FLG_DISABLE_CONSOLE) + return 0; +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ @@ -177,7 +178,10 @@ int getc (void) int tstc (void) { - DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_DISABLE_CONSOLE + if (gd->flags & GD_FLG_DISABLE_CONSOLE) + return 0; +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ @@ -190,7 +194,15 @@ int tstc (void) void putc (const char c) { - DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_SILENT_CONSOLE + if (gd->flags & GD_FLG_SILENT) + return; +#endif + +#ifdef CONFIG_DISABLE_CONSOLE + if (gd->flags & GD_FLG_DISABLE_CONSOLE) + return; +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ @@ -203,7 +215,15 @@ void putc (const char c) void puts (const char *s) { - DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_SILENT_CONSOLE + if (gd->flags & GD_FLG_SILENT) + return; +#endif + +#ifdef CONFIG_DISABLE_CONSOLE + if (gd->flags & GD_FLG_DISABLE_CONSOLE) + return; +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ @@ -218,7 +238,7 @@ void printf (const char *fmt, ...) { va_list args; uint i; - char printbuffer[CFG_PBSIZE]; + char printbuffer[CONFIG_SYS_PBSIZE]; va_start (args, fmt); @@ -232,13 +252,25 @@ void printf (const char *fmt, ...) puts (printbuffer); } +void vprintf (const char *fmt, va_list args) +{ + uint i; + char printbuffer[CONFIG_SYS_PBSIZE]; + + /* For this to work, printbuffer must be larger than + * anything we ever want to print. + */ + i = vsprintf (printbuffer, fmt, args); + + /* Print the string */ + puts (printbuffer); +} + /* test if ctrl-c was pressed */ static int ctrlc_disabled = 0; /* see disable_ctrl() */ static int ctrlc_was_pressed = 0; int ctrlc (void) { - DECLARE_GLOBAL_DATA_PTR; - if (!ctrlc_disabled && gd->have_console) { if (tstc ()) { switch (getc ()) { @@ -282,7 +314,7 @@ inline void dbg(const char *fmt, ...) { va_list args; uint i; - char printbuffer[CFG_PBSIZE]; + char printbuffer[CONFIG_SYS_PBSIZE]; if (!once) { memset(screen, 0, sizeof(screen)); @@ -313,9 +345,22 @@ inline void dbg(const char *fmt, ...) /** U-Boot INIT FUNCTIONS *************************************************/ +device_t *search_device (int flags, char *name) +{ + device_t *dev; + + dev = device_get_by_name(name); + + if(dev && (dev->flags & flags)) + return dev; + + return NULL; +} + int console_assign (int file, char *devname) { - int flag, i; + int flag; + device_t *dev; /* Check for valid file */ switch (file) { @@ -332,16 +377,10 @@ int console_assign (int file, char *devname) /* Check for valid device name */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); + dev = search_device(flag, devname); - if (strcmp (devname, dev->name) == 0) { - if (dev->flags & flag) - return console_setfile (file, dev); - - return -1; - } - } + if(dev) + return console_setfile (file, dev); return -1; } @@ -349,46 +388,32 @@ int console_assign (int file, char *devname) /* Called before relocation - use serial functions */ int console_init_f (void) { - DECLARE_GLOBAL_DATA_PTR; - gd->have_console = 1; - return (0); -} -#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) -/* search a device */ -device_t *search_device (int flags, char *name) -{ - int i, items; - device_t *dev = NULL; - - items = ListNumItems (devlist); - if (name == NULL) - return dev; +#ifdef CONFIG_SILENT_CONSOLE + if (getenv("silent") != NULL) + gd->flags |= GD_FLG_SILENT; +#endif - for (i = 1; i <= items; i++) { - dev = ListGetPtrToItem (devlist, i); - if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { - break; - } - } - return dev; + return (0); } -#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ -#ifdef CFG_CONSOLE_IS_IN_ENV +#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV /* Called after the relocation - use desired console functions */ int console_init_r (void) { char *stdinname, *stdoutname, *stderrname; device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL; +#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE + int i; +#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ /* set default handlers at first */ - syscall_tbl[SYSCALL_GETC] = serial_getc; - syscall_tbl[SYSCALL_TSTC] = serial_tstc; - syscall_tbl[SYSCALL_PUTC] = serial_putc; - syscall_tbl[SYSCALL_PUTS] = serial_puts; - syscall_tbl[SYSCALL_PRINTF] = serial_printf; + gd->jt[XF_getc] = serial_getc; + gd->jt[XF_tstc] = serial_tstc; + gd->jt[XF_putc] = serial_putc; + gd->jt[XF_puts] = serial_puts; + gd->jt[XF_printf] = serial_printf; /* stdin stdout and stderr are in environment */ /* scan for it */ @@ -396,7 +421,7 @@ int console_init_r (void) stdoutname = getenv ("stdout"); stderrname = getenv ("stderr"); - if (overwrite_console () == 0) { /* if not overwritten by config switch */ + if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ inputdev = search_device (DEV_FLAGS_INPUT, stdinname); outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname); errdev = search_device (DEV_FLAGS_OUTPUT, stderrname); @@ -422,36 +447,38 @@ int console_init_r (void) console_setfile (stdin, inputdev); } -#ifndef CFG_CONSOLE_INFO_QUIET + gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ + +#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET /* Print information */ - printf ("In: "); + puts ("In: "); if (stdio_devices[stdin] == NULL) { - printf ("No input devices available!\n"); + puts ("No input devices available!\n"); } else { printf ("%s\n", stdio_devices[stdin]->name); } - printf ("Out: "); + puts ("Out: "); if (stdio_devices[stdout] == NULL) { - printf ("No output devices available!\n"); + puts ("No output devices available!\n"); } else { printf ("%s\n", stdio_devices[stdout]->name); } - printf ("Err: "); + puts ("Err: "); if (stdio_devices[stderr] == NULL) { - printf ("No error devices available!\n"); + puts ("No error devices available!\n"); } else { printf ("%s\n", stdio_devices[stderr]->name); } -#endif /* CFG_CONSOLE_INFO_QUIET */ +#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ -#ifdef CFG_CONSOLE_ENV_OVERWRITE +#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE /* set the environment variables (will overwrite previous env settings) */ for (i = 0; i < 3; i++) { setenv (stdio_names[i], stdio_devices[i]->name); } -#endif /* CFG_CONSOLE_ENV_OVERWRITE */ +#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ #if 0 /* If nothing usable installed, use only the initial console */ @@ -461,25 +488,27 @@ int console_init_r (void) return (0); } -#else /* CFG_CONSOLE_IS_IN_ENV */ +#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ /* Called after the relocation - use desired console functions */ int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; - int i, items = ListNumItems (devlist); + int i; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev; #ifdef CONFIG_SPLASH_SCREEN - /* suppress all output if splash screen is enabled */ - outputdev = search_device (DEV_FLAGS_OUTPUT, "nulldev"); + /* suppress all output if splash screen is enabled and we have + a bmp to display */ + if (getenv("splashimage") != NULL) + gd->flags |= GD_FLG_SILENT; #endif /* Scan devices looking for input and output devices */ - for (i = 1; - (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); - i++ - ) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list); if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; @@ -487,6 +516,8 @@ int console_init_r (void) if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } + if(inputdev && outputdev) + break; } /* Initializes output console first */ @@ -500,29 +531,31 @@ int console_init_r (void) console_setfile (stdin, inputdev); } -#ifndef CFG_CONSOLE_INFO_QUIET + gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ + +#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET /* Print information */ - printf ("In: "); + puts ("In: "); if (stdio_devices[stdin] == NULL) { - printf ("No input devices available!\n"); + puts ("No input devices available!\n"); } else { printf ("%s\n", stdio_devices[stdin]->name); } - printf ("Out: "); + puts ("Out: "); if (stdio_devices[stdout] == NULL) { - printf ("No output devices available!\n"); + puts ("No output devices available!\n"); } else { printf ("%s\n", stdio_devices[stdout]->name); } - printf ("Err: "); + puts ("Err: "); if (stdio_devices[stderr] == NULL) { - printf ("No error devices available!\n"); + puts ("No error devices available!\n"); } else { printf ("%s\n", stdio_devices[stderr]->name); } -#endif /* CFG_CONSOLE_INFO_QUIET */ +#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ /* Setting environment variables */ for (i = 0; i < 3; i++) { @@ -538,4 +571,4 @@ int console_init_r (void) return (0); } -#endif /* CFG_CONSOLE_IS_IN_ENV */ +#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */