Skip to contentSkip to conversation

fdt: fix setting MAC addresses for multiple interfaces

PATCH New Lev Iserovich 5 participants 12 messages Jan 6, 2016 – May 4, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt: fix setting MAC addresses for multiple interfaces

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.

---

 common/fdt_support.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
common/fdt_support.c +2 -6
index 66464db..20e0e1c 100644
@@ -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);
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/1 fdt: fix setting MAC addresses for multiple interfaces

Hi Lev,

Quoted 2 lines · Lev Iserovich

For multiple ethernet interfaces the FDT offset of '/aliases' will change as we are adding MAC addresses to the FDT.

Could you please elaborate more under what situation the offset of '/aliases' will change?

Quoted 34 lines

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.

---

 common/fdt_support.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
common/fdt_support.c +1 -5
index 66464db..20e0e1c 100644
@@ -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");

common/fdt_support.c void fdt_fixup_ethernet(void *fdt) · line 504

Quoted 5 lines
common/fdt_support.c +1 -1
@@ -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);

Can you please rebase your patch on top of the following two:

http://patchwork.ozlabs.org/patch/539373/
http://patchwork.ozlabs.org/patch/539374/

common/fdt_support.c void fdt_fixup_ethernet(void *fdt)

Quoted 4 lines
common/fdt_support.c +0 -1
                if (!path) {
                        debug("No alias for %s\n", enet);
                        sprintf(mac, "eth%daddr", ++i);
--

Regards,
Bin

#2 lore raw

PATCH 1/1 fdt: fix setting MAC addresses for multiple interfaces

Hi Bin,

Quoted 2 lines · Bin Meng

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.

Quoted 4 lines

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

#3 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

In reply to Lev Iserovich

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.

---

Changes in v2:
- Rebase on u-boot-net patches:
http://patchwork.ozlabs.org/patch/539373/
http://patchwork.ozlabs.org/patch/539374/
- Recompute offset based on property index

---

  common/fdt_support.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +14 -7
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
  void fdt_fixup_ethernet(void *fdt)
  {
-       int node, i, j;
+       int i, j, prop;
         char *tmp, *end;
         char mac[16];
         const char *path;
         unsigned char mac_addr[6];
         int offset;
 
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                 return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       // Cycle through all aliases
+       for (prop = 0; ; prop++) {
                 const char *name;
                 int len = strlen("ethernet");
 
+               // FDT might have been edited, recompute the offset
+               offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt, "/aliases"));
+               // Select property number 'prop'
+               for (i = 0; i < prop; i++) {
+                       offset = fdt_next_property_offset(fdt, offset);
+               }
+               if (offset < 0)
+                       break;
+
                 path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                 if (!strncmp(name, "ethernet", len)) {
                         i = trailing_strtol(name);
#4 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

Quoted 9 lines · Lev Iserovich

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.

#5 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

In reply to Lev Iserovich

Hi Lev,

Quoted 38 lines · Lev Iserovich

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.

---

Changes in v2:
- Rebase on u-boot-net patches:

     http://patchwork.ozlabs.org/patch/539373/
     http://patchwork.ozlabs.org/patch/539374/

- Recompute offset based on property index

---

 common/fdt_support.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +1 -1
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
 void fdt_fixup_ethernet(void *fdt)
 {
-       int node, i, j;
+       int i, j, prop;
        char *tmp, *end;
        char mac[16];
        const char *path;
        unsigned char mac_addr[6];
        int offset;
 

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 494

Quoted 10 lines
common/fdt_support.c +3 -6
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       // Cycle through all aliases

Please do not use C++ comment style.

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 499

Quoted 5 lines
common/fdt_support.c +2 -0
+       for (prop = 0; ; prop++) {
                const char *name;
                int len = strlen("ethernet");
 
+               // FDT might have been edited, recompute the offset

ditto.

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 502

Quoted 3 lines
common/fdt_support.c +2 -0
+               offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt,
 "/aliases"));
+               // Select property number 'prop'

ditto.

Quoted 10 lines
common/fdt_support.c +6 -0
+               for (i = 0; i < prop; i++) {
+                       offset = fdt_next_property_offset(fdt, offset);
+               }
+               if (offset < 0)
+                       break;
+
                path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                if (!strncmp(name, "ethernet", len)) {
                        i = trailing_strtol(name);

Regards,
Bin

#6 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

Quoted 42 lines · Bin Meng

Hi Lev,

Quoted 38 lines · Lev Iserovich

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.

---

Changes in v2:
- Rebase on u-boot-net patches:

     http://patchwork.ozlabs.org/patch/539373/
     http://patchwork.ozlabs.org/patch/539374/

- Recompute offset based on property index

---

 common/fdt_support.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +1 -1
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
 void fdt_fixup_ethernet(void *fdt)
 {
-       int node, i, j;
+       int i, j, prop;
        char *tmp, *end;
        char mac[16];
        const char *path;
        unsigned char mac_addr[6];
        int offset;
 
Quoted 12 lines

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 494

Quoted 10 lines
common/fdt_support.c +3 -6
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       // Cycle through all aliases

Please do not use C++ comment style.

+Joe

Quoted 7 lines

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 499

Quoted 6 lines
common/fdt_support.c +2 -0
+       for (prop = 0; ; prop++) {
                const char *name;
                int len = strlen("ethernet");
 
+               // FDT might have been edited, recompute the offset
Quoted 19 lines

ditto.

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 502

Quoted 3 lines
common/fdt_support.c +2 -0
+               offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt,
 "/aliases"));
+               // Select property number 'prop'

ditto.

Quoted 10 lines
common/fdt_support.c +6 -0
+               for (i = 0; i < prop; i++) {
+                       offset = fdt_next_property_offset(fdt, offset);
+               }
+               if (offset < 0)
+                       break;
+
                path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                if (!strncmp(name, "ethernet", len)) {
                        i = trailing_strtol(name);

Regards,
Bin

#7 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

Quoted 56 lines · Bin Meng
Quoted 42 lines · Bin Meng

Hi Lev,

Quoted 38 lines · Lev Iserovich

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.

---

Changes in v2:
- Rebase on u-boot-net patches:

     http://patchwork.ozlabs.org/patch/539373/
     http://patchwork.ozlabs.org/patch/539374/

- Recompute offset based on property index

---

 common/fdt_support.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +1 -1
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
 void fdt_fixup_ethernet(void *fdt)
 {
-       int node, i, j;
+       int i, j, prop;
        char *tmp, *end;
        char mac[16];
        const char *path;
        unsigned char mac_addr[6];
        int offset;
 
Quoted 12 lines

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 494

Quoted 10 lines
common/fdt_support.c +3 -6
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       // Cycle through all aliases

Please do not use C++ comment style.

Quoted 1 line

+Joe

I fixed these in place when applying.

Quoted 13 lines
Quoted 13 lines

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 499

Quoted 6 lines
common/fdt_support.c +2 -0
+       for (prop = 0; ; prop++) {
                const char *name;
                int len = strlen("ethernet");
 
+               // FDT might have been edited, recompute the offset

ditto.

Quoted 3 lines
common/fdt_support.c +2 -0
+               offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt,
 "/aliases"));
+               // Select property number 'prop'
Quoted 5 lines
Quoted 5 lines

ditto.

Quoted 3 lines
common/fdt_support.c +3 -0
+               for (i = 0; i < prop; i++) {
+                       offset = fdt_next_property_offset(fdt, offset);
+               }

This is not checkpatch.pl clean either. Fixed when applied.

Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
common/fdt_support.c +3 -0
+               if (offset < 0)
+                       break;
+
                path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                if (!strncmp(name, "ethernet", len)) {
                        i = trailing_strtol(name);

Regards,
Bin
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#8 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

In reply to Bin Meng

Hi,

Updated with C-style comments:

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.

---

Changes in v2:
- Rebase on u-boot-net patches:
http://patchwork.ozlabs.org/patch/539373/
http://patchwork.ozlabs.org/patch/539374/
- Recompute offset based on property index
- C-style comments

---

  common/fdt_support.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +7 -7
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
  void fdt_fixup_ethernet(void *fdt)
  {
-       int node, i, j;
+       int i, j, prop;
         char *tmp, *end;
         char mac[16];
         const char *path;
         unsigned char mac_addr[6];
         int offset;
 
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                 return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       /* Cycle through all aliases */
+       for (prop = 0; ; prop++) {
                 const char *name;
                 int len = strlen("ethernet");
 
+               /* FDT might have been edited, recompute the offset */
+               offset = fdt_first_property_offset(fdt, 

fdt_path_offset(fdt, "/aliases"));
+ /* Select property number 'prop' */
+ for (i = 0; i < prop; i++) {
+ offset = fdt_next_property_offset(fdt, offset);
+ }
+ if (offset < 0)
+ break;
+

                 path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                 if (!strncmp(name, "ethernet", len)) {
                         i = trailing_strtol(name);
Quoted 78 lines · Bin Meng

Hi Lev,

Quoted 38 lines · Lev Iserovich

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.

---

Changes in v2:
- Rebase on u-boot-net patches:
http://patchwork.ozlabs.org/patch/539373/
http://patchwork.ozlabs.org/patch/539374/
- Recompute offset based on property index

---

  common/fdt_support.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
common/fdt_support.c +1 -1
index 48faba9..713d2a4 100644
@@ -481,23 +481,30 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
  void fdt_fixup_ethernet(void *fdt)
  {
-       int node, i, j;
+       int i, j, prop;
         char *tmp, *end;
         char mac[16];
         const char *path;
         unsigned char mac_addr[6];
         int offset;
 

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 494

Quoted 10 lines
common/fdt_support.c +3 -6
-       node = fdt_path_offset(fdt, "/aliases");
-       if (node < 0)
+       if (fdt_path_offset(fdt, "/aliases") < 0)
                 return;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset > 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
+
+       // Cycle through all aliases

Please do not use C++ comment style.

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 499

Quoted 5 lines
common/fdt_support.c +2 -0
+       for (prop = 0; ; prop++) {
                 const char *name;
                 int len = strlen("ethernet");
 
+               // FDT might have been edited, recompute the offset

ditto.

common/fdt_support.c int fdt_fixup_memory(void *blob, u64 start, u64 size) · line 502

Quoted 3 lines
common/fdt_support.c +2 -0
+               offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt,
 "/aliases"));
+               // Select property number 'prop'

ditto.

Quoted 10 lines
common/fdt_support.c +6 -0
+               for (i = 0; i < prop; i++) {
+                       offset = fdt_next_property_offset(fdt, offset);
+               }
+               if (offset < 0)
+                       break;
+
                 path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
                 if (!strncmp(name, "ethernet", len)) {
                         i = trailing_strtol(name);

Regards,
Bin

#9 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

Hi Lev,

Quoted 13 lines · Lev Iserovich

Hi,

Updated with C-style comments:

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.

Quoted 8 lines

---

Changes in v2:
- Rebase on u-boot-net patches:

     http://patchwork.ozlabs.org/patch/539373/
     http://patchwork.ozlabs.org/patch/539374/

- Recompute offset based on property index
- C-style comments

I had already applied your previous patch with a few minor adjustments. Please look at what's in my tree and send a patch on top of that if you care to make further improvements.

Also, you might want to consider using tools/patman/patman when working on patches and sending to the list.

Thanks,
-Joe

http://git.denx.de/?p=u-boot/u-boot-net.git;a=commitdiff;h=f383f32d5568a3a1a4d31efa97f5cf991961a5e8

#10 lore raw

PATCH v2 1/1 fdt: fix setting MAC addresses for multiple interfaces

Hi Joe,

Thanks for fixing that up, I'll try to stick to patman in the future.

--Lev

Quoted 13 lines · Joe Hershberger

Hi Lev,

I had already applied your previous patch with a few minor adjustments. Please look at what's in my tree and send a patch on top of that if you care to make further improvements.

Also, you might want to consider using tools/patman/patman when working on patches and sending to the list.

Thanks,
-Joe

http://git.denx.de/?p=u-boot/u-boot-net.git;a=commitdiff;h=f383f32d5568a3a1a4d31efa97f5cf991961a5e8