Skip to contentSkip to conversation

cmd: binop: Use new environment api

PATCH New Mario Six 2 participants 6 messages Jan 28, 2019 – Mar 29, 2019

lore
Share & tools
lore

Mario Six

author
#0 lore raw

PATCH 1/2 cmd: binop: Use new environment api

Since the binop command was introduced, the environment API was changed. Use the new API to make the command work again.

---
 cmd/binop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/binop.c +2 -2
index 787f7a26ead..be780bffd7b 100644
@@ -26,7 +26,7 @@ void write_to_env_var(char *varname, u8 *result, ulong len)
 		str_ptr += 2;
 	}
 	*str_ptr = '\0';
-	setenv(varname, str_output);
+	env_set(varname, str_output);
 
 	free(str_output);
 }
@@ -58,7 +58,7 @@ void read_from_env_var(char *varname, u8 *result)
 {
 	char *str_value;
 
-	str_value = getenv(varname);
+	str_value = env_get(varname);
 	if (str_value)
 		decode_hexstring(str_value, result);
 	else
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 2/2 cmd: binop: Use hex2bin

Use the new hex2bin function in the binop command instead of converting the data manually.

---
 cmd/binop.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)
cmd/binop.c +3 -25
index be780bffd7b..116a2c0d554 100644
@@ -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)
Signature · 1 line
2.20.1
author
#3 lore raw

PATCH 2/2 cmd: binop: Use hex2bin

Quoted 6 lines · Simon Glass
Quoted 4 lines · Mario Six

Use the new hex2bin function in the binop command instead of converting the data manually.

Quoted 6 lines
Quoted 4 lines
---
 cmd/binop.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)

Applied to u-boot-mpc83xx/next.

author
#5 lore raw

PATCH 1/2 cmd: binop: Use new environment api

Quoted 6 lines · Simon Glass
Quoted 4 lines · Mario Six

Since the binop command was introduced, the environment API was changed. Use the new API to make the command work again.

Quoted 7 lines
Quoted 5 lines
---
 cmd/binop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-mpc83xx/next.