diff mbox

[U-Boot] fdt: fix setting MAC addresses for multiple interfaces

Message ID 1452114118-11100-1-git-send-email-iserovil@deshawresearch.com
State Superseded
Headers show

Commit Message

Lev Iserovich Jan. 6, 2016, 9:01 p.m. UTC
For multiple ethernet interfaces the FDT offset of '/aliases' will change as we
are adding MAC addresses to the FDT.
Therefore only the first interface ('ethernet0') will get properly updated in
the FDT, with the rest getting FDT errors when we try to set their MAC address.

Switch to using fdt_get_alias() which is the proper way to get the FDT path.

Signed-off-by: Lev Iserovich <iserovil@deshawresearch.com>
---

 common/fdt_support.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Lev Iserovich Jan. 7, 2016, 8:21 p.m. UTC | #1
Hi Bin,

On 01/06/2016 09:42 PM, Bin Meng wrote:
> Could you please elaborate more under what situation the offset of 
> '/aliases' will change? 
I believe the offset of '/aliases' will change because we're editing the 
device tree in place (adding the MAC address to it where it wasn't before),
and 'aliases' is at the very end of the device tree.
I've seen this happen on my board (Freescale LS1043A-RDB).
I added some debugging printf's to my code, and saw that all ethernet 
interfaces after ethernet0 get a 'FDT_ERR_BADOFFSET' from the 
fdt_getprop() call , and Linux comes up with only 1 interface.
After this fix all the interfaces come up properly in Linux with the 
right MAC addresses.
> Can you please rebase your patch on top of the following two:
>
> http://patchwork.ozlabs.org/patch/539373/
> http://patchwork.ozlabs.org/patch/539374/
The second patch seems like a rewrite of the scan through interfaces 
loop, so it's not a simple rebase.
I will attempt to do this, and send another patch soon.

Thanks,

Lev
diff mbox

Patch

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 66464db..20e0e1c 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -481,16 +481,12 @@  int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
 void fdt_fixup_ethernet(void *fdt)
 {
-	int node, i, j;
+	int i, j;
 	char enet[16], *tmp, *end;
 	char mac[16];
 	const char *path;
 	unsigned char mac_addr[6];
 
-	node = fdt_path_offset(fdt, "/aliases");
-	if (node < 0)
-		return;
-
 	if (!getenv("ethaddr")) {
 		if (getenv("usbethaddr")) {
 			strcpy(mac, "usbethaddr");
@@ -505,7 +501,7 @@  void fdt_fixup_ethernet(void *fdt)
 	i = 0;
 	while ((tmp = getenv(mac)) != NULL) {
 		sprintf(enet, "ethernet%d", i);
-		path = fdt_getprop(fdt, node, enet, NULL);
+		path = fdt_get_alias(fdt, enet);
 		if (!path) {
 			debug("No alias for %s\n", enet);
 			sprintf(mac, "eth%daddr", ++i);