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> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 27 | #include <stdio_dev.h> |
wdenk | 874ac26 | 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 | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | 452cfd6 | 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 | 0383694 | 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 | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 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 | 61c636e | 2005-03-31 18:42:15 +0000 | [diff] [blame] | 46 | #define OVERWRITE_CONSOLE 0 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 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 | 0383694 | 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 | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 51 | static int console_setfile(int file, struct stdio_dev * 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 | c7dc672 | 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 | 874ac26 | 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 | 874ac26 | 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 | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 96 | #if defined(CONFIG_CONSOLE_MUX) |
| 97 | /** Console I/O multiplexing *******************************************/ |
| 98 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 99 | static struct stdio_dev *tstcdev; |
| 100 | struct stdio_dev **console_devices[MAX_FILES]; |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 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 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 109 | static int console_getc(int file) |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 119 | static int console_tstc(int file) |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 120 | { |
| 121 | int i, ret; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 122 | struct stdio_dev *dev; |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 141 | static void console_putc(int file, const char c) |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 142 | { |
| 143 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 144 | struct stdio_dev *dev; |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 153 | static void console_puts(int file, const char *s) |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 154 | { |
| 155 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 156 | struct stdio_dev *dev; |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 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 | } |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 164 | |
| 165 | static inline void console_printdevs(int file) |
| 166 | { |
| 167 | iomux_printdevs(file); |
| 168 | } |
| 169 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 170 | static inline void console_doenv(int file, struct stdio_dev *dev) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 171 | { |
| 172 | iomux_doenv(file, dev->name); |
| 173 | } |
| 174 | #else |
| 175 | static inline int console_getc(int file) |
| 176 | { |
| 177 | return stdio_devices[file]->getc(); |
| 178 | } |
| 179 | |
| 180 | static inline int console_tstc(int file) |
| 181 | { |
| 182 | return stdio_devices[file]->tstc(); |
| 183 | } |
| 184 | |
| 185 | static inline void console_putc(int file, const char c) |
| 186 | { |
| 187 | stdio_devices[file]->putc(c); |
| 188 | } |
| 189 | |
| 190 | static inline void console_puts(int file, const char *s) |
| 191 | { |
| 192 | stdio_devices[file]->puts(s); |
| 193 | } |
| 194 | |
| 195 | static inline void console_printdevs(int file) |
| 196 | { |
| 197 | printf("%s\n", stdio_devices[file]->name); |
| 198 | } |
| 199 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 200 | static inline void console_doenv(int file, struct stdio_dev *dev) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 201 | { |
| 202 | console_setfile(file, dev); |
| 203 | } |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 204 | #endif /* defined(CONFIG_CONSOLE_MUX) */ |
| 205 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 206 | /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
| 207 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 208 | void serial_printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 209 | { |
| 210 | va_list args; |
| 211 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 213 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 214 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 215 | |
| 216 | /* For this to work, printbuffer must be larger than |
| 217 | * anything we ever want to print. |
| 218 | */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 219 | i = vsprintf(printbuffer, fmt, args); |
| 220 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 221 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 222 | serial_puts(printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 225 | int fgetc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 226 | { |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 227 | if (file < MAX_FILES) { |
| 228 | #if defined(CONFIG_CONSOLE_MUX) |
| 229 | /* |
| 230 | * Effectively poll for input wherever it may be available. |
| 231 | */ |
| 232 | for (;;) { |
| 233 | /* |
| 234 | * Upper layer may have already called tstc() so |
| 235 | * check for that first. |
| 236 | */ |
| 237 | if (tstcdev != NULL) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 238 | return console_getc(file); |
| 239 | console_tstc(file); |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 240 | #ifdef CONFIG_WATCHDOG |
| 241 | /* |
| 242 | * If the watchdog must be rate-limited then it should |
| 243 | * already be handled in board-specific code. |
| 244 | */ |
| 245 | udelay(1); |
| 246 | #endif |
| 247 | } |
| 248 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 249 | return console_getc(file); |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 250 | #endif |
| 251 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 252 | |
| 253 | return -1; |
| 254 | } |
| 255 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 256 | int ftstc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 257 | { |
| 258 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 259 | return console_tstc(file); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 260 | |
| 261 | return -1; |
| 262 | } |
| 263 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 264 | void fputc(int file, const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 265 | { |
| 266 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 267 | console_putc(file, c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 270 | void fputs(int file, const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 271 | { |
| 272 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 273 | console_puts(file, s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 276 | void fprintf(int file, const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 277 | { |
| 278 | va_list args; |
| 279 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 280 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 281 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 282 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 283 | |
| 284 | /* For this to work, printbuffer must be larger than |
| 285 | * anything we ever want to print. |
| 286 | */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 287 | i = vsprintf(printbuffer, fmt, args); |
| 288 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 289 | |
| 290 | /* Send to desired file */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 291 | fputs(file, printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
| 295 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 296 | int getc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 297 | { |
Mark Jackson | 5de5621 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 298 | #ifdef CONFIG_DISABLE_CONSOLE |
| 299 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 300 | return 0; |
| 301 | #endif |
| 302 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 303 | if (gd->flags & GD_FLG_DEVINIT) { |
| 304 | /* Get from the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 305 | return fgetc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 309 | return serial_getc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 312 | int tstc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 313 | { |
Mark Jackson | 5de5621 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 314 | #ifdef CONFIG_DISABLE_CONSOLE |
| 315 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 316 | return 0; |
| 317 | #endif |
| 318 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 319 | if (gd->flags & GD_FLG_DEVINIT) { |
| 320 | /* Test the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 321 | return ftstc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 325 | return serial_tstc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 328 | void putc(const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 329 | { |
wdenk | 4b6e905 | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 330 | #ifdef CONFIG_SILENT_CONSOLE |
| 331 | if (gd->flags & GD_FLG_SILENT) |
wdenk | 927034e | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 332 | return; |
wdenk | 4b6e905 | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 333 | #endif |
| 334 | |
Mark Jackson | 5de5621 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 335 | #ifdef CONFIG_DISABLE_CONSOLE |
| 336 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 337 | return; |
| 338 | #endif |
| 339 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 340 | if (gd->flags & GD_FLG_DEVINIT) { |
| 341 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 342 | fputc(stdout, c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 343 | } else { |
| 344 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 345 | serial_putc(c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 349 | void puts(const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 350 | { |
wdenk | 4b6e905 | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 351 | #ifdef CONFIG_SILENT_CONSOLE |
| 352 | if (gd->flags & GD_FLG_SILENT) |
| 353 | return; |
| 354 | #endif |
| 355 | |
Mark Jackson | 5de5621 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 356 | #ifdef CONFIG_DISABLE_CONSOLE |
| 357 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 358 | return; |
| 359 | #endif |
| 360 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 361 | if (gd->flags & GD_FLG_DEVINIT) { |
| 362 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 363 | fputs(stdout, s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 364 | } else { |
| 365 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 366 | serial_puts(s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 370 | void printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 371 | { |
| 372 | va_list args; |
| 373 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 374 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 375 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 376 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 377 | |
| 378 | /* For this to work, printbuffer must be larger than |
| 379 | * anything we ever want to print. |
| 380 | */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 381 | i = vsprintf(printbuffer, fmt, args); |
| 382 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 383 | |
| 384 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 385 | puts(printbuffer); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 388 | void vprintf(const char *fmt, va_list args) |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 389 | { |
| 390 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 391 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 392 | |
| 393 | /* For this to work, printbuffer must be larger than |
| 394 | * anything we ever want to print. |
| 395 | */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 396 | i = vsprintf(printbuffer, fmt, args); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 397 | |
| 398 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 399 | puts(printbuffer); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 400 | } |
| 401 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 402 | /* test if ctrl-c was pressed */ |
| 403 | static int ctrlc_disabled = 0; /* see disable_ctrl() */ |
| 404 | static int ctrlc_was_pressed = 0; |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 405 | int ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 406 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 407 | if (!ctrlc_disabled && gd->have_console) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 408 | if (tstc()) { |
| 409 | switch (getc()) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 410 | case 0x03: /* ^C - Control C */ |
| 411 | ctrlc_was_pressed = 1; |
| 412 | return 1; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | /* pass 1 to disable ctrlc() checking, 0 to enable. |
| 422 | * returns previous state |
| 423 | */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 424 | int disable_ctrlc(int disable) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 425 | { |
| 426 | int prev = ctrlc_disabled; /* save previous state */ |
| 427 | |
| 428 | ctrlc_disabled = disable; |
| 429 | return prev; |
| 430 | } |
| 431 | |
| 432 | int had_ctrlc (void) |
| 433 | { |
| 434 | return ctrlc_was_pressed; |
| 435 | } |
| 436 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 437 | void clear_ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 438 | { |
| 439 | ctrlc_was_pressed = 0; |
| 440 | } |
| 441 | |
| 442 | #ifdef CONFIG_MODEM_SUPPORT_DEBUG |
| 443 | char screen[1024]; |
| 444 | char *cursor = screen; |
| 445 | int once = 0; |
| 446 | inline void dbg(const char *fmt, ...) |
| 447 | { |
| 448 | va_list args; |
| 449 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 450 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 451 | |
| 452 | if (!once) { |
| 453 | memset(screen, 0, sizeof(screen)); |
| 454 | once++; |
| 455 | } |
| 456 | |
| 457 | va_start(args, fmt); |
| 458 | |
| 459 | /* For this to work, printbuffer must be larger than |
| 460 | * anything we ever want to print. |
| 461 | */ |
| 462 | i = vsprintf(printbuffer, fmt, args); |
| 463 | va_end(args); |
| 464 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 465 | if ((screen + sizeof(screen) - 1 - cursor) |
| 466 | < strlen(printbuffer) + 1) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 467 | memset(screen, 0, sizeof(screen)); |
| 468 | cursor = screen; |
| 469 | } |
| 470 | sprintf(cursor, printbuffer); |
| 471 | cursor += strlen(printbuffer); |
| 472 | |
| 473 | } |
| 474 | #else |
| 475 | inline void dbg(const char *fmt, ...) |
| 476 | { |
| 477 | } |
| 478 | #endif |
| 479 | |
| 480 | /** U-Boot INIT FUNCTIONS *************************************************/ |
| 481 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 482 | struct stdio_dev *search_device(int flags, char *name) |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 483 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 484 | struct stdio_dev *dev; |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 485 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 486 | dev = stdio_get_by_name(name); |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 487 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 488 | if (dev && (dev->flags & flags)) |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 489 | return dev; |
| 490 | |
| 491 | return NULL; |
| 492 | } |
| 493 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 494 | int console_assign(int file, char *devname) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 495 | { |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 496 | int flag; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 497 | struct stdio_dev *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 498 | |
| 499 | /* Check for valid file */ |
| 500 | switch (file) { |
| 501 | case stdin: |
| 502 | flag = DEV_FLAGS_INPUT; |
| 503 | break; |
| 504 | case stdout: |
| 505 | case stderr: |
| 506 | flag = DEV_FLAGS_OUTPUT; |
| 507 | break; |
| 508 | default: |
| 509 | return -1; |
| 510 | } |
| 511 | |
| 512 | /* Check for valid device name */ |
| 513 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 514 | dev = search_device(flag, devname); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 515 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 516 | if (dev) |
| 517 | return console_setfile(file, dev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 518 | |
| 519 | return -1; |
| 520 | } |
| 521 | |
| 522 | /* Called before relocation - use serial functions */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 523 | int console_init_f(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 524 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 525 | gd->have_console = 1; |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 526 | |
| 527 | #ifdef CONFIG_SILENT_CONSOLE |
| 528 | if (getenv("silent") != NULL) |
| 529 | gd->flags |= GD_FLG_SILENT; |
| 530 | #endif |
| 531 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 532 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Jean-Christophe PLAGNIOL-VILLARD | 5a30936 | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 535 | void stdio_print_current_devices(void) |
| 536 | { |
David Brownell | a2bbf4e | 2009-08-30 11:05:29 -0700 | [diff] [blame] | 537 | #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
Jean-Christophe PLAGNIOL-VILLARD | 5a30936 | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 538 | /* Print information */ |
| 539 | puts("In: "); |
| 540 | if (stdio_devices[stdin] == NULL) { |
| 541 | puts("No input devices available!\n"); |
| 542 | } else { |
| 543 | printf ("%s\n", stdio_devices[stdin]->name); |
| 544 | } |
| 545 | |
| 546 | puts("Out: "); |
| 547 | if (stdio_devices[stdout] == NULL) { |
| 548 | puts("No output devices available!\n"); |
| 549 | } else { |
| 550 | printf ("%s\n", stdio_devices[stdout]->name); |
| 551 | } |
| 552 | |
| 553 | puts("Err: "); |
| 554 | if (stdio_devices[stderr] == NULL) { |
| 555 | puts("No error devices available!\n"); |
| 556 | } else { |
| 557 | printf ("%s\n", stdio_devices[stderr]->name); |
| 558 | } |
| 559 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
| 560 | } |
| 561 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 562 | #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 563 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 564 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 565 | { |
| 566 | char *stdinname, *stdoutname, *stderrname; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 567 | struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 568 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 569 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 570 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 571 | #ifdef CONFIG_CONSOLE_MUX |
| 572 | int iomux_err = 0; |
| 573 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 574 | |
| 575 | /* set default handlers at first */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 576 | gd->jt[XF_getc] = serial_getc; |
| 577 | gd->jt[XF_tstc] = serial_tstc; |
| 578 | gd->jt[XF_putc] = serial_putc; |
| 579 | gd->jt[XF_puts] = serial_puts; |
| 580 | gd->jt[XF_printf] = serial_printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 581 | |
| 582 | /* stdin stdout and stderr are in environment */ |
| 583 | /* scan for it */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 584 | stdinname = getenv("stdin"); |
| 585 | stdoutname = getenv("stdout"); |
| 586 | stderrname = getenv("stderr"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 587 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 588 | if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 589 | inputdev = search_device(DEV_FLAGS_INPUT, stdinname); |
| 590 | outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); |
| 591 | errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 592 | #ifdef CONFIG_CONSOLE_MUX |
| 593 | iomux_err = iomux_doenv(stdin, stdinname); |
| 594 | iomux_err += iomux_doenv(stdout, stdoutname); |
| 595 | iomux_err += iomux_doenv(stderr, stderrname); |
| 596 | if (!iomux_err) |
| 597 | /* Successful, so skip all the code below. */ |
| 598 | goto done; |
| 599 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 600 | } |
| 601 | /* if the devices are overwritten or not found, use default device */ |
| 602 | if (inputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 603 | inputdev = search_device(DEV_FLAGS_INPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 604 | } |
| 605 | if (outputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 606 | outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 607 | } |
| 608 | if (errdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 609 | errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 610 | } |
| 611 | /* Initializes output console first */ |
| 612 | if (outputdev != NULL) { |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 613 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 614 | console_doenv(stdout, outputdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 615 | } |
| 616 | if (errdev != NULL) { |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 617 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 618 | console_doenv(stderr, errdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 619 | } |
| 620 | if (inputdev != NULL) { |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 621 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 63331a0 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 622 | console_doenv(stdin, inputdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 625 | #ifdef CONFIG_CONSOLE_MUX |
| 626 | done: |
| 627 | #endif |
| 628 | |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 629 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 630 | |
Jean-Christophe PLAGNIOL-VILLARD | 5a30936 | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 631 | stdio_print_current_devices(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 632 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 633 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 634 | /* set the environment variables (will overwrite previous env settings) */ |
| 635 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 636 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 637 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 638 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 639 | |
| 640 | #if 0 |
| 641 | /* If nothing usable installed, use only the initial console */ |
| 642 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 643 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 644 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 645 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 648 | #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 649 | |
| 650 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 651 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 652 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 653 | struct stdio_dev *inputdev = NULL, *outputdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 654 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 655 | struct list_head *list = stdio_get_list(); |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 656 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 657 | struct stdio_dev *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 658 | |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 659 | #ifdef CONFIG_SPLASH_SCREEN |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 660 | /* |
| 661 | * suppress all output if splash screen is enabled and we have |
Anatolij Gustschin | ec8744a | 2010-03-16 15:29:33 +0100 | [diff] [blame] | 662 | * a bmp to display. We redirect the output from frame buffer |
| 663 | * console to serial console in this case or suppress it if |
| 664 | * "silent" mode was requested. |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 665 | */ |
Anatolij Gustschin | ec8744a | 2010-03-16 15:29:33 +0100 | [diff] [blame] | 666 | if (getenv("splashimage") != NULL) { |
| 667 | if (!(gd->flags & GD_FLG_SILENT)) |
| 668 | outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); |
| 669 | } |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 670 | #endif |
| 671 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 672 | /* Scan devices looking for input and output devices */ |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 673 | list_for_each(pos, list) { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 674 | dev = list_entry(pos, struct stdio_dev, list); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 675 | |
| 676 | if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { |
| 677 | inputdev = dev; |
| 678 | } |
| 679 | if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { |
| 680 | outputdev = dev; |
| 681 | } |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 682 | if(inputdev && outputdev) |
| 683 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* Initializes output console first */ |
| 687 | if (outputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 688 | console_setfile(stdout, outputdev); |
| 689 | console_setfile(stderr, outputdev); |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 690 | #ifdef CONFIG_CONSOLE_MUX |
| 691 | console_devices[stdout][0] = outputdev; |
| 692 | console_devices[stderr][0] = outputdev; |
| 693 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* Initializes input console */ |
| 697 | if (inputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 698 | console_setfile(stdin, inputdev); |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 699 | #ifdef CONFIG_CONSOLE_MUX |
| 700 | console_devices[stdin][0] = inputdev; |
| 701 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 702 | } |
| 703 | |
wdenk | 5958f4a | 2003-09-18 09:21:33 +0000 | [diff] [blame] | 704 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 705 | |
Jean-Christophe PLAGNIOL-VILLARD | 5a30936 | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 706 | stdio_print_current_devices(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 707 | |
| 708 | /* Setting environment variables */ |
| 709 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 710 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | #if 0 |
| 714 | /* If nothing usable installed, use only the initial console */ |
| 715 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 716 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 717 | #endif |
| 718 | |
Jean-Christophe PLAGNIOL-VILLARD | c7dc672 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 719 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 722 | #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |