Skip to contentSkip to conversation

fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

PATCH New Kumar Gala 2 participants 5 messages Aug 18, 2008

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

Move to using the environment variables 'ethaddr', 'eth1addr', etc.. instead of bd->bi_enetaddr, bi_enet1addr, etc.

This makes the code a bit more flexible to the number of ethernet interfaces. Right now we assume a max of 10 interfaces.

---
 common/fdt_support.c  |   65 +++++++++++++++++++++++-------------------------
 cpu/74xx_7xx/cpu.c    |    2 +-
 cpu/mpc512x/cpu.c     |    2 +-
 cpu/mpc8260/cpu.c     |    2 +-
 cpu/mpc83xx/fdt.c     |    2 +-
 cpu/mpc85xx/fdt.c     |    2 +-
 cpu/mpc86xx/fdt.c     |    2 +-
 cpu/mpc8xx/fdt.c      |    2 +-
 cpu/ppc4xx/fdt.c      |    2 +-
 include/fdt_support.h |    2 +-
 10 files changed, 40 insertions(+), 43 deletions(-)
common/fdt_support.c +31 -34
index 93b144e..0b67ee0 100644
@@ -371,49 +371,46 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
 
-void fdt_fixup_ethernet(void *fdt, bd_t *bd)
+#define CFG_MAX_NUM_ETH	(10)
+void fdt_fixup_ethernet(void *fdt)
 {
+	int i, j;
 	int node;
 	const char *path;
 
 	node = fdt_path_offset(fdt, "/aliases");
 	if (node >= 0) {
-#if defined(CONFIG_HAS_ETH0)
-		path = fdt_getprop(fdt, node, "ethernet0", NULL);
-		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address",
-				bd->bi_enetaddr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address",
-				bd->bi_enetaddr, 6, 1);
-		}
-#endif
-#if defined(CONFIG_HAS_ETH1)
-		path = fdt_getprop(fdt, node, "ethernet1", NULL);
-		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address",
-				bd->bi_enet1addr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address",
-				bd->bi_enet1addr, 6, 1);
-		}
-#endif
-#if defined(CONFIG_HAS_ETH2)
-		path = fdt_getprop(fdt, node, "ethernet2", NULL);
-		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address",
-				bd->bi_enet2addr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address",
-				bd->bi_enet2addr, 6, 1);
-		}
-#endif
-#if defined(CONFIG_HAS_ETH3)
-		path = fdt_getprop(fdt, node, "ethernet3", NULL);
-		if (path) {
+		char enet[12], mac[10], *tmp, *end;
+		unsigned char mac_addr[6];
+
+		for (i = 0; i < CFG_MAX_NUM_ETH; i++) {
+			sprintf(enet, "ethernet%d", i);
+			sprintf(mac, "eth%daddr",i);
+
+			sprintf(mac, i ? "eth%daddr" : "ethaddr", i);
+			tmp = getenv(mac);
+			path = fdt_getprop(fdt, node, enet, NULL);
+
+			if (!path) {
+				debug("No alias for %s\n", enet);
+				continue;
+			}
+			if (!tmp) {
+				debug("No environment variable for %s\n", mac);
+				continue;
+			}
+
+			for (j = 0; j < 6; j++) {
+				mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
+				if (tmp)
+					tmp = (*end) ? end+1 : end;
+			}
+
 			do_fixup_by_path(fdt, path, "mac-address",
-				bd->bi_enet3addr, 6, 0);
+					&mac_addr, 6, 0);
 			do_fixup_by_path(fdt, path, "local-mac-address",
-				bd->bi_enet3addr, 6, 1);
+					&mac_addr, 6, 1);
 		}
-#endif
 	}
 }
 #endif
cpu/74xx_7xx/cpu.c +1 -1
index ea43c9a..c007abc 100644
@@ -314,7 +314,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 
 	fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
 
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 }
 #endif
 /* ------------------------------------------------------------------------- */
cpu/mpc512x/cpu.c +1 -1
index 703e188..1f39ac4 100644
@@ -191,7 +191,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 #endif
 	ft_clock_setup(blob, bd);
 #ifdef CONFIG_HAS_ETH0
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 #endif
 }
 #endif
cpu/mpc8260/cpu.c +1 -1
index 4d5d141..efb8ed6 100644
@@ -307,7 +307,7 @@ void ft_cpu_setup (void *blob, bd_t *bd)
 
 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 #endif
 
 	do_fixup_by_path_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1);
cpu/mpc83xx/fdt.c +1 -1
index fda85c1..39bd9dc 100644
@@ -53,7 +53,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 
 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 #endif
 
 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
cpu/mpc85xx/fdt.c +1 -1
index c159934..bc1550d 100644
@@ -212,7 +212,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 
 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
     defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 #endif
 
 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
cpu/mpc86xx/fdt.c +1 -1
index 80a5c78..12d9052 100644
@@ -25,7 +25,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 
 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) \
     || defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 #endif
 
 #ifdef CFG_NS16550
cpu/mpc8xx/fdt.c +1 -1
index 567094a..7130983 100644
@@ -40,7 +40,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 		gd->brg_clk, 1);
 
 	/* Fixup ethernet MAC addresses */
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 
 	fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
 }
cpu/ppc4xx/fdt.c +1 -1
index 0323dc5..a97484f 100644
@@ -130,7 +130,7 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 	 * Fixup all ethernet nodes
 	 * Note: aliases in the dts are required for this
 	 */
-	fdt_fixup_ethernet(blob, bd);
+	fdt_fixup_ethernet(blob);
 
 	/*
 	 * Fixup all available PCIe nodes by setting the device_type property
include/fdt_support.h +1 -1
index a7c6326..f2f2cd5 100644
@@ -45,7 +45,7 @@ void do_fixup_by_compat(void *fdt, const char *compat,
 void do_fixup_by_compat_u32(void *fdt, const char *compat,
 			    const char *prop, u32 val, int create);
 int fdt_fixup_memory(void *blob, u64 start, u64 size);
-void fdt_fixup_ethernet(void *fdt, bd_t *bd);
+void fdt_fixup_ethernet(void *fdt);
 int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
 			 const void *val, int len, int create);
 void fdt_fixup_qe_firmware(void *fdt);
Signature · 1 line
1.5.5.1
#1 lore raw

PATCH 1/1 fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

Dear Kumar Gala,

Quoted 5 lines · In message <[email protected]> you wrote:

Move to using the environment variables 'ethaddr', 'eth1addr', etc.. instead of bd->bi_enetaddr, bi_enet1addr, etc.

This makes the code a bit more flexible to the number of ethernet interfaces. Right now we assume a max of 10 interfaces.

How does this match with our very static way of selecting this using 'CONFIG_HAS_ETH<n>' #defines? There is no such thing as CONFIG_HAS_ETH8 anywhere in the code...

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The one who says it cannot be done should never interrupt the one who
is doing it.
author
#2 lore raw

PATCH 1/1 fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

Quoted 7 lines · Wolfgang Denk

Dear Kumar Gala,

In message <[email protected]>

Quoted 3 lines · you

Move to using the environment variables 'ethaddr', 'eth1addr', etc.. instead of bd->bi_enetaddr, bi_enet1addr, etc.

Quoted 6 lines
Quoted 2 lines

This makes the code a bit more flexible to the number of ethernet interfaces. Right now we assume a max of 10 interfaces.

How does this match with our very static way of selecting this using 'CONFIG_HAS_ETH<n>' #defines? There is no such thing as CONFIG_HAS_ETH8 anywhere in the code...

oops, forgot about that. I think we just have the code exist always (for CONFIG_OF_LIBFDT)

- k

author
#3 lore raw

PATCH 1/1 fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

Quoted 13 lines · Kumar Gala
Quoted 10 lines · Wolfgang Denk

Dear Kumar Gala,

In message <[email protected]>

Quoted 5 lines · you

Move to using the environment variables 'ethaddr', 'eth1addr', etc.. instead of bd->bi_enetaddr, bi_enet1addr, etc.

This makes the code a bit more flexible to the number of ethernet interfaces. Right now we assume a max of 10 interfaces.

Quoted 6 lines
Quoted 3 lines

How does this match with our very static way of selecting this using 'CONFIG_HAS_ETH<n>' #defines? There is no such thing as CONFIG_HAS_ETH8 anywhere in the code...

oops, forgot about that. I think we just have the code exist always (for CONFIG_OF_LIBFDT)

74xx_7xx, mpc8xx, ppc4xx -- called regardless of CONFIG_HAS_ETHn mpc512x -- called only based on HAS_ETH0
mpc8260, mpc83xx, mpc85xx, mpc86xx -- called if HAS_ETH0 || HAS_ETH1 || HAS_ETH2 || HAS_ETH3

With ETH3 being the max today.

We have a part (p4080) in the works with 8 interfaces (its unlikely we'll have support for all 8 in u-boot, but do want to be ablity to set mac addresses for all 8.)

- k

#4 lore raw

PATCH 1/1 fdt: rework fdt_fixup_ethernet() to use env instead of bd_t

Dear Kumar Gala,

Quoted 7 lines · In message <[email protected]> you wrote:

74xx_7xx, mpc8xx, ppc4xx -- called regardless of CONFIG_HAS_ETHn mpc512x -- called only based on HAS_ETH0
mpc8260, mpc83xx, mpc85xx, mpc86xx -- called if HAS_ETH0 || HAS_ETH1 || HAS_ETH2 || HAS_ETH3

With ETH3 being the max today.

Yes. and I have to admit that I really dislike this static configuration which prevents any loops in the code.

Quoted 3 lines

We have a part (p4080) in the works with 8 interfaces (its unlikely we'll have support for all 8 in u-boot, but do want to be ablity to set mac addresses for all 8.)

I guess we should try to find some clever way of overcoming the old style.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Don't panic.