6.2. nvm — Non-volatile memory

A non-volatile memory is typically used for long-term persistent storage.

This module implements a singleton non-volatile memory, often on top of an EEPROM or software emulated EEPROM.


Source code: src/oam/nvm.h, src/oam/nvm.c

Test coverage: src/oam/nvm.c


Functions

int nvm_module_init(void)

Initialize the NVM module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int nvm_mount(void)

Mount the non-volatile memory.

Return
zero(0) if the memory was successfully mounted, otherwise negative error code.

int nvm_format(void)

Format the non-volatile memory, writing 0xff/erasing to the whole memory. A formatted NVM can always be mounted with nvm_mount().

Return
zero(0) or negative error code.

ssize_t nvm_read(void *dst_p, uint32_t src, size_t size)

Read into given buffer from given NVM address.

Return
Number of bytes read or negative error code.
Parameters
  • dst_p: Buffer to read into.
  • src: Address in NVM to read from. Addressing starts at zero(0).
  • size: Number of bytes to read.

ssize_t nvm_write(uint32_t dst, const void *src_p, size_t size)

Write given buffer to given NVM address.

Return
Number of bytes written or negative error code.
Parameters
  • dst: Address in NVM to write to. Addressing starts at zero(0).
  • src_p: Buffer to write.
  • size: Number of bytes to write.

ssize_t nvm_vwrite(struct iov_uintptr_t *dst_p, struct iov_t *src_p, size_t length)

Write given buffers to given NVM addresses.

Return
Number of bytes written or negative error code.
Parameters
  • dst_p: Address ranges in NVM to write to. Addressing starts at zero(0).
  • src_p: Buffers to write in the same order as in dst_p. The size fields are not used.
  • length: Number of elements in dst_p and src_p.