mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: neil.armstrong@linaro.org
To: u-boot-amlogic@groups.io, christianshewitt@gmail.com,
	u-boot@lists.denx.de, linux-amlogic@lists.infradead.org
Subject: Re: [PATCH 2/3] ARM: board: meson: update efuse MAC reading code
Date: Mon, 18 Mar 2024 09:48:43 +0100	[thread overview]
Message-ID: <7cf7abf8-9c38-4481-afc3-7a822f9ddb9f@linaro.org> (raw)
In-Reply-To: <20240316135430.826898-3-christianshewitt@gmail.com>

Hi,
On 16/03/2024 14:54, Christian Hewitt wrote:
> Current code used for reading the factory programmed MAC from efuse on
> p200 boards does not appear to work resulting in a random MAC being
> generated. Update the p200 board data reusing the function from the VIM3
> source.

I'm pretty sure this code works on the Odroid-C2, but hardkernel had a custom
way to store the mac address so perhaps you should move this code to an odroid-c2
board file first ?

Or try both methods ? if first method doesn't give a valid mac address
try the ASCII format.

Neil

> 
> Signed-off-by: Christian Hewitt <christianshewitt@gmail.com>
> ---
>   board/amlogic/p200/p200.c | 35 +++++++++++++++++++++--------------
>   1 file changed, 21 insertions(+), 14 deletions(-)
> 
> diff --git a/board/amlogic/p200/p200.c b/board/amlogic/p200/p200.c
> index 7c432f9d281..fb07eefa532 100644
> --- a/board/amlogic/p200/p200.c
> +++ b/board/amlogic/p200/p200.c
> @@ -14,29 +14,36 @@
>   #include <asm/arch/eth.h>
>   #include <asm/arch/mem.h>
>   
> -#define EFUSE_SN_OFFSET		20
> -#define EFUSE_SN_SIZE		16
> -#define EFUSE_MAC_OFFSET	52
> -#define EFUSE_MAC_SIZE		6
> +#define EFUSE_MAC_OFFSET	0
> +#define EFUSE_MAC_SIZE		12
> +#define MAC_ADDR_LEN		6
>   
>   int misc_init_r(void)
>   {
> -	u8 mac_addr[EFUSE_MAC_SIZE];
> -	char serial[EFUSE_SN_SIZE];
> +	u8 mac_addr[MAC_ADDR_LEN];
> +	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
>   	ssize_t len;
>   
>   	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
>   		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
> -					  mac_addr, EFUSE_MAC_SIZE);
> -		if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
> +					  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();
>   
> -	if (!env_get("serial#")) {
> -		len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
> -			EFUSE_SN_SIZE);
> -		if (len == EFUSE_SN_SIZE)
> -			env_set("serial#", serial);
> +		eth_env_get_enetaddr("ethaddr", mac_addr);
>   	}
>   
>   	return 0;


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2024-03-18  8:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-16 13:54 [PATCH 0/3] ARM: dts: fix Ethernet and random MAC's on WeTek Hub/Play2 Christian Hewitt
2024-03-16 13:54 ` [PATCH 1/3] ARM: dts: fix Ethernet " Christian Hewitt
2024-03-18  8:44   ` neil.armstrong
2024-03-16 13:54 ` [PATCH 2/3] ARM: board: meson: update efuse MAC reading code Christian Hewitt
2024-03-18  8:48   ` neil.armstrong [this message]
2024-03-16 13:54 ` [PATCH 3/3] configs: amlogic: set board family to avoid random MAC on WeTek Hub/Play2 Christian Hewitt
2024-03-18  8:50   ` neil.armstrong

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=7cf7abf8-9c38-4481-afc3-7a822f9ddb9f@linaro.org \
    --to=neil.armstrong@linaro.org \
    --cc=christianshewitt@gmail.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=u-boot-amlogic@groups.io \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®