mbed-os/features/storage/nvstore
Oleg Kapshii aedec74b9a Added support for PSA target to WIFI_BT board
Added WiFi_Bt CM4 PSA target in mbedos json
Added SPE-NSPE mailbox initialization for CM4 SystemInit
Made similar to FUTURE_SEQUANA configurations
Copied FUTURE_SEQUANA CM0 SPM part for WiFi_Bt smoke test
Added CY8CKIT_062_WIFI_BT_M0 and CY8CKIT_062_WIFI_BT_M0_PSA targets
Sorted files for new CY8CKIT_062_WIFI_BT_M0 and CY8CKIT_062_WIFI_BT_M0_PSA targets
Copied files for CY8CKIT_062_WIFI_BT_M0_PSA from FUTURE_SEQUANA
Copied and updated cm0p start files
Corrected according to FUTURE_SEQUANA
Changes to M0 startup files to have SPM started
Fixed implicit declaration warning
Commented interrupts enabling according to FUTURE_SEQUANA flow
Updated prebuild spm_smore CM0 hex for CM4 target
Turned on greentea environment
Used special memory region for common CM0/CM4 data
Updated prebuild CM0 SPM hex
Placed shared memory region for flash operations into SPM shared memory region
Updated cyprotection code and configuration
Start address of protected regions is set by a defined number from target.json
Added masters pcMask configuration
Added support for PSA target to WIFI_BT board
Enabled resources protection for SPM
Aligned RAM usage according to Cypress FlashBoot and CyBootloader
alligned protection config
Added CYW943012P6EVB_01_M0 target
Enlarged heap size, remobed nv_seed
Added heap reservation in linker script from mbed-os
Removed heap size definition
turned on nv_seed config
Removed nv_seed macros
Enabled protection for PSoC6 CM0
Added PSoC6 CM0 PSA readme
Enabled mbed_hal-spm test
Enabled nv_seed and removed unneeded ipc config define
Added SPDX string to feature_ble cypress target files
Removed unneeded supported_toolchains lines for Cypress targets
Disabled protection settings
Corrected flash initialization for PSoC6 CM0 PSA
Changed PSoC6 IPC6 protection for flash
Enabled special flash initialization and enabled protection settings
Updated and added new prebuild PSoC6 CM0 PSA hex files
Disabled HW TRNG and CRC for PSoC6 CM4 PSA target
Added missing const to allow types to match
Updated PSoC6 WIFI_BT_PSA prebuilt directory
Moved PSoC6 shared section usage area definition to begin of ld
Added initial ARM_STD linker and startup files for PSoC6 CM0
Added initial IAR linker and startup files for PSoC6 CM0
Added defines to disable some SPM protection settings for PSoC64
Moved Flash function variables into separate memory region
Added defines for new Public area definition
Updated PSoC6 CM0_PSA hex-files
2019-03-07 08:40:20 -08:00
..
TESTS/nvstore/functionality NVStore: fix area calculation function 2019-01-24 16:16:56 +02:00
source Merge pull request #9445 from davidsaada/david_nvstore_fix_area_calc 2019-01-31 10:20:44 -06:00
README.md Moving SD, SPIF and FLASHIAP into mbedos and refactoring features storage directory structure. 2018-08-29 12:01:11 +03:00
mbed_lib.json Added support for PSA target to WIFI_BT board 2019-03-07 08:40:20 -08:00

README.md

NVStore

NVStore is a lightweight module that stores data by keys in the internal flash for security purposes.

Description

NVStore provides the ability to store a minimal set of system critical items in the internal flash. For each item key, the NVStore module provides the ability to set the item data or get it. Newly added values are added to the end of the existing data, superseding the previous value that was there for the same key. The NVStore module ensures that power failures don't harm existing data during any operation. The full interface can be found under nvstore.h.

Flash structure

NVStore uses two Flash areas, active and nonactive. Each area must consist of at least one erasable unit (sector). Data is written to the active area until it becomes full. When it does, garbage collection is invoked. This compacts items from the active area to the nonactive one and switches activity between areas. Each item is kept in an entry containing a header and data, where the header holds the item key, size and CRC.

APIs

  • init: Initialize NVStore (also lazily called by get, set, set_once and remove APIs).
  • deinit: Deinitialize NVStore.
  • get: Get the value of an item, given key.
  • set: Set the value of an item, given key and value.
  • set_once: Like set, but allows only a one time setting of this item (and disables deleting of this item).
  • alloc_key: Allocates a free key (from the keys that are not predefined) to an owner (an owning feature).
  • free_all_keys_by_owner: Free all allocated keys, given an owner.
  • remove: Remove an item, given key.
  • get_item_size: Get the item value size (in bytes).
  • set_max_keys: Set maximal value of unique keys. Overriding the default of NVSTORE_MAX_KEYS. This affects RAM consumption, as NVStore consumes 4 bytes per unique key. Reinitializes the module.

Usage

Enabling NVStore and configuring it for your board

NVStore is enabled by default for all devices with the internal flash driver (have "FLASH" in the device_has attribute). One can disable it by setting its "enabled" attribute to false. Unless specifically configured by the user, NVStore selects the last two flash sectors as its areas, with the minimum size of 4KBs, meaning that if the sectors are smaller, few continuous ones will be used for each area. The user can override this by setting the addresses and sizes of both areas in mbed_lib.json on a per board basis. In this case, all following four attributes need to be set:

  • area_1_address
  • area_1_size
  • area_2_address
  • area_2_size

In addition, the num_keys value should be modified to change the default number of different keys.

Using NVStore

NVStore is a singleton class, meaning that the system can have only a single instance of it. To instantiate NVStore, one needs to call its get_instance member function as following:

    NVStore &nvstore = NVStore::get_instance();

After the NVStore instantiation, one can call the init API, but it is not necessary because all NVStore APIs (get, set and so on) perform a "lazy initialization".

Testing NVStore

Run the NVStore functionality test with the mbed command as following: mbed test -n features-nvstore-tests-nvstore-functionality