All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses
@ 2016-07-09 13:12 Hans de Goede
  2016-07-10  8:15 ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2016-07-09 13:12 UTC (permalink / raw)
  To: u-boot

Currently we fill ethaddr with a fixed unique address based on the SoCs
serial (from the sid) to make sure that boards which use the integrated
emac / gmac get a fixed mac rather then a random one.

On some boards the wifi does not come with a fixed mac either, so we need
to also set eth1addr.

This commit changes the ethaddr setting code to check for ethernet%d
aliases (as fdt_fixup_ethernet does) and set an ethaddr variable for
all present aliases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Only set ethaddr env variable for ethernet interfaces which have
 an ethernet%d alias in the dt aliases node
---
 board/sunxi/board.c | 59 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 78dfda5..955a44f 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -26,6 +26,7 @@
 #endif
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <libfdt.h>
 #include <nand.h>
 #include <net.h>
 #include <sy8106a.h>
@@ -609,36 +610,38 @@ static void parse_spl_header(const uint32_t spl_addr)
 }
 #endif
 
-#ifdef CONFIG_MISC_INIT_R
-int misc_init_r(void)
+static void setup_environment(const void *fdt)
 {
 	char serial_string[17] = { 0 };
 	unsigned int sid[4];
 	uint8_t mac_addr[6];
-	int ret;
-
-#if !defined(CONFIG_SPL_BUILD)
-	setenv("fel_booted", NULL);
-	setenv("fel_scriptaddr", NULL);
-	/* determine if we are running in FEL mode */
-	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
-		setenv("fel_booted", "1");
-		parse_spl_header(SPL_ADDR);
-	}
-#endif
+	char ethaddr[16];
+	int i, ret;
 
 	ret = sunxi_get_sid(sid);
 	if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
-		if (!getenv("ethaddr")) {
+		for (i = 0; i < 4; i++) {
+			sprintf(ethaddr, "ethernet%d", i);
+			if (!fdt_get_alias(fdt, ethaddr))
+				continue;
+
+			if (i == 0)
+				strcpy(ethaddr, "ethaddr");
+			else
+				sprintf(ethaddr, "eth%daddr", i);
+
+			if (getenv(ethaddr))
+				continue;
+
 			/* Non OUI / registered MAC address */
-			mac_addr[0] = 0x02;
+			mac_addr[0] = (i << 4) | 0x02;
 			mac_addr[1] = (sid[0] >>  0) & 0xff;
 			mac_addr[2] = (sid[3] >> 24) & 0xff;
 			mac_addr[3] = (sid[3] >> 16) & 0xff;
 			mac_addr[4] = (sid[3] >>  8) & 0xff;
 			mac_addr[5] = (sid[3] >>  0) & 0xff;
 
-			eth_setenv_enetaddr("ethaddr", mac_addr);
+			eth_setenv_enetaddr(ethaddr, mac_addr);
 		}
 
 		if (!getenv("serial#")) {
@@ -648,6 +651,24 @@ int misc_init_r(void)
 			setenv("serial#", serial_string);
 		}
 	}
+}
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+	int ret;
+
+#if !defined(CONFIG_SPL_BUILD)
+	setenv("fel_booted", NULL);
+	setenv("fel_scriptaddr", NULL);
+	/* determine if we are running in FEL mode */
+	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
+		setenv("fel_booted", "1");
+		parse_spl_header(SPL_ADDR);
+	}
+#endif
+
+	setup_environment(gd->fdt_blob);
 
 #ifndef CONFIG_MACH_SUN9I
 	ret = sunxi_usb_phy_probe();
@@ -664,6 +685,12 @@ int ft_board_setup(void *blob, bd_t *bd)
 {
 	int __maybe_unused r;
 
+	/*
+	 * Call setup_environment again in case the boot fdt has
+	 * ethernet aliases the u-boot copy does not have.
+	 */
+	setup_environment(blob);
+
 #ifdef CONFIG_VIDEO_DT_SIMPLEFB
 	r = sunxi_simplefb_setup(blob);
 	if (r)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses
  2016-07-09 13:12 [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses Hans de Goede
@ 2016-07-10  8:15 ` Ian Campbell
  2016-07-11  9:02   ` Hans de Goede
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2016-07-10  8:15 UTC (permalink / raw)
  To: u-boot

On Sat, 2016-07-09 at 15:12 +0200, Hans de Goede wrote:
> Currently we fill ethaddr with a fixed unique address based on the
> SoCs
> serial (from the sid) to make sure that boards which use the
> integrated
> emac / gmac get a fixed mac rather then a random one.
> 
> On some boards the wifi does not come with a fixed mac either, so we
> need
> to also set eth1addr.
> 
> This commit changes the ethaddr setting code to check for ethernet%d
> aliases (as fdt_fixup_ethernet does) and set an ethaddr variable for
> all present aliases.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Ian Campbell <ijc@hellion.org.uk>

> [...]
> +static void setup_environment(const void *fdt)

It might be worth adding a commit to this function noting that it must
remain idempotent.

Ian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses
  2016-07-10  8:15 ` Ian Campbell
@ 2016-07-11  9:02   ` Hans de Goede
  2016-07-11 13:08     ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2016-07-11  9:02 UTC (permalink / raw)
  To: u-boot

Hi,

On 10-07-16 10:15, Ian Campbell wrote:
> On Sat, 2016-07-09 at 15:12 +0200, Hans de Goede wrote:
>> Currently we fill ethaddr with a fixed unique address based on the
>> SoCs
>> serial (from the sid) to make sure that boards which use the
>> integrated
>> emac / gmac get a fixed mac rather then a random one.
>>
>> On some boards the wifi does not come with a fixed mac either, so we
>> need
>> to also set eth1addr.
>>
>> This commit changes the ethaddr setting code to check for ethernet%d
>> aliases (as fdt_fixup_ethernet does) and set an ethaddr variable for
>> all present aliases.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>
> Acked-by: Ian Campbell <ijc@hellion.org.uk>
>
>> [...]
>> +static void setup_environment(const void *fdt)
>
> It might be worth adding a commit to this function noting that it must
> remain idempotent.

Done, although I avoided the use of the word idempotent, I had to google
it to make sure it meant what I thought it meant, so using a simpler
description for us non native Enlgish speakers seemed better :)

Regards,

Hans

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses
  2016-07-11  9:02   ` Hans de Goede
@ 2016-07-11 13:08     ` Ian Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2016-07-11 13:08 UTC (permalink / raw)
  To: u-boot

On Mon, 2016-07-11 at 11:02 +0200, Hans de Goede wrote:
> > On Sat, 2016-07-09 at 15:12 +0200, Hans de Goede wrote:
> > > 
> > > [...]
> > > +static void setup_environment(const void *fdt)
> > 
> > It might be worth adding a commit to this function noting that it
> > must
> > remain idempotent.
> 
> Done, although I avoided the use of the word idempotent, I had to google
> it to make sure it meant what I thought it meant, so using a simpler
> description for us non native Enlgish speakers seemed better :)

Fair enough.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-11 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-09 13:12 [U-Boot] [PATCH v2] sunxi: Add support for multiple ethadrr-esses Hans de Goede
2016-07-10  8:15 ` Ian Campbell
2016-07-11  9:02   ` Hans de Goede
2016-07-11 13:08     ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.