summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-05-23 11:25:19 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-06-09 11:22:23 +0200
commitd17f29dba03058294ccc9fed73af3d34014e4d6a (patch)
treea254a3b2ae53549ca8cda9f46b946191a17756ea /common
parente72bdad5c112935922adc4d389a13e0cc66c9539 (diff)
downloadbarebox-d17f29dba03058294ccc9fed73af3d34014e4d6a.tar.gz
barebox-d17f29dba03058294ccc9fed73af3d34014e4d6a.tar.xz
console: add new $global.bootm.earlycon parameter
barebox already fixes up a suitable console= parameter if it can determine one into the kernel command line. This doesn't help with early Linux issues, which can instead be debugged by the earlycon mechanism. For earlycon to work, the kernel DT must have a stdout-path or the user needs to explicitly specify what driver to use and how to access it (base address, optionally access_type). Make this easier by just having barebox fix up the needed information when $global.bootm.earlycon is true and the barebox serial driver provides the needed information. If the serial driver doesn't, a plain "earlycon" parameter will be fixed up. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220523092526.791716-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/bootm.c24
-rw-r--r--common/console.c17
2 files changed, 41 insertions, 0 deletions
diff --git a/common/bootm.c b/common/bootm.c
index 3c80e8bf94..712e6ebe49 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -41,6 +41,7 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
}
static int bootm_appendroot;
+static int bootm_earlycon;
static int bootm_provide_machine_id;
static int bootm_verbosity;
@@ -732,6 +733,26 @@ int bootm_boot(struct bootm_data *bootm_data)
}
}
+ if (bootm_earlycon) {
+ struct console_device *console;
+ const char *earlycon = NULL;
+
+ for_each_console(console) {
+ if (!(console->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR)))
+ continue;
+
+ earlycon = dev_get_param(&console->class_dev, "linux.bootargs.earlycon");
+ if (earlycon)
+ break;
+ }
+
+ if (!earlycon)
+ earlycon = "earlycon";
+
+ pr_info("Adding \"%s\" to Kernel commandline\n", earlycon);
+ globalvar_add_simple("linux.bootargs.bootm.earlycon", earlycon);
+ }
+
if (bootm_data->provide_machine_id) {
const char *machine_id = getenv_nonempty("global.machine_id");
char *machine_id_bootarg;
@@ -798,6 +819,7 @@ err_out:
if (data->of_root_node && data->of_root_node != of_get_root_node())
of_delete_node(data->of_root_node);
+ globalvar_remove("linux.bootargs.bootm.earlycon");
globalvar_remove("linux.bootargs.bootm.appendroot");
free(data->os_header);
free(data->os_file);
@@ -897,6 +919,7 @@ static int bootm_init(void)
globalvar_add_simple("bootm.root_dev", NULL);
globalvar_add_simple("bootm.tee", NULL);
globalvar_add_simple_bool("bootm.appendroot", &bootm_appendroot);
+ globalvar_add_simple_bool("bootm.earlycon", &bootm_earlycon);
globalvar_add_simple_bool("bootm.provide_machine_id", &bootm_provide_machine_id);
if (IS_ENABLED(CONFIG_BOOTM_INITRD)) {
globalvar_add_simple("bootm.initrd", NULL);
@@ -936,6 +959,7 @@ BAREBOX_MAGICVAR(global.bootm.oftree, "bootm default oftree");
BAREBOX_MAGICVAR(global.bootm.tee, "bootm default tee image");
BAREBOX_MAGICVAR(global.bootm.verify, "bootm default verify level");
BAREBOX_MAGICVAR(global.bootm.verbose, "bootm default verbosity level (0=quiet)");
+BAREBOX_MAGICVAR(global.bootm.earlycon, "Add earlycon option to Kernel for early log output");
BAREBOX_MAGICVAR(global.bootm.appendroot, "Add root= option to Kernel to mount rootfs from the device the Kernel comes from (default, device can be overridden via global.bootm.root_dev)");
BAREBOX_MAGICVAR(global.bootm.root_dev, "bootm default root device (overrides default device in global.bootm.appendroot)");
BAREBOX_MAGICVAR(global.bootm.provide_machine_id, "If true, append systemd.machine_id=$global.machine_id to Kernel command line");
diff --git a/common/console.c b/common/console.c
index 8727b187cf..c442c2dde1 100644
--- a/common/console.c
+++ b/common/console.c
@@ -220,6 +220,21 @@ static void console_init_early(void)
initialized = CONSOLE_INITIALIZED_BUFFER;
}
+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,%dn8", cdev->linux_earlycon_name,
+ (ulong)cdev->phys_base, baudrate);
+
+ dev_add_param_fixed(&cdev->class_dev, "linux.bootargs.earlycon", str);
+
+ free(str);
+}
+
static void console_set_stdoutpath(struct console_device *cdev, unsigned baudrate)
{
int id;
@@ -332,6 +347,8 @@ int console_register(struct console_device *newcdev)
console_set_stdoutpath(newcdev, baudrate);
}
+ console_add_earlycon_param(newcdev, baudrate);
+
if (newcdev->setbrg) {
ret = newcdev->setbrg(newcdev, baudrate);
if (ret)