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