From ca97fa7ac3c035532bbf493613c644514313a190 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Thu, 1 Oct 2015 15:52:56 +0200 Subject: cbfstool: Add bintohex function We need to emit some hex strings. Change-Id: I9e7e184282f6ad0470f2e269f5dc874e78f8b697 Signed-off-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/11766 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- util/cbfstool/common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util/cbfstool/common.c') diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index e0474b3435..7e36b7f217 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; +} -- cgit v1.2.3