cancel
Showing results for 
Search instead for 
Did you mean: 

Using NVMEM cells as files

GTelk
Associate II

I have a STM32MP135 with a M24C64 64k bit I2C EEPROM. The EEPROM is divided into NVMEM cells, which can be written and read back via nodes in /sys/bus/nvmem/devices/... (NVMEM subsystem).

The NVMEM cells do not behave in the same way as files: The length always corresponds to the size of the cell and the cell is always present (even if it has not yet been initialised).
For certain applications it would be an advantage if the NVMEM cells behaved in the same way as a file.

We could emulate the behaviour of a file by starting each NVMEM cell with a 12 byte header (4 byte magic, 4 byte size, 4 byte CRC):
* if there is no magic, the ‘file’ does not exist.
* the length information stores how many bytes have actually been written. This is also displayed as the file size.
* a CRC secures the payload
This principle corresponds to the u-boot-env layout (see https://github.com/torvalds/linux/blob/master/drivers/nvmem/layouts/u-boot-env.c)

Unfortunately, the problem cannot be solved using the NVMEM API alone.
Are there any solution ideas for this? For example, a separate file system driver that maps the NVMEM cells into a separate directory and with which the payload of the NVMEM cells can be written like a file?

0 REPLIES 0