From 8ec61e52a6a27ed518d0abb5a19d6261edf9dab1 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 9 Aug 2013 00:40:06 -0700 Subject: [PATCH] cbmem: Terminate the cbmem console at the cursor position. If the cbmem console buffer isn't zero filled before it's used, there won't be a terminator at the end. We need to put one at the cursor position manually. BUG=chrome-os-partner:19420 TEST=Booted and ran cbmem -c on pit. No longer saw lots of garbage printed after the actual console output. BRANCH=None Change-Id: I69870c2b24b67ce3cbcd402b62f3574acb4c2a8f Signed-off-by: Gabe Black Reviewed-on: https://gerrit.chromium.org/gerrit/65300 Reviewed-by: Hung-Te Lin Commit-Queue: Gabe Black Tested-by: Gabe Black --- util/cbmem/cbmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 11eeb1a5e8..2bae322b1b 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -368,7 +368,7 @@ static void dump_console(void) { void *console_p; char *console_c; - uint32_t size; + uint32_t size, cursor; if (console.tag != LB_TAG_CBMEM_CONSOLE) { fprintf(stderr, "No console found in coreboot table.\n"); @@ -382,7 +382,8 @@ static void dump_console(void) * char console[size] * Hence we have to add 8 to get to the actual console string. */ - size = *(uint32_t *)console_p; + size = ((uint32_t *)console_p)[0]; + cursor = ((uint32_t *)console_p)[1]; console_c = malloc(size + 1); if (!console_c) { fprintf(stderr, "Not enough memory for console.\n"); @@ -391,6 +392,7 @@ static void dump_console(void) memcpy(console_c, console_p + 8, size); console_c[size] = 0; + console_c[cursor] = 0; printf("%s", console_c);