<p>Lee Leahy has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/20441">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">libpayload/libc: Add second version of hexdump<br><br>Add hexdump_gpl.c which is selected with CONFIG_GPL.  Simplify the<br>conditional logic.<br><br>Don't continue displaying data after the end of the specified buffer.<br>Use the version from coreboot to display only the data requested.  This<br>version also compresses the all ones display.<br><br>TEST=Build and run on Galileo Gen2<br><br>Change-Id: I0e2f943346cd4f421987075cc37d1ac6d3e980ef<br>Signed-off-by: Lee Leahy <Leroy.P.Leahy@intel.com><br>---<br>M payloads/libpayload/libc/Makefile.inc<br>A payloads/libpayload/libc/hexdump_gpl.c<br>2 files changed, 80 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/41/20441/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/payloads/libpayload/libc/Makefile.inc b/payloads/libpayload/libc/Makefile.inc<br>index edef62c..39f4584 100644<br>--- a/payloads/libpayload/libc/Makefile.inc<br>+++ b/payloads/libpayload/libc/Makefile.inc<br>@@ -28,18 +28,24 @@<br> ## SUCH DAMAGE.<br> ##<br> <br>-libc-$(CONFIG_LP_LIBC) += malloc.c printf.c console.c string.c<br>-libc-$(CONFIG_LP_LIBC) += memory.c ctype.c ipchecksum.c lib.c libgcc.c<br>-libc-$(CONFIG_LP_LIBC) += rand.c time.c exec.c<br>-libc-$(CONFIG_LP_LIBC) += readline.c getopt_long.c sysinfo.c<br>-libc-$(CONFIG_LP_LIBC) += args.c<br>-libc-$(CONFIG_LP_LIBC) += strlcpy.c<br>-libc-$(CONFIG_LP_LIBC) += qsort.c<br>-libc-$(CONFIG_LP_LIBC) += hexdump.c<br>-libc-$(CONFIG_LP_LIBC) += die.c<br>-libc-$(CONFIG_LP_LIBC) += coreboot.c<br>-libc-$(CONFIG_LP_LIBC) += fmap.c<br>+ifeq ($(CONFIG_LP_LIBC),y)<br> <br>-ifeq ($(CONFIG_LP_ARCH_MIPS),y)<br>-libc-$(CONFIG_LP_LIBC) += 64bit_div.c<br>+libc-y += malloc.c printf.c console.c string.c<br>+libc-y += memory.c ctype.c ipchecksum.c lib.c libgcc.c<br>+libc-y += rand.c time.c exec.c<br>+libc-y += readline.c getopt_long.c sysinfo.c<br>+libc-y += args.c<br>+libc-y += strlcpy.c<br>+libc-y += qsort.c<br>+ifeq ($(CONFIG_GPL),y)<br>+libc-y += hexdump_gpl.c<br>+else<br>+libc-y += hexdump.c<br>+endif<br>+libc-y += die.c<br>+libc-y += coreboot.c<br>+libc-y += fmap.c<br>+<br>+libc-$(CONFIG_LP_ARCH_MIPS) += 64bit_div.c<br>+<br> endif<br>diff --git a/payloads/libpayload/libc/hexdump_gpl.c b/payloads/libpayload/libc/hexdump_gpl.c<br>new file mode 100644<br>index 0000000..9f99a79<br>--- /dev/null<br>+++ b/payloads/libpayload/libc/hexdump_gpl.c<br>@@ -0,0 +1,61 @@<br>+/*<br>+ * Copyright 2013 Google Inc.<br>+ *<br>+ * This program is free software; you can redistribute it and/or<br>+ * modify it under the terms of the GNU General Public License as<br>+ * published by the Free Software Foundation; either version 2 of<br>+ * the License, or (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but without any warranty; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>+ */<br>+<br>+#include <libpayload.h><br>+<br>+void hexdump(const void *memory, size_t length)<br>+{<br>+  int i;<br>+       uint8_t *line;<br>+       int all_zero = 0;<br>+    int all_one = 0;<br>+     size_t num_bytes;<br>+<br>+ for (i = 0; i < length; i += 16) {<br>+                int j;<br>+               num_bytes = MIN(length - i, 16);<br>+             line = ((uint8_t *)memory) + i;<br>+<br>+           all_zero++;<br>+          all_one++;<br>+           for (j = 0; j < num_bytes; j++) {<br>+                 if (line[j] != 0) {<br>+                          all_zero = 0;<br>+                                break;<br>+                       }<br>+            }<br>+<br>+         for (j = 0; j < num_bytes; j++) {<br>+                 if (line[j] != 0xff) {<br>+                               all_one = 0;<br>+                         break;<br>+                       }<br>+            }<br>+<br>+         if ((all_zero < 2) && (all_one < 2)) {<br>+                 printf("%p:", memory + i);<br>+                 for (j = 0; j < num_bytes; j++)<br>+                           printf(" %02x", line[j]);<br>+                  for (; j < 16; j++)<br>+                               printf("   ");<br>+                     printf("  ");<br>+                      for (j = 0; j < num_bytes; j++)<br>+                           printf("%c",<br>+                                      isprint(line[j]) ? line[j] : '.');<br>+                    printf("\n");<br>+              } else if ((all_zero == 2) || (all_one == 2)) {<br>+                      printf("...\n");<br>+           }<br>+    }<br>+}<br></pre><p>To view, visit <a href="https://review.coreboot.org/20441">change 20441</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/20441"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0e2f943346cd4f421987075cc37d1ac6d3e980ef </div>
<div style="display:none"> Gerrit-Change-Number: 20441 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Lee Leahy <leroy.p.leahy@intel.com> </div>