Re: [RESEND RFC 2/3] nvmem: Add 'nvmem-blob' driver

From: Trent Piepho
Date: Tue Mar 08 2016 - 18:30:09 EST


On Tue, 2016-03-08 at 14:46 -0800, Andrey Smirnov wrote:
> >> I don't think I understand what you mean, could you give me an example
> >> of how I'd use local-mac-address property for that use case? AFAIK,
> >> local-mac-address is just an array of bytes embedded into device tree,
> >
> > Well, yeah, but the nvmem-blob is also just an array of bytes embedded
> > into the DT, right?
>
> One is accessible via "nvmem" API and the other one isn't.
>
> >
> >> how would it get populated with data from OTP memory of SoC?
> >
> > In the bootloader, or Linux, read the OTP, patch the DT to add that
> > node, done.
>
> No, it's not really "done", because if you read my previous messages,
> "read the OTP, patch the DT" is exactly the problem I am trying to
> solve. The overall goal is to be able to read a certain "nvmem" cell
> and patch DT with that data as MAC address, however in it's current
> incarnation "nvmem" doesn't have provisions to make cells that are
> just combination of other cells (patch #3) and to embed certain data

So I did something that solved this a few years ago for another board
and embedded the data into the local-mac-address property.

I think maybe the problem isn't here isn't clear. For some boards
(mxs), only part of a MAC address is stored in nvmem while the rest of
the address is fixed data. Currently embedded in the kernel source,
though embedded in the device tree would clearly be better. While
splitting the MAC into two locations like this is not, at least in my
opinion, the best design, it's burned into the one time programmable
memory so there's not much that can be done.

The kernel looks for 'mac-address' and then 'local-mac-address', with
the former having precedence.

So what I did was embed the fixed portion in 'local-mac-address', have
the bootloader extract the variable part from nvmem, and then combine
the two and place it into 'mac-address' for the kernel to use.

My DT binding that described the placement of data from nvmem into the
MAC used a permutation list instead of a series of ranges. So a list
like [0 0 0 1 2 3] could be used to specify the first three bytes of the
mac address do not come from nvmem. This also allows changing byte
order concisely. But doesn't scale well to larger regions.