Skip to contentSkip to conversation

Add an earlyprintk debug console

RFC PATCH New Catalin Marinas 6 participants 9 messages Nov 5, 2009 – Nov 10, 2009 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K?nig <[email protected]>

---

The first variant of this patch was posted earlier this year -
http://thread.gmane.org/gmane.linux.ports.arm.kernel/52478 - and there were a few comments but no follow-up patch. I implemented those comments and I think we should merge this (it's much easier to pass earlyprintk on the kernel command line than hacking the printk code to do a printascii).

 arch/arm/Kconfig.debug         |    8 ++++++
 arch/arm/kernel/Makefile       |    1 +
 arch/arm/kernel/early_printk.c |   57 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/kernel/early_printk.c
arch/arm/Kconfig.debug +8 -0
index 1a6f70e..feb7b11 100644
@@ -71,6 +71,14 @@ config DEBUG_LL
 	  in the kernel.  This is helpful if you are debugging code that
 	  executes before the console is initialized.
 
+config EARLY_PRINTK
+	bool "Early printk"
+	depends on DEBUG_LL
+	help
+	  Say Y here if you want to have an early console using the
+	  kernel low-level debugging functions. Add earlyprintk to your
+	  kernel parameters to enable this console.
+
 config DEBUG_ICEDCC
 	bool "Kernel low-level debugging via EmbeddedICE DCC channel"
 	depends on DEBUG_LL
arch/arm/kernel/Makefile +1 -0
index 79087dd..d0e40b7 100644
@@ -52,5 +52,6 @@ endif
 
 head-y			:= head$(MMUEXT).o
 obj-$(CONFIG_DEBUG_LL)	+= debug.o
+obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 extra-y := $(head-y) init_task.o vmlinux.lds
arch/arm/kernel/early_printk.c new file +57 -0

57 lines not on this page · raw message

#1 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

Quoted 8 lines · Catalin Marinas

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K?nig <[email protected]>
Quoted 8 lines

---

The first variant of this patch was posted earlier this year -
http://thread.gmane.org/gmane.linux.ports.arm.kernel/52478 - and there were a few comments but no follow-up patch. I implemented those comments and I think we should merge this (it's much easier to pass earlyprintk on the kernel command line than hacking the printk code to do a printascii).

Nice :)

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#2 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

In reply to Catalin Marinas
Quoted 2 lines

-----Original Message-----

From: [email protected] [mailto:linux-arm-kernel-

Quoted 10 lines

bounces at lists.infradead.org] On Behalf Of Catalin Marinas
Sent: Thursday, November 05, 2009 4:35 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Sascha Hauer; Uwe Kleine-K?nig
Subject: [RFC PATCH] Add an earlyprintk debug console

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Nice work...
Linux-omap has been using for couple of years this hackery, which finally has a solution now:

kernel/printk.c +3 -0
index f38b07f..1def076 100644
@@ -36,6 +36,10 @@
 
+#ifdef CONFIG_DEBUG_LL
+       printascii(printk_buf);
+#endif
 
        p = printk_buf;
 
 
Quoted 5 lines
Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K?nig <[email protected]>

---

#3 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

Hello,

Quoted 22 lines · Vikram
Quoted 9 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel- bounces at lists.infradead.org] On Behalf Of Catalin Marinas
Sent: Thursday, November 05, 2009 4:35 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Sascha Hauer; Uwe Kleine-K?nig
Subject: [RFC PATCH] Add an earlyprintk debug console

Quoted 4 lines

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Nice work...
Linux-omap has been using for couple of years this hackery, which finally has a solution now:

kernel/printk.c +0 -0
index f38b07f..1def076 100644

kernel/printk.c line 41

Quoted 6 lines
kernel/printk.c +3 -0
@@ -36,6 +36,10 @@
 
+#ifdef CONFIG_DEBUG_LL
+       printascii(printk_buf);
+#endif
 
        p = printk_buf;

I guess this won't be accepted, as kernel/printk.c is generic code, CONFIG_DEBUG_LL is ARM specific. (And IIRC you need to declare printascii first.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#4 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

In reply to Catalin Marinas

Hello Catalin,

Quoted 8 lines · Catalin Marinas

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K?nig <[email protected]>
Quoted 8 lines

---

The first variant of this patch was posted earlier this year -
http://thread.gmane.org/gmane.linux.ports.arm.kernel/52478 - and there were a few comments but no follow-up patch. I implemented those comments and I think we should merge this (it's much easier to pass earlyprintk on the kernel command line than hacking the printk code to do a printascii).

Great that you pick that up!

Quoted 42 lines
 arch/arm/Kconfig.debug         |    8 ++++++
 arch/arm/kernel/Makefile       |    1 +
 arch/arm/kernel/early_printk.c |   57 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/kernel/early_printk.c
arch/arm/Kconfig.debug +8 -0
index 1a6f70e..feb7b11 100644
@@ -71,6 +71,14 @@ config DEBUG_LL
 	  in the kernel.  This is helpful if you are debugging code that
 	  executes before the console is initialized.
 
+config EARLY_PRINTK
+	bool "Early printk"
+	depends on DEBUG_LL
+	help
+	  Say Y here if you want to have an early console using the
+	  kernel low-level debugging functions. Add earlyprintk to your
+	  kernel parameters to enable this console.
+
 config DEBUG_ICEDCC
 	bool "Kernel low-level debugging via EmbeddedICE DCC channel"
 	depends on DEBUG_LL
arch/arm/kernel/Makefile +1 -0
index 79087dd..d0e40b7 100644
@@ -52,5 +52,6 @@ endif
 
 head-y			:= head$(MMUEXT).o
 obj-$(CONFIG_DEBUG_LL)	+= debug.o
+obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 extra-y := $(head-y) init_task.o vmlinux.lds
arch/arm/kernel/early_printk.c new file +0 -0
new file mode 100644
index 0000000..85aa2b2

arch/arm/kernel/early_printk.c line 4

Quoted 4 lines
arch/arm/kernel/early_printk.c new file +4 -0
@@ -0,0 +1,57 @@
+/*
+ *  linux/arch/arm/kernel/early_printk.c
+ *
+ *  Copyright (C) 2009 Sascha Hauer <[email protected]>

<nitpick>
remove one space before "linux" and "Copyright"
</nitpick>

Quoted 11 lines
arch/arm/kernel/early_printk.c new file +11 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/init.h>
+
+extern void printch(int);

arch/arm/kernel/early_printk.c line 25

Quoted 10 lines
arch/arm/kernel/early_printk.c new file +10 -0
+
+static void early_write(const char *s, unsigned n)
+{
+	while (n-- > 0) {
+		if (*s == '\n')
+			printch('\r');
+		printch(*s);
+		s++;
+	}
+}

Can you better use uart_console_write here? (If yes, don't forget to select CONFIG_SERIAL_CORE.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#5 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

Hi Uwe,

Quoted 15 lines · Uwe Kleine-K?nig

arch/arm/kernel/early_printk.c line 4

Quoted 10 lines · Catalin Marinas
arch/arm/kernel/early_printk.c new file +4 -0
new file mode 100644
index 0000000..85aa2b2
@@ -0,0 +1,57 @@
+/*
+ *  linux/arch/arm/kernel/early_printk.c
+ *
+ *  Copyright (C) 2009 Sascha Hauer <[email protected]>

<nitpick>
remove one space before "linux" and "Copyright"
</nitpick>

That's how many other files with Russell's copyright were written (e.g. drivers/serial/serial_core.c, mmu.c etc.), so we just follow the tradition :-).

Quoted 4 lines
Quoted 4 lines
arch/arm/kernel/early_printk.c new file +4 -0
+static void early_write(const char *s, unsigned n)
+{
+     while (n-- > 0) {
+             if (*s == '\n')
Quoted 8 lines

arch/arm/kernel/early_printk.c line 25

Quoted 5 lines
arch/arm/kernel/early_printk.c new file +5 -0
+                     printch('\r');
+             printch(*s);
+             s++;
+     }
+}

Can you better use uart_console_write here? (If yes, don't forget to select CONFIG_SERIAL_CORE.)

This early console should work with ICE DCC as well, so adding the uart_* calls may be a bit confusing (plus one more indirection of calls to drop the first argument passed to printch by uart_console_write). The x86 variant doesn't do this either.

Signature · 1 line
Catalin
#6 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

Hello,

Quoted 17 lines · Catalin Marinas
Quoted 15 lines · Uwe Kleine-K?nig

arch/arm/kernel/early_printk.c line 4

Quoted 10 lines · Catalin Marinas
arch/arm/kernel/early_printk.c new file +4 -0
new file mode 100644
index 0000000..85aa2b2
@@ -0,0 +1,57 @@
+/*
+ *  linux/arch/arm/kernel/early_printk.c
+ *
+ *  Copyright (C) 2009 Sascha Hauer <[email protected]>

<nitpick>
remove one space before "linux" and "Copyright"
</nitpick>

Quoted 3 lines

That's how many other files with Russell's copyright were written (e.g. drivers/serial/serial_core.c, mmu.c etc.), so we just follow the tradition :-).

OK, will check and send a few patches :-) Honestly, I don't care much. Wouldn't have bothered without my comment below.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
arch/arm/kernel/early_printk.c new file +4 -0
+static void early_write(const char *s, unsigned n)
+{
+     while (n-- > 0) {
+             if (*s == '\n')
Quoted 8 lines

arch/arm/kernel/early_printk.c line 25

Quoted 5 lines
arch/arm/kernel/early_printk.c new file +5 -0
+                     printch('\r');
+             printch(*s);
+             s++;
+     }
+}

Can you better use uart_console_write here? (If yes, don't forget to select CONFIG_SERIAL_CORE.)

Quoted 3 lines

This early console should work with ICE DCC as well, so adding the uart_* calls may be a bit confusing (plus one more indirection of calls to drop the first argument passed to printch by uart_console_write).

My comment was a question on purpose. If you don't like it it's OK for me, too.

Quoted 2 lines

The
x86 variant doesn't do this either.

You have no ambition to be better than x86? :-)

Anyhow:

Best regards and thanks for picking that patch up
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#7 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

In reply to Catalin Marinas
Quoted 9 lines · On Thu, 05 Nov 2009 12:35:12 +0000 Catalin Marinas <[email protected]>…

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K?nig <[email protected]>

---

Finally :) Hate having to hacking in printascii everytime I want debuginfo.

Quoted 114 lines

The first variant of this patch was posted earlier this year -
http://thread.gmane.org/gmane.linux.ports.arm.kernel/52478 - and there were a few comments but no follow-up patch. I implemented those comments and I think we should merge this (it's much easier to pass earlyprintk on the kernel command line than hacking the printk code to do a printascii).

 arch/arm/Kconfig.debug         |    8 ++++++
 arch/arm/kernel/Makefile       |    1 +
 arch/arm/kernel/early_printk.c |   57 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/kernel/early_printk.c
arch/arm/Kconfig.debug +8 -0
index 1a6f70e..feb7b11 100644
@@ -71,6 +71,14 @@ config DEBUG_LL
 	  in the kernel.  This is helpful if you are debugging code that
 	  executes before the console is initialized.
 
+config EARLY_PRINTK
+	bool "Early printk"
+	depends on DEBUG_LL
+	help
+	  Say Y here if you want to have an early console using the
+	  kernel low-level debugging functions. Add earlyprintk to your
+	  kernel parameters to enable this console.
+
 config DEBUG_ICEDCC
 	bool "Kernel low-level debugging via EmbeddedICE DCC channel"
 	depends on DEBUG_LL
arch/arm/kernel/Makefile +1 -0
index 79087dd..d0e40b7 100644
@@ -52,5 +52,6 @@ endif
 
 head-y			:= head$(MMUEXT).o
 obj-$(CONFIG_DEBUG_LL)	+= debug.o
+obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 extra-y := $(head-y) init_task.o vmlinux.lds
arch/arm/kernel/early_printk.c new file +57 -0
new file mode 100644
index 0000000..85aa2b2
@@ -0,0 +1,57 @@
+/*
+ *  linux/arch/arm/kernel/early_printk.c
+ *
+ *  Copyright (C) 2009 Sascha Hauer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/init.h>
+
+extern void printch(int);
+
+static void early_write(const char *s, unsigned n)
+{
+	while (n-- > 0) {
+		if (*s == '\n')
+			printch('\r');
+		printch(*s);
+		s++;
+	}
+}
+
+static void early_console_write(struct console *con, const char *s, unsigned n)
+{
+	early_write(s, n);
+}
+
+static struct console early_console = {
+	.name =		"earlycon",
+	.write =	early_console_write,
+	.flags =	CON_PRINTBUFFER | CON_BOOT,
+	.index =	-1,
+};
+
+asmlinkage void early_printk(const char *fmt, ...)
+{
+	char buf[512];
+	int n;
+	va_list ap;
+
+	va_start(ap, fmt);
+	n = vscnprintf(buf, sizeof(buf), fmt, ap);
+	early_write(buf, n);
+	va_end(ap);
+}
+
+static int __init setup_early_printk(char *buf)
+{
+	register_console(&early_console);
+	return 0;
+}
+
+early_param("earlyprintk", setup_early_printk);

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 1 line
Kristoffer Ericson <[email protected]>
#8 lore raw

RFC PATCH 1/1 Add an earlyprintk debug console

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

This patch allows an earlyprintk console if CONFIG_DEBUG_LL is enabled, using the printch asm function.

The patch is based on the original work by Sascha Hauer.

Cc Sascha Hauer <[email protected]>
Cc Uwe Kleine-K??nig <[email protected]>

Yes, please. Figuring out debug_ll means earlyprintk is non-trivial and having to patch the code to get the output is unnice.

ACK.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html