diff options
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 110 |
1 files changed, 69 insertions, 41 deletions
diff --git a/common/console.c b/common/console.c index e6e029848d..73b4c4d4db 100644 --- a/common/console.c +++ b/common/console.c @@ -1,20 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright 2000 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include <config.h> @@ -30,7 +17,7 @@ #include <clock.h> #include <kfifo.h> #include <module.h> -#include <poller.h> +#include <sched.h> #include <ratp_bb.h> #include <magicvar.h> #include <globalvar.h> @@ -178,12 +165,12 @@ int console_set_baudrate(struct console_device *cdev, unsigned baudrate) int ret; unsigned char c; - if (!cdev->setbrg) - return -ENOSYS; - if (cdev->baudrate == baudrate) return 0; + if (!cdev->setbrg) + return -ENOSYS; + /* * If the device is already active, change its baudrate. * The baudrate of an inactive device will be set at activation time. @@ -233,7 +220,22 @@ static void console_init_early(void) initialized = CONSOLE_INITIALIZED_BUFFER; } -static void console_set_stdoutpath(struct console_device *cdev) +static void console_add_earlycon_param(struct console_device *cdev, unsigned baudrate) +{ + char *str; + + if (!cdev->linux_earlycon_name) + return; + + str = basprintf("earlycon=%s,0x%lx", cdev->linux_earlycon_name, + (ulong)cdev->phys_base); + + dev_add_param_fixed(&cdev->class_dev, "linux.bootargs.earlycon", str); + + free(str); +} + +void console_set_stdoutpath(struct console_device *cdev, unsigned baudrate) { int id; char *str; @@ -241,26 +243,45 @@ static void console_set_stdoutpath(struct console_device *cdev) if (!cdev->linux_console_name) return; - id = of_alias_get_id(cdev->dev->device_node, "serial"); + id = of_alias_get_id(cdev->dev->of_node, "serial"); if (id < 0) return; - str = basprintf("console=%s%d,%dn8", cdev->linux_console_name, id, - cdev->baudrate); + str = basprintf("console=%s%d,%dn8", cdev->linux_console_name, id, baudrate); globalvar_add_simple("linux.bootargs.console", str); free(str); } +struct console_device *of_console_by_stdout_path(void) +{ + struct console_device *console; + struct device_node *stdout_np; + + stdout_np = of_get_stdoutpath(NULL); + if (!stdout_np) + return NULL; + + for_each_console(console) { + if (dev_of_node(console->dev) == stdout_np) + return console; + } + + return NULL; +} + static int __console_puts(struct console_device *cdev, const char *s, size_t nbytes) { size_t i; for (i = 0; i < nbytes; i++) { - if (*s == '\n') + if (*s == '\n') { cdev->putc(cdev, '\r'); + if (IS_ENABLED(CONFIG_CONSOLE_FLUSH_LINE_BREAK) && cdev->flush) + cdev->flush(cdev); + } cdev->putc(cdev, *s); s++; @@ -308,8 +329,9 @@ static ssize_t fops_write(struct cdev* dev, const void* buf, size_t count, int console_register(struct console_device *newcdev) { struct device_node *serdev_node = console_is_serdev_node(newcdev); - struct device_d *dev = &newcdev->class_dev; + struct device *dev = &newcdev->class_dev; int activate = 0, ret; + unsigned baudrate = CONFIG_BAUDRATE; if (!serdev_node && initialized == CONSOLE_UNINITIALIZED) console_init_early(); @@ -340,15 +362,24 @@ int console_register(struct console_device *newcdev) if (serdev_node) return of_platform_populate(serdev_node, NULL, dev); + if (newcdev->dev && of_device_is_stdout_path(newcdev->dev, &baudrate)) { + activate = CONSOLE_STDIOE; + console_set_stdoutpath(newcdev, baudrate); + } + + console_add_earlycon_param(newcdev, baudrate); + if (newcdev->setbrg) { - ret = newcdev->setbrg(newcdev, CONFIG_BAUDRATE); + ret = newcdev->setbrg(newcdev, baudrate); if (ret) return ret; - newcdev->baudrate_param = newcdev->baudrate = CONFIG_BAUDRATE; + newcdev->baudrate_param = baudrate; dev_add_param_uint32(dev, "baudrate", console_baudrate_set, NULL, &newcdev->baudrate_param, "%u", newcdev); } + newcdev->baudrate = baudrate; + if (newcdev->putc && !newcdev->puts) newcdev->puts = __console_puts; @@ -357,21 +388,18 @@ int console_register(struct console_device *newcdev) if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) { if (list_empty(&console_list)) - activate = 1; + activate = CONSOLE_STDIOE; } else if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_ALL)) { - activate = 1; - } - - if (newcdev->dev && of_device_is_stdout_path(newcdev->dev)) { - activate = 1; - console_set_stdoutpath(newcdev); + activate = CONSOLE_STDIOE; } list_add_tail(&newcdev->list, &console_list); + if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT)) + activate &= ~CONSOLE_STDIN; + if (activate) - console_set_active(newcdev, CONSOLE_STDIN | - CONSOLE_STDOUT | CONSOLE_STDERR); + console_set_active(newcdev, activate); /* expose console as device in fs */ newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name, @@ -398,7 +426,7 @@ EXPORT_SYMBOL(console_register); int console_unregister(struct console_device *cdev) { - struct device_d *dev = &cdev->class_dev; + struct device *dev = &cdev->class_dev; int status; /* @@ -592,15 +620,15 @@ int ctrlc(void) { int ret = 0; + resched(); + if (!ctrlc_allowed) return 0; if (ctrlc_abort) return 1; - poller_call(); - -#ifdef ARCH_HAS_CTRLC +#ifdef CONFIG_ARCH_HAS_CTRLC ret = arch_ctrlc(); #else if (tstc() && getchar() == 3) @@ -631,8 +659,8 @@ void console_ctrlc_forbid(void) ctrlc_allowed = 0; } -BAREBOX_MAGICVAR_NAMED(global_console_ctrlc_allowed, global.console.ctrlc_allowed, +BAREBOX_MAGICVAR(global.console.ctrlc_allowed, "If true, scripts can be aborted with ctrl-c"); -BAREBOX_MAGICVAR_NAMED(global_linux_bootargs_console, global.linux.bootargs.console, +BAREBOX_MAGICVAR(global.linux.bootargs.console, "console= argument for Linux from the stdout-path property in /chosen node"); |