[coreboot-gerrit] Change in coreboot[master]: libpayload/libc: Add second version of hexdump

Lee Leahy (Code Review) gerrit at coreboot.org
Fri Jun 30 19:23:20 CEST 2017


Lee Leahy has uploaded this change for review. ( https://review.coreboot.org/20441


Change subject: libpayload/libc: Add second version of hexdump
......................................................................

libpayload/libc: Add second version of hexdump

Add hexdump_gpl.c which is selected with CONFIG_GPL.  Simplify the
conditional logic.

Don't continue displaying data after the end of the specified buffer.
Use the version from coreboot to display only the data requested.  This
version also compresses the all ones display.

TEST=Build and run on Galileo Gen2

Change-Id: I0e2f943346cd4f421987075cc37d1ac6d3e980ef
Signed-off-by: Lee Leahy <Leroy.P.Leahy at intel.com>
---
M payloads/libpayload/libc/Makefile.inc
A payloads/libpayload/libc/hexdump_gpl.c
2 files changed, 80 insertions(+), 13 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/41/20441/1

diff --git a/payloads/libpayload/libc/Makefile.inc b/payloads/libpayload/libc/Makefile.inc
index edef62c..39f4584 100644
--- a/payloads/libpayload/libc/Makefile.inc
+++ b/payloads/libpayload/libc/Makefile.inc
@@ -28,18 +28,24 @@
 ## SUCH DAMAGE.
 ##
 
-libc-$(CONFIG_LP_LIBC) += malloc.c printf.c console.c string.c
-libc-$(CONFIG_LP_LIBC) += memory.c ctype.c ipchecksum.c lib.c libgcc.c
-libc-$(CONFIG_LP_LIBC) += rand.c time.c exec.c
-libc-$(CONFIG_LP_LIBC) += readline.c getopt_long.c sysinfo.c
-libc-$(CONFIG_LP_LIBC) += args.c
-libc-$(CONFIG_LP_LIBC) += strlcpy.c
-libc-$(CONFIG_LP_LIBC) += qsort.c
-libc-$(CONFIG_LP_LIBC) += hexdump.c
-libc-$(CONFIG_LP_LIBC) += die.c
-libc-$(CONFIG_LP_LIBC) += coreboot.c
-libc-$(CONFIG_LP_LIBC) += fmap.c
+ifeq ($(CONFIG_LP_LIBC),y)
 
-ifeq ($(CONFIG_LP_ARCH_MIPS),y)
-libc-$(CONFIG_LP_LIBC) += 64bit_div.c
+libc-y += malloc.c printf.c console.c string.c
+libc-y += memory.c ctype.c ipchecksum.c lib.c libgcc.c
+libc-y += rand.c time.c exec.c
+libc-y += readline.c getopt_long.c sysinfo.c
+libc-y += args.c
+libc-y += strlcpy.c
+libc-y += qsort.c
+ifeq ($(CONFIG_GPL),y)
+libc-y += hexdump_gpl.c
+else
+libc-y += hexdump.c
+endif
+libc-y += die.c
+libc-y += coreboot.c
+libc-y += fmap.c
+
+libc-$(CONFIG_LP_ARCH_MIPS) += 64bit_div.c
+
 endif
diff --git a/payloads/libpayload/libc/hexdump_gpl.c b/payloads/libpayload/libc/hexdump_gpl.c
new file mode 100644
index 0000000..9f99a79
--- /dev/null
+++ b/payloads/libpayload/libc/hexdump_gpl.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but without any warranty; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <libpayload.h>
+
+void hexdump(const void *memory, size_t length)
+{
+	int i;
+	uint8_t *line;
+	int all_zero = 0;
+	int all_one = 0;
+	size_t num_bytes;
+
+	for (i = 0; i < length; i += 16) {
+		int j;
+		num_bytes = MIN(length - i, 16);
+		line = ((uint8_t *)memory) + i;
+
+		all_zero++;
+		all_one++;
+		for (j = 0; j < num_bytes; j++) {
+			if (line[j] != 0) {
+				all_zero = 0;
+				break;
+			}
+		}
+
+		for (j = 0; j < num_bytes; j++) {
+			if (line[j] != 0xff) {
+				all_one = 0;
+				break;
+			}
+		}
+
+		if ((all_zero < 2) && (all_one < 2)) {
+			printf("%p:", memory + i);
+			for (j = 0; j < num_bytes; j++)
+				printf(" %02x", line[j]);
+			for (; j < 16; j++)
+				printf("   ");
+			printf("  ");
+			for (j = 0; j < num_bytes; j++)
+				printf("%c",
+				       isprint(line[j]) ? line[j] : '.');
+			printf("\n");
+		} else if ((all_zero == 2) || (all_one == 2)) {
+			printf("...\n");
+		}
+	}
+}

-- 
To view, visit https://review.coreboot.org/20441
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e2f943346cd4f421987075cc37d1ac6d3e980ef
Gerrit-Change-Number: 20441
Gerrit-PatchSet: 1
Gerrit-Owner: Lee Leahy <leroy.p.leahy at intel.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170630/b3763709/attachment-0001.html>


More information about the coreboot-gerrit mailing list