Chapter 2. API Reference
Item hash list To reduce the number of reads from flash memory, each member of the Page class maintains a list
of pairs: item index; item hash. This list makes searches much quicker. Instead of iterating over all entries, reading
them from flash one at a time, Page::findItem first performs a search for the item hash in the hash list. This gives the
item index within the page if such an item exists. Due to a hash collision, it is possible that a different item will be
found. This is handled by falling back to iteration over items in flash.
Each node in the hash list contains a 24-bit hash and 8-bit item index. Hash is calculated based on item namespace,
key name, and ChunkIndex. CRC32 is used for calculation; the result is truncated to 24 bits. To reduce the overhead
for storing 32-bit entries in a linked list, the list is implemented as a double-linked list of arrays. Each array holds
29 entries, for the total size of 128 bytes, together with linked list pointers and a 32-bit count field. The minimum
amount of extra RAM usage per page is therefore 128 bytes; maximum is 640 bytes.
API Reference
Header File
• components/nvs_flash/include/nvs_flash.h
Functions
esp_err_t nvs_flash_init(void)
Initialize the default NVS partition.
This API initialises the default NVS partition. The default NVS partition is the one that is labeled “nvs”in
the partition table.
When “NVS_ENCRYPTION”is enabled in the menuconfig, this API enables the NVS encryption for the
default NVS partition as follows
1. Read security configurations from the first NVS key partition listed in the partition table. (NVS key
partition is any “data”type partition which has the subtype value set to “nvs_keys”)
2. If the NVS key partiton obtained in the previous step is empty, generate and store new keys in that NVS
key partiton.
3. Internally call“nvs_flash_secure_init()”with the security configurations obtained/generated in the pre-
vious steps.
Post initialization NVS read/write APIs remain the same irrespective of NVS encryption.
Return
• ESP_OK if storage was successfully initialized.
• ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages (which may hap-
pen if NVS partition was truncated)
• ESP_ERR_NOT_FOUND if no partition with label “nvs”is found in the partition table
• ESP_ERR_NO_MEM in case memory could not be allocated for the internal structures
• one of the error codes from the underlying flash storage driver
• error codes from nvs_flash_read_security_cfg API (when “NVS_ENCRYPTION”is enabled).
• error codes from nvs_flash_generate_keys API (when “NVS_ENCRYPTION”is enabled).
• error codes from nvs_flash_secure_init_partition API (when“NVS_ENCRYPTION”is enabled) .
esp_err_t nvs_flash_init_partition(const char *partition_label)
Initialize NVS flash storage for the specified partition.
Return
• ESP_OK if storage was successfully initialized.
• ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages (which may hap-
pen if NVS partition was truncated)
• ESP_ERR_NOT_FOUND if specified partition is not found in the partition table
• ESP_ERR_NO_MEM in case memory could not be allocated for the internal structures
• one of the error codes from the underlying flash storage driver
Parameters
• [in] partition_label: Label of the partition. Must be no longer than 16 characters.
Espressif Systems 712
Submit Document Feedback
Release v4.4