Skip to content

Conversation

pdgendt
Copy link
Contributor

@pdgendt pdgendt commented Sep 22, 2025

Introduce the NVMEM subsystem. Inspired from linux this subsystem allows to read and write data to Non-Volatile memory, for example to store a MAC address or SoC/Device specific data.

It comes with support for EEPROM devices. The device API backend is determined at runtime using DEVICE_API_IS.

See #96598 for an example use case.

Derived from #74835

@pdgendt pdgendt force-pushed the nvmem branch 2 times, most recently from 3950927 to 4536d4e Compare September 23, 2025 05:55
@Laczen
Copy link
Contributor

Laczen commented Sep 23, 2025

@pdgendt this is a nice addition.

Can it be extended to other backends (e.g. fuses, bbram) ?

IMHO it should be straightforward to add a settings backend for this (e.g. store/retrieve items under "nvmem/xxx").

@pdgendt
Copy link
Contributor Author

pdgendt commented Sep 23, 2025

Can it be extended to other backends (e.g. fuses, bbram) ?

That's the idea, in nvmem.c it checks the device API at runtime, logic can be added there.

IMHO it should be straightforward to add a settings backend for this (e.g. store/retrieve items under "nvmem/xxx").

Sure, maybe. Outside of the scope of this PR though.

@pdgendt pdgendt force-pushed the nvmem branch 2 times, most recently from 91b7c21 to 1ae57e1 Compare September 23, 2025 12:00
@pdgendt pdgendt marked this pull request as ready for review September 23, 2025 12:04
@pdgendt
Copy link
Contributor Author

pdgendt commented Sep 23, 2025

Removed the draft state to get some early feedback before adding more documentation bits.

decsny
decsny previously requested changes Sep 23, 2025
Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please review linux binding https://www.kernel.org/doc/Documentation/devicetree/bindings/nvmem/ , note also the layouts folder

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Simple, yet extensible and a good level of abstraction. A few comments below:

cell_nodelabel: cell@START_OFFSET {
reg = <0xSTART_OFFSET 0xSIZE>;
#nvmem-cell-cells = <0>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Pieter, what are you planning to do with #nvmem-cell-cells? Isn't it enough to work with reg and #address-cells + #size-cells. It's not documented for now so might as well remove it if not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required to work with phandle-array binding types (see the docs). I didn't want to introduce special treatment in some of the python code for this.

I don't have plans for this, but it can be used for future types of NVMEM providers. I can't give an example from the top of my head though.

* #size-cells = <1>;
* mac_address: mac_address@fa {
* reg = <0xfa 0x06>;
* #nvmem-cell-cells = <0>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not necessary (previous comment), can remove occurences in this file.


int nvmem_cell_read(const struct nvmem_cell *cell, void *buf, off_t off, size_t len)
{
if (off < 0 || cell->size < off + len) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to check if cell isn't NULL? ditto in other exposed APIs if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's up to the caller to check for non-NULL cells, same for buf, the contract of the API to the pass a pointer to a struct nvmem_cell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR with asserts for non-NULL cell pointers.

@henrikbrixandersen henrikbrixandersen moved this from Todo to Done in Architecture Review Oct 6, 2025
@nordicjm nordicjm requested a review from de-nordic October 6, 2025 07:15
*
* @kconfig_dep{CONFIG_NVMEM}
*
* @return 0 on success, negative errno code on failure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these use @return some use @retval, I vaugley remember that @retval needs multiple lines one per value, unsure on @return or if one should be used over the other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had one (wrong) use of @retval, updated, thanks!

talih0 and others added 8 commits October 6, 2025 19:37
Adds property nvmem-cells for referencing a node that stores some
configuration information. A typical use case is the reading of MAC
address from an EEPROM device.

Signed-off-by: Andriy Gelman <[email protected]>
Signed-off-by: Pieter De Gendt <[email protected]>
Add a devicetree binding to represent a fixed layout in an NVMEM provider.

Signed-off-by: Pieter De Gendt <[email protected]>
This commit adds the NVMEM subsystem with a basic implementation for use
with EEPROM devices.

Signed-off-by: Pieter De Gendt <[email protected]>
Add basic testing to validate the API of the NVMEM subsystem.
Add testing with an EEPROM backend.

Signed-off-by: Pieter De Gendt <[email protected]>
Add test cases tot the devicetree API testsuite for NVMEM macros.

Signed-off-by: Pieter De Gendt <[email protected]>
Introduce a page for the Non-Volatile Memory subsystem with a reference to
the doxygen API.

Signed-off-by: Pieter De Gendt <[email protected]>
Add an entry to the API and options section for the Non-Volatile Memory
subsystem.

Signed-off-by: Pieter De Gendt <[email protected]>
Create a section for the newly maintained NVMEM area.

Signed-off-by: Pieter De Gendt <[email protected]>
@JarmouniA
Copy link
Contributor

Can this be used with SoC Flash, external NOR Flash?

Copy link

sonarqubecloud bot commented Oct 6, 2025

@henrikbrixandersen
Copy link
Member

Can this be used with SoC Flash, external NOR Flash?

Current implementation in this PR only supports EEPROMs as NVMEM providers, but this can very easily be extended in the future.

@pdgendt
Copy link
Contributor Author

pdgendt commented Oct 6, 2025

Can this be used with SoC Flash, external NOR Flash?

I guess it can, especially for read-only cells. The tricky bit would probably be writing, as it could require additional erase logic.
Not in scope of this PR though. I want to do the follow-up PR where the network drivers can use NVMEM cells for MAC address logic.

@nashif
Copy link
Member

nashif commented Oct 6, 2025

@pdgendt @henrikbrixandersen

nice stuff, i have seen this on arch wg agenda last week, are there some minutes somewhere with the outcome?

Copy link
Contributor

@mbolivar mbolivar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding looks like a good start, no need to boil the ocean and support everything out of the box IMO.

@pdgendt
Copy link
Contributor Author

pdgendt commented Oct 6, 2025

@pdgendt @henrikbrixandersen

nice stuff, i have seen this on arch wg agenda last week, are there some minutes somewhere with the outcome?

Not sure if notes were taken, I presented the idea and what it is trying to solve (the MAC address logic in network drivers for me), feedback was very positive overall, as far as I can remember.

@henrikbrixandersen
Copy link
Member

Architecture WG meeting, 2025-09-30:

  • @pdgendt presented the motivation for adding the NVMEM subsystem, providing an abstraction for referencing/obtaining data from specific locations in non-volatile memory devices in both devicetree/C code (one example being to read an Ethernet MAC address from a given offset in an EEPROM).
  • PoC for using the for retrieving MAC addresses is available in [PoC] drivers: ethernet/wifi: Use NVMEM cell to get MAC address #96598
  • The bindings are inspired by the same fixed-layout as used in the Linux kernel devicetree.
  • Currently, this only supports EEPROM backends, but other backends (fuses, flash, etc.) can be added in the future as needed, as long as the backend supports read and optionally write operations.
  • Consensus is that this is a welcome addition, attempt to target Zephyr v4.3

@henrikbrixandersen
Copy link
Member

My apologies, just realised I never got around to cleanup my notes from the meeting and actually post them.

@cfriedt cfriedt merged commit 58b2153 into zephyrproject-rtos:main Oct 6, 2025
27 checks passed
@pdgendt pdgendt deleted the nvmem branch October 6, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Boards/SoCs area: Devicetree Bindings area: Devicetree area: EEPROM area: MAINTAINER File area: Tests Issues related to a particular existing or missing test Release Notes To be mentioned in the release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.