[PATCH 19/20] fbconsole: adapt logging depending on activated streams

Ahmad Fatoum a.fatoum at barebox.org
Sun May 3 01:33:21 PDT 2026


The console_device::f_active member is only set after the console has
been successfully opened. Setting it earlier is not feasible as that
means a poller could attempt outputting on a console while it's being
enabled.

Instead, let's pass the activation flags as argument to the optional
open callback. The callback is only used by the netconsole and the
fbconsole.

This resolves two issues at the same time:

- We can suppress log messages when the device is briefly opened via
  `echo -a /dev/fbconsoleX MESSAGE`. Otherwise writing a message while
  the fbconsole is not activated for a CONSOLE_STD* stream, would each
  time result in a message like "fb0: framebuffer console WxH
  activated".

- We can replay all accumulated log messages, so users without access
  to the serial output still see what had transpired prior to console
  activation. This is especially useful for the framebuffer console as
  it does not support output on its own.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 common/console.c          |  8 ++++----
 common/serdev.c           |  2 +-
 drivers/video/fbconsole.c | 12 ++++++++----
 include/console.h         |  4 ++--
 net/netconsole.c          |  2 +-
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/common/console.c b/common/console.c
index acb4c772672c..fd859b97bf4a 100644
--- a/common/console.c
+++ b/common/console.c
@@ -48,12 +48,12 @@ static struct kfifo __console_output_fifo;
 static struct kfifo *console_input_fifo = &__console_input_fifo;
 static struct kfifo *console_output_fifo = &__console_output_fifo;
 
-int console_open(struct console_device *cdev)
+int console_open(struct console_device *cdev, unsigned activate)
 {
 	int ret;
 
 	if (cdev->open && !cdev->open_count) {
-		ret = cdev->open(cdev);
+		ret = cdev->open(cdev, activate);
 		if (ret)
 			return ret;
 	}
@@ -102,7 +102,7 @@ int console_set_active(struct console_device *cdev, unsigned flag)
 		if (ret)
 			return ret;
 	} else {
-		ret = console_open(cdev);
+		ret = console_open(cdev, flag);
 		if (ret)
 			return ret;
 	}
@@ -311,7 +311,7 @@ static int fops_open(struct cdev *cdev, unsigned long flags)
 	if ((flags & (O_WRONLY | O_RDWR)) && !priv->puts )
 		return -EPERM;
 
-	return console_open(priv);
+	return console_open(priv, 0);
 }
 
 static int fops_close(struct cdev *dev)
diff --git a/common/serdev.c b/common/serdev.c
index 1c8cfbd59447..319a17580760 100644
--- a/common/serdev.c
+++ b/common/serdev.c
@@ -80,7 +80,7 @@ int serdev_device_open(struct serdev_device *serdev)
 	if (ret)
 		goto err_free_fifo;
 
-	ret = console_open(cdev);
+	ret = console_open(cdev, 0);
 	if (ret)
 		goto err_poller_unregister;
 
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 3a2a680fc719..a86005ada244 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -922,7 +922,7 @@ static int setup_font(struct fbc_priv *priv)
 	return 0;
 }
 
-static int fbc_open(struct console_device *cdev)
+static int fbc_open(struct console_device *cdev, unsigned activate)
 {
 	struct fbc_priv *priv = container_of(cdev,
 					struct fbc_priv, cdev);
@@ -941,11 +941,15 @@ static int fbc_open(struct console_device *cdev)
 
 	priv->state = LIT;
 
-	dev_info(priv->cdev.dev, "framebuffer console %dx%d activated\n",
-		priv->cols, priv->rows);
-
 	priv->active = true;
 
+	if (activate)
+		dev_info(priv->cdev.dev, "framebuffer console %dx%d activated\n",
+			priv->cols, priv->rows);
+
+	if (activate & CONSOLE_STDERR)
+		log_print(&priv->cdev, 0, GENMASK(LOGLEVEL, 0));
+
 	return 0;
 }
 
diff --git a/include/console.h b/include/console.h
index cfd2480f30d3..4b2893d5c4df 100644
--- a/include/console.h
+++ b/include/console.h
@@ -41,7 +41,7 @@ struct console_device {
 	int (*setbrg)(struct console_device *cdev, int baudrate);
 	void (*flush)(struct console_device *cdev);
 	int (*set_mode)(struct console_device *cdev, enum console_mode mode);
-	int (*open)(struct console_device *cdev);
+	int (*open)(struct console_device *cdev, unsigned activate);
 	int (*close)(struct console_device *cdev);
 	int (*get_size)(struct console_device *cdev, int *width, int *height);
 
@@ -110,7 +110,7 @@ struct console_device *of_console_get_by_alias(const char *alias);
 
 #define CFG_PBSIZE (CONFIG_CBSIZE+sizeof(CONFIG_PROMPT)+16)
 
-int console_open(struct console_device *cdev);
+int console_open(struct console_device *cdev, unsigned activate);
 int console_close(struct console_device *cdev);
 int console_set_active(struct console_device *cdev, unsigned active);
 unsigned console_get_active(struct console_device *cdev);
diff --git a/net/netconsole.c b/net/netconsole.c
index 859cfe8e6f35..f2e9447526bf 100644
--- a/net/netconsole.c
+++ b/net/netconsole.c
@@ -94,7 +94,7 @@ static void nc_putc(struct console_device *cdev, char c)
 	priv->busy = 0;
 }
 
-static int nc_open(struct console_device *cdev)
+static int nc_open(struct console_device *cdev, unsigned activate)
 {
 	struct nc_priv *priv = container_of(cdev,
 					struct nc_priv, cdev);
-- 
2.47.3




More information about the barebox mailing list