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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame^] | 9 | #include <console.h> |
Simon Glass | d6ea530 | 2015-06-23 15:38:33 -0600 | [diff] [blame] | 10 | #include <debug_uart.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 11 | #include <stdarg.h> |
Jeroen Hofstee | 482f469 | 2014-10-08 22:57:48 +0200 | [diff] [blame] | 12 | #include <iomux.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 13 | #include <malloc.h> |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 14 | #include <os.h> |
Joe Hershberger | 849d5d9 | 2012-12-11 22:16:29 -0600 | [diff] [blame] | 15 | #include <serial.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 16 | #include <stdio_dev.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 17 | #include <exports.h> |
Joe Hershberger | 849d5d9 | 2012-12-11 22:16:29 -0600 | [diff] [blame] | 18 | #include <environment.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 19 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Joe Hershberger | 849d5d9 | 2012-12-11 22:16:29 -0600 | [diff] [blame] | 22 | static int on_console(const char *name, const char *value, enum env_op op, |
| 23 | int flags) |
| 24 | { |
| 25 | int console = -1; |
| 26 | |
| 27 | /* Check for console redirection */ |
| 28 | if (strcmp(name, "stdin") == 0) |
| 29 | console = stdin; |
| 30 | else if (strcmp(name, "stdout") == 0) |
| 31 | console = stdout; |
| 32 | else if (strcmp(name, "stderr") == 0) |
| 33 | console = stderr; |
| 34 | |
| 35 | /* if not actually setting a console variable, we don't care */ |
| 36 | if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0) |
| 37 | return 0; |
| 38 | |
| 39 | switch (op) { |
| 40 | case env_op_create: |
| 41 | case env_op_overwrite: |
| 42 | |
| 43 | #ifdef CONFIG_CONSOLE_MUX |
| 44 | if (iomux_doenv(console, value)) |
| 45 | return 1; |
| 46 | #else |
| 47 | /* Try assigning specified device */ |
| 48 | if (console_assign(console, value) < 0) |
| 49 | return 1; |
| 50 | #endif /* CONFIG_CONSOLE_MUX */ |
| 51 | return 0; |
| 52 | |
| 53 | case env_op_delete: |
| 54 | if ((flags & H_FORCE) == 0) |
| 55 | printf("Can't delete \"%s\"\n", name); |
| 56 | return 1; |
| 57 | |
| 58 | default: |
| 59 | return 0; |
| 60 | } |
| 61 | } |
| 62 | U_BOOT_ENV_CALLBACK(console, on_console); |
| 63 | |
Joe Hershberger | e080d54 | 2012-12-11 22:16:30 -0600 | [diff] [blame] | 64 | #ifdef CONFIG_SILENT_CONSOLE |
| 65 | static int on_silent(const char *name, const char *value, enum env_op op, |
| 66 | int flags) |
| 67 | { |
| 68 | #ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_SET |
| 69 | if (flags & H_INTERACTIVE) |
| 70 | return 0; |
| 71 | #endif |
| 72 | #ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC |
| 73 | if ((flags & H_INTERACTIVE) == 0) |
| 74 | return 0; |
| 75 | #endif |
| 76 | |
| 77 | if (value != NULL) |
| 78 | gd->flags |= GD_FLG_SILENT; |
| 79 | else |
| 80 | gd->flags &= ~GD_FLG_SILENT; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | U_BOOT_ENV_CALLBACK(silent, on_silent); |
| 85 | #endif |
| 86 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 87 | #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 88 | /* |
| 89 | * if overwrite_console returns 1, the stdin, stderr and stdout |
| 90 | * are switched to the serial port, else the settings in the |
| 91 | * environment are used |
| 92 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 94 | extern int overwrite_console(void); |
| 95 | #define OVERWRITE_CONSOLE overwrite_console() |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 96 | #else |
wdenk | 83e40ba | 2005-03-31 18:42:15 +0000 | [diff] [blame] | 97 | #define OVERWRITE_CONSOLE 0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 99 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 101 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 102 | static int console_setfile(int file, struct stdio_dev * dev) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 103 | { |
| 104 | int error = 0; |
| 105 | |
| 106 | if (dev == NULL) |
| 107 | return -1; |
| 108 | |
| 109 | switch (file) { |
| 110 | case stdin: |
| 111 | case stdout: |
| 112 | case stderr: |
| 113 | /* Start new device */ |
| 114 | if (dev->start) { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 115 | error = dev->start(dev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 116 | /* If it's not started dont use it */ |
| 117 | if (error < 0) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | /* Assign the new device (leaving the existing one started) */ |
| 122 | stdio_devices[file] = dev; |
| 123 | |
| 124 | /* |
| 125 | * Update monitor functions |
| 126 | * (to use the console stuff by other applications) |
| 127 | */ |
| 128 | switch (file) { |
| 129 | case stdin: |
Martin Dorwig | 49cad54 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 130 | gd->jt->getc = getc; |
| 131 | gd->jt->tstc = tstc; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 132 | break; |
| 133 | case stdout: |
Martin Dorwig | 49cad54 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 134 | gd->jt->putc = putc; |
| 135 | gd->jt->puts = puts; |
| 136 | gd->jt->printf = printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 137 | break; |
| 138 | } |
| 139 | break; |
| 140 | |
| 141 | default: /* Invalid file ID */ |
| 142 | error = -1; |
| 143 | } |
| 144 | return error; |
| 145 | } |
| 146 | |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 147 | #if defined(CONFIG_CONSOLE_MUX) |
| 148 | /** Console I/O multiplexing *******************************************/ |
| 149 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 150 | static struct stdio_dev *tstcdev; |
| 151 | struct stdio_dev **console_devices[MAX_FILES]; |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 152 | int cd_count[MAX_FILES]; |
| 153 | |
| 154 | /* |
| 155 | * This depends on tstc() always being called before getc(). |
| 156 | * This is guaranteed to be true because this routine is called |
| 157 | * only from fgetc() which assures it. |
| 158 | * No attempt is made to demultiplex multiple input sources. |
| 159 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 160 | static int console_getc(int file) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 161 | { |
| 162 | unsigned char ret; |
| 163 | |
| 164 | /* This is never called with testcdev == NULL */ |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 165 | ret = tstcdev->getc(tstcdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 166 | tstcdev = NULL; |
| 167 | return ret; |
| 168 | } |
| 169 | |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 170 | static int console_tstc(int file) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 171 | { |
| 172 | int i, ret; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 173 | struct stdio_dev *dev; |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 174 | |
| 175 | disable_ctrlc(1); |
| 176 | for (i = 0; i < cd_count[file]; i++) { |
| 177 | dev = console_devices[file][i]; |
| 178 | if (dev->tstc != NULL) { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 179 | ret = dev->tstc(dev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 180 | if (ret > 0) { |
| 181 | tstcdev = dev; |
| 182 | disable_ctrlc(0); |
| 183 | return ret; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | disable_ctrlc(0); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 192 | static void console_putc(int file, const char c) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 193 | { |
| 194 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 195 | struct stdio_dev *dev; |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 196 | |
| 197 | for (i = 0; i < cd_count[file]; i++) { |
| 198 | dev = console_devices[file][i]; |
| 199 | if (dev->putc != NULL) |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 200 | dev->putc(dev, c); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 204 | #ifdef CONFIG_PRE_CONSOLE_BUFFER |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 205 | static void console_puts_noserial(int file, const char *s) |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 206 | { |
| 207 | int i; |
| 208 | struct stdio_dev *dev; |
| 209 | |
| 210 | for (i = 0; i < cd_count[file]; i++) { |
| 211 | dev = console_devices[file][i]; |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 212 | if (dev->puts != NULL && strcmp(dev->name, "serial") != 0) |
| 213 | dev->puts(dev, s); |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | #endif |
| 217 | |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 218 | static void console_puts(int file, const char *s) |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 219 | { |
| 220 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 221 | struct stdio_dev *dev; |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 222 | |
| 223 | for (i = 0; i < cd_count[file]; i++) { |
| 224 | dev = console_devices[file][i]; |
| 225 | if (dev->puts != NULL) |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 226 | dev->puts(dev, s); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 227 | } |
| 228 | } |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 229 | |
| 230 | static inline void console_printdevs(int file) |
| 231 | { |
| 232 | iomux_printdevs(file); |
| 233 | } |
| 234 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 235 | 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] | 236 | { |
| 237 | iomux_doenv(file, dev->name); |
| 238 | } |
| 239 | #else |
| 240 | static inline int console_getc(int file) |
| 241 | { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 242 | return stdio_devices[file]->getc(stdio_devices[file]); |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static inline int console_tstc(int file) |
| 246 | { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 247 | return stdio_devices[file]->tstc(stdio_devices[file]); |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static inline void console_putc(int file, const char c) |
| 251 | { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 252 | stdio_devices[file]->putc(stdio_devices[file], c); |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 255 | #ifdef CONFIG_PRE_CONSOLE_BUFFER |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 256 | static inline void console_puts_noserial(int file, const char *s) |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 257 | { |
| 258 | if (strcmp(stdio_devices[file]->name, "serial") != 0) |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 259 | stdio_devices[file]->puts(stdio_devices[file], s); |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 260 | } |
| 261 | #endif |
| 262 | |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 263 | static inline void console_puts(int file, const char *s) |
| 264 | { |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 265 | stdio_devices[file]->puts(stdio_devices[file], s); |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static inline void console_printdevs(int file) |
| 269 | { |
| 270 | printf("%s\n", stdio_devices[file]->name); |
| 271 | } |
| 272 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 273 | 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] | 274 | { |
| 275 | console_setfile(file, dev); |
| 276 | } |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 277 | #endif /* defined(CONFIG_CONSOLE_MUX) */ |
| 278 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 279 | /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
| 280 | |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 281 | int serial_printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 282 | { |
| 283 | va_list args; |
| 284 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 285 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 286 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 287 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 288 | |
| 289 | /* For this to work, printbuffer must be larger than |
| 290 | * anything we ever want to print. |
| 291 | */ |
Sonny Rao | 068af6f | 2011-10-10 09:22:31 +0000 | [diff] [blame] | 292 | i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 293 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 294 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 295 | serial_puts(printbuffer); |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 296 | return i; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 299 | int fgetc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 300 | { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 301 | if (file < MAX_FILES) { |
| 302 | #if defined(CONFIG_CONSOLE_MUX) |
| 303 | /* |
| 304 | * Effectively poll for input wherever it may be available. |
| 305 | */ |
| 306 | for (;;) { |
| 307 | /* |
| 308 | * Upper layer may have already called tstc() so |
| 309 | * check for that first. |
| 310 | */ |
| 311 | if (tstcdev != NULL) |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 312 | return console_getc(file); |
| 313 | console_tstc(file); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 314 | #ifdef CONFIG_WATCHDOG |
| 315 | /* |
| 316 | * If the watchdog must be rate-limited then it should |
| 317 | * already be handled in board-specific code. |
| 318 | */ |
| 319 | udelay(1); |
| 320 | #endif |
| 321 | } |
| 322 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 323 | return console_getc(file); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 324 | #endif |
| 325 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 326 | |
| 327 | return -1; |
| 328 | } |
| 329 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 330 | int ftstc(int file) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 331 | { |
| 332 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 333 | return console_tstc(file); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 334 | |
| 335 | return -1; |
| 336 | } |
| 337 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 338 | void fputc(int file, const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 339 | { |
| 340 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 341 | console_putc(file, c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 344 | void fputs(int file, const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 345 | { |
| 346 | if (file < MAX_FILES) |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 347 | console_puts(file, s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 350 | int fprintf(int file, const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 351 | { |
| 352 | va_list args; |
| 353 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 354 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 355 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 356 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 357 | |
| 358 | /* For this to work, printbuffer must be larger than |
| 359 | * anything we ever want to print. |
| 360 | */ |
Sonny Rao | 068af6f | 2011-10-10 09:22:31 +0000 | [diff] [blame] | 361 | i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 362 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 363 | |
| 364 | /* Send to desired file */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 365 | fputs(file, printbuffer); |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 366 | return i; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
| 370 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 371 | int getc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 372 | { |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 373 | #ifdef CONFIG_DISABLE_CONSOLE |
| 374 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 375 | return 0; |
| 376 | #endif |
| 377 | |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 378 | if (!gd->have_console) |
| 379 | return 0; |
| 380 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 381 | if (gd->flags & GD_FLG_DEVINIT) { |
| 382 | /* Get from the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 383 | return fgetc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 387 | return serial_getc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 390 | int tstc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 391 | { |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 392 | #ifdef CONFIG_DISABLE_CONSOLE |
| 393 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 394 | return 0; |
| 395 | #endif |
| 396 | |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 397 | if (!gd->have_console) |
| 398 | return 0; |
| 399 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 400 | if (gd->flags & GD_FLG_DEVINIT) { |
| 401 | /* Test the standard input */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 402 | return ftstc(stdin); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /* Send directly to the handler */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 406 | return serial_tstc(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 409 | #define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 |
| 410 | #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 |
| 411 | |
Simon Glass | 3fa4977 | 2012-03-19 21:59:14 -0700 | [diff] [blame] | 412 | #ifdef CONFIG_PRE_CONSOLE_BUFFER |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 413 | #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ) |
| 414 | |
| 415 | static void pre_console_putc(const char c) |
| 416 | { |
| 417 | char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR; |
| 418 | |
| 419 | buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c; |
| 420 | } |
| 421 | |
| 422 | static void pre_console_puts(const char *s) |
| 423 | { |
| 424 | while (*s) |
| 425 | pre_console_putc(*s++); |
| 426 | } |
| 427 | |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 428 | static void print_pre_console_buffer(int flushpoint) |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 429 | { |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 430 | unsigned long in = 0, out = 0; |
| 431 | char *buf_in = (char *)CONFIG_PRE_CON_BUF_ADDR; |
| 432 | char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 433 | |
| 434 | if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 435 | in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 436 | |
Hans de Goede | a8552c7 | 2015-05-05 13:13:36 +0200 | [diff] [blame] | 437 | while (in < gd->precon_buf_idx) |
| 438 | buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)]; |
| 439 | |
| 440 | buf_out[out] = 0; |
| 441 | |
| 442 | switch (flushpoint) { |
| 443 | case PRE_CONSOLE_FLUSHPOINT1_SERIAL: |
| 444 | puts(buf_out); |
| 445 | break; |
| 446 | case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: |
| 447 | console_puts_noserial(stdout, buf_out); |
| 448 | break; |
| 449 | } |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 450 | } |
| 451 | #else |
| 452 | static inline void pre_console_putc(const char c) {} |
| 453 | static inline void pre_console_puts(const char *s) {} |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 454 | static inline void print_pre_console_buffer(int flushpoint) {} |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 455 | #endif |
| 456 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 457 | void putc(const char c) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 458 | { |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 459 | #ifdef CONFIG_SANDBOX |
Simon Glass | da229e4 | 2015-06-23 15:38:34 -0600 | [diff] [blame] | 460 | /* sandbox can send characters to stdout before it has a console */ |
Simon Glass | 093f79a | 2014-07-23 06:55:07 -0600 | [diff] [blame] | 461 | if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 462 | os_putc(c); |
| 463 | return; |
| 464 | } |
| 465 | #endif |
Simon Glass | d6ea530 | 2015-06-23 15:38:33 -0600 | [diff] [blame] | 466 | #ifdef CONFIG_DEBUG_UART |
| 467 | /* if we don't have a console yet, use the debug UART */ |
| 468 | if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { |
| 469 | printch(c); |
| 470 | return; |
| 471 | } |
| 472 | #endif |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 473 | #ifdef CONFIG_SILENT_CONSOLE |
| 474 | if (gd->flags & GD_FLG_SILENT) |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 475 | return; |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 476 | #endif |
| 477 | |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 478 | #ifdef CONFIG_DISABLE_CONSOLE |
| 479 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 480 | return; |
| 481 | #endif |
| 482 | |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 483 | if (!gd->have_console) |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 484 | return pre_console_putc(c); |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 485 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 486 | if (gd->flags & GD_FLG_DEVINIT) { |
| 487 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 488 | fputc(stdout, c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 489 | } else { |
| 490 | /* Send directly to the handler */ |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 491 | pre_console_putc(c); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 492 | serial_putc(c); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 496 | void puts(const char *s) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 497 | { |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 498 | #ifdef CONFIG_SANDBOX |
Simon Glass | 093f79a | 2014-07-23 06:55:07 -0600 | [diff] [blame] | 499 | if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 500 | os_puts(s); |
| 501 | return; |
| 502 | } |
| 503 | #endif |
Simon Glass | d6ea530 | 2015-06-23 15:38:33 -0600 | [diff] [blame] | 504 | #ifdef CONFIG_DEBUG_UART |
| 505 | if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { |
| 506 | while (*s) { |
| 507 | int ch = *s++; |
Simon Glass | 91b136c | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 508 | |
Simon Glass | d6ea530 | 2015-06-23 15:38:33 -0600 | [diff] [blame] | 509 | printch(ch); |
| 510 | if (ch == '\n') |
| 511 | printch('\r'); |
| 512 | } |
| 513 | return; |
| 514 | } |
| 515 | #endif |
wdenk | a6cccae | 2004-02-06 21:48:22 +0000 | [diff] [blame] | 516 | #ifdef CONFIG_SILENT_CONSOLE |
| 517 | if (gd->flags & GD_FLG_SILENT) |
| 518 | return; |
| 519 | #endif |
| 520 | |
Mark Jackson | f5c3ba7 | 2008-08-25 19:21:30 +0100 | [diff] [blame] | 521 | #ifdef CONFIG_DISABLE_CONSOLE |
| 522 | if (gd->flags & GD_FLG_DISABLE_CONSOLE) |
| 523 | return; |
| 524 | #endif |
| 525 | |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 526 | if (!gd->have_console) |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 527 | return pre_console_puts(s); |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 528 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 529 | if (gd->flags & GD_FLG_DEVINIT) { |
| 530 | /* Send to the standard output */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 531 | fputs(stdout, s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 532 | } else { |
| 533 | /* Send directly to the handler */ |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 534 | pre_console_puts(s); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 535 | serial_puts(s); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 539 | int printf(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 540 | { |
| 541 | va_list args; |
| 542 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 543 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 544 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 545 | va_start(args, fmt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 546 | |
| 547 | /* For this to work, printbuffer must be larger than |
| 548 | * anything we ever want to print. |
| 549 | */ |
Sonny Rao | 068af6f | 2011-10-10 09:22:31 +0000 | [diff] [blame] | 550 | i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 551 | va_end(args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 552 | |
| 553 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 554 | puts(printbuffer); |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 555 | return i; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 558 | int vprintf(const char *fmt, va_list args) |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 559 | { |
| 560 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 561 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 562 | |
Simon Glass | 7793ac9 | 2014-07-23 06:55:06 -0600 | [diff] [blame] | 563 | #if defined(CONFIG_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SANDBOX) |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 564 | if (!gd->have_console) |
| 565 | return 0; |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 566 | #endif |
Graeme Russ | e3e454c | 2011-08-29 02:14:05 +0000 | [diff] [blame] | 567 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 568 | /* For this to work, printbuffer must be larger than |
| 569 | * anything we ever want to print. |
| 570 | */ |
Sonny Rao | 068af6f | 2011-10-10 09:22:31 +0000 | [diff] [blame] | 571 | i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 572 | |
| 573 | /* Print the string */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 574 | puts(printbuffer); |
Wolfgang Denk | d9c2725 | 2010-06-20 17:14:14 +0200 | [diff] [blame] | 575 | return i; |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 576 | } |
| 577 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 578 | /* test if ctrl-c was pressed */ |
| 579 | static int ctrlc_disabled = 0; /* see disable_ctrl() */ |
| 580 | static int ctrlc_was_pressed = 0; |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 581 | int ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 582 | { |
Simon Glass | 8969ea3 | 2014-09-14 12:40:15 -0600 | [diff] [blame] | 583 | #ifndef CONFIG_SANDBOX |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 584 | if (!ctrlc_disabled && gd->have_console) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 585 | if (tstc()) { |
| 586 | switch (getc()) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 587 | case 0x03: /* ^C - Control C */ |
| 588 | ctrlc_was_pressed = 1; |
| 589 | return 1; |
| 590 | default: |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | } |
Simon Glass | 8969ea3 | 2014-09-14 12:40:15 -0600 | [diff] [blame] | 595 | #endif |
| 596 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 597 | return 0; |
| 598 | } |
Pierre Aubert | a5dffa4 | 2014-04-24 10:30:07 +0200 | [diff] [blame] | 599 | /* Reads user's confirmation. |
| 600 | Returns 1 if user's input is "y", "Y", "yes" or "YES" |
| 601 | */ |
| 602 | int confirm_yesno(void) |
| 603 | { |
| 604 | int i; |
| 605 | char str_input[5]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 606 | |
Pierre Aubert | a5dffa4 | 2014-04-24 10:30:07 +0200 | [diff] [blame] | 607 | /* Flush input */ |
| 608 | while (tstc()) |
| 609 | getc(); |
| 610 | i = 0; |
| 611 | while (i < sizeof(str_input)) { |
| 612 | str_input[i] = getc(); |
| 613 | putc(str_input[i]); |
| 614 | if (str_input[i] == '\r') |
| 615 | break; |
| 616 | i++; |
| 617 | } |
| 618 | putc('\n'); |
| 619 | if (strncmp(str_input, "y\r", 2) == 0 || |
| 620 | strncmp(str_input, "Y\r", 2) == 0 || |
| 621 | strncmp(str_input, "yes\r", 4) == 0 || |
| 622 | strncmp(str_input, "YES\r", 4) == 0) |
| 623 | return 1; |
| 624 | return 0; |
| 625 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 626 | /* pass 1 to disable ctrlc() checking, 0 to enable. |
| 627 | * returns previous state |
| 628 | */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 629 | int disable_ctrlc(int disable) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 630 | { |
| 631 | int prev = ctrlc_disabled; /* save previous state */ |
| 632 | |
| 633 | ctrlc_disabled = disable; |
| 634 | return prev; |
| 635 | } |
| 636 | |
| 637 | int had_ctrlc (void) |
| 638 | { |
| 639 | return ctrlc_was_pressed; |
| 640 | } |
| 641 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 642 | void clear_ctrlc(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 643 | { |
| 644 | ctrlc_was_pressed = 0; |
| 645 | } |
| 646 | |
| 647 | #ifdef CONFIG_MODEM_SUPPORT_DEBUG |
| 648 | char screen[1024]; |
| 649 | char *cursor = screen; |
| 650 | int once = 0; |
| 651 | inline void dbg(const char *fmt, ...) |
| 652 | { |
| 653 | va_list args; |
| 654 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 655 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 656 | |
| 657 | if (!once) { |
| 658 | memset(screen, 0, sizeof(screen)); |
| 659 | once++; |
| 660 | } |
| 661 | |
| 662 | va_start(args, fmt); |
| 663 | |
| 664 | /* For this to work, printbuffer must be larger than |
| 665 | * anything we ever want to print. |
| 666 | */ |
Sonny Rao | 068af6f | 2011-10-10 09:22:31 +0000 | [diff] [blame] | 667 | i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 668 | va_end(args); |
| 669 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 670 | if ((screen + sizeof(screen) - 1 - cursor) |
| 671 | < strlen(printbuffer) + 1) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 672 | memset(screen, 0, sizeof(screen)); |
| 673 | cursor = screen; |
| 674 | } |
| 675 | sprintf(cursor, printbuffer); |
| 676 | cursor += strlen(printbuffer); |
| 677 | |
| 678 | } |
| 679 | #else |
Jeroen Hofstee | 482f469 | 2014-10-08 22:57:48 +0200 | [diff] [blame] | 680 | static inline void dbg(const char *fmt, ...) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 681 | { |
| 682 | } |
| 683 | #endif |
| 684 | |
| 685 | /** U-Boot INIT FUNCTIONS *************************************************/ |
| 686 | |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 687 | struct stdio_dev *search_device(int flags, const char *name) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 688 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 689 | struct stdio_dev *dev; |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 690 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 691 | dev = stdio_get_by_name(name); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 692 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 693 | if (dev && (dev->flags & flags)) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 694 | return dev; |
| 695 | |
| 696 | return NULL; |
| 697 | } |
| 698 | |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 699 | int console_assign(int file, const char *devname) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 700 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 701 | int flag; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 702 | struct stdio_dev *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 703 | |
| 704 | /* Check for valid file */ |
| 705 | switch (file) { |
| 706 | case stdin: |
| 707 | flag = DEV_FLAGS_INPUT; |
| 708 | break; |
| 709 | case stdout: |
| 710 | case stderr: |
| 711 | flag = DEV_FLAGS_OUTPUT; |
| 712 | break; |
| 713 | default: |
| 714 | return -1; |
| 715 | } |
| 716 | |
| 717 | /* Check for valid device name */ |
| 718 | |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 719 | dev = search_device(flag, devname); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 720 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 721 | if (dev) |
| 722 | return console_setfile(file, dev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 723 | |
| 724 | return -1; |
| 725 | } |
| 726 | |
| 727 | /* Called before relocation - use serial functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 728 | int console_init_f(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 729 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 730 | gd->have_console = 1; |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 731 | |
| 732 | #ifdef CONFIG_SILENT_CONSOLE |
| 733 | if (getenv("silent") != NULL) |
| 734 | gd->flags |= GD_FLG_SILENT; |
| 735 | #endif |
| 736 | |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 737 | print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL); |
Graeme Russ | 9558b48 | 2011-09-01 00:48:27 +0000 | [diff] [blame] | 738 | |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 739 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e3be7c | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 742 | void stdio_print_current_devices(void) |
| 743 | { |
Jean-Christophe PLAGNIOL-VILLARD | 7e3be7c | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 744 | /* Print information */ |
| 745 | puts("In: "); |
| 746 | if (stdio_devices[stdin] == NULL) { |
| 747 | puts("No input devices available!\n"); |
| 748 | } else { |
| 749 | printf ("%s\n", stdio_devices[stdin]->name); |
| 750 | } |
| 751 | |
| 752 | puts("Out: "); |
| 753 | if (stdio_devices[stdout] == NULL) { |
| 754 | puts("No output devices available!\n"); |
| 755 | } else { |
| 756 | printf ("%s\n", stdio_devices[stdout]->name); |
| 757 | } |
| 758 | |
| 759 | puts("Err: "); |
| 760 | if (stdio_devices[stderr] == NULL) { |
| 761 | puts("No error devices available!\n"); |
| 762 | } else { |
| 763 | printf ("%s\n", stdio_devices[stderr]->name); |
| 764 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e3be7c | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 767 | #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 768 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 769 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 770 | { |
| 771 | char *stdinname, *stdoutname, *stderrname; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 772 | struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 773 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 774 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 775 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 776 | #ifdef CONFIG_CONSOLE_MUX |
| 777 | int iomux_err = 0; |
| 778 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 779 | |
| 780 | /* set default handlers at first */ |
Martin Dorwig | 49cad54 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 781 | gd->jt->getc = serial_getc; |
| 782 | gd->jt->tstc = serial_tstc; |
| 783 | gd->jt->putc = serial_putc; |
| 784 | gd->jt->puts = serial_puts; |
| 785 | gd->jt->printf = serial_printf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 786 | |
| 787 | /* stdin stdout and stderr are in environment */ |
| 788 | /* scan for it */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 789 | stdinname = getenv("stdin"); |
| 790 | stdoutname = getenv("stdout"); |
| 791 | stderrname = getenv("stderr"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 792 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 793 | if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 794 | inputdev = search_device(DEV_FLAGS_INPUT, stdinname); |
| 795 | outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); |
| 796 | errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 797 | #ifdef CONFIG_CONSOLE_MUX |
| 798 | iomux_err = iomux_doenv(stdin, stdinname); |
| 799 | iomux_err += iomux_doenv(stdout, stdoutname); |
| 800 | iomux_err += iomux_doenv(stderr, stderrname); |
| 801 | if (!iomux_err) |
| 802 | /* Successful, so skip all the code below. */ |
| 803 | goto done; |
| 804 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 805 | } |
| 806 | /* if the devices are overwritten or not found, use default device */ |
| 807 | if (inputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 808 | inputdev = search_device(DEV_FLAGS_INPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 809 | } |
| 810 | if (outputdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 811 | outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 812 | } |
| 813 | if (errdev == NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 814 | errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 815 | } |
| 816 | /* Initializes output console first */ |
| 817 | if (outputdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 818 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 819 | console_doenv(stdout, outputdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 820 | } |
| 821 | if (errdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 822 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 823 | console_doenv(stderr, errdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 824 | } |
| 825 | if (inputdev != NULL) { |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 826 | /* need to set a console if not done above. */ |
Jean-Christophe PLAGNIOL-VILLARD | 5f03201 | 2009-02-01 17:07:52 +0100 | [diff] [blame] | 827 | console_doenv(stdin, inputdev); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 830 | #ifdef CONFIG_CONSOLE_MUX |
| 831 | done: |
| 832 | #endif |
| 833 | |
Simon Glass | 78c112c | 2012-12-05 14:46:43 +0000 | [diff] [blame] | 834 | #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
Jean-Christophe PLAGNIOL-VILLARD | 7e3be7c | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 835 | stdio_print_current_devices(); |
Simon Glass | 78c112c | 2012-12-05 14:46:43 +0000 | [diff] [blame] | 836 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 837 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 838 | #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 839 | /* set the environment variables (will overwrite previous env settings) */ |
| 840 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 841 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 842 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 843 | #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 844 | |
Joe Hershberger | c4e0057 | 2012-12-11 22:16:19 -0600 | [diff] [blame] | 845 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 846 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 847 | #if 0 |
| 848 | /* If nothing usable installed, use only the initial console */ |
| 849 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 850 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 851 | #endif |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 852 | print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 853 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 856 | #else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 857 | |
| 858 | /* Called after the relocation - use desired console functions */ |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 859 | int console_init_r(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 860 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 861 | struct stdio_dev *inputdev = NULL, *outputdev = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 862 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 863 | struct list_head *list = stdio_get_list(); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 864 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 865 | struct stdio_dev *dev; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 866 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 867 | #ifdef CONFIG_SPLASH_SCREEN |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 868 | /* |
| 869 | * suppress all output if splash screen is enabled and we have |
Anatolij Gustschin | a749081 | 2010-03-16 15:29:33 +0100 | [diff] [blame] | 870 | * a bmp to display. We redirect the output from frame buffer |
| 871 | * console to serial console in this case or suppress it if |
| 872 | * "silent" mode was requested. |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 873 | */ |
Anatolij Gustschin | a749081 | 2010-03-16 15:29:33 +0100 | [diff] [blame] | 874 | if (getenv("splashimage") != NULL) { |
| 875 | if (!(gd->flags & GD_FLG_SILENT)) |
| 876 | outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); |
| 877 | } |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 878 | #endif |
| 879 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 880 | /* Scan devices looking for input and output devices */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 881 | list_for_each(pos, list) { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 882 | dev = list_entry(pos, struct stdio_dev, list); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 883 | |
| 884 | if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { |
| 885 | inputdev = dev; |
| 886 | } |
| 887 | if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { |
| 888 | outputdev = dev; |
| 889 | } |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 890 | if(inputdev && outputdev) |
| 891 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /* Initializes output console first */ |
| 895 | if (outputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 896 | console_setfile(stdout, outputdev); |
| 897 | console_setfile(stderr, outputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 898 | #ifdef CONFIG_CONSOLE_MUX |
| 899 | console_devices[stdout][0] = outputdev; |
| 900 | console_devices[stderr][0] = outputdev; |
| 901 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /* Initializes input console */ |
| 905 | if (inputdev != NULL) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 906 | console_setfile(stdin, inputdev); |
Gary Jennejohn | 16a28ef | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 907 | #ifdef CONFIG_CONSOLE_MUX |
| 908 | console_devices[stdin][0] = inputdev; |
| 909 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Simon Glass | 78c112c | 2012-12-05 14:46:43 +0000 | [diff] [blame] | 912 | #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
Jean-Christophe PLAGNIOL-VILLARD | 7e3be7c | 2009-05-16 12:14:55 +0200 | [diff] [blame] | 913 | stdio_print_current_devices(); |
Simon Glass | 78c112c | 2012-12-05 14:46:43 +0000 | [diff] [blame] | 914 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 915 | |
| 916 | /* Setting environment variables */ |
| 917 | for (i = 0; i < 3; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 918 | setenv(stdio_names[i], stdio_devices[i]->name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Joe Hershberger | c4e0057 | 2012-12-11 22:16:19 -0600 | [diff] [blame] | 921 | gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
| 922 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 923 | #if 0 |
| 924 | /* If nothing usable installed, use only the initial console */ |
| 925 | if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 926 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 927 | #endif |
Siarhei Siamashka | 2766966 | 2015-01-08 09:02:31 +0200 | [diff] [blame] | 928 | print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
Jean-Christophe PLAGNIOL-VILLARD | ec6f149 | 2009-02-01 17:07:51 +0100 | [diff] [blame] | 929 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 932 | #endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ |