X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Fbinop.c;h=6d2df5f3dd4fafc9a865f504038e38a36b9b9545;hb=44fb0d6c9f5147a41c710032869e5e01b3c9e310;hp=be780bffd7baf460d7fcfeab9f34d7735acc08af;hpb=29dada9c2e1637aede9985ded2959342e2d4a458;p=oweals%2Fu-boot.git diff --git a/cmd/binop.c b/cmd/binop.c index be780bffd7..6d2df5f3dd 100644 --- a/cmd/binop.c +++ b/cmd/binop.c @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include #include @@ -31,38 +33,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)