mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>, barebox@lists.infradead.org
Cc: David Jander <david@protonic.nl>
Subject: Re: [PATCH v1] nvmem: bsec.c: Use SMC_READ_OTP in stm32_bsec_read_mac()
Date: Fri, 26 Nov 2021 17:09:22 +0100	[thread overview]
Message-ID: <efcbb9fd-478b-57d6-b774-17afd3320116@pengutronix.de> (raw)
In-Reply-To: <20211126133108.3003431-1-o.rempel@pengutronix.de>

Hello Oleksij, David,

On 26.11.21 14:31, Oleksij Rempel wrote:
> From: David Jander <david@protonic.nl>
> 
> TF-A (version >= v2.4?) apparently does not copy all of OTP to shadow
> registers so reading the MAC address area will read all-zeroes.
> Make sure to read the _real_ OTP register in this case.

Thanks for the fix. Linux reads the lowest 32 words of OTP directly from shadow
registers and calls into TF-A for reading shadow memory beyond that, which should
include MAC address (offset 0x39, didn't test though).

It never does READ_OTP, so it seems the TF-A change would affect Linux as well?
It's for sure something we'll need to address in TF-A eventually, but as a bug
fix, this is ok:

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>


> Signed-off-by: David Jander <david@protonic.nl>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/nvmem/bsec.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
> index d9b38c8414..a31eff7358 100644
> --- a/drivers/nvmem/bsec.c
> +++ b/drivers/nvmem/bsec.c
> @@ -82,20 +82,27 @@ static void stm32_bsec_set_unique_machine_id(struct regmap *map)
>  	machine_id_set_hashable(unique_id, sizeof(unique_id));
>  }
>  
> -static int stm32_bsec_read_mac(struct regmap *map, int offset, u8 *mac)
> +static int stm32_bsec_read_mac(struct bsec_priv *priv, int offset, u8 *mac)
>  {
> -	u8 res[8];
> +	u32 val[2];
>  	int ret;
>  
> -	ret = regmap_bulk_read(map, offset * 4, res, 8);
> +	/* Some TF-A does not copy all of OTP into shadow registers, so make
> +	 * sure we read the _real_ OTP bits here.
> +	 */
> +	ret = bsec_smc(priv, BSEC_SMC_READ_OTP, offset * 4, 0, &val[0]);
> +	if (ret)
> +		return ret;
> +	ret = bsec_smc(priv, BSEC_SMC_READ_OTP, offset * 4 + 4, 0, &val[1]);
>  	if (ret)
>  		return ret;
>  
> -	memcpy(mac, res, ETH_ALEN);
> +	memcpy(mac, val, ETH_ALEN);
>  	return 0;
>  }
>  
> -static void stm32_bsec_init_dt(struct device_d *dev, struct regmap *map)
> +static void stm32_bsec_init_dt(struct bsec_priv *priv, struct device_d *dev,
> +			       struct regmap *map)
>  {
>  	struct device_node *node = dev->device_node;
>  	struct device_node *rnode;
> @@ -118,7 +125,7 @@ static void stm32_bsec_init_dt(struct device_d *dev, struct regmap *map)
>  	rnode = of_find_node_by_phandle(phandle);
>  	offset = be32_to_cpup(prop++);
>  
> -	ret = stm32_bsec_read_mac(map, offset, mac);
> +	ret = stm32_bsec_read_mac(priv, offset, mac);
>  	if (ret) {
>  		dev_warn(dev, "error setting MAC address: %s\n", strerror(-ret));
>  		return;
> @@ -159,7 +166,7 @@ static int stm32_bsec_probe(struct device_d *dev)
>  	if (IS_ENABLED(CONFIG_MACHINE_ID))
>  		stm32_bsec_set_unique_machine_id(map);
>  
> -	stm32_bsec_init_dt(dev, map);
> +	stm32_bsec_init_dt(priv, dev, map);
>  
>  	return 0;
>  }
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-11-26 16:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-26 13:31 Oleksij Rempel
2021-11-26 16:09 ` Ahmad Fatoum [this message]
2021-11-30 10:08 ` Sascha Hauer

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=efcbb9fd-478b-57d6-b774-17afd3320116@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=david@protonic.nl \
    --cc=o.rempel@pengutronix.de \
    --subject='Re: [PATCH v1] nvmem: bsec.c: Use SMC_READ_OTP in stm32_bsec_read_mac()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox