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