[PATCH 7/7] commands: dmesg: give log_print a console_device parameter
Ahmad Fatoum
a.fatoum at barebox.org
Mon Apr 13 03:09:42 PDT 2026
log_print currently prints out unconditionally to stdout and thus has no
support for printing to a single specific console, e.g. the framebuffer
console.
Make use of the new console_printf() to address this.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
commands/dmesg.c | 2 +-
common/console_common.c | 17 +++++++++--------
include/linux/printk.h | 3 ++-
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/commands/dmesg.c b/commands/dmesg.c
index 0313c8cdea74..06796287aaec 100644
--- a/commands/dmesg.c
+++ b/commands/dmesg.c
@@ -158,7 +158,7 @@ static int do_dmesg(int argc, char *argv[])
return 0;
}
- ret = log_print(flags, levels);
+ ret = log_print(CONSOLE_DEV_STDOUT, flags, levels);
if (ret)
return 1;
diff --git a/common/console_common.c b/common/console_common.c
index 310534affa58..de0a213f833c 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -215,13 +215,14 @@ int log_writefile(const char *filepath)
/**
* log_print - print the log buffer
*
+ * @con: Console device to print to
* @flags: Flags selecting output formatting
* @levels: bitmask of loglevels to print, 0 for all
*
* This function prints the messages of the selected levels; optionally with
* additional information and formatting.
*/
-int log_print(unsigned flags, unsigned levels)
+int log_print(struct console_device *con, unsigned flags, unsigned levels)
{
struct log_entry *log;
unsigned long last = 0;
@@ -237,30 +238,30 @@ int log_print(unsigned flags, unsigned levels)
if (!(flags & (BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME
| BAREBOX_LOG_DIFF_TIME)))
- print_colored_log_level(CONSOLE_DEV_STDOUT, log->level);
+ print_colored_log_level(con, log->level);
if (flags & BAREBOX_LOG_PRINT_RAW)
- printf("<%i>", log->level);
+ console_printf(con, "<%i>", log->level);
/* convert ns to us */
do_div(time_ns, 1000);
time = time_ns;
if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
- printf("[");
+ console_printf(con, "[");
if (flags & BAREBOX_LOG_PRINT_TIME)
- printf("%10luus", time);
+ console_printf(con, "%10luus", time);
if (flags & BAREBOX_LOG_DIFF_TIME) {
- printf(" < %10luus", time - last);
+ console_printf(con, " < %10luus", time - last);
last = time;
}
if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
- printf("] ");
+ console_printf(con, "] ");
- printf("%s", log->msg);
+ console_printf(con, "%s", log->msg);
}
return 0;
diff --git a/include/linux/printk.h b/include/linux/printk.h
index deaaa44b31a7..4d6df821e1f1 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -192,7 +192,8 @@ extern void log_clean(unsigned int limit);
#define BAREBOX_LOG_PRINT_TIME BIT(0)
int log_writefile(const char *filepath);
-int log_print(unsigned flags, unsigned levels);
+struct console_device;
+int log_print(struct console_device *console, unsigned flags, unsigned levels);
struct va_format {
const char *fmt;
--
2.47.3
More information about the barebox
mailing list