mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Juergen Borleis <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 09/15] pstore: add console support
Date: Fri, 15 Mar 2019 10:14:47 +0100	[thread overview]
Message-ID: <20190315091453.22393-9-jbe@pengutronix.de> (raw)
In-Reply-To: <20190315091453.22393-1-jbe@pengutronix.de>

From: Philipp Zabel <p.zabel@pengutronix.de>

Add support for writing console messages to pstore.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Documentation-added-by: Juergen Borleis <jbe@pengutronix.de>
---
 Documentation/filesystems/pstore.rst |  4 ++
 fs/pstore/Kconfig                    |  6 +++
 fs/pstore/platform.c                 | 74 ++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/Documentation/filesystems/pstore.rst b/Documentation/filesystems/pstore.rst
index 6215f2296c..c128daae9f 100644
--- a/Documentation/filesystems/pstore.rst
+++ b/Documentation/filesystems/pstore.rst
@@ -75,3 +75,7 @@ All pstore files that could be found are added to the /pstore directory. This is
 a read-only filesystem. If you disable the Kconfig option FS_PSTORE_RAMOOPS_RO,
 the RAMOOPS area is reset and its ECC recalculated. But that does not allow any
 writes from Barebox into that area.
+
+If the menu entry ``FS_PSTORE_CONSOLE`` is enabled, Barebox itself will add all
+its own console output to the *ramoops:console* part, which enables the regular
+userland later on to have access to the bootloaders output.
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 0e042cb162..30c2de19c8 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -8,6 +8,12 @@ menuconfig FS_PSTORE
 
 if FS_PSTORE
 
+config FS_PSTORE_CONSOLE
+	bool
+	prompt "Log console messages"
+	help
+	  When the option is enabled, pstore will log console messages.
+
 config FS_PSTORE_RAMOOPS
 	bool
 	depends on RELOCATABLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 6eebad63de..5d0018693b 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
+#include <console.h>
 #include <malloc.h>
 #include <printk.h>
 #include <module.h>
@@ -43,6 +44,77 @@ void pstore_set_kmsg_bytes(int bytes)
 	kmsg_bytes = bytes;
 }
 
+#ifdef CONFIG_FS_PSTORE_CONSOLE
+static void pstore_console_write(const char *s, unsigned c)
+{
+	const char *e = s + c;
+
+	while (s < e) {
+		struct pstore_record record = {
+			.type = PSTORE_TYPE_CONSOLE,
+			.psi = psinfo,
+		};
+
+		if (c > psinfo->bufsize)
+			c = psinfo->bufsize;
+
+		record.buf = (char *)s;
+		record.size = c;
+		psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &record.id, 0,
+				  record.buf, 0, record.size, psinfo);
+		s += c;
+		c = e - s;
+	}
+}
+
+static int pstore_console_puts(struct console_device *cdev, const char *s)
+{
+	pstore_console_write(s, strlen(s));
+	return strlen(s);
+}
+
+static void pstore_console_putc(struct console_device *cdev, char c)
+{
+	const char s[1] = { c };
+
+	pstore_console_write(s, 1);
+}
+
+static void pstore_console_capture_log(void)
+{
+	struct log_entry *log;
+
+	list_for_each_entry(log, &barebox_logbuf, list)
+		pstore_console_write(log->msg, strlen(log->msg));
+}
+
+static struct console_device *pstore_cdev;
+
+static void pstore_register_console(void)
+{
+	struct console_device *cdev;
+	int ret;
+
+	cdev = xzalloc(sizeof(struct console_device));
+	pstore_cdev = cdev;
+
+	cdev->puts = pstore_console_puts;
+	cdev->putc = pstore_console_putc;
+	cdev->devname = "pstore";
+	cdev->devid = DEVICE_ID_SINGLE;
+
+        ret = console_register(cdev);
+        if (ret)
+                pr_err("registering failed with %s\n", strerror(-ret));
+
+	pstore_console_capture_log();
+
+	console_set_active(pstore_cdev, CONSOLE_STDOUT);
+}
+#else
+static void pstore_register_console(void) {}
+#endif
+
 static int pstore_write_compat(enum pstore_type_id type,
 			       enum kmsg_dump_reason reason,
 			       u64 *id, unsigned int part, int count,
@@ -81,6 +153,8 @@ int pstore_register(struct pstore_info *psi)
 
 	pstore_get_records(0);
 
+	pstore_register_console();
+
 	pr_info("Registered %s as persistent store backend\n", psi->name);
 
 	return 0;
-- 
2.11.0


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

  parent reply	other threads:[~2019-03-15  9:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15  9:14 [PATCH 01/15] ramoops: probe from device tree if OFTREE is enabled Juergen Borleis
2019-03-15  9:14 ` [PATCH 02/15] pstore/ram: add Device Tree bindings Juergen Borleis
2019-03-15  9:14 ` [PATCH 03/15] ramoops: use DT reserved-memory bindings Juergen Borleis
2019-03-15  9:14 ` [PATCH 04/15] pstore: Make ramoops_init_przs generic for other prz arrays Juergen Borleis
2019-03-15  9:14 ` [PATCH 05/15] pstore/ram: Do not use stack VLA for parity workspace Juergen Borleis
2019-03-15  9:14 ` [PATCH 06/15] pstore: improve error report for failed setup Juergen Borleis
2019-03-15  9:14 ` [PATCH 07/15] pstore/ram: Clarify resource reservation labels Juergen Borleis
2019-03-15  9:14 ` [PATCH 08/15] pstore: Extract common arguments into structure Juergen Borleis
2019-03-15  9:14 ` Juergen Borleis [this message]
2019-03-15  9:14 ` [PATCH 10/15] pstore: Switch pstore_mkfile to pass record Juergen Borleis
2019-03-15  9:14 ` [PATCH 11/15] pstore: Replace arguments for read() API Juergen Borleis
2019-03-15  9:14 ` [PATCH 12/15] pstore: Replace arguments for write() API Juergen Borleis
2019-03-15  9:14 ` [PATCH 13/15] pstore: pass ramoops configuration to kernel via device tree Juergen Borleis
2019-03-15  9:14 ` [PATCH 14/15] pstore: ramoops: allow zapping invalid buffers in read-only mode Juergen Borleis
2019-03-15  9:14 ` [PATCH 15/15] pstore/doc: fix layout Juergen Borleis
2019-03-18  8:44 ` [PATCH 01/15] ramoops: probe from device tree if OFTREE is enabled Sascha Hauer

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=20190315091453.22393-9-jbe@pengutronix.de \
    --to=jbe@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