[U-Boot] [PATCH] pxe: get ethaddr from the current device instead of env

Rob Herring robherring2 at gmail.com
Tue Dec 6 01:04:33 CET 2011


From: Rob Herring <rob.herring at calxeda.com>

The env variable "ethaddr" may not be set, so get the address from the
eth_device struct instead. This also enables pxe for secondary ethernet
devices.

Signed-off-by: Rob Herring <rob.herring at calxeda.com>
---
 common/cmd_pxe.c |   31 ++++++++++++-------------------
 1 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
index 3efd700..f14ef89 100644
--- a/common/cmd_pxe.c
+++ b/common/cmd_pxe.c
@@ -56,38 +56,31 @@ static char *from_env(char *envvar)
  */
 static int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
-	size_t ethaddr_len;
-	char *p, *ethaddr;
-
-	ethaddr = from_env("ethaddr");
-
-	if (!ethaddr)
-		return -ENOENT;
-
-	ethaddr_len = strlen(ethaddr);
+	char *p;
+	struct eth_device *dev;
 
 	/*
 	 * ethaddr_len + 4 gives room for "01-", ethaddr, and a NUL byte at
 	 * the end.
 	 */
-	if (outbuf_len < ethaddr_len + 4) {
-		printf("outbuf is too small (%d < %d)\n",
-				outbuf_len, ethaddr_len + 4);
-
+	if (outbuf_len < 21) {
+		printf("outbuf is too small (%d < 21)\n", outbuf_len);
 		return -EINVAL;
 	}
 
-	strcpy(outbuf, "01-");
+	eth_set_current();
+	dev = eth_get_dev();
+	if (!dev)
+		return -ENODEV;
 
-	for (p = outbuf + 3; *ethaddr; ethaddr++, p++) {
-		if (*ethaddr == ':')
+	sprintf(outbuf, "01-%pM", dev->enetaddr);
+	for (p = outbuf + 3; *p; p++) {
+		if (*p == ':')
 			*p = '-';
 		else
-			*p = tolower(*ethaddr);
+			*p = tolower(*p);
 	}
 
-	*p = '\0';
-
 	return 1;
 }
 
-- 
1.7.5.4



More information about the U-Boot mailing list