Re: [PATCH v4 3/5] nvmem: rockchip-otp: Derive MAC addresses from the CPU ID

From: Alexey Charkov

Date: Wed Nov 25 2026 - 13:02:04 EST


On Wed, Nov 25, 2026 at 8:41 PM Andrew Lunn <andrew@xxxxxxx> wrote:
>
> > > 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().
> >
> > They still need to relax the size check as done by patch 2/5 in this
> > series, because the CPUID cell is 16 bytes long. Srinivas rejected a
> > prior version of this series that attempted to return cell contents of
> > different sizes depending on the use case. Currently any cell size !=
> > ETH_ALEN gets rejected by the net core, not just < ETH_ALEN.
>
> Ah! I had not looked at the whole series.
>
> Having to change the core like this is an argument for doing it in the
> MAC driver. It asked for a MAC address. What it got back is not a MAC
> address if it does not have 6 octets.
>
> Please throw this all away and do it in the MAC driver. If there are
> multiple RealTek MAC drivers involved, you can put it into a little
> library and share it across the drivers.
>
> It is actually an interesting idea. Maybe it should be placed in
> of_net.c, so other drivers can use it. How generic is it having a CPU
> ID in the OTP? Are there other vendors doing it?

>From a quick overview, Allwinner does a similar thing [1] by reading a
"SID" from its eFuses, and Amlogic [2] by reading its secure-monitor
serial number - so it's a reasonably common pattern. Everyone uses
their own derivation functions though.

I think I could try and add another branch in of_net.c to parse an
NVMEM cell called e.g. "unique-id" with platform-specified derivation
functions selected by the cell's compatible string. Then derive the
MAC index from the OF alias, so that the phandle argument can go away,
and the numbering cannot drift apart. Will send a v5 with that
approach if it works out.

[1] https://elixir.bootlin.com/u-boot/v2027.01-rc2/source/board/sunxi/board.c#L783-L828
[2] https://elixir.bootlin.com/u-boot/v2027.01-rc2/source/arch/arm/mach-meson/board-common.c#L79-L107

Best regards,
Alexey