mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/8] console: add new $global.bootm.earlycon parameter
Date: Mon, 23 May 2022 11:25:19 +0200	[thread overview]
Message-ID: <20220523092526.791716-1-a.fatoum@pengutronix.de> (raw)

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>
---
 common/bootm.c    | 24 ++++++++++++++++++++++++
 common/console.c  | 17 +++++++++++++++++
 include/console.h |  2 ++
 3 files changed, 43 insertions(+)

diff --git a/common/bootm.c b/common/bootm.c
index 3c80e8bf949b..712e6ebe4911 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 8727b187cf7c..c442c2dde132 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)
diff --git a/include/console.h b/include/console.h
index 5d5783ca6668..7fea8eeb9e7d 100644
--- a/include/console.h
+++ b/include/console.h
@@ -53,6 +53,8 @@ struct console_device {
 	unsigned int baudrate_param;
 
 	const char *linux_console_name;
+	const char *linux_earlycon_name;
+	void __iomem *phys_base;
 
 	struct cdev devfs;
 	struct cdev_operations fops;
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


             reply	other threads:[~2022-05-23 10:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23  9:25 Ahmad Fatoum [this message]
2022-05-23  9:25 ` [PATCH 2/8] serial: ns16550: add $global.bootm.earlycon fixup support Ahmad Fatoum
2022-05-23  9:25 ` [PATCH 3/8] serial: amba-pl011: " Ahmad Fatoum
2022-05-23  9:25 ` [PATCH 4/8] serial: atmel: " Ahmad Fatoum
2022-05-23  9:25 ` [PATCH 5/8] serial: imx: " Ahmad Fatoum
2022-05-23 11:04   ` Sascha Hauer
2022-05-23 11:10     ` Ahmad Fatoum
2022-05-23 11:25       ` Sascha Hauer
2022-05-24  7:35         ` Ahmad Fatoum
2022-06-09  9:25           ` Sascha Hauer
2022-05-23  9:25 ` [PATCH 6/8] serial: litex: add linux console/earlycon " Ahmad Fatoum
2022-05-23  9:25 ` [PATCH 7/8] serial: lpuart: add $global.bootm.earlycon " Ahmad Fatoum
2022-05-23  9:25 ` [PATCH 8/8] video: efi_gop: add $global.bootm.earlycon fixup for framebuffer console Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220523092526.791716-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox