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