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