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