[Concept,04/13] console: Add length-based pre-console support

Message ID 20260204001002.2638622-5-sjg@u-boot.org
State New
Headers
Series Add putsn() for length-based console output |

Commit Message

Simon Glass Feb. 4, 2026, 12:09 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add pre_console_putsn() for length-based output to the pre-console
buffer. This allows putsn() to work correctly before the console is
fully initialised.

Refactor pre_console_puts() to use pre_console_putsn() to reduce code
duplication.

Co-developed-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 common/console.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/common/console.c b/common/console.c
index 581c383ce5e..c058d3d30a2 100644
--- a/common/console.c
+++ b/common/console.c
@@ -721,15 +721,20 @@  static void pre_console_putc(const char c)
 	unmap_sysmem(buffer);
 }
 
-static void pre_console_puts(const char *s)
+static void pre_console_putsn(const char *s, int len)
 {
 	if (gd->precon_buf_idx < 0)
 		return;
 
-	while (*s)
+	while (len--)
 		pre_console_putc(*s++);
 }
 
+static void pre_console_puts(const char *s)
+{
+	pre_console_putsn(s, strlen(s));
+}
+
 static void print_pre_console_buffer(int flushpoint)
 {
 	long in = 0, out = 0;
@@ -762,6 +767,7 @@  static void print_pre_console_buffer(int flushpoint)
 }
 #else
 static inline void pre_console_putc(const char c) {}
+static inline void pre_console_putsn(const char *s, int len) {}
 static inline void pre_console_puts(const char *s) {}
 static inline void print_pre_console_buffer(int flushpoint) {}
 #endif