mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 6/7] console: implement console_printf
Date: Mon, 13 Apr 2026 12:09:41 +0200	[thread overview]
Message-ID: <20260413101118.1462119-6-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260413101118.1462119-1-a.fatoum@barebox.org>

printf formats to a buffer and then prints it out with puts().

Allow printing to arbitrary consoles while reusing this logic by adding
a new console_printf().

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/console_common.c | 29 ++++++++++++++++++++++++-----
 include/console.h       |  3 +++
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/common/console_common.c b/common/console_common.c
index 86d9f523b1c5..310534affa58 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -266,7 +266,7 @@ int log_print(unsigned flags, unsigned levels)
 	return 0;
 }
 
-int printf(const char *fmt, ...)
+int console_printf(struct console_device *con, const char *fmt, ...)
 {
 	va_list args;
 	int i;
@@ -282,13 +282,13 @@ int printf(const char *fmt, ...)
 	va_end(args);
 
 	/* Print the string */
-	puts(printbuffer);
+	console_puts(con, printbuffer);
 
 	return i;
 }
-EXPORT_SYMBOL(printf);
+EXPORT_SYMBOL(console_printf);
 
-int vprintf(const char *fmt, va_list args)
+int console_vprintf(struct console_device *con, const char *fmt, va_list args)
 {
 	int i;
 	char printbuffer[CFG_PBSIZE];
@@ -300,10 +300,29 @@ int vprintf(const char *fmt, va_list args)
 	i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
 
 	/* Print the string */
-	puts(printbuffer);
+	console_puts(con, printbuffer);
 
 	return i;
 }
+EXPORT_SYMBOL(console_vprintf);
+
+int printf(const char *fmt, ...)
+{
+	va_list args;
+	int i;
+
+	va_start(args, fmt);
+	i = console_vprintf(CONSOLE_DEV_STDOUT, fmt, args);
+	va_end(args);
+
+	return i;
+}
+EXPORT_SYMBOL(printf);
+
+int vprintf(const char *fmt, va_list args)
+{
+	return console_vprintf(CONSOLE_DEV_STDOUT, fmt, args);
+}
 EXPORT_SYMBOL(vprintf);
 
 struct console_device *console_get_by_dev(struct device *dev)
diff --git a/include/console.h b/include/console.h
index 5a4dbcdf1327..ed5b501b65a4 100644
--- a/include/console.h
+++ b/include/console.h
@@ -248,6 +248,9 @@ int console_puts(struct console_device *con, const char *s);
 void console_putbin(struct console_device *con, const u8 *str, size_t len);
 void console_flush(void);
 
+int console_printf(struct console_device *con, const char *fmt, ...) __printf(2, 3);
+int console_vprintf(struct console_device *con, const char *fmt, va_list args);
+
 int ctrlc(void);
 int ctrlc_non_interruptible(void);
 void ctrlc_handled(void);
-- 
2.47.3




  parent reply	other threads:[~2026-04-13 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 10:09 [PATCH 1/7] console: return characters written from console_putc Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 2/7] stddef: implement scoped_var for use in iterators Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 3/7] console: have for_each_console declare the iterator internally Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 4/7] console: make console_puts and friends accept a console_device Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 5/7] console: implement console_putc in terms of console_putbin Ahmad Fatoum
2026-04-13 10:09 ` Ahmad Fatoum [this message]
2026-04-13 10:09 ` [PATCH 7/7] commands: dmesg: give log_print a console_device parameter Ahmad Fatoum
2026-04-13 12:28 ` [PATCH 1/7] console: return characters written from console_putc 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=20260413101118.1462119-6-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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