[coreboot-gerrit] Patch set updated for coreboot: cbfstool: Add bintohex function

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Oct 1 14:00:21 CET 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11766

-gerrit

commit 0fcd7c5487eb56fa812583a926b895e4aeb6cb73
Author: Patrick Georgi <patrick at georgi-clan.de>
Date:   Thu Oct 1 15:52:56 2015 +0200

    cbfstool: Add bintohex function
    
    We need to emit some hex strings.
    
    Change-Id: I9e7e184282f6ad0470f2e269f5dc874e78f8b697
    Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
 util/cbfstool/common.c | 17 +++++++++++++++++
 util/cbfstool/common.h |  7 +++++++
 2 files changed, 24 insertions(+)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index e0474b3..ac28abd 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -196,3 +196,20 @@ uint64_t intfiletype(const char *name)
 			return filetypes[i].type;
 	return -1;
 }
+
+char *bintohex(uint8_t *data, size_t len)
+{
+	static const char translate[16] = "0123456789abcdef";
+
+	char *result = malloc(len * 2 + 1);
+	if (result == NULL)
+		return NULL;
+
+	result[len*2] = 0;
+	unsigned int i;
+	for (i = 0; i < len; i++) {
+		result[i*2] = translate[(data[i] >> 4) & 0xf];
+		result[i*2+1] = translate[data[i] & 0xf];
+	}
+	return result;
+}
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 8073d12..86ae484 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -210,4 +210,11 @@ extern struct xdr xdr_le, xdr_be;
 size_t bgets(struct buffer *input, void *output, size_t len);
 size_t bputs(struct buffer *b, const void *data, size_t len);
 
+/* Returns a 0-terminated string containing a hex representation of
+ * len bytes starting at data.
+ * The string is malloc'd and it's the caller's responsibility to free
+ * the memory.
+ * On error, bintohex returns NULL.
+ */
+char *bintohex(uint8_t *data, size_t len);
 #endif



More information about the coreboot-gerrit mailing list