All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
@ 2021-01-11 11:19 ` Artem Lapkin
  0 siblings, 0 replies; 8+ messages in thread
From: Artem Lapkin @ 2021-01-11 11:19 UTC (permalink / raw)
  To: u-boot

Add the board specific code for reading built-in ethernet MAC address from efuse

NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset

if mac from efuse not valid we use meson_generate_serial_ethaddr

NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong@baylibre.com>

Signed-off-by: Artem Lapkin <art@khadas.com>
---
 board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
index 09ef39ff30..c5d19cc17b 100644
--- a/board/amlogic/vim3/vim3.c
+++ b/board/amlogic/vim3/vim3.c
@@ -11,9 +11,14 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/eth.h>
+#include <asm/arch/sm.h>
 #include <i2c.h>
 #include "khadas-mcu.h"
 
+#define EFUSE_MAC_OFFSET	0
+#define EFUSE_MAC_SIZE		12
+#define MAC_ADDR_LEN		6
+
 /*
  * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
  * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
@@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
 
 int misc_init_r(void)
 {
+	u8 mac_addr[MAC_ADDR_LEN];
+	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
+	ssize_t len;
+
 	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
 
+	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
+
+		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
+		if (len != EFUSE_MAC_SIZE)
+			return 0;
+
+		/* MAC is stored in ASCII format, 1bytes = 2characters */
+		for (int i = 0; i < 6; i++) {
+			tmp[0] = efuse_mac_addr[i * 2];
+			tmp[1] = efuse_mac_addr[i * 2 + 1];
+			tmp[2] = '\0';
+			mac_addr[i] = simple_strtoul(tmp, NULL, 16);
+		}
+
+		if (is_valid_ethaddr(mac_addr))
+			eth_env_set_enetaddr("ethaddr", mac_addr);
+		else
+			meson_generate_serial_ethaddr();
+
+		eth_env_get_enetaddr("ethaddr", mac_addr);
+		printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
+			mac_addr[0],mac_addr[1],mac_addr[2],
+			mac_addr[3],mac_addr[4],mac_addr[5]);
+
+	}
+
 	return 0;
 }
-- 
2.25.1

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

* [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
@ 2021-01-11 11:19 ` Artem Lapkin
  0 siblings, 0 replies; 8+ messages in thread
From: Artem Lapkin @ 2021-01-11 11:19 UTC (permalink / raw)
  To: narmstrong
  Cc: u-boot-amlogic, u-boot, khilman, christianshewitt,
	martin.blumenstingl, m.szyprowski, jh80.chung, art, nick, gouwa

Add the board specific code for reading built-in ethernet MAC address from efuse

NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset

if mac from efuse not valid we use meson_generate_serial_ethaddr

NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong@baylibre.com>

Signed-off-by: Artem Lapkin <art@khadas.com>
---
 board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
index 09ef39ff30..c5d19cc17b 100644
--- a/board/amlogic/vim3/vim3.c
+++ b/board/amlogic/vim3/vim3.c
@@ -11,9 +11,14 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/eth.h>
+#include <asm/arch/sm.h>
 #include <i2c.h>
 #include "khadas-mcu.h"
 
+#define EFUSE_MAC_OFFSET	0
+#define EFUSE_MAC_SIZE		12
+#define MAC_ADDR_LEN		6
+
 /*
  * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
  * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
@@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
 
 int misc_init_r(void)
 {
+	u8 mac_addr[MAC_ADDR_LEN];
+	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
+	ssize_t len;
+
 	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
 
+	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
+
+		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
+		if (len != EFUSE_MAC_SIZE)
+			return 0;
+
+		/* MAC is stored in ASCII format, 1bytes = 2characters */
+		for (int i = 0; i < 6; i++) {
+			tmp[0] = efuse_mac_addr[i * 2];
+			tmp[1] = efuse_mac_addr[i * 2 + 1];
+			tmp[2] = '\0';
+			mac_addr[i] = simple_strtoul(tmp, NULL, 16);
+		}
+
+		if (is_valid_ethaddr(mac_addr))
+			eth_env_set_enetaddr("ethaddr", mac_addr);
+		else
+			meson_generate_serial_ethaddr();
+
+		eth_env_get_enetaddr("ethaddr", mac_addr);
+		printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
+			mac_addr[0],mac_addr[1],mac_addr[2],
+			mac_addr[3],mac_addr[4],mac_addr[5]);
+
+	}
+
 	return 0;
 }
-- 
2.25.1


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

* [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
  2021-01-11 11:19 ` Artem Lapkin
@ 2021-01-11 13:59   ` Neil Armstrong
  -1 siblings, 0 replies; 8+ messages in thread
From: Neil Armstrong @ 2021-01-11 13:59 UTC (permalink / raw)
  To: u-boot

Hi Artem,

On 11/01/2021 12:19, Artem Lapkin wrote:
> Add the board specific code for reading built-in ethernet MAC address from efuse
> 
> NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
> 
> if mac from efuse not valid we use meson_generate_serial_ethaddr
> 
> NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong@baylibre.com>

So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski at samsung.com/) doesn't work ?
Are you sure the MAC is stored in ASCII like Odroid-N2 ?

Please look at my u-boot-amlogic-next tree I will push this week for the next u-boot release:
https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next

Neil

> 
> Signed-off-by: Artem Lapkin <art@khadas.com>
> ---
>  board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> index 09ef39ff30..c5d19cc17b 100644
> --- a/board/amlogic/vim3/vim3.c
> +++ b/board/amlogic/vim3/vim3.c
> @@ -11,9 +11,14 @@
>  #include <net.h>
>  #include <asm/io.h>
>  #include <asm/arch/eth.h>
> +#include <asm/arch/sm.h>
>  #include <i2c.h>
>  #include "khadas-mcu.h"
>  
> +#define EFUSE_MAC_OFFSET	0
> +#define EFUSE_MAC_SIZE		12
> +#define MAC_ADDR_LEN		6
> +
>  /*
>   * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
>   * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
> @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>  
>  int misc_init_r(void)
>  {
> +	u8 mac_addr[MAC_ADDR_LEN];
> +	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
> +	ssize_t len;
> +
>  	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
>  
> +	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
> +
> +		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
> +		if (len != EFUSE_MAC_SIZE)
> +			return 0;
> +
> +		/* MAC is stored in ASCII format, 1bytes = 2characters */
> +		for (int i = 0; i < 6; i++) {
> +			tmp[0] = efuse_mac_addr[i * 2];
> +			tmp[1] = efuse_mac_addr[i * 2 + 1];
> +			tmp[2] = '\0';
> +			mac_addr[i] = simple_strtoul(tmp, NULL, 16);
> +		}
> +
> +		if (is_valid_ethaddr(mac_addr))
> +			eth_env_set_enetaddr("ethaddr", mac_addr);
> +		else
> +			meson_generate_serial_ethaddr();
> +
> +		eth_env_get_enetaddr("ethaddr", mac_addr);
> +		printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
> +			mac_addr[0],mac_addr[1],mac_addr[2],
> +			mac_addr[3],mac_addr[4],mac_addr[5]);
> +
> +	}
> +
>  	return 0;
>  }
> 

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

* Re: [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
@ 2021-01-11 13:59   ` Neil Armstrong
  0 siblings, 0 replies; 8+ messages in thread
From: Neil Armstrong @ 2021-01-11 13:59 UTC (permalink / raw)
  To: Artem Lapkin
  Cc: u-boot-amlogic, u-boot, khilman, christianshewitt,
	martin.blumenstingl, m.szyprowski, jh80.chung, art, nick, gouwa

Hi Artem,

On 11/01/2021 12:19, Artem Lapkin wrote:
> Add the board specific code for reading built-in ethernet MAC address from efuse
> 
> NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
> 
> if mac from efuse not valid we use meson_generate_serial_ethaddr
> 
> NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong@baylibre.com>

So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski@samsung.com/) doesn't work ?
Are you sure the MAC is stored in ASCII like Odroid-N2 ?

Please look at my u-boot-amlogic-next tree I will push this week for the next u-boot release:
https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next

Neil

> 
> Signed-off-by: Artem Lapkin <art@khadas.com>
> ---
>  board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> index 09ef39ff30..c5d19cc17b 100644
> --- a/board/amlogic/vim3/vim3.c
> +++ b/board/amlogic/vim3/vim3.c
> @@ -11,9 +11,14 @@
>  #include <net.h>
>  #include <asm/io.h>
>  #include <asm/arch/eth.h>
> +#include <asm/arch/sm.h>
>  #include <i2c.h>
>  #include "khadas-mcu.h"
>  
> +#define EFUSE_MAC_OFFSET	0
> +#define EFUSE_MAC_SIZE		12
> +#define MAC_ADDR_LEN		6
> +
>  /*
>   * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
>   * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
> @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>  
>  int misc_init_r(void)
>  {
> +	u8 mac_addr[MAC_ADDR_LEN];
> +	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
> +	ssize_t len;
> +
>  	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
>  
> +	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
> +
> +		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
> +		if (len != EFUSE_MAC_SIZE)
> +			return 0;
> +
> +		/* MAC is stored in ASCII format, 1bytes = 2characters */
> +		for (int i = 0; i < 6; i++) {
> +			tmp[0] = efuse_mac_addr[i * 2];
> +			tmp[1] = efuse_mac_addr[i * 2 + 1];
> +			tmp[2] = '\0';
> +			mac_addr[i] = simple_strtoul(tmp, NULL, 16);
> +		}
> +
> +		if (is_valid_ethaddr(mac_addr))
> +			eth_env_set_enetaddr("ethaddr", mac_addr);
> +		else
> +			meson_generate_serial_ethaddr();
> +
> +		eth_env_get_enetaddr("ethaddr", mac_addr);
> +		printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
> +			mac_addr[0],mac_addr[1],mac_addr[2],
> +			mac_addr[3],mac_addr[4],mac_addr[5]);
> +
> +	}
> +
>  	return 0;
>  }
> 


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

* [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
  2021-01-11 13:59   ` Neil Armstrong
@ 2021-01-11 14:15     ` Art Nikpal
  -1 siblings, 0 replies; 8+ messages in thread
From: Art Nikpal @ 2021-01-11 14:15 UTC (permalink / raw)
  To: u-boot

> So the patch from Marek (
https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski at samsung.com/)
doesn't work ?
yes doesnt works properly im sure if we read as raw 6 bytes from efuse we
have

		if (is_valid_ethaddr(mac_addr)) # is always not valid
			eth_env_set_enetaddr("ethaddr", mac_addr);		else    # and always
generated from serial 			meson_generate_serial_ethaddr();

> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
yes im check two times on my vim3 vim3l boards and our amlogic vendor uboot
have same method

On Mon, Jan 11, 2021 at 9:59 PM Neil Armstrong <narmstrong@baylibre.com>
wrote:

> Hi Artem,
>
> On 11/01/2021 12:19, Artem Lapkin wrote:
> > Add the board specific code for reading built-in ethernet MAC address
> from efuse
> >
> > NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
> >
> > if mac from efuse not valid we use meson_generate_serial_ethaddr
> >
> > NOTE: remake odroid-n2.c variant from Neil Armstrong <
> narmstrong at baylibre.com>
>
> So the patch from Marek (
> https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski at samsung.com/)
> doesn't work ?
> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
>
> Please look at my u-boot-amlogic-next tree I will push this week for the
> next u-boot release:
>
> https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next
>
> Neil
>
> >
> > Signed-off-by: Artem Lapkin <art@khadas.com>
> > ---
> >  board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> >
> > diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> > index 09ef39ff30..c5d19cc17b 100644
> > --- a/board/amlogic/vim3/vim3.c
> > +++ b/board/amlogic/vim3/vim3.c
> > @@ -11,9 +11,14 @@
> >  #include <net.h>
> >  #include <asm/io.h>
> >  #include <asm/arch/eth.h>
> > +#include <asm/arch/sm.h>
> >  #include <i2c.h>
> >  #include "khadas-mcu.h"
> >
> > +#define EFUSE_MAC_OFFSET     0
> > +#define EFUSE_MAC_SIZE               12
> > +#define MAC_ADDR_LEN         6
> > +
> >  /*
> >   * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
> >   * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
> > @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info
> *bd)
> >
> >  int misc_init_r(void)
> >  {
> > +     u8 mac_addr[MAC_ADDR_LEN];
> > +     char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
> > +     ssize_t len;
> > +
> >       meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
> >
> > +     if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
> > +
> > +             len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
> efuse_mac_addr, EFUSE_MAC_SIZE);
> > +             if (len != EFUSE_MAC_SIZE)
> > +                     return 0;
> > +
> > +             /* MAC is stored in ASCII format, 1bytes = 2characters */
> > +             for (int i = 0; i < 6; i++) {
> > +                     tmp[0] = efuse_mac_addr[i * 2];
> > +                     tmp[1] = efuse_mac_addr[i * 2 + 1];
> > +                     tmp[2] = '\0';
> > +                     mac_addr[i] = simple_strtoul(tmp, NULL, 16);
> > +             }
> > +
> > +             if (is_valid_ethaddr(mac_addr))
> > +                     eth_env_set_enetaddr("ethaddr", mac_addr);
> > +             else
> > +                     meson_generate_serial_ethaddr();
> > +
> > +             eth_env_get_enetaddr("ethaddr", mac_addr);
> > +             printf("[i] setup onboard mac
> %02X:%02X:%02X:%02X:%02X:%02X\n",
> > +                     mac_addr[0],mac_addr[1],mac_addr[2],
> > +                     mac_addr[3],mac_addr[4],mac_addr[5]);
> > +
> > +     }
> > +
> >       return 0;
> >  }
> >
>
>

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

* Re: [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
@ 2021-01-11 14:15     ` Art Nikpal
  0 siblings, 0 replies; 8+ messages in thread
From: Art Nikpal @ 2021-01-11 14:15 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: u-boot-amlogic, u-boot, khilman, Christian Hewitt,
	Martin Blumenstingl, m.szyprowski, Jaehoon Chung, Artem Lapkin,
	nick, Gouwa Wang

[-- Attachment #1: Type: text/plain, Size: 3721 bytes --]

> So the patch from Marek (
https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski@samsung.com/)
doesn't work ?
yes doesnt works properly im sure if we read as raw 6 bytes from efuse we
have

		if (is_valid_ethaddr(mac_addr)) # is always not valid
			eth_env_set_enetaddr("ethaddr", mac_addr);		else    # and always
generated from serial 			meson_generate_serial_ethaddr();

> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
yes im check two times on my vim3 vim3l boards and our amlogic vendor uboot
have same method

On Mon, Jan 11, 2021 at 9:59 PM Neil Armstrong <narmstrong@baylibre.com>
wrote:

> Hi Artem,
>
> On 11/01/2021 12:19, Artem Lapkin wrote:
> > Add the board specific code for reading built-in ethernet MAC address
> from efuse
> >
> > NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
> >
> > if mac from efuse not valid we use meson_generate_serial_ethaddr
> >
> > NOTE: remake odroid-n2.c variant from Neil Armstrong <
> narmstrong@baylibre.com>
>
> So the patch from Marek (
> https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski@samsung.com/)
> doesn't work ?
> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
>
> Please look at my u-boot-amlogic-next tree I will push this week for the
> next u-boot release:
>
> https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next
>
> Neil
>
> >
> > Signed-off-by: Artem Lapkin <art@khadas.com>
> > ---
> >  board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> >
> > diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> > index 09ef39ff30..c5d19cc17b 100644
> > --- a/board/amlogic/vim3/vim3.c
> > +++ b/board/amlogic/vim3/vim3.c
> > @@ -11,9 +11,14 @@
> >  #include <net.h>
> >  #include <asm/io.h>
> >  #include <asm/arch/eth.h>
> > +#include <asm/arch/sm.h>
> >  #include <i2c.h>
> >  #include "khadas-mcu.h"
> >
> > +#define EFUSE_MAC_OFFSET     0
> > +#define EFUSE_MAC_SIZE               12
> > +#define MAC_ADDR_LEN         6
> > +
> >  /*
> >   * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
> >   * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
> > @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info
> *bd)
> >
> >  int misc_init_r(void)
> >  {
> > +     u8 mac_addr[MAC_ADDR_LEN];
> > +     char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
> > +     ssize_t len;
> > +
> >       meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
> >
> > +     if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
> > +
> > +             len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
> efuse_mac_addr, EFUSE_MAC_SIZE);
> > +             if (len != EFUSE_MAC_SIZE)
> > +                     return 0;
> > +
> > +             /* MAC is stored in ASCII format, 1bytes = 2characters */
> > +             for (int i = 0; i < 6; i++) {
> > +                     tmp[0] = efuse_mac_addr[i * 2];
> > +                     tmp[1] = efuse_mac_addr[i * 2 + 1];
> > +                     tmp[2] = '\0';
> > +                     mac_addr[i] = simple_strtoul(tmp, NULL, 16);
> > +             }
> > +
> > +             if (is_valid_ethaddr(mac_addr))
> > +                     eth_env_set_enetaddr("ethaddr", mac_addr);
> > +             else
> > +                     meson_generate_serial_ethaddr();
> > +
> > +             eth_env_get_enetaddr("ethaddr", mac_addr);
> > +             printf("[i] setup onboard mac
> %02X:%02X:%02X:%02X:%02X:%02X\n",
> > +                     mac_addr[0],mac_addr[1],mac_addr[2],
> > +                     mac_addr[3],mac_addr[4],mac_addr[5]);
> > +
> > +     }
> > +
> >       return 0;
> >  }
> >
>
>

[-- Attachment #2: Type: text/html, Size: 5567 bytes --]

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

* [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
  2021-01-11 14:15     ` Art Nikpal
@ 2021-01-11 14:17       ` Neil Armstrong
  -1 siblings, 0 replies; 8+ messages in thread
From: Neil Armstrong @ 2021-01-11 14:17 UTC (permalink / raw)
  To: u-boot

Hi,

On 11/01/2021 15:15, Art Nikpal wrote:
>> So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski at samsung.com/) doesn't work ?
> yes doesnt works properly im sure if we read as raw 6 bytes from efuse we have
> 
> if (is_valid_ethaddr(mac_addr)) # is always not valid
> eth_env_set_enetaddr("ethaddr", mac_addr);
> else    # and always generated from serial 
> meson_generate_serial_ethaddr();
> 
>> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
> yes im check two times on my vim3 vim3l boards and our amlogic vendor uboot have same method

OK, can you send a patch over the https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next branch ?

Neil

> 
> On Mon, Jan 11, 2021 at 9:59 PM Neil Armstrong <narmstrong at baylibre.com <mailto:narmstrong@baylibre.com>> wrote:
> 
>     Hi Artem,
> 
>     On 11/01/2021 12:19, Artem Lapkin wrote:
>     > Add the board specific code for reading built-in ethernet MAC address from efuse
>     >
>     > NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
>     >
>     > if mac from efuse not valid we use meson_generate_serial_ethaddr
>     >
>     > NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong at baylibre.com <mailto:narmstrong@baylibre.com>>
> 
>     So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski at samsung.com/) doesn't work ?
>     Are you sure the MAC is stored in ASCII like Odroid-N2 ?
> 
>     Please look at my u-boot-amlogic-next tree I will push this week for the next u-boot release:
>     https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next
> 
>     Neil
> 
>     >
>     > Signed-off-by: Artem Lapkin <art at khadas.com <mailto:art@khadas.com>>
>     > ---
>     >? board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
>     >? 1 file changed, 35 insertions(+)
>     >
>     > diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
>     > index 09ef39ff30..c5d19cc17b 100644
>     > --- a/board/amlogic/vim3/vim3.c
>     > +++ b/board/amlogic/vim3/vim3.c
>     > @@ -11,9 +11,14 @@
>     >? #include <net.h>
>     >? #include <asm/io.h>
>     >? #include <asm/arch/eth.h>
>     > +#include <asm/arch/sm.h>
>     >? #include <i2c.h>
>     >? #include "khadas-mcu.h"
>     >?
>     > +#define EFUSE_MAC_OFFSET? ? ?0
>     > +#define EFUSE_MAC_SIZE? ? ? ? ? ? ? ?12
>     > +#define MAC_ADDR_LEN? ? ? ? ?6
>     > +
>     >? /*
>     >? ?* The VIM3 on-board? MCU can mux the PCIe/USB3.0 shared differential
>     >? ?* lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
>     > @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>     >?
>     >? int misc_init_r(void)
>     >? {
>     > +? ? ?u8 mac_addr[MAC_ADDR_LEN];
>     > +? ? ?char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
>     > +? ? ?ssize_t len;
>     > +
>     >? ? ? ?meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
>     >?
>     > +? ? ?if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
>     > +
>     > +? ? ? ? ? ? ?len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
>     > +? ? ? ? ? ? ?if (len != EFUSE_MAC_SIZE)
>     > +? ? ? ? ? ? ? ? ? ? ?return 0;
>     > +
>     > +? ? ? ? ? ? ?/* MAC is stored in ASCII format, 1bytes = 2characters */
>     > +? ? ? ? ? ? ?for (int i = 0; i < 6; i++) {
>     > +? ? ? ? ? ? ? ? ? ? ?tmp[0] = efuse_mac_addr[i * 2];
>     > +? ? ? ? ? ? ? ? ? ? ?tmp[1] = efuse_mac_addr[i * 2 + 1];
>     > +? ? ? ? ? ? ? ? ? ? ?tmp[2] = '\0';
>     > +? ? ? ? ? ? ? ? ? ? ?mac_addr[i] = simple_strtoul(tmp, NULL, 16);
>     > +? ? ? ? ? ? ?}
>     > +
>     > +? ? ? ? ? ? ?if (is_valid_ethaddr(mac_addr))
>     > +? ? ? ? ? ? ? ? ? ? ?eth_env_set_enetaddr("ethaddr", mac_addr);
>     > +? ? ? ? ? ? ?else
>     > +? ? ? ? ? ? ? ? ? ? ?meson_generate_serial_ethaddr();
>     > +
>     > +? ? ? ? ? ? ?eth_env_get_enetaddr("ethaddr", mac_addr);
>     > +? ? ? ? ? ? ?printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
>     > +? ? ? ? ? ? ? ? ? ? ?mac_addr[0],mac_addr[1],mac_addr[2],
>     > +? ? ? ? ? ? ? ? ? ? ?mac_addr[3],mac_addr[4],mac_addr[5]);
>     > +
>     > +? ? ?}
>     > +
>     >? ? ? ?return 0;
>     >? }
>     >
> 

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

* Re: [PATCH] board: amlogic: vim3: setup ethernet mac from efuse
@ 2021-01-11 14:17       ` Neil Armstrong
  0 siblings, 0 replies; 8+ messages in thread
From: Neil Armstrong @ 2021-01-11 14:17 UTC (permalink / raw)
  To: Art Nikpal
  Cc: u-boot-amlogic, u-boot, khilman, Christian Hewitt,
	Martin Blumenstingl, m.szyprowski, Jaehoon Chung, Artem Lapkin,
	nick, Gouwa Wang

Hi,

On 11/01/2021 15:15, Art Nikpal wrote:
>> So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski@samsung.com/) doesn't work ?
> yes doesnt works properly im sure if we read as raw 6 bytes from efuse we have
> 
> if (is_valid_ethaddr(mac_addr)) # is always not valid
> eth_env_set_enetaddr("ethaddr", mac_addr);
> else    # and always generated from serial 
> meson_generate_serial_ethaddr();
> 
>> Are you sure the MAC is stored in ASCII like Odroid-N2 ?
> yes im check two times on my vim3 vim3l boards and our amlogic vendor uboot have same method

OK, can you send a patch over the https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next branch ?

Neil

> 
> On Mon, Jan 11, 2021 at 9:59 PM Neil Armstrong <narmstrong@baylibre.com <mailto:narmstrong@baylibre.com>> wrote:
> 
>     Hi Artem,
> 
>     On 11/01/2021 12:19, Artem Lapkin wrote:
>     > Add the board specific code for reading built-in ethernet MAC address from efuse
>     >
>     > NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset
>     >
>     > if mac from efuse not valid we use meson_generate_serial_ethaddr
>     >
>     > NOTE: remake odroid-n2.c variant from Neil Armstrong <narmstrong@baylibre.com <mailto:narmstrong@baylibre.com>>
> 
>     So the patch from Marek (https://patchwork.ozlabs.org/project/uboot/patch/20201217072642.1319-1-m.szyprowski@samsung.com/) doesn't work ?
>     Are you sure the MAC is stored in ASCII like Odroid-N2 ?
> 
>     Please look at my u-boot-amlogic-next tree I will push this week for the next u-boot release:
>     https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/-/tree/u-boot-amlogic-next
> 
>     Neil
> 
>     >
>     > Signed-off-by: Artem Lapkin <art@khadas.com <mailto:art@khadas.com>>
>     > ---
>     >  board/amlogic/vim3/vim3.c | 35 +++++++++++++++++++++++++++++++++++
>     >  1 file changed, 35 insertions(+)
>     >
>     > diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
>     > index 09ef39ff30..c5d19cc17b 100644
>     > --- a/board/amlogic/vim3/vim3.c
>     > +++ b/board/amlogic/vim3/vim3.c
>     > @@ -11,9 +11,14 @@
>     >  #include <net.h>
>     >  #include <asm/io.h>
>     >  #include <asm/arch/eth.h>
>     > +#include <asm/arch/sm.h>
>     >  #include <i2c.h>
>     >  #include "khadas-mcu.h"
>     > 
>     > +#define EFUSE_MAC_OFFSET     0
>     > +#define EFUSE_MAC_SIZE               12
>     > +#define MAC_ADDR_LEN         6
>     > +
>     >  /*
>     >   * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
>     >   * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
>     > @@ -131,7 +136,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>     > 
>     >  int misc_init_r(void)
>     >  {
>     > +     u8 mac_addr[MAC_ADDR_LEN];
>     > +     char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
>     > +     ssize_t len;
>     > +
>     >       meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
>     > 
>     > +     if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
>     > +
>     > +             len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, efuse_mac_addr, EFUSE_MAC_SIZE);
>     > +             if (len != EFUSE_MAC_SIZE)
>     > +                     return 0;
>     > +
>     > +             /* MAC is stored in ASCII format, 1bytes = 2characters */
>     > +             for (int i = 0; i < 6; i++) {
>     > +                     tmp[0] = efuse_mac_addr[i * 2];
>     > +                     tmp[1] = efuse_mac_addr[i * 2 + 1];
>     > +                     tmp[2] = '\0';
>     > +                     mac_addr[i] = simple_strtoul(tmp, NULL, 16);
>     > +             }
>     > +
>     > +             if (is_valid_ethaddr(mac_addr))
>     > +                     eth_env_set_enetaddr("ethaddr", mac_addr);
>     > +             else
>     > +                     meson_generate_serial_ethaddr();
>     > +
>     > +             eth_env_get_enetaddr("ethaddr", mac_addr);
>     > +             printf("[i] setup onboard mac %02X:%02X:%02X:%02X:%02X:%02X\n",
>     > +                     mac_addr[0],mac_addr[1],mac_addr[2],
>     > +                     mac_addr[3],mac_addr[4],mac_addr[5]);
>     > +
>     > +     }
>     > +
>     >       return 0;
>     >  }
>     >
> 


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

end of thread, other threads:[~2021-01-11 14:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 11:19 [PATCH] board: amlogic: vim3: setup ethernet mac from efuse Artem Lapkin
2021-01-11 11:19 ` Artem Lapkin
2021-01-11 13:59 ` Neil Armstrong
2021-01-11 13:59   ` Neil Armstrong
2021-01-11 14:15   ` Art Nikpal
2021-01-11 14:15     ` Art Nikpal
2021-01-11 14:17     ` Neil Armstrong
2021-01-11 14:17       ` Neil Armstrong

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.