All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] char: ttyprintk: register console
@ 2022-02-15 14:17 Vincent Whitchurch
  2022-02-21 18:27 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Whitchurch @ 2022-02-15 14:17 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman
  Cc: kernel, Vincent Whitchurch, linux-kernel

Register a console in the ttyprintk driver so that it can be selected
for /dev/console with console=ttyprintk on the kernel command line,
similar to other console drivers.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 drivers/char/Kconfig     |  3 ++-
 drivers/char/ttyprintk.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 740811893c57..c553a8a50d03 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -18,7 +18,8 @@ config TTY_PRINTK
 	  The feature is useful to inline user messages with kernel
 	  messages.
 	  In order to use this feature, you should output user messages
-	  to /dev/ttyprintk or redirect console to this TTY.
+	  to /dev/ttyprintk or redirect console to this TTY, or boot
+	  the kernel with console=ttyprintk.
 
 	  If unsure, say N.
 
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index adf941c47506..ed45d04905c2 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -11,6 +11,7 @@
  * of the boot process, for example.
  */
 
+#include <linux/console.h>
 #include <linux/device.h>
 #include <linux/serial.h>
 #include <linux/tty.h>
@@ -163,6 +164,18 @@ static const struct tty_port_operations tpk_port_ops = {
 
 static struct tty_driver *ttyprintk_driver;
 
+static struct tty_driver *ttyprintk_console_device(struct console *c,
+						   int *index)
+{
+	*index = 0;
+	return ttyprintk_driver;
+}
+
+static struct console ttyprintk_console = {
+	.name = "ttyprintk",
+	.device = ttyprintk_console_device,
+};
+
 static int __init ttyprintk_init(void)
 {
 	int ret;
@@ -195,6 +208,8 @@ static int __init ttyprintk_init(void)
 		goto error;
 	}
 
+	register_console(&ttyprintk_console);
+
 	return 0;
 
 error:
@@ -205,6 +220,7 @@ static int __init ttyprintk_init(void)
 
 static void __exit ttyprintk_exit(void)
 {
+	unregister_console(&ttyprintk_console);
 	tty_unregister_driver(ttyprintk_driver);
 	tty_driver_kref_put(ttyprintk_driver);
 	tty_port_destroy(&tpk_port.port);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] char: ttyprintk: register console
  2022-02-15 14:17 [PATCH] char: ttyprintk: register console Vincent Whitchurch
@ 2022-02-21 18:27 ` Greg Kroah-Hartman
  2022-02-24 10:08   ` Vincent Whitchurch
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-02-21 18:27 UTC (permalink / raw)
  To: Vincent Whitchurch; +Cc: Arnd Bergmann, kernel, linux-kernel

On Tue, Feb 15, 2022 at 03:17:49PM +0100, Vincent Whitchurch wrote:
> Register a console in the ttyprintk driver so that it can be selected
> for /dev/console with console=ttyprintk on the kernel command line,
> similar to other console drivers.
> 
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
>  drivers/char/Kconfig     |  3 ++-
>  drivers/char/ttyprintk.c | 16 ++++++++++++++++
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> index 740811893c57..c553a8a50d03 100644
> --- a/drivers/char/Kconfig
> +++ b/drivers/char/Kconfig
> @@ -18,7 +18,8 @@ config TTY_PRINTK
>  	  The feature is useful to inline user messages with kernel
>  	  messages.
>  	  In order to use this feature, you should output user messages
> -	  to /dev/ttyprintk or redirect console to this TTY.
> +	  to /dev/ttyprintk or redirect console to this TTY, or boot
> +	  the kernel with console=ttyprintk.

Why do you want to use this tty device as a console?  What benifit does
that provide?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] char: ttyprintk: register console
  2022-02-21 18:27 ` Greg Kroah-Hartman
@ 2022-02-24 10:08   ` Vincent Whitchurch
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Whitchurch @ 2022-02-24 10:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, kernel, linux-kernel

On Mon, Feb 21, 2022 at 07:27:04PM +0100, Greg Kroah-Hartman wrote:
> On Tue, Feb 15, 2022 at 03:17:49PM +0100, Vincent Whitchurch wrote:
> > Register a console in the ttyprintk driver so that it can be selected
> > for /dev/console with console=ttyprintk on the kernel command line,
> > similar to other console drivers.
> > 
> > Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> > ---
> >  drivers/char/Kconfig     |  3 ++-
> >  drivers/char/ttyprintk.c | 16 ++++++++++++++++
> >  2 files changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> > index 740811893c57..c553a8a50d03 100644
> > --- a/drivers/char/Kconfig
> > +++ b/drivers/char/Kconfig
> > @@ -18,7 +18,8 @@ config TTY_PRINTK
> >  	  The feature is useful to inline user messages with kernel
> >  	  messages.
> >  	  In order to use this feature, you should output user messages
> > -	  to /dev/ttyprintk or redirect console to this TTY.
> > +	  to /dev/ttyprintk or redirect console to this TTY, or boot
> > +	  the kernel with console=ttyprintk.
> 
> Why do you want to use this tty device as a console?  What benifit
> does that provide?

I run Linux on a secondary processor on my SoC.  This secondary
processor doesn't have any output peripherals of its own, so it uses
pstore to put its kernel messages at a fixed location in memory from
which the primary processor can read them out.

In order to access logs from the secondary processor's userspace, a
simple way is to use ttyprintk.  Userspace logs to the console as normal
and the primary processor can read the unified kernel+userspace logs
from the pstore area.

There are similar uses in other cases not involving multiple processors.
I had mentioned on the lists a couple of years ago that I had this patch
(without posting it), and last week I received a request (off-list) for
it from someone who was looking to use it to debug userspace
initialization in postmarketOS on an Android phone (they only had the
ability to retreive the kernel's logs after a reboot using pstore).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-24 10:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 14:17 [PATCH] char: ttyprintk: register console Vincent Whitchurch
2022-02-21 18:27 ` Greg Kroah-Hartman
2022-02-24 10:08   ` Vincent Whitchurch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.