From 20ec9ba02d908bb97b95838451b14f1a4589fa4c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 30 Sep 2008 10:48:40 +0200 Subject: [PATCH] Ethernet: write MAC address to hardware when it's changed Instead of writing the MAC address into the hardware on device open time write it to the hardware when the user changes the parameter. This way a user can change the MAC address in the hardware without actually using the device. This helps Linux Network drivers which expect a valid MAC address on startup. Signed-off-by: Sascha Hauer --- net/eth.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/eth.c b/net/eth.c index d3854c190..c1c16668d 100644 --- a/net/eth.c +++ b/net/eth.c @@ -49,10 +49,6 @@ int eth_open(void) if (!eth_current) return 0; - string_to_ethaddr(dev_get_param(eth_current->dev, "ethaddr"), mac); - - eth_current->set_ethaddr(eth_current, mac); - eth_current->open(eth_current); return 0; @@ -86,6 +82,7 @@ int eth_rx(void) static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const char *val) { + struct eth_device *edev = dev->type_data; char ethaddr[sizeof("xx:xx:xx:xx:xx:xx")]; if (string_to_ethaddr(val, ethaddr) < 0) @@ -94,6 +91,8 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch free(param->value); param->value = strdup(val); + edev->set_ethaddr(edev, ethaddr); + return 0; } @@ -137,15 +136,14 @@ int eth_register(struct eth_device *edev) dev_add_param(dev, &edev->param_netmask); dev_add_param(dev, &edev->param_serverip); + edev->init(edev); + if (edev->get_ethaddr(edev, ethaddr) == 0) { ethaddr_to_string(ethaddr, ethaddr_str); printf("got MAC address from EEPROM: %s\n",ethaddr_str); dev_set_param(dev, "ethaddr", ethaddr_str); -// memcpy(edev->enetaddr, ethaddr, 6); } - edev->init(edev); - eth_current = edev; return 0;