[PATCH master 38/39] console: introduce helper for printing binary buffers as-is
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Feb 16 00:44:38 PST 2026
Both console_putc(), console_puts() and console->puts always do
LF to CRLF conversion. For cases where this is not desired, code must
manually call console_putc in a loop.
Add a helper to simplify this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
common/console.c | 31 +++++++++++++++++++++++++++++++
include/console.h | 1 +
2 files changed, 32 insertions(+)
diff --git a/common/console.c b/common/console.c
index 8a55fd1a1dc6..62ca57e43b05 100644
--- a/common/console.c
+++ b/common/console.c
@@ -637,6 +637,37 @@ int console_puts(unsigned int ch, const char *str)
}
EXPORT_SYMBOL(console_puts);
+void console_putbin(unsigned int ch, const u8 *str, size_t len)
+{
+ struct console_device *cdev;
+
+ switch (initialized) {
+ case CONSOLE_UNINITIALIZED:
+ console_init_early();
+ fallthrough;
+ case CONSOLE_INITIALIZED_BUFFER:
+ kfifo_put(console_output_fifo, str, len);
+ for (size_t i = 0; i < len; i++)
+ putc_ll(str[i]);
+ return;
+ case CONSOLE_INIT_FULL:
+ for_each_console(cdev) {
+ if (!(cdev->f_active & ch))
+ continue;
+
+ for (size_t i = 0; i < len; i++)
+ cdev->putc(cdev, str[i]);
+ }
+ return;
+ default:
+ /* If we have problems inititalizing our data
+ * get them early
+ */
+ hang();
+ }
+}
+EXPORT_SYMBOL(console_putbin);
+
void console_flush(void)
{
struct console_device *cdev;
diff --git a/include/console.h b/include/console.h
index 149378fc2839..b163c6684ee1 100644
--- a/include/console.h
+++ b/include/console.h
@@ -230,6 +230,7 @@ int arch_ctrlc(void);
/* stdout */
void console_putc(unsigned int ch, const char c);
int console_puts(unsigned int ch, const char *s);
+void console_putbin(unsigned int ch, const u8 *str, size_t len);
void console_flush(void);
int ctrlc(void);
--
2.47.3
More information about the barebox
mailing list