wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <stdarg.h> |
| 26 | #include <malloc.h> |
| 27 | #include <console.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 28 | #include <exports.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 29 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_AMIGAONEG3SE |
| 33 | int console_changed = 0; |
| 34 | #endif |
| 35 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 37 | /* |
| 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 |
| 41 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 43 | extern int overwrite_console(void); |
| 44 | #define OVERWRITE_CONSOLE overwrite_console() |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 45 | #else |
wdenk | 83e40ba | 2005-03-31 18:42:15 +0000 | [diff] [blame] | 46 | #define OVERWRITE_CONSOLE 0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 48 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 50 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 51 | static int console_setfile(int file, device_t * dev) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 52 | { |
| 53 | int error = 0; |
| 54 | |
| 55 | if (dev == NULL) |
| 56 | return -1; |
| 57 | |
| 58 | switch (file) { |
| 59 | case stdin: |
| 60 | case stdout: |
| 61 | case stderr: |
| 62 | /* Start new device */ |
| 63 | if (dev->start) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 64 | error = dev->start(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 65 | /* If it's not started dont use it */ |
| 66 | if (error < 0) |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | /* Assign the new device (leaving the existing one started) */ |
| 71 | stdio_devices[file] = dev; |
| 72 | |
| 73 | /* |
| 74 | * Update monitor functions |
| 75 | * (to use the console stuff by other applications) |
| 76 | */ |
| 77 | switch (file) { |
| 78 | case stdin: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 79 | gd->jt[XF_getc] = dev->getc; |
| 80 | gd->jt[XF_tstc] = dev->tstc; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 81 | break; |
| 82 | case stdout: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 83 | gd->jt[XF_putc] = dev->putc; |
| 84 | gd->jt[XF_puts] = dev->puts; |
| 85 | gd->jt[XF_printf] = printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 86 | break; |
| 87 | } |
| 88 | break; |
| 89 | |
| 90 | default: /* Invalid file ID */ |
| 91 | error = -1; |
| 92 | } |
| 93 | return error; |
| 94 | } |
| 95 | |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 96 | #if defined(CONFIG_CONSOLE_MUX) |
| 97 | /** Console I/O multiplexing *******************************************/ |
| 98 | |
| 99 | static device_t *tstcdev; |
| 100 | device_t **console_devices[MAX_FILES]; |
| 101 | int cd_count[MAX_FILES]; |
| 102 | |
| 103 | /* |
| 104 | * This depends on tstc() always being called before getc(). |
| 105 | * This is guaranteed to be true because this routine is called |
| 106 | * only from fgetc() which assures it. |
| 107 | * No attempt is made to demultiplex multiple input sources. |
| 108 | */ |
| 109 | static int iomux_getc(void) |
| 110 | { |
| 111 | unsigned char ret; |
| 112 | |
| 113 | /* This is never called with testcdev == NULL */ |
| 114 | ret = tstcdev->getc(); |
| 115 | tstcdev = NULL; |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | static int iomux_tstc(int file) |
| 120 | { |
| 121 | int i, ret; |
| 122 | device_t *dev; |
| 123 | |
| 124 | disable_ctrlc(1); |
| 125 | for (i = 0; i < cd_count[file]; i++) { |
| 126 | dev = console_devices[file][i]; |
| 127 | if (dev->tstc != NULL) { |
| 128 | ret = dev->tstc(); |
| 129 | if (ret > 0) { |
| 130 | tstcdev = dev; |
| 131 | disable_ctrlc(0); |
| 132 | return ret; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | disable_ctrlc(0); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static void iomux_putc(int file, const char c) |
| 142 | { |
| 143 | int i; |
| 144 | device_t *dev; |
| 145 | |
| 146 | for (i = 0; i < cd_count[file]; i++) { |
| 147 | dev = console_devices[file][i]; |
| 148 | if (dev->putc != NULL) |
| 149 | dev->putc(c); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | static void iomux_puts(int file, const char *s) |
| 154 | { |
| 155 | int i; |
| 156 | device_t *dev; |
| 157 | |
| 158 | for (i = 0; i < cd_count[file]; i++) { |
| 159 | dev = console_devices[file][i]; |
| 160 | if (dev->puts != NULL) |
| 161 | dev->puts(s); |
| 162 | } |
| 163 | } |
| 164 | #endif /* defined(CONFIG_CONSOLE_MUX) */ |
| 165 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 166 | /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
| 167 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 168 | void serial_printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 169 | { |
| 170 | va_list args; |
| 171 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 173 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 174 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 175 | |
| 176 | /* For this to work, printbuffer must be larger than |
| 177 | * anything we ever want to print. |
| 178 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 179 | i = vsprintf(printbuffer, fmt, args); |
| 180 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 181 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 182 | serial_puts(printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 185 | int fgetc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 186 | { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 187 | if (file < MAX_FILES) { |
| 188 | #if defined(CONFIG_CONSOLE_MUX) |
| 189 | /* |
| 190 | * Effectively poll for input wherever it may be available. |
| 191 | */ |
| 192 | for (;;) { |
| 193 | /* |
| 194 | * Upper layer may have already called tstc() so |
| 195 | * check for that first. |
| 196 | */ |
| 197 | if (tstcdev != NULL) |
| 198 | return iomux_getc(); |
| 199 | iomux_tstc(file); |
| 200 | #ifdef CONFIG_WATCHDOG |
| 201 | /* |
| 202 | * If the watchdog must be rate-limited then it should |
| 203 | * already be handled in board-specific code. |
| 204 | */ |
| 205 | udelay(1); |
| 206 | #endif |
| 207 | } |
| 208 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 209 | return stdio_devices[file]->getc(); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 210 | #endif |
| 211 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 212 | |
| 213 | return -1; |
| 214 | } |
| 215 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 216 | int ftstc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 217 | { |
| 218 | if (file < MAX_FILES) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 219 | #if defined(CONFIG_CONSOLE_MUX) |
| 220 | return iomux_tstc(file); |
| 221 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 222 | return stdio_devices[file]->tstc(); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 223 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 224 | |
| 225 | return -1; |
| 226 | } |
| 227 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 228 | void fputc(int file, const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 229 | { |
| 230 | if (file < MAX_FILES) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 231 | #if defined(CONFIG_CONSOLE_MUX) |
| 232 | iomux_putc(file, c); |
| 233 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 234 | stdio_devices[file]->putc(c); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 235 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 238 | void fputs(int file, const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 239 | { |
| 240 | if (file < MAX_FILES) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 241 | #if defined(CONFIG_CONSOLE_MUX) |
| 242 | iomux_puts(file, s); |
| 243 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 244 | stdio_devices[file]->puts(s); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 245 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 248 | void fprintf(int file, const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 249 | { |
| 250 | va_list args; |
| 251 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 252 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 253 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 254 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 255 | |
| 256 | /* For this to work, printbuffer must be larger than |
| 257 | * anything we ever want to print. |
| 258 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 259 | i = vsprintf(printbuffer, fmt, args); |
| 260 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 261 | |
| 262 | /* Send to desired file */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 263 | fputs(file, printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
| 267 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 268 | int getc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 269 | { |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 270 | #ifdef CONFIG_DISABLE_CONSOLE |
| 271 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 272 | return 0; |
| 273 | #endif |
| 274 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 275 | if (gd->flags & GD_FLG_DEVINIT) { |
| 276 | /* Get from the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 277 | return fgetc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 281 | return serial_getc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 284 | int tstc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 285 | { |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 286 | #ifdef CONFIG_DISABLE_CONSOLE |
| 287 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 288 | return 0; |
| 289 | #endif |
| 290 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 291 | if (gd->flags & GD_FLG_DEVINIT) { |
| 292 | /* Test the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 293 | return ftstc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 297 | return serial_tstc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 300 | void putc(const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 301 | { |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 302 | #ifdef CONFIG_SILENT_CONSOLE |
| 303 | if (gd->flags & GD_FLG_SILENT) |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 304 | return; |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 305 | #endif |
| 306 | |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 307 | #ifdef CONFIG_DISABLE_CONSOLE |
| 308 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 309 | return; |
| 310 | #endif |
| 311 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 312 | if (gd->flags & GD_FLG_DEVINIT) { |
| 313 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 314 | fputc(stdout, c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 315 | } else { |
| 316 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 317 | serial_putc(c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 321 | void puts(const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 322 | { |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 323 | #ifdef CONFIG_SILENT_CONSOLE |
| 324 | if (gd->flags & GD_FLG_SILENT) |
| 325 | return; |
| 326 | #endif |
| 327 | |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 328 | #ifdef CONFIG_DISABLE_CONSOLE |
| 329 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 330 | return; |
| 331 | #endif |
| 332 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 333 | if (gd->flags & GD_FLG_DEVINIT) { |
| 334 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 335 | fputs(stdout, s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 336 | } else { |
| 337 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 338 | serial_puts(s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 342 | void printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 343 | { |
| 344 | va_list args; |
| 345 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 346 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 347 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 348 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 349 | |
| 350 | /* For this to work, printbuffer must be larger than |
| 351 | * anything we ever want to print. |
| 352 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 353 | i = vsprintf(printbuffer, fmt, args); |
| 354 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 355 | |
| 356 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 357 | puts(printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 360 | void vprintf(const char *fmt, va_list args) |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 361 | { |
| 362 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 363 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 364 | |
| 365 | /* For this to work, printbuffer must be larger than |
| 366 | * anything we ever want to print. |
| 367 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 368 | i = vsprintf(printbuffer, fmt, args); |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 369 | |
| 370 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 371 | puts(printbuffer); |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 372 | } |
| 373 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 374 | /* test if ctrl-c was pressed */ |
| 375 | static int ctrlc_disabled = 0; /* see disable_ctrl() */ |
| 376 | static int ctrlc_was_pressed = 0; |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 377 | int ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 378 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 379 | if (!ctrlc_disabled && gd->have_console) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 380 | if (tstc()) { |
| 381 | switch (getc()) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 382 | case 0x03: /* ^C - Control C */ |
| 383 | ctrlc_was_pressed = 1; |
| 384 | return 1; |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /* pass 1 to disable ctrlc() checking, 0 to enable. |
| 394 | * returns previous state |
| 395 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 396 | int disable_ctrlc(int disable) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 397 | { |
| 398 | int prev = ctrlc_disabled; /* save previous state */ |
| 399 | |
| 400 | ctrlc_disabled = disable; |
| 401 | return prev; |
| 402 | } |
| 403 | |
| 404 | int had_ctrlc (void) |
| 405 | { |
| 406 | return ctrlc_was_pressed; |
| 407 | } |
| 408 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 409 | void clear_ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 410 | { |
| 411 | ctrlc_was_pressed = 0; |
| 412 | } |
| 413 | |
| 414 | #ifdef CONFIG_MODEM_SUPPORT_DEBUG |
| 415 | char screen[1024]; |
| 416 | char *cursor = screen; |
| 417 | int once = 0; |
| 418 | inline void dbg(const char *fmt, ...) |
| 419 | { |
| 420 | va_list args; |
| 421 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 422 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 423 | |
| 424 | if (!once) { |
| 425 | memset(screen, 0, sizeof(screen)); |
| 426 | once++; |
| 427 | } |
| 428 | |
| 429 | va_start(args, fmt); |
| 430 | |
| 431 | /* For this to work, printbuffer must be larger than |
| 432 | * anything we ever want to print. |
| 433 | */ |
| 434 | i = vsprintf(printbuffer, fmt, args); |
| 435 | va_end(args); |
| 436 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 437 | if ((screen + sizeof(screen) - 1 - cursor) |
| 438 | < strlen(printbuffer) + 1) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 439 | memset(screen, 0, sizeof(screen)); |
| 440 | cursor = screen; |
| 441 | } |
| 442 | sprintf(cursor, printbuffer); |
| 443 | cursor += strlen(printbuffer); |
| 444 | |
| 445 | } |
| 446 | #else |
| 447 | inline void dbg(const char *fmt, ...) |
| 448 | { |
| 449 | } |
| 450 | #endif |
| 451 | |
| 452 | /** U-Boot INIT FUNCTIONS *************************************************/ |
| 453 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 454 | device_t *search_device(int flags, char *name) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 455 | { |
| 456 | device_t *dev; |
| 457 | |
| 458 | dev = device_get_by_name(name); |
| 459 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 460 | if (dev && (dev->flags & flags)) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 461 | return dev; |
| 462 | |
| 463 | return NULL; |
| 464 | } |
| 465 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 466 | int console_assign(int file, char *devname) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 467 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 468 | int flag; |
| 469 | device_t *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 470 | |
| 471 | /* Check for valid file */ |
| 472 | switch (file) { |
| 473 | case stdin: |
| 474 | flag = DEV_FLAGS_INPUT; |
| 475 | break; |
| 476 | case stdout: |
| 477 | case stderr: |
| 478 | flag = DEV_FLAGS_OUTPUT; |
| 479 | break; |
| 480 | default: |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | /* Check for valid device name */ |
| 485 | |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 486 | dev = search_device(flag, devname); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 487 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 488 | if (dev) |
| 489 | return console_setfile(file, dev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 490 | |
| 491 | return -1; |
| 492 | } |
| 493 | |
| 494 | /* Called before relocation - use serial functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 495 | int console_init_f(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 496 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 497 | gd->have_console = 1; |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 498 | |
| 499 | #ifdef CONFIG_SILENT_CONSOLE |
| 500 | if (getenv("silent") != NULL) |
| 501 | gd->flags |= GD_FLG_SILENT; |
| 502 | #endif |
| 503 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 504 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 507 | #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 508 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 509 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 510 | { |
| 511 | char *stdinname, *stdoutname, *stderrname; |
| 512 | device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 513 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 514 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 515 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 516 | #ifdef CONFIG_CONSOLE_MUX |
| 517 | int iomux_err = 0; |
| 518 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 519 | |
| 520 | /* set default handlers at first */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 521 | gd->jt[XF_getc] = serial_getc; |
| 522 | gd->jt[XF_tstc] = serial_tstc; |
| 523 | gd->jt[XF_putc] = serial_putc; |
| 524 | gd->jt[XF_puts] = serial_puts; |
| 525 | gd->jt[XF_printf] = serial_printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 526 | |
| 527 | /* stdin stdout and stderr are in environment */ |
| 528 | /* scan for it */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 529 | stdinname = getenv("stdin"); |
| 530 | stdoutname = getenv("stdout"); |
| 531 | stderrname = getenv("stderr"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 532 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 533 | if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 534 | inputdev = search_device(DEV_FLAGS_INPUT, stdinname); |
| 535 | outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); |
| 536 | errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 537 | #ifdef CONFIG_CONSOLE_MUX |
| 538 | iomux_err = iomux_doenv(stdin, stdinname); |
| 539 | iomux_err += iomux_doenv(stdout, stdoutname); |
| 540 | iomux_err += iomux_doenv(stderr, stderrname); |
| 541 | if (!iomux_err) |
| 542 | /* Successful, so skip all the code below. */ |
| 543 | goto done; |
| 544 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 545 | } |
| 546 | /* if the devices are overwritten or not found, use default device */ |
| 547 | if (inputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 548 | inputdev = search_device(DEV_FLAGS_INPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 549 | } |
| 550 | if (outputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 551 | outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 552 | } |
| 553 | if (errdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 554 | errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 555 | } |
| 556 | /* Initializes output console first */ |
| 557 | if (outputdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 558 | #ifdef CONFIG_CONSOLE_MUX |
| 559 | /* need to set a console if not done above. */ |
| 560 | iomux_doenv(stdout, outputdev->name); |
| 561 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 562 | console_setfile(stdout, outputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 563 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 564 | } |
| 565 | if (errdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 566 | #ifdef CONFIG_CONSOLE_MUX |
| 567 | /* need to set a console if not done above. */ |
| 568 | iomux_doenv(stderr, errdev->name); |
| 569 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 570 | console_setfile(stderr, errdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 571 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 572 | } |
| 573 | if (inputdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 574 | #ifdef CONFIG_CONSOLE_MUX |
| 575 | /* need to set a console if not done above. */ |
| 576 | iomux_doenv(stdin, inputdev->name); |
| 577 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 578 | console_setfile(stdin, inputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 579 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 582 | #ifdef CONFIG_CONSOLE_MUX |
| 583 | done: |
| 584 | #endif |
| 585 | |
wdenk | 5f535fe | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 586 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 587 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 588 | #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 589 | /* Print information */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 590 | puts("In: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 591 | if (stdio_devices[stdin] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 592 | puts("No input devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 593 | } else { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 594 | #ifdef CONFIG_CONSOLE_MUX |
| 595 | iomux_printdevs(stdin); |
| 596 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 597 | printf("%s\n", stdio_devices[stdin]->name); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 598 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 601 | puts("Out: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 602 | if (stdio_devices[stdout] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 603 | puts("No output devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 604 | } else { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 605 | #ifdef CONFIG_CONSOLE_MUX |
| 606 | iomux_printdevs(stdout); |
| 607 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 608 | printf("%s\n", stdio_devices[stdout]->name); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 609 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 612 | puts("Err: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 613 | if (stdio_devices[stderr] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 614 | puts("No error devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 615 | } else { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 616 | #ifdef CONFIG_CONSOLE_MUX |
| 617 | iomux_printdevs(stderr); |
| 618 | #else |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 619 | printf("%s\n", stdio_devices[stderr]->name); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 620 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 621 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 622 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 623 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 624 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 625 | /* set the environment variables (will overwrite previous env settings) */ |
| 626 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 627 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 628 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 629 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 630 | |
| 631 | #if 0 |
| 632 | /* If nothing usable installed, use only the initial console */ |
| 633 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 634 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 635 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 636 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 639 | #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 640 | |
| 641 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 642 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 643 | { |
| 644 | device_t *inputdev = NULL, *outputdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 645 | int i; |
| 646 | struct list_head *list = device_get_list(); |
| 647 | struct list_head *pos; |
| 648 | device_t *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 649 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 650 | #ifdef CONFIG_SPLASH_SCREEN |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 651 | /* |
| 652 | * suppress all output if splash screen is enabled and we have |
| 653 | * a bmp to display |
| 654 | */ |
dzu | 87970eb | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 655 | if (getenv("splashimage") != NULL) |
Ladislav Michl | 4ec5bd5 | 2007-04-25 16:01:26 +0200 | [diff] [blame] | 656 | gd->flags |= GD_FLG_SILENT; |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 657 | #endif |
| 658 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 659 | /* Scan devices looking for input and output devices */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 660 | list_for_each(pos, list) { |
| 661 | dev = list_entry(pos, device_t, list); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 662 | |
| 663 | if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { |
| 664 | inputdev = dev; |
| 665 | } |
| 666 | if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { |
| 667 | outputdev = dev; |
| 668 | } |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 669 | if(inputdev && outputdev) |
| 670 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* Initializes output console first */ |
| 674 | if (outputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 675 | console_setfile(stdout, outputdev); |
| 676 | console_setfile(stderr, outputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 677 | #ifdef CONFIG_CONSOLE_MUX |
| 678 | console_devices[stdout][0] = outputdev; |
| 679 | console_devices[stderr][0] = outputdev; |
| 680 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /* Initializes input console */ |
| 684 | if (inputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 685 | console_setfile(stdin, inputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 686 | #ifdef CONFIG_CONSOLE_MUX |
| 687 | console_devices[stdin][0] = inputdev; |
| 688 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 689 | } |
| 690 | |
wdenk | 5f535fe | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 691 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 692 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 693 | #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
wdenk | 47cd00f | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 694 | /* Print information */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 695 | puts("In: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 696 | if (stdio_devices[stdin] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 697 | puts("No input devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 698 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 699 | printf("%s\n", stdio_devices[stdin]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 702 | puts("Out: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 703 | if (stdio_devices[stdout] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 704 | puts("No output devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 705 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 706 | printf("%s\n", stdio_devices[stdout]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 709 | puts("Err: "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 710 | if (stdio_devices[stderr] == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 711 | puts("No error devices available!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 712 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 713 | printf("%s\n", stdio_devices[stderr]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 714 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 715 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 716 | |
| 717 | /* Setting environment variables */ |
| 718 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 719 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | #if 0 |
| 723 | /* If nothing usable installed, use only the initial console */ |
| 724 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 725 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 726 | #endif |
| 727 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame^] | 728 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 731 | #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |