Yu-Ping Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/37667 )
Change subject: libpayload: Read from cbmem console ......................................................................
libpayload: Read from cbmem console
To support the new recovery ui (the Groot project) and show cbmem log on the screen, add a function cbmem_console_read() to read from cbmem console. Non-printable characters are automatically replaced with '?' to ensure that the returned string is printable.
BRANCH=none BUG=b:146105976 TEST=emerge-nami libpayload
Change-Id: Ie324055f5fd8276f1d833fc9d04f60a792dbb9f6 Signed-off-by: Yu-Ping Wu yupingso@chromium.org --- M payloads/libpayload/drivers/cbmem_console.c M payloads/libpayload/include/libpayload.h 2 files changed, 48 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/37667/1
diff --git a/payloads/libpayload/drivers/cbmem_console.c b/payloads/libpayload/drivers/cbmem_console.c index 9435e1c..c6d7ee1 100644 --- a/payloads/libpayload/drivers/cbmem_console.c +++ b/payloads/libpayload/drivers/cbmem_console.c @@ -75,3 +75,50 @@
do_write(buffer, count); } + +void cbmem_console_read(void **buffer_p, size_t *count) +{ + const struct cbmem_console *console_p = cbmem_console_p; + char *console_c; + uint32_t size, cursor, overflow; + + if (!console_p) { + printf("ERROR: No cbmem console found in coreboot table.\n"); + return; + } + + cursor = console_p->cursor & CURSOR_MASK; + overflow = console_p->cursor & OVERFLOW; + if (!overflow && cursor < console_p->size) + size = cursor; + else + size = console_p->size; + + console_c = malloc(size + 1); + if (!console_c) { + printf("ERROR: Not enough memory for console.\n"); + return; + } + console_c[size] = '\0'; + + if (overflow) { + if (cursor >= size) { + printf("cbmem: ERROR: CBMEM console struct is illegal, " + "output may be corrupt or out of order!\n\n"); + cursor = 0; + } + memcpy(console_c, console_p->body + cursor, size - cursor); + memcpy(console_c + size - cursor, console_p->body, cursor); + } else { + memcpy(console_c, console_p->body, size); + } + + /* Slight memory corruption may occur between reboots and give us a few + unprintable characters like '\0'. Replace them with '?' on output. */ + for (cursor = 0; cursor < size; cursor++) + if (!isprint(console_c[cursor]) && !isspace(console_c[cursor])) + console_c[cursor] = '?'; + + *buffer_p = console_c; + *count = size; +} diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 934c368..6d814f1 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -313,6 +313,7 @@ */ void cbmem_console_init(void); void cbmem_console_write(const void *buffer, size_t count); +void cbmem_console_read(void **buffer_p, size_t *count); /** @} */
/* drivers/option.c */