]> git.sur5r.net Git - u-boot/blobdiff - cmd/nvedit.c
arm: socfpga: Fixes: include <debug_uart.h>
[u-boot] / cmd / nvedit.c
index 4cb25b824865f9aad6da83b5f63ee9312b3d8b4d..ddc888a4fdfc7c98216d9a1ded75f0e8bcea5cd4 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000-2013
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -6,8 +7,6 @@
  * Andreas Heppel <aheppel@sysgo.de>
  *
  * Copyright 2011 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -341,6 +340,36 @@ ulong env_get_hex(const char *varname, ulong default_val)
        return value;
 }
 
+void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr)
+{
+       char *end;
+       int i;
+
+       for (i = 0; i < 6; ++i) {
+               enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
+               if (addr)
+                       addr = (*end) ? end + 1 : end;
+       }
+}
+
+int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr)
+{
+       eth_parse_enetaddr(env_get(name), enetaddr);
+       return is_valid_ethaddr(enetaddr);
+}
+
+int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr)
+{
+       char buf[ARP_HLEN_ASCII + 1];
+
+       if (eth_env_get_enetaddr(name, (uint8_t *)buf))
+               return -EEXIST;
+
+       sprintf(buf, "%pM", enetaddr);
+
+       return env_set(name, buf);
+}
+
 #ifndef CONFIG_SPL_BUILD
 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -691,7 +720,7 @@ int env_get_f(const char *name, char *buf, unsigned len)
 /**
  * Decode the integer value of an environment variable and return it.
  *
- * @param name         Name of environemnt variable
+ * @param name         Name of environment variable
  * @param base         Number base to use (normally 10, or 16 for hex)
  * @param default_val  Default value to return if the variable is not
  *                     found