Attention is currently required from: Martin L Roth.
Stefan Reinauer has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/77196?usp=email )
Change subject: Add strtohex() function ......................................................................
Add strtohex() function
Move hexdump.c to util.c and add strtohex from Dediprog there.
Change-Id: I02a8a84e7fbd24ab349d2164d5b9b6c17c2ac806 Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org --- M Makefile M em100.h R util.c 3 files changed, 24 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/96/77196/1
diff --git a/Makefile b/Makefile index 6503932..92a4f6b 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ PREFIX ?= /usr/local
XZ = xz/xz_crc32.c xz/xz_crc64.c xz/xz_dec_bcj.c xz/xz_dec_lzma2.c xz/xz_dec_stream.c -SOURCES = em100.c firmware.c fpga.c hexdump.c sdram.c spi.c system.c trace.c usb.c +SOURCES = em100.c firmware.c fpga.c sdram.c spi.c system.c trace.c usb.c util.c SOURCES += image.c curl.c chips.c tar.c ini.c $(XZ) OBJECTS = $(SOURCES:.c=.o)
diff --git a/em100.h b/em100.h index 5a762cc..e74516a 100644 --- a/em100.h +++ b/em100.h @@ -69,8 +69,9 @@ #define FPGA_REG_DEVID 0x40 #define FPGA_REG_VENDID 0x42
-/* hexdump.c */ +/* util.c */ void hexdump(const void *memory, size_t length); +int strtohex(const char *pb_src);
/* sdram.c */ int read_sdram(struct em100 *em100, void *data, int address, int length); diff --git a/hexdump.c b/util.c similarity index 82% rename from hexdump.c rename to util.c index 72accfb..e60a686 100644 --- a/hexdump.c +++ b/util.c @@ -1,5 +1,6 @@ /* * Copyright 2013-2015 Google Inc. + * Copyright 2023 Dediprog 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 @@ -14,6 +15,7 @@ #include <stdio.h> #include <stdint.h> #include <stddef.h> +#include <string.h> #include <ctype.h> #include "em100.h"
@@ -57,3 +59,22 @@ } } } + +int strtohex(const char *pb_src) +{ + char h1, h2; + char s1, s2; + + h1 = pb_src[0]; + h2 = pb_src[1]; + + s1 = toupper(h1) - 0x30; + if (s1 > 9) + s1 -= 7; + + s2 = toupper(h2) - 0x30; + if (s2 > 9) + s2 -= 7; + + return (s1 * 16 + s2); +}