From 297ac72881b89d34f7940020319fd3e2a68fbe67 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 8 Jul 2019 09:47:09 +0200 Subject: pstore: Only capture log messages With this pstore only captures barebox log messages printed with pr_* and dev_*, but no longer anything printed with printf and friends. When capturing the barebox output with pstore only the log messages are of interest, but not the ones printed with printf and certainly not the things typed interactively on the command line. These are logged currently because we register pstore as a barebox console. Instead, hook into pr_puts which only outputs the barebox log messages. Signed-off-by: Sascha Hauer --- fs/pstore/platform.c | 85 ++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 60 deletions(-) (limited to 'fs') diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 755363c309..aafa5559dc 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -44,76 +44,40 @@ 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 int pstore_ready; -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) +void pstore_log(const char *str) { - struct log_entry *log; + uint64_t id; + static int in_pstore; - list_for_each_entry(log, &barebox_logbuf, list) - pstore_console_write(log->msg, strlen(log->msg)); -} + if (!IS_ENABLED(CONFIG_FS_PSTORE_CONSOLE)) + return; -static struct console_device *pstore_cdev; + if (!pstore_ready) + return; -static void pstore_register_console(void) -{ - struct console_device *cdev; - int ret; + if (in_pstore) + return; - cdev = xzalloc(sizeof(struct console_device)); - pstore_cdev = cdev; + in_pstore = 1; - cdev->puts = pstore_console_puts; - cdev->putc = pstore_console_putc; - cdev->devname = "pstore"; - cdev->devid = DEVICE_ID_SINGLE; + psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &id, 0, + str, 0, strlen(str), psinfo); - ret = console_register(cdev); - if (ret) - pr_err("registering failed with %s\n", strerror(-ret)); + in_pstore = 0; +} - pstore_console_capture_log(); +static void pstore_console_capture_log(void) +{ + uint64_t id; + struct log_entry *log, *tmp; - console_set_active(pstore_cdev, CONSOLE_STDOUT); + list_for_each_entry_safe(log, tmp, &barebox_logbuf, list) { + psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &id, 0, + log->msg, 0, strlen(log->msg), psinfo); + } } -#else -static void pstore_register_console(void) {} -#endif static int pstore_write_compat(struct pstore_record *record) { @@ -151,7 +115,8 @@ int pstore_register(struct pstore_info *psi) pstore_get_records(0); - pstore_register_console(); + pstore_console_capture_log(); + pstore_ready = 1; pr_info("Registered %s as persistent store backend\n", psi->name); -- cgit v1.2.3