Commit 86848a74c3c8eb2f8dd179d039ee604dc45288cf

Authored by Mike Frysinger
Committed by Ben Warren
1 parent 0ebf04c607

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there.  So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

Showing 2 changed files with 24 additions and 30 deletions Side-by-side Diff

... ... @@ -119,10 +119,10 @@
119 119 extern struct eth_device *eth_get_dev_by_name(char *devname); /* get device */
120 120 extern struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */
121 121 extern int eth_get_dev_index (void); /* get the device index */
122   -extern void eth_set_enetaddr(int num, char* a); /* Set new MAC address */
123 122 extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
124 123 extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
125 124 extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
  125 +extern int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr);
126 126  
127 127 extern int eth_init(bd_t *bis); /* Initialize the device */
128 128 extern int eth_send(volatile void *packet, int length); /* Send a packet */
... ... @@ -53,6 +53,13 @@
53 53  
54 54 return setenv(name, buf);
55 55 }
  56 +
  57 +int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr)
  58 +{
  59 + char enetvar[32];
  60 + sprintf(enetvar, index ? "eth%daddr" : "ethaddr", index);
  61 + return eth_getenv_enetaddr(enetvar, enetaddr);
  62 +}
56 63 #endif
57 64  
58 65 #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
... ... @@ -180,7 +187,6 @@
180 187  
181 188 int eth_initialize(bd_t *bis)
182 189 {
183   - char enetvar[32];
184 190 unsigned char env_enetaddr[6];
185 191 int eth_number = 0;
186 192  
... ... @@ -221,8 +227,7 @@
221 227 puts (" [PRIME]");
222 228 }
223 229  
224   - sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number);
225   - eth_getenv_enetaddr(enetvar, env_enetaddr);
  230 + eth_getenv_enetaddr_by_index(eth_number, env_enetaddr);
226 231  
227 232 if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
228 233 if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
... ... @@ -259,31 +264,6 @@
259 264 return eth_number;
260 265 }
261 266  
262   -void eth_set_enetaddr(int num, char *addr) {
263   - struct eth_device *dev;
264   - unsigned char enetaddr[6];
265   -
266   - debug("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr);
267   -
268   - if (!eth_devices)
269   - return;
270   -
271   - eth_parse_enetaddr(addr, enetaddr);
272   -
273   - dev = eth_devices;
274   - while(num-- > 0) {
275   - dev = dev->next;
276   -
277   - if (dev == eth_devices)
278   - return;
279   - }
280   -
281   - debug("Setting new HW address on %s\n"
282   - "New Address is %pM\n",
283   - dev->name, enetaddr);
284   -
285   - memcpy(dev->enetaddr, enetaddr, 6);
286   -}
287 267 #ifdef CONFIG_MCAST_TFTP
288 268 /* Multicast.
289 269 * mcast_addr: multicast ipaddr from which multicast Mac is made
290 270  
... ... @@ -332,12 +312,26 @@
332 312  
333 313 int eth_init(bd_t *bis)
334 314 {
335   - struct eth_device* old_current;
  315 + int eth_number;
  316 + struct eth_device *old_current, *dev;
336 317  
337 318 if (!eth_current) {
338 319 puts ("No ethernet found.\n");
339 320 return -1;
340 321 }
  322 +
  323 + /* Sync environment with network devices */
  324 + eth_number = 0;
  325 + dev = eth_devices;
  326 + do {
  327 + uchar env_enetaddr[6];
  328 +
  329 + if (eth_getenv_enetaddr_by_index(eth_number, env_enetaddr))
  330 + memcpy(dev->enetaddr, env_enetaddr, 6);
  331 +
  332 + ++eth_number;
  333 + dev = dev->next;
  334 + } while (dev != eth_devices);
341 335  
342 336 old_current = eth_current;
343 337 do {