summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2022-05-03 16:13:27 +0300
committerTom Rini <trini@konsulko.com>2022-08-31 19:16:01 +0300
commit04a20ca5dc9f9eb8929097ff0c93cfe905bc7191 (patch)
tree2440575898a261dcfaa19cc2932a5d49e1a658f8 /common/console.c
parent1573b6a86993fcf80d4badc866a46b78df7e6bda (diff)
downloadu-boot-04a20ca5dc9f9eb8929097ff0c93cfe905bc7191.tar.xz
common/console.c: prevent pre-console buffer contents from being added to itself
I do not have any non-serial output devices, so a print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL) does nothing for me. However, I was manually inspected the pre-console buffer using md.b, and I noticed that the early part of it was repeated. The reason is that the first call of print_pre_console_buffer(), from console_init_f(), ends up invoking puts() with the contents of the buffer at that point, and puts() at that point ends up in the else branch of if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ fputs(stdout, s); } else { /* Send directly to the handler */ pre_console_puts(s); serial_puts(s); } so indeed the contents is added again. That can be somewhat confusing (both when reading the buffer manually, but also if it did actually come out on some device). So disable all use of the pre-console buffer while print_pre_console_buffer() is emitting it. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/console.c b/common/console.c
index bde9412239..e783f309bf 100644
--- a/common/console.c
+++ b/common/console.c
@@ -600,6 +600,9 @@ static void pre_console_putc(const char c)
{
char *buffer;
+ if (gd->precon_buf_idx < 0)
+ return;
+
buffer = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), CONFIG_VAL(PRE_CON_BUF_SZ));
buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
@@ -609,13 +612,16 @@ static void pre_console_putc(const char c)
static void pre_console_puts(const char *s)
{
+ if (gd->precon_buf_idx < 0)
+ return;
+
while (*s)
pre_console_putc(*s++);
}
static void print_pre_console_buffer(int flushpoint)
{
- unsigned long in = 0, out = 0;
+ long in = 0, out = 0;
char buf_out[CONFIG_VAL(PRE_CON_BUF_SZ) + 1];
char *buf_in;
@@ -632,6 +638,7 @@ static void print_pre_console_buffer(int flushpoint)
buf_out[out] = 0;
+ gd->precon_buf_idx = -1;
switch (flushpoint) {
case PRE_CONSOLE_FLUSHPOINT1_SERIAL:
puts(buf_out);
@@ -640,6 +647,7 @@ static void print_pre_console_buffer(int flushpoint)
console_puts_select(stdout, false, buf_out);
break;
}
+ gd->precon_buf_idx = in;
}
#else
static inline void pre_console_putc(const char c) {}