summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2019-04-15 11:32:13 +0200
committerTom Warren <twarren@nvidia.com>2019-06-05 09:16:32 -0700
commitebf30e8451f457aebc8232a674fa75823dd10d49 (patch)
treee7ecd8f5cdc54875abb8dc0fb9b3b77ffb7636b0 /lib
parent6d93d245c148f10f15724601650fab3a665f102c (diff)
fdtdec: Add fdtdec_set_ethernet_mac_address()
This function can be used to set the local MAC address for the default Ethernet interface in its device tree node. The default interface is identified by the "ethernet" alias. One case where this is useful is for devices that store their MAC address in a custom location. Once extracted, board code can store the MAC address in U-Boot's control DTB so that it will automatically be used by the Ethernet uclass. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Tom Warren <twarren@nvidia.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fdtdec.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index d0ba888973..3ee786b579 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1261,6 +1261,35 @@ __weak void *board_fdt_blob_setup(void)
}
#endif
+int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size)
+{
+ const char *path;
+ int offset, err;
+
+ if (!is_valid_ethaddr(mac))
+ return -EINVAL;
+
+ path = fdt_get_alias(fdt, "ethernet");
+ if (!path)
+ return 0;
+
+ debug("ethernet alias found: %s\n", path);
+
+ offset = fdt_path_offset(fdt, path);
+ if (offset < 0) {
+ debug("ethernet alias points to absent node %s\n", path);
+ return -ENOENT;
+ }
+
+ err = fdt_setprop_inplace(fdt, offset, "local-mac-address", mac, size);
+ if (err < 0)
+ return err;
+
+ debug("MAC address: %pM\n", mac);
+
+ return 0;
+}
+
static int fdtdec_init_reserved_memory(void *blob)
{
int na, ns, node, err;