summaryrefslogtreecommitdiff
path: root/util/cbmem/cbmem.c
diff options
context:
space:
mode:
authorVladimir Serbinenko <phcoder@gmail.com>2013-03-30 12:15:12 +0100
committerRonald G. Minnich <rminnich@gmail.com>2013-04-09 23:52:36 +0200
commitf4a0d019fa07a0d867a23b36673ff300cdefce6c (patch)
treea20e02abbe6ae5bf15454963e4e035610fa7639f /util/cbmem/cbmem.c
parent33e83caff59f7b6ff2ba62d3b496235ef5c4e543 (diff)
downloadcoreboot-f4a0d019fa07a0d867a23b36673ff300cdefce6c.tar.xz
util/cbmem: Don't output trailing garbage for cbmemc
Current code outputs the whole cbmemc buffer even if only part of it is really used. Fix it to output only the used part and notify the user if the buffer was too small for the required data. Change-Id: I68c1970cf84d49b2d7d6007dae0679d7a7a0cb99 Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-on: http://review.coreboot.org/2991 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'util/cbmem/cbmem.c')
-rw-r--r--util/cbmem/cbmem.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index bc6bd6b9c8..f3f5add2a7 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -314,6 +314,7 @@ static void dump_console(void)
void *console_p;
char *console_c;
uint32_t size;
+ uint32_t cursor;
if (console.tag != LB_TAG_CBMEM_CONSOLE) {
fprintf(stderr, "No console found in coreboot table.\n");
@@ -328,6 +329,12 @@ static void dump_console(void)
* Hence we have to add 8 to get to the actual console string.
*/
size = *(uint32_t *)console_p;
+ cursor = *(uint32_t *) (console_p + 4);
+ /* Cursor continues to go on even after no more data fits in
+ * the buffer but the data is dropped in this case.
+ */
+ if (size > cursor)
+ size = cursor;
console_c = malloc(size + 1);
if (!console_c) {
fprintf(stderr, "Not enough memory for console.\n");
@@ -337,7 +344,10 @@ static void dump_console(void)
memcpy(console_c, console_p + 8, size);
console_c[size] = 0;
- printf("%s", console_c);
+ printf("%s\n", console_c);
+ if (size < cursor)
+ printf("%d %s lost\n", cursor - size,
+ (cursor - size) == 1 ? "byte":"bytes");
free(console_c);