[U-Boot,v2] fdt_support: Fixup 'ethernet' aliases not ending in digits

Submitted by Tuomas Tynkkynen on March 20, 2017, 8:04 a.m.

Details

Message ID 20170320080455.24993-1-tuomas@tuxera.com
State Accepted
Commit f8e57c650d691e3617c49a16ec7a4dcab436100e
Delegated to: Joe Hershberger
Headers show

Commit Message

Tuomas Tynkkynen March 20, 2017, 8:04 a.m.
The Raspberry Pi device tree files since Linux v4.9 have a "ethernet"
alias pointing to the on-board Ethernet device node. However,
U-Boot's fdt_fixup_ethernet() only looks at ethernet aliases ending
in digits.

As the spec doesn't mandate that aliases must end in numbers and there
have been much older uses of an "ethernet" aliases in the wild
(according to Tom Rini), change the code to accept "ethernet" as well.

Without this Linux isn't told of the MAC address provided by the
RPI firmware and the ethernet interface is always assigned a random MAC
address.

Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
---
v2: Change code & commit messages to imply that plain 'ethernet' usage
    is not a bug in the DT, kill the 'len' variable.
 common/fdt_support.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Tom Rini March 20, 2017, 2:29 p.m.
On Mon, Mar 20, 2017 at 10:04:55AM +0200, Tuomas Tynkkynen wrote:

> The Raspberry Pi device tree files since Linux v4.9 have a "ethernet"
> alias pointing to the on-board Ethernet device node. However,
> U-Boot's fdt_fixup_ethernet() only looks at ethernet aliases ending
> in digits.
> 
> As the spec doesn't mandate that aliases must end in numbers and there
> have been much older uses of an "ethernet" aliases in the wild
> (according to Tom Rini), change the code to accept "ethernet" as well.
> 
> Without this Linux isn't told of the MAC address provided by the
> RPI firmware and the ethernet interface is always assigned a random MAC
> address.
> 
> Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Joe Hershberger March 21, 2017, 6:30 p.m.
On Mon, Mar 20, 2017 at 3:04 AM, Tuomas Tynkkynen <tuomas@tuxera.com> wrote:
> The Raspberry Pi device tree files since Linux v4.9 have a "ethernet"
> alias pointing to the on-board Ethernet device node. However,
> U-Boot's fdt_fixup_ethernet() only looks at ethernet aliases ending
> in digits.
>
> As the spec doesn't mandate that aliases must end in numbers and there
> have been much older uses of an "ethernet" aliases in the wild
> (according to Tom Rini), change the code to accept "ethernet" as well.
>
> Without this Linux isn't told of the MAC address provided by the
> RPI firmware and the ethernet interface is always assigned a random MAC
> address.
>
> Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger March 27, 2017, 4:52 p.m.
Hi Tuomas,

https://patchwork.ozlabs.org/patch/740833/ was applied to u-boot-net.git.

Thanks!
-Joe

Patch hide | download patch | download mbox

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 55d4d6f6d4..c6a76b7ad2 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -482,7 +482,6 @@  void fdt_fixup_ethernet(void *fdt)
 	/* 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,
@@ -495,8 +494,13 @@  void fdt_fixup_ethernet(void *fdt)
 			break;
 
 		path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
-		if (!strncmp(name, "ethernet", len)) {
-			i = trailing_strtol(name);
+		if (!strncmp(name, "ethernet", 8)) {
+			/* Treat plain "ethernet" same as "ethernet0". */
+			if (!strcmp(name, "ethernet"))
+				i = 0;
+			else
+				i = trailing_strtol(name);
+
 			if (i != -1) {
 				if (i == 0)
 					strcpy(mac, "ethaddr");