Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TDB_EXTERNAL_NO_RBP and FILESYSTEM_NO_RBP from kv_config #14490

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 2 additions & 118 deletions storage/docs/Configuration/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ kvstore
├───tdb_external
│ mbed_lib.json
├───tdb_external_no_rbp
│ mbed_lib.json
├───filesystem
│ mbed_lib.json
├───filesystem_no_rbp
│ mbed_lib.json
└───tdb_internal
mbed_lib.json
```
Expand All @@ -46,9 +40,7 @@ You can find the configuration files `conf/<configuration name>`:

* `conf/tdb_internal` - storage type `TDB_INTERNAL` configuration is intended to be used when all data will be stored in internal memory only. No need for additional security features. A single TDBStore object will be allocated in internal flash.
* `conf/tdb_external` - storage type `TDB_EXTERNAL` configuration is providing full security and intended to be used when data is stored in external flash. It allocates: SecureStore, TDBStore in external flash and TDBStore in internal flash (for rollback protection - RBP).
* `conf/tdb_external_no_rbp` - storage type `TDB_EXTERNAL_NO_RBP` configuration allows security but without rollback protection. Similar to `tdb_external` but without the TDBStore in internal memory.
* `conf/filesystem` - This configuration will allocate: SecureStore, FileSystemStore, filesystem, TDBStore in internal memory and the required block devices. The allocated file system will be selected according to the COMPONENT set in `targets.json`, (FATFS for SD card and LittleFS for SPIF); however, you can set this differently by overriding the respective parameter. Use this configuration if you need the file system with a POSIX API in addition to the set/get API.
* `conf/filesystem_no_rbp` - storage type `FILESYSTEM_NO_RBP` configuration allows security like FILESYSTEM configuration but without rollback protection.

A standalone block device is allocated for each component in internal and external memory and SD cards as required for the configurations. The full size of the memory allocated for each block device is used by the respective component.

Expand All @@ -59,9 +51,7 @@ The following is a list of all storage parameters available and their descriptio
* `storage_type` - Used to select one of the predefined configurations.
* `TDB_INTERNAL`.
* `TDB_EXTERNAL`.
* `TDB_EXTERNAL_NO_RBP`.
* `FILESYSTEM`.
* `FILESYSTEM_NO_RBP`.
* `default`
If the `default` configuration is set, the system will choose the type of storage TDB_INTERNAL.
* `default_kv` - This is a string representing the path for the default KVStore instantiation. Applications can pass an empty path (only the key name) or pass the generated name for this parameter (`MBED_CONF_STORAGE_DEFAULT_KV`) as the path to use this configuration.
Expand All @@ -85,7 +75,7 @@ Below is the main storage configuration `mbed_lib.json` file:
"name": "storage",
"config": {
"storage_type": {
"help": "Options are TDB_INTERNAL, TDB_EXTERNAL, TDB_EXTERNAL_NO_RBP, FILESYSTEM, FILESYSTEM_NO_RBP or default. If default, the storage type will be chosen according to the component defined in targets.json",
"help": "Options are TDB_INTERNAL, TDB_EXTERNAL, FILESYSTEM, or default. If default, the storage type will be chosen according to the component defined in targets.json",
"value": "NULL"
},
"default_kv": {
Expand Down Expand Up @@ -172,39 +162,6 @@ Below is the `TDB_EXTERNAL` configuration `mbed_lib.json`:
}
}
```

### TDB_External_no_RBP

![External](./TDB_External_no_rbp.jpg)

`TDB_EXTERNAL_NO_RBF` configuration has no support for rollback protection and is therefore less secure.

The `TDB_EXTERNAL_NO_RBP` uses only one TDBStore on the external flash for all data. In this configuration, all KVStore C API calls are mapped to work with the SecureStore class. The external TDBStore works on top of the default block device; however, you can set the external TDBStore block device to any of the following block devices: SPIF, QSPIF, DATAFASH and SD.

You can enable this configuration by setting `storage_type` in storage `mbed_lib.json` to `TDB_EXTERNAL_NO_RBP`.

Below is the `TDB_EXTERNAL_NO_RBP` configuration `mbed_lib.json`:

```
{
"name": "tdb_external_no_rbp",
"config": {
"external_size": {
"help": "Size of the external block device",
"value": "NULL"
},
"external_base_address": {
"help": "If not defined the default is from address 0",
"value": "NULL"
},
"blockdevice": {
"help": "Options are default, SPIF, DATAFASH, QSPIF or FILESYSTEM",
"value": "NULL"
}
}
}
```

### FILESYSTEM

![FILESYSTEM](./FILESYSTEM.jpg)
Expand Down Expand Up @@ -263,55 +220,10 @@ Below is the FILESYSTEM configuration `mbed_lib.json`:

If file system is not set, the default file system and block device are applied and `blockdevice`, `external_size` and `external_base_address` are ignored.

### FILESYSTEM_NO_RBP

![FILESYSTEM](./FILESYSTEM_no_rbp.jpg)

The `FILESYSTEM_NO_RBP` configuration resembles the `EXTERNAL_NO_RBP` but uses FileSystemStore on the external flash. By default, FileSystemStore uses the default file system and the default block device. This Configuration has no support for rollback protection and is therefore less secure.

In this configuration, all KVStore C API calls are mapped to the SecureStore class. This class handles the use of the external FileSystemStore.

You can enable this configuration by setting `storage_type` in `storage mbed_lib.json` to `FILESYSTEM_NO_RBF`.

Below is the FILESYSTEM configuration `mbed_lib.json`:

```
{
"name": "filesystem_store_no_rbp",
"config": {
"filesystem": {
"help": "Options are default, FAT or LITTLE. If not specified default filesystem will be used",
"value": "NULL"
},
"blockdevice": {
"help": "Options are default, SPIF, DATAFASH, QSPIF or FILESYSTEM. If not set the default block device will be used",
"value": "NULL"
},
"external_size": {
"help": "Size in bytes of the external block device, if not specified the maximum is the default.",
"value": "NULL"
},
"external_base_address": {
"help": "If not defined the default is from address 0",
"value": "NULL"
},
"mount_point": {
"help": "Where to mount the filesystem. Ignored if the default file system is applied.",
"value": "/sd"
},
"folder_path": {
"help": "Path for the working directory where the FileSyetemStore stores the data",
"value": "/kvstore"
}
}
}
```

If file system is not set, the default file system and block device are applied and `blockdevice`, `external_size` and `external_base_address` are ignored.

### Configuration functions API

Applications must call the function **storage_configuration()** to instantiate the required configuration. This function is defined as weak to allow the replacement of this function with a completely different implementation of the instantiation of components.
Applications must call the function **kv_init_storage_config()** to instantiate the required configuration. This function is defined as weak to allow the replacement of this function with a completely different implementation of the instantiation of components.

Below is a list of setup functions that `storage_configuration()` calls in each case, and their description:

Expand Down Expand Up @@ -349,18 +261,6 @@ bool _storage_config_TDB_INTERNAL();
*/
bool _storage_config_TDB_EXTERNAL();

/**
* @brief This function initialize a predefined external memory secure storage
* This includes a SecureStore class with external TDBStore over a blockdevice or,
* if no blockdevice was set the default blockdevice will be used.
* The following is a list of configuration parameter:
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_SIZE - Size of the external blockdevice in bytes or NULL for max possible size.
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BLOCK_DEVICE - Alowed vlaues are: default, SPIF, DATAFASH, QSPIF or SD
* @returns true on success or false on failure.
*/
bool _storage_config_TDB_EXTERNAL_NO_RBP();

/**
* @brief This function initialize a predefined FILESYSTEM memory secure storage
* This includes a SecureStore class with TDBStore over FlashIAPBlockdevice
Expand All @@ -380,22 +280,6 @@ bool _storage_config_TDB_EXTERNAL_NO_RBP();
*/
bool _storage_config_FILESYSTEM();

/**
* @brief This function initialize a predefined FILESYSTEM_NO_RBP memory secure storage with no
* rollback protection. This includes a SecureStore class an external FileSysteStore over a default
* filesystem with default blockdevice unless differently configured.
* The following is a list of configuration parameter:
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FILESYSTEM - Allowed values are: default, FAT or LITTLE
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_BLOCKDEVICE - Allowed values are: default, SPIF, DATAFASH, QSPIF or SD
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE - Blockdevice size in bytes. or NULL for max possible size.
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address.
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT - Where to mount the filesystem
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH - The working folder paths
*
* @returns true on success or false on failure.
*/
bool _storage_config_FILESYSTEM_NO_RBP();

MBED_WEAK bool storage_configuration()
{
return _STORAGE_CONFIG(MBED_CONF_STORAGE_STORAGE_TYPE);
Expand Down
34 changes: 0 additions & 34 deletions storage/kvstore/kv_config/filesystem_no_rbp/mbed_lib.json

This file was deleted.

2 changes: 1 addition & 1 deletion storage/kvstore/kv_config/global/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "storage",
"config": {
"storage_type": {
"help": "Options are TDB_INTERNAL, TDB_EXTERNAL, TDB_EXTERNAL_NO_RBP, FILESYSTEM, FILESYSTEM_NO_RBP or default. If default, the storage type will be chosen according to the component defined in targets.json",
"help": "Options are TDB_INTERNAL, TDB_EXTERNAL, FILESYSTEM or default. If default, the storage type will be chosen according to the component defined in targets.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

@0xc0170
If we don't want a breaking change (removal of TDB_EXTERNAL_NO_RBP and FILESYSTEM_NO_RBP) for now, the most we can do is say

`TDB_EXTERNAL_NO_RBP` and `FILESYSTEM_NO_RBP` do not work and are thus deprecated

in this help text and above functions that define them. We may not benefit from compile-time deprecation warnings due to preprocessor being unable to compare macros with strings, but I don't have any best ideas.

"value": "default"
},
"default_kv": {
Expand Down
110 changes: 2 additions & 108 deletions storage/kvstore/kv_config/source/kv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ int _storage_config_TDB_INTERNAL();
*/
int _storage_config_TDB_EXTERNAL();

/**
* @brief This function initialize a external memory secure storage
* This includes a SecureStore class with external TDBStore over a blockdevice or,
* if no blockdevice was set the default blockdevice will be used.
* The following is a list of configuration parameter:
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_SIZE - Size of the external blockdevice in bytes
* or NULL for max possible size.
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address
* MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BLOCK_DEVICE - Alowed vlaues are: default, SPIF, DATAFASH, QSPIF, OSPIF or SD
* @returns 0 on success or negative value on failure.
*/
int _storage_config_TDB_EXTERNAL_NO_RBP();

/**
* @brief This function initialize a FILESYSTEM memory secure storage
* This includes a SecureStore class with TDBStore over FlashIAPBlockdevice
Expand All @@ -122,22 +109,6 @@ int _storage_config_TDB_EXTERNAL_NO_RBP();
*/
int _storage_config_FILESYSTEM();

/**
* @brief This function initialize a FILESYSTEM_NO_RBP memory secure storage with no
* rollback protection. This includes a SecureStore class an external FileSysteStore over a default
* filesystem with default blockdevice unless differently configured.
* The following is a list of configuration parameter:
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FILESYSTEM - Allowed values are: default, FAT or LITTLE
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_BLOCKDEVICE - Allowed values are: default, SPIF, DATAFASH, QSPIF, OSPIF or SD
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE - Blockdevice size in bytes. or NULL for max possible size.
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address.
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT - Where to mount the filesystem
* MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH - The working folder paths
*
* @returns 0 on success or negative value on failure.
*/
int _storage_config_FILESYSTEM_NO_RBP();

int _storage_config_tdb_external_common();
int _storage_config_filesystem_common();

Expand Down Expand Up @@ -494,8 +465,7 @@ BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size)
return NULL;
}

if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 ||
strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
//In TDBStore profile, we have a constraint of 4GByte
if (start_address == 0 && size == 0 && bd.size() < (uint32_t)(-1)) {
return &bd;
Expand Down Expand Up @@ -573,8 +543,7 @@ BlockDevice *_get_blockdevice_other(bd_addr_t start_address, bd_size_t size)
return NULL;
}

if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 ||
strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
//In TDBStore profile, we have a constraint of 4GByte
if (start_address == 0 && size == 0 && bd->size() < (uint32_t)(-1)) {
return bd;
Expand Down Expand Up @@ -746,35 +715,6 @@ int _storage_config_TDB_EXTERNAL()
#endif
}

int _storage_config_TDB_EXTERNAL_NO_RBP()
{
#if !SECURESTORE_ENABLED
return MBED_ERROR_UNSUPPORTED;
#endif

#ifdef MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS
bd_size_t size = MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_SIZE;
bd_addr_t address = MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS;

//Get external block device
BlockDevice *bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_BLOCKDEVICE, address, size);
if (bd == NULL) {
tr_error("KV Config: Fail to get external BlockDevice.");
return MBED_ERROR_FAILED_OPERATION ;
}

kvstore_config.external_bd = bd;

//Masking flag - Actually used to remove any KVStore flag which is not supported
//in the chosen KVStore profile.
kvstore_config.flags_mask = ~(KVStore::REQUIRE_REPLAY_PROTECTION_FLAG);

return _storage_config_tdb_external_common();
#else
return MBED_ERROR_CONFIG_UNSUPPORTED;
#endif
}

int _storage_config_tdb_external_common()
{
#if SECURESTORE_ENABLED
Expand Down Expand Up @@ -879,52 +819,6 @@ int _storage_config_FILESYSTEM()
#endif
}

int _storage_config_FILESYSTEM_NO_RBP()
{
#if !SECURESTORE_ENABLED
return MBED_ERROR_UNSUPPORTED;
#endif

#ifdef MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS
filesystemstore_folder_path = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH);

bd_size_t size = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE;
bd_addr_t address = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS;
const char *mount_point = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT);

//Get external block device for FileSystem.
kvstore_config.external_bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_BLOCKDEVICE, address, size);
if (kvstore_config.external_bd == NULL) {
tr_error("KV Config: Fail to get external BlockDevice ");
return MBED_ERROR_FAILED_OPERATION ;
}

int ret = kvstore_config.external_bd->init();
if (MBED_SUCCESS != ret) {
tr_error("KV Config: Fail to init external BlockDevice ");
return MBED_ERROR_FAILED_OPERATION ;
}

//Get FileSystem. Can be FAT, LITTLE or default. in case of default, the type will be decided base on the default
//component block device configured in the system. The priority is:
//QSPI -> SPI -> DATAFLASH == LITTLE
//SD == FAT
kvstore_config.external_fs = GET_FILESYSTEM(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FILESYSTEM, mount_point);
if (kvstore_config.external_fs == NULL) {
tr_error("KV Config: Fail to get FileSystem");
return MBED_ERROR_FAILED_OPERATION ;
}

//Masking flag - Actually used to remove any KVStore flag which is not supported
//in the chosen KVStore profile.
kvstore_config.flags_mask = ~(KVStore::REQUIRE_REPLAY_PROTECTION_FLAG);

return _storage_config_filesystem_common();
#else
return MBED_ERROR_CONFIG_UNSUPPORTED;
#endif
}

int _storage_config_filesystem_common()
{
#if SECURESTORE_ENABLED
Expand Down
Loading