summaryrefslogtreecommitdiffstats
path: root/common/fdt_support.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2016-01-13 18:03:05 -0500
committerTom Rini <trini@konsulko.com>2016-01-13 21:05:16 -0500
commit774da4b9aadeea4d6973a16debc02a6801ff9344 (patch)
tree6221335ba4d66b83fa3211d8ec3ac8feedbdde6a /common/fdt_support.c
parent48ad68deb8f3f2046aad4197e7b1bc70533b4bb2 (diff)
parent140bc33e05382545b762ef51d6fc31dd5b6ec82c (diff)
downloadtalos-obmc-uboot-774da4b9aadeea4d6973a16debc02a6801ff9344.tar.gz
talos-obmc-uboot-774da4b9aadeea4d6973a16debc02a6801ff9344.zip
Merge git://git.denx.de/u-boot-net
Diffstat (limited to 'common/fdt_support.c')
-rw-r--r--common/fdt_support.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/common/fdt_support.c b/common/fdt_support.c
index a539389a9e..09f923716c 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -482,47 +482,49 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
void fdt_fixup_ethernet(void *fdt)
{
int node, i, j;
- char enet[16], *tmp, *end;
+ char *tmp, *end;
char mac[16];
const char *path;
unsigned char mac_addr[6];
+ int offset;
node = fdt_path_offset(fdt, "/aliases");
if (node < 0)
return;
- if (!getenv("ethaddr")) {
- if (getenv("usbethaddr")) {
- strcpy(mac, "usbethaddr");
- } else {
- debug("No ethernet MAC Address defined\n");
- return;
- }
- } else {
- strcpy(mac, "ethaddr");
- }
-
- i = 0;
- while ((tmp = getenv(mac)) != NULL) {
- sprintf(enet, "ethernet%d", i);
- path = fdt_getprop(fdt, node, enet, NULL);
- if (!path) {
- debug("No alias for %s\n", enet);
- sprintf(mac, "eth%daddr", ++i);
- continue;
- }
+ for (offset = fdt_first_property_offset(fdt, node);
+ offset > 0;
+ offset = fdt_next_property_offset(fdt, offset)) {
+ const char *name;
+ int len = strlen("ethernet");
+
+ path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
+ if (!strncmp(name, "ethernet", len)) {
+ i = trailing_strtol(name);
+ if (i != -1) {
+ if (i == 0)
+ strcpy(mac, "ethaddr");
+ else
+ sprintf(mac, "eth%daddr", i);
+ } else {
+ continue;
+ }
+ tmp = getenv(mac);
+ if (!tmp)
+ continue;
+
+ for (j = 0; j < 6; j++) {
+ mac_addr[j] = tmp ?
+ simple_strtoul(tmp, &end, 16) : 0;
+ if (tmp)
+ tmp = (*end) ? end + 1 : end;
+ }
- for (j = 0; j < 6; j++) {
- mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
- if (tmp)
- tmp = (*end) ? end+1 : end;
+ do_fixup_by_path(fdt, path, "mac-address",
+ &mac_addr, 6, 0);
+ do_fixup_by_path(fdt, path, "local-mac-address",
+ &mac_addr, 6, 1);
}
-
- do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0);
- do_fixup_by_path(fdt, path, "local-mac-address",
- &mac_addr, 6, 1);
-
- sprintf(mac, "eth%daddr", ++i);
}
}
OpenPOWER on IntegriCloud