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>
This commit is contained in:
parent
48a346061d
commit
24acb83d8f
9
README
9
README
@ -1603,6 +1603,15 @@ The following options need to be configured:
|
|||||||
|
|
||||||
See doc/README.link-local for more information.
|
See doc/README.link-local for more information.
|
||||||
|
|
||||||
|
- MAC address from environment variables
|
||||||
|
|
||||||
|
FDT_SEQ_MACADDR_FROM_ENV
|
||||||
|
|
||||||
|
Fix-up device tree with MAC addresses fetched sequentially from
|
||||||
|
environment variables. This config work on assumption that
|
||||||
|
non-usable ethernet node of device-tree are either not present
|
||||||
|
or their status has been marked as "disabled".
|
||||||
|
|
||||||
- CDP Options:
|
- CDP Options:
|
||||||
CONFIG_CDP_DEVICE_ID
|
CONFIG_CDP_DEVICE_ID
|
||||||
|
|
||||||
|
@ -508,12 +508,16 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
|
|||||||
|
|
||||||
void fdt_fixup_ethernet(void *fdt)
|
void fdt_fixup_ethernet(void *fdt)
|
||||||
{
|
{
|
||||||
int i, j, prop;
|
int i = 0, j, prop;
|
||||||
char *tmp, *end;
|
char *tmp, *end;
|
||||||
char mac[16];
|
char mac[16];
|
||||||
const char *path;
|
const char *path;
|
||||||
unsigned char mac_addr[ARP_HLEN];
|
unsigned char mac_addr[ARP_HLEN];
|
||||||
int offset;
|
int offset;
|
||||||
|
#ifdef FDT_SEQ_MACADDR_FROM_ENV
|
||||||
|
int nodeoff;
|
||||||
|
const struct fdt_property *fdt_prop;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fdt_path_offset(fdt, "/aliases") < 0)
|
if (fdt_path_offset(fdt, "/aliases") < 0)
|
||||||
return;
|
return;
|
||||||
@ -526,7 +530,7 @@ void fdt_fixup_ethernet(void *fdt)
|
|||||||
offset = fdt_first_property_offset(fdt,
|
offset = fdt_first_property_offset(fdt,
|
||||||
fdt_path_offset(fdt, "/aliases"));
|
fdt_path_offset(fdt, "/aliases"));
|
||||||
/* Select property number 'prop' */
|
/* Select property number 'prop' */
|
||||||
for (i = 0; i < prop; i++)
|
for (j = 0; j < prop; j++)
|
||||||
offset = fdt_next_property_offset(fdt, offset);
|
offset = fdt_next_property_offset(fdt, offset);
|
||||||
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
@ -535,11 +539,16 @@ void fdt_fixup_ethernet(void *fdt)
|
|||||||
path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
|
path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
|
||||||
if (!strncmp(name, "ethernet", 8)) {
|
if (!strncmp(name, "ethernet", 8)) {
|
||||||
/* Treat plain "ethernet" same as "ethernet0". */
|
/* 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;
|
i = 0;
|
||||||
|
#ifndef FDT_SEQ_MACADDR_FROM_ENV
|
||||||
else
|
else
|
||||||
i = trailing_strtol(name);
|
i = trailing_strtol(name);
|
||||||
|
#endif
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
strcpy(mac, "ethaddr");
|
strcpy(mac, "ethaddr");
|
||||||
@ -548,6 +557,14 @@ void fdt_fixup_ethernet(void *fdt)
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
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);
|
tmp = env_get(mac);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user