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

Message ID 20170317194459.10109-1-tuomas@tuxera.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Tuomas Tynkkynen March 17, 2017, 7:44 p.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() (and the kernel's of_alias_scan()) only
looks at ethernet aliases ending in digits. Make it also check the
"ethernet" alias.

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

The device trees themselves can't be fixed as someone is already
depending on the "ethernet" alias:

Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
 common/fdt_support.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)


diff --git a/common/fdt_support.c b/common/fdt_support.c
index 55d4d6f6d4..6e509b38e5 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -496,7 +496,15 @@  void fdt_fixup_ethernet(void *fdt)
 		path = fdt_getprop_by_offset(fdt, offset, &name, NULL);
 		if (!strncmp(name, "ethernet", len)) {
-			i = trailing_strtol(name);
+			/*
+			 * Some device trees (bcm2835) have an alias without
+			 * the number at end. Support that as well.
+			 */
+			if (!strcmp(name, "ethernet"))
+				i = 0;
+			else
+				i = trailing_strtol(name);
 			if (i != -1) {
 				if (i == 0)
 					strcpy(mac, "ethaddr");