[U-Boot] [PATCH 2/3] net: add getenv/setenv enetaddr function to use ethernet device num

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Tue Aug 11 22:49:06 CEST 2009


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 include/net.h |    2 ++
 net/eth.c     |   28 +++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/include/net.h b/include/net.h
index 2a8a12d..dc4ae41 100644
--- a/include/net.h
+++ b/include/net.h
@@ -124,6 +124,8 @@ extern void eth_set_enetaddr(int num, char* a);	/* Set new MAC address */
 extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
 extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
 extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
+extern int eth_getenv_num_enetaddr(int num, uchar *enetaddr);
+extern int eth_setenv_num_enetaddr(int num, const uchar *enetaddr);
 
 extern int eth_init(bd_t *bis);			/* Initialize the device */
 extern int eth_send(volatile void *packet, int length);	   /* Send a packet */
diff --git a/net/eth.c b/net/eth.c
index 2316a22..9bdf961 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -27,6 +27,12 @@
 #include <miidev.h>
 
 #ifdef CONFIG_CMD_NET
+
+static void get_enetvar(int num, char *enetvar)
+{
+	sprintf(enetvar, num ? "eth%daddr" : "ethaddr", num);
+}
+
 void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
 {
 	char *end;
@@ -53,6 +59,24 @@ int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
 
 	return setenv(name, buf);
 }
+
+int eth_getenv_num_enetaddr(int num, uchar *enetaddr)
+{
+	char enetvar[32];
+
+	get_enetvar(num, enetvar);
+
+	return eth_getenv_enetaddr(enetvar, enetaddr);
+}
+
+int eth_setenv_num_enetaddr(int num, const uchar *enetaddr)
+{
+	char enetvar[32];
+
+	get_enetvar(num, enetvar);
+
+	return eth_setenv_enetaddr(enetvar, enetaddr);
+}
 #endif
 
 #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
@@ -173,7 +197,6 @@ int eth_register(struct eth_device* dev)
 
 int eth_initialize(bd_t *bis)
 {
-	char enetvar[32];
 	unsigned char env_enetaddr[6];
 	int eth_number = 0;
 
@@ -214,8 +237,7 @@ int eth_initialize(bd_t *bis)
 				puts (" [PRIME]");
 			}
 
-			sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number);
-			eth_getenv_enetaddr(enetvar, env_enetaddr);
+			eth_getenv_num_enetaddr(eth_number, env_enetaddr);
 
 			if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
 				if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
-- 
1.6.4



More information about the U-Boot mailing list