aboutsummaryrefslogtreecommitdiff
path: root/cmd/binop.c
diff options
context:
space:
mode:
authorMario Six <mario.six@gdsys.cc>2019-01-28 09:43:43 +0100
committerMario Six <mario.six@gdsys.cc>2019-05-21 07:52:34 +0200
commit32dbe8c58a28ea4cd1c9370be9e99fd644b9d5a7 (patch)
treef304aaa9286a906c68ad8cb0c27ad28ca28b5932 /cmd/binop.c
parent29dada9c2e1637aede9985ded2959342e2d4a458 (diff)
downloadu-boot-32dbe8c58a28ea4cd1c9370be9e99fd644b9d5a7.zip
u-boot-32dbe8c58a28ea4cd1c9370be9e99fd644b9d5a7.tar.gz
u-boot-32dbe8c58a28ea4cd1c9370be9e99fd644b9d5a7.tar.bz2
cmd: binop: Use hex2bin
Use the new hex2bin function in the binop command instead of converting the data manually. Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd/binop.c')
-rw-r--r--cmd/binop.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/cmd/binop.c b/cmd/binop.c
index be780bf..116a2c0 100644
--- a/cmd/binop.c
+++ b/cmd/binop.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <command.h>
+#include <hexdump.h>
#include <malloc.h>
#include <mapmem.h>
#include <linux/ctype.h>
@@ -31,38 +32,15 @@ void write_to_env_var(char *varname, u8 *result, ulong len)
free(str_output);
}
-void decode_hexstring(char *hexstr, u8 *result)
-{
- int i;
- int acc = 0;
-
- for (i = 0; i < strlen(hexstr); ++i) {
- char d = hexstr[i];
- int value;
-
- if (isdigit(d))
- value = (d - '0');
- else
- value = (islower(d) ? toupper(d) : d) - 'A' + 10;
-
- if (i % 2 == 0) {
- acc = value * 16;
- } else {
- result[i / 2] = acc + value;
- acc = 0;
- }
- }
-}
-
void read_from_env_var(char *varname, u8 *result)
{
char *str_value;
str_value = env_get(varname);
if (str_value)
- decode_hexstring(str_value, result);
+ hex2bin(result, str_value, strlen(str_value) / 2);
else
- decode_hexstring(varname, result);
+ hex2bin(result, varname, strlen(varname) / 2);
}
void read_from_mem(ulong addr, u8 *result, ulong len)