Re: [PATCH v4 3/5] nvmem: rockchip-otp: Derive MAC addresses from the CPU ID
From: Andrew Lunn
Date: Wed Nov 25 2026 - 10:23:54 EST
On Wed, Nov 25, 2026 at 06:41:42PM +0400, Alexey Charkov wrote:
> On Wed, Nov 25, 2026 at 6:21 PM Andrew Lunn <andrew@xxxxxxx> wrote:
> >
> > > > +static int rockchip_otp_cpuid_pp(void *priv, const char *id, int index,
> > > > + unsigned int offset, void *buf, size_t bytes)
> > > > +{
> > > > + char cpuid[ROCKCHIP_CPUID_LEN * 2];
> > > > + u8 digest[SHA256_DIGEST_SIZE];
> > > > + u8 *mac = buf;
> > > > +
> > > > + if (!id || strcmp(id, "mac-address"))
> > > > + return 0;
> >
> > I don't know OTP drivers. But to me, a function called
> > rockchip_otp_cpuid_pp() which does not actually return the CPU ID is
> > architecturally wrong.
>
> There is precedent for this at least in IMX [1], [2]. To me the
> interpretation is "Rockchip CPU ID used as a MAC address base with
> offset X", which is exactly what the derivation does. IMO, this is
> less clunky than the alternatives (e.g., a custom NVMEM layout which I
> used in v1-v2; a "virtual" NVMEM driver referencing the real cell and
> returning the processed one, which Ryan proposed in v2 discussion, or
> caller-side processing).
>
> [1] https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/nvmem/imx-ocotp.c#L224-L238
I would say this one is different. The cell specifically contains the
MAC address. But its endianness is wrong. Nothing about CPU ID here.
> [2] https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/nvmem/imx-ocotp-ele.c#L115-L129
And this seems to be the same.
As i said, i don't like the concept that a function called
rockchip_otp_cpuid_pp() returns something which is not a CPU ID. The
two examples you give ask for a MAC address, and they get a MAC
address.
Does nvmem support aliases? Can you put two different names on the
same cell? If you access the cell via the name cpu-id, it calls a
function _cpu_id_, it gives you the CPU ID. If you access the cell via
the name mac-address, it calls a function called _mac_address_, and it
gives you a MAC address.
That way of_get_mac_address_nvmem() just works, so the MAC driver just
needs to call of_get_mac_address() or of_get_ethdev_address().
Andrew