All of lore.kernel.org
 help / color / mirror / Atom feed
From: Neil Armstrong <narmstrong@baylibre.com>
To: u-boot@lists.denx.de
Subject: [PATCH] board: amlogic: vim3: fix setup ethernet mac from efuse
Date: Tue, 12 Jan 2021 14:21:55 +0100	[thread overview]
Message-ID: <7ec3f4d4-295e-5862-008d-bec83fffaeac@baylibre.com> (raw)
In-Reply-To: <20210112114212.1427365-1-art@khadas.com>

Hi Artem,

On 12/01/2021 12:42, Artem Lapkin wrote:
> Fix 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 from Neil Armstrong <narmstrong@baylibre.com>
> 
> Signed-off-by: Artem Lapkin <art@khadas.com>
> ---
>  board/amlogic/vim3/vim3.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> index 824fff8262..87d9fe1f02 100644
> --- a/board/amlogic/vim3/vim3.c
> +++ b/board/amlogic/vim3/vim3.c
> @@ -139,26 +139,42 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>  }
>  
>  #define EFUSE_MAC_OFFSET	0
> -#define EFUSE_MAC_SIZE		6
> +#define EFUSE_MAC_SIZE		12
> +#define MAC_ADDR_LEN		6
>  
>  int misc_init_r(void)
>  {
> -	uint8_t mac_addr[EFUSE_MAC_SIZE];
> +	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,
> -					  mac_addr, EFUSE_MAC_SIZE);
> +					  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]);


Yes, it's not necessary to print the MAC, I'll drop while applying.

>  	}
>  
>  	return 0;
>  }
> +
> 

Applying to u-boot-amlogic

Neil

WARNING: multiple messages have this Message-ID (diff)
From: "Neil Armstrong" <narmstrong@baylibre.com>
To: Artem Lapkin <email2tema@gmail.com>
Cc: u-boot@lists.denx.de, u-boot-amlogic@groups.io,
	m.szyprowski@samsung.com, jh80.chung@samsung.com, art@khadas.com,
	nick@khadas.com, gouwa@khadas.com
Subject: Re: [PATCH] board: amlogic: vim3: fix setup ethernet mac from efuse
Date: Tue, 12 Jan 2021 14:21:55 +0100	[thread overview]
Message-ID: <7ec3f4d4-295e-5862-008d-bec83fffaeac@baylibre.com> (raw)
In-Reply-To: <20210112114212.1427365-1-art@khadas.com>

Hi Artem,

On 12/01/2021 12:42, Artem Lapkin wrote:
> Fix 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 from Neil Armstrong <narmstrong@baylibre.com>
> 
> Signed-off-by: Artem Lapkin <art@khadas.com>
> ---
>  board/amlogic/vim3/vim3.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
> index 824fff8262..87d9fe1f02 100644
> --- a/board/amlogic/vim3/vim3.c
> +++ b/board/amlogic/vim3/vim3.c
> @@ -139,26 +139,42 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
>  }
>  
>  #define EFUSE_MAC_OFFSET	0
> -#define EFUSE_MAC_SIZE		6
> +#define EFUSE_MAC_SIZE		12
> +#define MAC_ADDR_LEN		6
>  
>  int misc_init_r(void)
>  {
> -	uint8_t mac_addr[EFUSE_MAC_SIZE];
> +	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,
> -					  mac_addr, EFUSE_MAC_SIZE);
> +					  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]);


Yes, it's not necessary to print the MAC, I'll drop while applying.

>  	}
>  
>  	return 0;
>  }
> +
> 

Applying to u-boot-amlogic

Neil

  reply	other threads:[~2021-01-12 13:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 11:42 [PATCH] board: amlogic: vim3: fix setup ethernet mac from efuse Artem Lapkin
2021-01-12 11:42 ` Artem Lapkin
2021-01-12 13:21 ` Neil Armstrong [this message]
2021-01-12 13:21   ` Neil Armstrong
     [not found] <CGME20210112050445epcas1p19c5a31ae23bda75d62c393433f4e89d9@epcas1p1.samsung.com>
2021-01-12  5:03 ` Artem Lapkin
2021-01-12  5:03   ` Artem Lapkin
2021-01-12 11:08   ` Jaehoon Chung
2021-01-12 11:08     ` Jaehoon Chung
2021-01-12 12:12   ` Marek Szyprowski
2021-01-12 12:12     ` Marek Szyprowski
     [not found] <CGME20210112043201epcas1p2eddcb51eed5f193425cacb7b5d51326e@epcas1p2.samsung.com>
2021-01-12  4:30 ` Artem Lapkin
2021-01-12  4:56   ` Jaehoon Chung

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ec3f4d4-295e-5862-008d-bec83fffaeac@baylibre.com \
    --to=narmstrong@baylibre.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.