Commit 24acb83d8f04e9a49f161c07d38da50c70e9f16d

Authored by Prabhakar Kushwaha
Committed by Simon Glass
1 parent 48a346061d

common: Fix-up MAC addr in dts by fetching env variable serially

The MAC addresses get fixed in the device tree for "ethernet" nodes
is by using trailing number behind "ethernet" found in "/aliases".
It may not be necessary for the "ethernet" nodes to be sequential.
There can be gaps in between or any node disabled

So provide a support to fetch MAC addr sequentially from env
and apply them to "ethernet" nodes in the order they appear in
device tree only if "ethernet" is not "disabled"

Signed-off-by: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

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

... ... @@ -1603,6 +1603,15 @@
1603 1603  
1604 1604 See doc/README.link-local for more information.
1605 1605  
  1606 + - MAC address from environment variables
  1607 +
  1608 + FDT_SEQ_MACADDR_FROM_ENV
  1609 +
  1610 + Fix-up device tree with MAC addresses fetched sequentially from
  1611 + environment variables. This config work on assumption that
  1612 + non-usable ethernet node of device-tree are either not present
  1613 + or their status has been marked as "disabled".
  1614 +
1606 1615 - CDP Options:
1607 1616 CONFIG_CDP_DEVICE_ID
1608 1617  
common/fdt_support.c
... ... @@ -508,12 +508,16 @@
508 508  
509 509 void fdt_fixup_ethernet(void *fdt)
510 510 {
511   - int i, j, prop;
  511 + int i = 0, j, prop;
512 512 char *tmp, *end;
513 513 char mac[16];
514 514 const char *path;
515 515 unsigned char mac_addr[ARP_HLEN];
516 516 int offset;
  517 +#ifdef FDT_SEQ_MACADDR_FROM_ENV
  518 + int nodeoff;
  519 + const struct fdt_property *fdt_prop;
  520 +#endif
517 521  
518 522 if (fdt_path_offset(fdt, "/aliases") < 0)
519 523 return;
... ... @@ -526,7 +530,7 @@
526 530 offset = fdt_first_property_offset(fdt,
527 531 fdt_path_offset(fdt, "/aliases"));
528 532 /* Select property number 'prop' */
529   - for (i = 0; i < prop; i++)
  533 + for (j = 0; j < prop; j++)
530 534 offset = fdt_next_property_offset(fdt, offset);
531 535  
532 536 if (offset < 0)
533 537  
534 538  
... ... @@ -535,11 +539,16 @@
535 539 path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
536 540 if (!strncmp(name, "ethernet", 8)) {
537 541 /* Treat plain "ethernet" same as "ethernet0". */
538   - if (!strcmp(name, "ethernet"))
  542 + if (!strcmp(name, "ethernet")
  543 +#ifdef FDT_SEQ_MACADDR_FROM_ENV
  544 + || !strcmp(name, "ethernet0")
  545 +#endif
  546 + )
539 547 i = 0;
  548 +#ifndef FDT_SEQ_MACADDR_FROM_ENV
540 549 else
541 550 i = trailing_strtol(name);
542   -
  551 +#endif
543 552 if (i != -1) {
544 553 if (i == 0)
545 554 strcpy(mac, "ethaddr");
... ... @@ -548,6 +557,14 @@
548 557 } else {
549 558 continue;
550 559 }
  560 +#ifdef FDT_SEQ_MACADDR_FROM_ENV
  561 + nodeoff = fdt_path_offset(fdt, path);
  562 + fdt_prop = fdt_get_property(fdt, nodeoff, "status",
  563 + NULL);
  564 + if (fdt_prop && !strcmp(fdt_prop->data, "disabled"))
  565 + continue;
  566 + i++;
  567 +#endif
551 568 tmp = env_get(mac);
552 569 if (!tmp)
553 570 continue;