mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-27 08:50:17 +00:00
kboot: Provide MAC addresses in device tree
Read the MAC addresses from the ADT and store them in "local-mac-address" properties on the relevant nodes in the FDT. This relies on appropriate aliases in the provided FDT, which matches how U-Boot provides MAC addresses on embedded targets. Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
This commit is contained in:
parent
e833e3c052
commit
d33d7ba89d
1 changed files with 37 additions and 0 deletions
37
src/kboot.c
37
src/kboot.c
|
@ -244,6 +244,41 @@ static int dt_set_cpus(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *aliases[] = {
|
||||
"bluetooth0",
|
||||
"ethernet0",
|
||||
"wifi0",
|
||||
};
|
||||
|
||||
static int dt_set_mac_addresses(void)
|
||||
{
|
||||
int anode = adt_path_offset(adt, "/chosen");
|
||||
|
||||
if (anode < 0)
|
||||
bail("ADT: /chosen not found\n");
|
||||
|
||||
for (size_t i = 0; i < sizeof(aliases) / sizeof(*aliases); i++) {
|
||||
char propname[32];
|
||||
sprintf(propname, "mac-address-%s", aliases[i]);
|
||||
|
||||
uint8_t addr[6];
|
||||
if (ADT_GETPROP_ARRAY(adt, anode, propname, addr) < 0)
|
||||
continue;
|
||||
|
||||
const char *path = fdt_get_alias(dt, aliases[i]);
|
||||
if (path == NULL)
|
||||
continue;
|
||||
|
||||
int node = fdt_path_offset(dt, path);
|
||||
if (node < 0)
|
||||
continue;
|
||||
|
||||
fdt_setprop(dt, node, "local-mac-address", addr, sizeof(addr));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kboot_set_initrd(void *start, size_t size)
|
||||
{
|
||||
initrd_start = start;
|
||||
|
@ -292,6 +327,8 @@ int kboot_prepare_dt(void *fdt)
|
|||
return -1;
|
||||
if (dt_set_cpus())
|
||||
return -1;
|
||||
if (dt_set_mac_addresses())
|
||||
return -1;
|
||||
|
||||
if (fdt_pack(dt))
|
||||
bail("FDT: fdt_pack() failed\n");
|
||||
|
|
Loading…
Reference in a new issue