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 <s.hauer@pengutronix.de>
This commit is contained in:
parent
ae3f56c84a
commit
20ec9ba02d
12
net/eth.c
12
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;
|
||||
|
|
Loading…
Reference in New Issue