mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-28 23:50:26 +09:00
fdt: Rewrite the logic in fdt_fixup_ethernet()
Currently in fdt_fixup_ethernet() the MAC address fix up is handled in a loop of which the exit condition is to test the "eth%daddr" env is not NULL. However this creates unnecessary constrains that those "eth%daddr" env variables must be sequential even if "ethernet%d" does not start from 0 in the "/aliases" node. For example, with "/aliases" node below: aliases { ethernet3 = &enet3; ethernet4 = &enet4; }; "ethaddr", "eth1addr", "eth2addr" must exist in order to fix up ethernet3's MAC address successfully. Now we change the loop logic to iterate the properties in the "/aliases" node. For each property, test if it is in a format of "ethernet%d", then get its MAC address from corresponding "eth%daddr" env and fix it up in the dtb. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Tom Rini <trini@konsulko.com> On OMAP4 Panda (+v4.3 kernel) Tested-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
52d825cc7b
commit
bc393a7954
@ -482,37 +482,49 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
|
|||||||
void fdt_fixup_ethernet(void *fdt)
|
void fdt_fixup_ethernet(void *fdt)
|
||||||
{
|
{
|
||||||
int node, i, j;
|
int node, i, j;
|
||||||
char enet[16], *tmp, *end;
|
char *tmp, *end;
|
||||||
char mac[16];
|
char mac[16];
|
||||||
const char *path;
|
const char *path;
|
||||||
unsigned char mac_addr[6];
|
unsigned char mac_addr[6];
|
||||||
|
int offset;
|
||||||
|
|
||||||
node = fdt_path_offset(fdt, "/aliases");
|
node = fdt_path_offset(fdt, "/aliases");
|
||||||
if (node < 0)
|
if (node < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i = 0;
|
for (offset = fdt_first_property_offset(fdt, node);
|
||||||
strcpy(mac, "ethaddr");
|
offset > 0;
|
||||||
while ((tmp = getenv(mac)) != NULL) {
|
offset = fdt_next_property_offset(fdt, offset)) {
|
||||||
sprintf(enet, "ethernet%d", i);
|
const char *name;
|
||||||
path = fdt_getprop(fdt, node, enet, NULL);
|
int len = strlen("ethernet");
|
||||||
if (!path) {
|
|
||||||
debug("No alias for %s\n", enet);
|
path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
|
||||||
sprintf(mac, "eth%daddr", ++i);
|
if (!strncmp(name, "ethernet", len)) {
|
||||||
continue;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
sprintf(mac, "eth%daddr", ++i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user