summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorManish Pandey <manish.pandey2@arm.com>2022-07-08 13:29:58 +0200
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2022-07-08 13:29:58 +0200
commita4a36421dffe9133b6712bd085cb12a5284d590c (patch)
tree282d1065e27e468447add85b84258541e90df4cb /common
parenta1a2b6d1e2ec168e58ef109670ac567b62b03e96 (diff)
parent1aa7e302a84bbf46a97bcfbb54b6b6d57de76cee (diff)
downloadarm-trusted-firmware-a4a36421dffe9133b6712bd085cb12a5284d590c.tar.gz
Merge "feat(libfdt): add function to set MAC addresses" into integration
Diffstat (limited to 'common')
-rw-r--r--common/fdt_fixup.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/common/fdt_fixup.c b/common/fdt_fixup.c
index b1d628cc0..1bad74fe6 100644
--- a/common/fdt_fixup.c
+++ b/common/fdt_fixup.c
@@ -583,3 +583,44 @@ int fdt_adjust_gic_redist(void *dtb, unsigned int nr_cores,
(ac + sc + ac) * 4,
val, sc * 4);
}
+/**
+ * fdt_set_mac_address () - store MAC address in device tree
+ * @dtb: pointer to the device tree blob in memory
+ * @eth_idx: number of Ethernet interface in /aliases node
+ * @mac_addr: pointer to 6 byte MAC address to store
+ *
+ * Use the generic local-mac-address property in a network device DT node
+ * to define the MAC address this device should be using. Many platform
+ * network devices lack device-specific non-volatile storage to hold this
+ * address, and leave it up to firmware to find and store a unique MAC
+ * address in the DT.
+ * The MAC address could be read from some board or firmware defined storage,
+ * or could be derived from some other unique property like a serial number.
+ *
+ * Return: 0 on success, a negative libfdt error value otherwise.
+ */
+int fdt_set_mac_address(void *dtb, unsigned int ethernet_idx,
+ const uint8_t *mac_addr)
+{
+ char eth_alias[12];
+ const char *path;
+ int node;
+
+ if (ethernet_idx > 9U) {
+ return -FDT_ERR_BADVALUE;
+ }
+ snprintf(eth_alias, sizeof(eth_alias), "ethernet%d", ethernet_idx);
+
+ path = fdt_get_alias(dtb, eth_alias);
+ if (path == NULL) {
+ return -FDT_ERR_NOTFOUND;
+ }
+
+ node = fdt_path_offset(dtb, path);
+ if (node < 0) {
+ ERROR("Path \"%s\" not found in DT: %d\n", path, node);
+ return node;
+ }
+
+ return fdt_setprop(dtb, node, "local-mac-address", mac_addr, 6);
+}