[U-Boot] [PATCH 1/3] common: Fix-up MAC addr in dts by fetching env variable serially
Prabhakar Kushwaha
prabhakar.kushwaha at nxp.com
Tue Nov 21 16:26:25 UTC 2017
Current implementation of MAC address fix-up of device tree uses
tailing number behind "ethernet" found in "/aliases". It is not
necessary for trailing number of “ethernet” to be sequential. There
can be hole in between or any node disabled.
So provide support device tree fix-up of “ethernent” node with MAC
addresses fetched sequentially from environment variables.
Signed-off-by: Prabhakar Kushwaha <prabhakar.kushwaha at nxp.com>
---
README | 10 ++++++++++
common/fdt_support.c | 25 +++++++++++++++++++++----
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/README b/README
index 7a4f342..640b310 100644
--- a/README
+++ b/README
@@ -1603,6 +1603,16 @@ The following options need to be configured:
See doc/README.link-local for more information.
+ - MAC address from environment variables
+
+ FDT_SEQ_MACADDR_FROM_ENV
+
+ Fix-up device tree with MAC address fetched sequentially from
+ environment variables. This will avoid dependency on device-tree
+ to get env variable sequence number. This config has assumption
+ of non-usable ethernet node of device-tree are either not present
+ or their status has been marked as "disabled".
+
- CDP Options:
CONFIG_CDP_DEVICE_ID
diff --git a/common/fdt_support.c b/common/fdt_support.c
index f4f9543..43ca8db 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -469,12 +469,16 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
void fdt_fixup_ethernet(void *fdt)
{
- int i, j, prop;
+ int i = 0, j, prop;
char *tmp, *end;
char mac[16];
const char *path;
unsigned char mac_addr[ARP_HLEN];
int offset;
+#ifdef FDT_SEQ_MACADDR_FROM_ENV
+ int nodeoff;
+ const struct fdt_property *fdt_prop;
+#endif
if (fdt_path_offset(fdt, "/aliases") < 0)
return;
@@ -487,7 +491,7 @@ void fdt_fixup_ethernet(void *fdt)
offset = fdt_first_property_offset(fdt,
fdt_path_offset(fdt, "/aliases"));
/* Select property number 'prop' */
- for (i = 0; i < prop; i++)
+ for (j = 0; j < prop; j++)
offset = fdt_next_property_offset(fdt, offset);
if (offset < 0)
@@ -496,11 +500,16 @@ void fdt_fixup_ethernet(void *fdt)
path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
if (!strncmp(name, "ethernet", 8)) {
/* Treat plain "ethernet" same as "ethernet0". */
- if (!strcmp(name, "ethernet"))
+ if (!strcmp(name, "ethernet")
+#ifdef FDT_SEQ_MACADDR_FROM_ENV
+ || !strcmp(name, "ethernet0")
+#endif
+ )
i = 0;
+#ifndef FDT_SEQ_MACADDR_FROM_ENV
else
i = trailing_strtol(name);
-
+#endif
if (i != -1) {
if (i == 0)
strcpy(mac, "ethaddr");
@@ -509,6 +518,14 @@ void fdt_fixup_ethernet(void *fdt)
} else {
continue;
}
+#ifdef FDT_SEQ_MACADDR_FROM_ENV
+ nodeoff = fdt_path_offset(fdt, path);
+ fdt_prop = fdt_get_property(fdt, nodeoff, "status",
+ NULL);
+ if (fdt_prop && !strcmp(fdt_prop->data, "disabled"))
+ continue;
+ i++;
+#endif
tmp = env_get(mac);
if (!tmp)
continue;
--
2.7.4
More information about the U-Boot
mailing list