From 19fdcca467ad3436d68ef88899b4dcd78154a9c6 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 19 Apr 2017 15:36:09 -0700 Subject: coreboot: Adapt to upstream CBMEM console changes coreboot's CBMEM console format changed with https://review.coreboot.org/#/c/18301. This patch adapts the SeaBIOS implementation to support the new format. (SeaBIOS versions with this patch will continue to work fine with older version of coreboot. SeaBIOS versions without this patch may fail to log messages to the CBMEM console if run with newer versions of coreboot, but should not experience any more serious issues than that.) Signed-off-by: Julius Werner --- src/fw/coreboot.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 4957b80d..7214f8ae 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -80,10 +80,12 @@ struct cb_cbmem_ref { #define CB_TAG_CBMEM_CONSOLE 0x17 struct cbmem_console { - u32 buffer_size; - u32 buffer_cursor; - u8 buffer_body[0]; + u32 size; + u32 cursor; + u8 body[0]; } PACKED; +#define CBMC_CURSOR_MASK ((1 << 28) - 1) +#define CBMC_OVERFLOW (1 << 31) static struct cbmem_console *cbcon = NULL; static u16 @@ -220,9 +222,16 @@ void coreboot_debug_putc(char c) return; if (!cbcon) return; - u32 cursor = cbcon->buffer_cursor++; - if (cursor < cbcon->buffer_size) - cbcon->buffer_body[cursor] = c; + u32 cursor = cbcon->cursor & CBMC_CURSOR_MASK; + u32 flags = cbcon->cursor & ~CBMC_CURSOR_MASK; + if (cursor >= cbcon->size) + return; // Old coreboot version with legacy overflow mechanism. + cbcon->body[cursor++] = c; + if (cursor >= cbcon->size) { + cursor = 0; + flags |= CBMC_OVERFLOW; + } + cbcon->cursor = flags | cursor; } /**************************************************************** -- cgit