SDHI_driver patch (mbedOS 5.11.5)

Committer:
tvendov
Date:
Fri Mar 29 19:47:34 2019 +0200
Revision:
2:7c75ab32d7c9
Fix: Folder structure changed. All SD Auto tests pass with OK!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tvendov 2:7c75ab32d7c9 1 /*
tvendov 2:7c75ab32d7c9 2 * Copyright (c) 2018 ARM Limited. All rights reserved.
tvendov 2:7c75ab32d7c9 3 * SPDX-License-Identifier: Apache-2.0
tvendov 2:7c75ab32d7c9 4 * Licensed under the Apache License, Version 2.0 (the License); you may
tvendov 2:7c75ab32d7c9 5 * not use this file except in compliance with the License.
tvendov 2:7c75ab32d7c9 6 * You may obtain a copy of the License at
tvendov 2:7c75ab32d7c9 7 *
tvendov 2:7c75ab32d7c9 8 * http://www.apache.org/licenses/LICENSE-2.0
tvendov 2:7c75ab32d7c9 9 *
tvendov 2:7c75ab32d7c9 10 * Unless required by applicable law or agreed to in writing, software
tvendov 2:7c75ab32d7c9 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
tvendov 2:7c75ab32d7c9 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tvendov 2:7c75ab32d7c9 13 * See the License for the specific language governing permissions and
tvendov 2:7c75ab32d7c9 14 * limitations under the License.
tvendov 2:7c75ab32d7c9 15 */
tvendov 2:7c75ab32d7c9 16
tvendov 2:7c75ab32d7c9 17 #include "kv_config.h"
tvendov 2:7c75ab32d7c9 18 #include "KVStore.h"
tvendov 2:7c75ab32d7c9 19 #include "KVMap.h"
tvendov 2:7c75ab32d7c9 20 #include "BlockDevice.h"
tvendov 2:7c75ab32d7c9 21 #include "FileSystem.h"
tvendov 2:7c75ab32d7c9 22 #include "FileSystemStore.h"
tvendov 2:7c75ab32d7c9 23 #include "SlicingBlockDevice.h"
tvendov 2:7c75ab32d7c9 24 #include "FATFileSystem.h"
tvendov 2:7c75ab32d7c9 25 #include "LittleFileSystem.h"
tvendov 2:7c75ab32d7c9 26 #include "TDBStore.h"
tvendov 2:7c75ab32d7c9 27 #include "mbed_error.h"
tvendov 2:7c75ab32d7c9 28 #include "FlashIAP.h"
tvendov 2:7c75ab32d7c9 29 #include "FlashSimBlockDevice.h"
tvendov 2:7c75ab32d7c9 30 #include "mbed_trace.h"
tvendov 2:7c75ab32d7c9 31 #include "SecureStore.h"
tvendov 2:7c75ab32d7c9 32 #define TRACE_GROUP "KVCFG"
tvendov 2:7c75ab32d7c9 33
tvendov 2:7c75ab32d7c9 34 #if COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 35 #include "FlashIAPBlockDevice.h"
tvendov 2:7c75ab32d7c9 36 #endif
tvendov 2:7c75ab32d7c9 37
tvendov 2:7c75ab32d7c9 38 #if COMPONENT_QSPIF
tvendov 2:7c75ab32d7c9 39 #include "QSPIFBlockDevice.h"
tvendov 2:7c75ab32d7c9 40 #endif
tvendov 2:7c75ab32d7c9 41
tvendov 2:7c75ab32d7c9 42 #if COMPONENT_SPIF
tvendov 2:7c75ab32d7c9 43 #include "SPIFBlockDevice.h"
tvendov 2:7c75ab32d7c9 44 #endif
tvendov 2:7c75ab32d7c9 45
tvendov 2:7c75ab32d7c9 46 #if COMPONENT_DATAFLASH
tvendov 2:7c75ab32d7c9 47 #include "DataFlashBlockDevice.h"
tvendov 2:7c75ab32d7c9 48 #endif
tvendov 2:7c75ab32d7c9 49
tvendov 2:7c75ab32d7c9 50 #if COMPONENT_SD
tvendov 2:7c75ab32d7c9 51 #include "SDBlockDevice.h"
tvendov 2:7c75ab32d7c9 52 #endif
tvendov 2:7c75ab32d7c9 53
tvendov 2:7c75ab32d7c9 54 #if COMPONENT_RZ_SDHI
tvendov 2:7c75ab32d7c9 55 #include "RZ_SDHIBlockDevice.hpp"
tvendov 2:7c75ab32d7c9 56 #endif
tvendov 2:7c75ab32d7c9 57
tvendov 2:7c75ab32d7c9 58 /**
tvendov 2:7c75ab32d7c9 59 * @brief This function initializes internal memory secure storage
tvendov 2:7c75ab32d7c9 60 * This includes a TDBStore instance with a FlashIAPBlockdevice
tvendov 2:7c75ab32d7c9 61 * as the supported storage.
tvendov 2:7c75ab32d7c9 62 * The following is a list of configuration parameter
tvendov 2:7c75ab32d7c9 63 * MBED_CONF_STORAGE_TDB_INTERNAL_SIZE - The size of the underlying FlashIAPBlockdevice
tvendov 2:7c75ab32d7c9 64 * MBED_CONF_STORAGE_TDB_INTERNAL_BASE_ADDRESS - The start address of the underlying FlashIAPBlockdevice
tvendov 2:7c75ab32d7c9 65 * @returns 0 on success or negative value on failure.
tvendov 2:7c75ab32d7c9 66 */
tvendov 2:7c75ab32d7c9 67 int _storage_config_TDB_INTERNAL();
tvendov 2:7c75ab32d7c9 68
tvendov 2:7c75ab32d7c9 69 /**
tvendov 2:7c75ab32d7c9 70 * @brief This function initialize external memory secure storage
tvendov 2:7c75ab32d7c9 71 * This includes a SecureStore class with TDBStore over FlashIAPBlockdevice
tvendov 2:7c75ab32d7c9 72 * and an external TDBStore over a default blockdevice unless configured differently.
tvendov 2:7c75ab32d7c9 73 * The following is a list of configuration parameter:
tvendov 2:7c75ab32d7c9 74 * MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE - Size of the internal FlashIAPBlockDevice and by
tvendov 2:7c75ab32d7c9 75 * default is set to from start address to the end of the flash.
tvendov 2:7c75ab32d7c9 76 * If start address is 0 the start address will be set to end of
tvendov 2:7c75ab32d7c9 77 * flash - rbp_internal_size.
tvendov 2:7c75ab32d7c9 78 * MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS - The satrt address of the internal FlashIAPBlockDevice.
tvendov 2:7c75ab32d7c9 79 * MBED_CONF_STORAGE_TDB_EXTERNAL_EXTERNAL_SIZE - Size of the external blockdevice in bytes or NULL for
tvendov 2:7c75ab32d7c9 80 * max possible size.
tvendov 2:7c75ab32d7c9 81 * MBED_CONF_STORAGE_TDB_EXTERNAL_EXTERNAL_BASE_ADDRESS - The block device start address.
tvendov 2:7c75ab32d7c9 82 * MBED_CONF_STORAGE_TDB_EXTERNAL_EXTERNAL_BLOCK_DEVICE - Alowed vlaues are: default, SPIF, DATAFASH, QSPIF or SD
tvendov 2:7c75ab32d7c9 83 * @returns 0 on success or negative value on failure.
tvendov 2:7c75ab32d7c9 84 */
tvendov 2:7c75ab32d7c9 85 int _storage_config_TDB_EXTERNAL();
tvendov 2:7c75ab32d7c9 86
tvendov 2:7c75ab32d7c9 87 /**
tvendov 2:7c75ab32d7c9 88 * @brief This function initialize a external memory secure storage
tvendov 2:7c75ab32d7c9 89 * This includes a SecureStore class with external TDBStore over a blockdevice or,
tvendov 2:7c75ab32d7c9 90 * if no blockdevice was set the default blockdevice will be used.
tvendov 2:7c75ab32d7c9 91 * The following is a list of configuration parameter:
tvendov 2:7c75ab32d7c9 92 * MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_SIZE - Size of the external blockdevice in bytes
tvendov 2:7c75ab32d7c9 93 * or NULL for max possible size.
tvendov 2:7c75ab32d7c9 94 * MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address
tvendov 2:7c75ab32d7c9 95 * MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BLOCK_DEVICE - Alowed vlaues are: default, SPIF, DATAFASH, QSPIF or SD
tvendov 2:7c75ab32d7c9 96 * @returns 0 on success or negative value on failure.
tvendov 2:7c75ab32d7c9 97 */
tvendov 2:7c75ab32d7c9 98 int _storage_config_TDB_EXTERNAL_NO_RBP();
tvendov 2:7c75ab32d7c9 99
tvendov 2:7c75ab32d7c9 100 /**
tvendov 2:7c75ab32d7c9 101 * @brief This function initialize a FILESYSTEM memory secure storage
tvendov 2:7c75ab32d7c9 102 * This includes a SecureStore class with TDBStore over FlashIAPBlockdevice
tvendov 2:7c75ab32d7c9 103 * in the internal memory and an external FileSysteStore. If blockdevice and filesystem not set,
tvendov 2:7c75ab32d7c9 104 * the system will use the default block device and default filesystem
tvendov 2:7c75ab32d7c9 105 * The following is a list of configuration parameter:
tvendov 2:7c75ab32d7c9 106 * MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE - Size of the internal FlashIAPBlockDevice and by
tvendov 2:7c75ab32d7c9 107 * default is set to from start address to the end of the flash.
tvendov 2:7c75ab32d7c9 108 * If start address is 0 the start address will be set to end of
tvendov 2:7c75ab32d7c9 109 * flash - rbp_internal_size.
tvendov 2:7c75ab32d7c9 110 * MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS - The satrt address of the internal FlashIAPBlockDevice.
tvendov 2:7c75ab32d7c9 111 * MBED_CONF_STORAGE_FILESYSTEM_FILESYSTEM - Allowed values are: default, FAT or LITTLE
tvendov 2:7c75ab32d7c9 112 * MBED_CONF_STORAGE_FILESYSTEM_BLOCKDEVICE - Allowed values are: default, SPIF, DATAFASH, QSPIF or SD
tvendov 2:7c75ab32d7c9 113 * MBED_CONF_STORAGE_FILESYSTEM_EXTERNAL_SIZE - External Blockdevice size in bytes or NULL for max possible size.
tvendov 2:7c75ab32d7c9 114 * MBED_CONF_STORAGE_FILESYSTEM_EXTERNAL_BASE_ADDRESS - The block device start address.
tvendov 2:7c75ab32d7c9 115 * MBED_CONF_STORAGE_FILESYSTEM_MOUNT_POINT - Where to mount the filesystem
tvendov 2:7c75ab32d7c9 116 * MBED_CONF_STORAGE_FILESYSTEM_FOLDER_PATH - The working folder paths
tvendov 2:7c75ab32d7c9 117 *
tvendov 2:7c75ab32d7c9 118 * @returns 0 on success or negative value on failure.
tvendov 2:7c75ab32d7c9 119 */
tvendov 2:7c75ab32d7c9 120 int _storage_config_FILESYSTEM();
tvendov 2:7c75ab32d7c9 121
tvendov 2:7c75ab32d7c9 122 /**
tvendov 2:7c75ab32d7c9 123 * @brief This function initialize a FILESYSTEM_NO_RBP memory secure storage with no
tvendov 2:7c75ab32d7c9 124 * rollback protection. This includes a SecureStore class an external FileSysteStore over a default
tvendov 2:7c75ab32d7c9 125 * filesystem with default blockdevice unless differently configured.
tvendov 2:7c75ab32d7c9 126 * The following is a list of configuration parameter:
tvendov 2:7c75ab32d7c9 127 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FILESYSTEM - Allowed values are: default, FAT or LITTLE
tvendov 2:7c75ab32d7c9 128 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_BLOCKDEVICE - Allowed values are: default, SPIF, DATAFASH, QSPIF or SD
tvendov 2:7c75ab32d7c9 129 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE - Blockdevice size in bytes. or NULL for max possible size.
tvendov 2:7c75ab32d7c9 130 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS - The block device start address.
tvendov 2:7c75ab32d7c9 131 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT - Where to mount the filesystem
tvendov 2:7c75ab32d7c9 132 * MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH - The working folder paths
tvendov 2:7c75ab32d7c9 133 *
tvendov 2:7c75ab32d7c9 134 * @returns 0 on success or negative value on failure.
tvendov 2:7c75ab32d7c9 135 */
tvendov 2:7c75ab32d7c9 136 int _storage_config_FILESYSTEM_NO_RBP();
tvendov 2:7c75ab32d7c9 137
tvendov 2:7c75ab32d7c9 138 int _storage_config_tdb_external_common();
tvendov 2:7c75ab32d7c9 139 int _storage_config_filesystem_common();
tvendov 2:7c75ab32d7c9 140
tvendov 2:7c75ab32d7c9 141 static const char *filesystemstore_folder_path = NULL;
tvendov 2:7c75ab32d7c9 142
tvendov 2:7c75ab32d7c9 143 using namespace mbed;
tvendov 2:7c75ab32d7c9 144
tvendov 2:7c75ab32d7c9 145
tvendov 2:7c75ab32d7c9 146 static SingletonPtr<PlatformMutex> mutex;
tvendov 2:7c75ab32d7c9 147 static bool is_kv_config_initialize = false;
tvendov 2:7c75ab32d7c9 148 static kvstore_config_t kvstore_config;
tvendov 2:7c75ab32d7c9 149
tvendov 2:7c75ab32d7c9 150 #define INTERNAL_BLOCKDEVICE_NAME FLASHIAP
tvendov 2:7c75ab32d7c9 151
tvendov 2:7c75ab32d7c9 152 #define STR_EXPAND(tok) #tok
tvendov 2:7c75ab32d7c9 153 #define STR(tok) STR_EXPAND(tok)
tvendov 2:7c75ab32d7c9 154
tvendov 2:7c75ab32d7c9 155 #define _GET_FILESYSTEM_concat(dev, ...) _get_filesystem_##dev(__VA_ARGS__)
tvendov 2:7c75ab32d7c9 156 #define GET_FILESYSTEM(dev, ...) _GET_FILESYSTEM_concat(dev, __VA_ARGS__)
tvendov 2:7c75ab32d7c9 157
tvendov 2:7c75ab32d7c9 158 #define _GET_BLOCKDEVICE_concat(dev, ...) _get_blockdevice_##dev(__VA_ARGS__)
tvendov 2:7c75ab32d7c9 159 #define GET_BLOCKDEVICE(dev, ...) _GET_BLOCKDEVICE_concat(dev, __VA_ARGS__)
tvendov 2:7c75ab32d7c9 160
tvendov 2:7c75ab32d7c9 161 static inline uint32_t align_up(uint64_t val, uint64_t size)
tvendov 2:7c75ab32d7c9 162 {
tvendov 2:7c75ab32d7c9 163 return (((val - 1) / size) + 1) * size;
tvendov 2:7c75ab32d7c9 164 }
tvendov 2:7c75ab32d7c9 165
tvendov 2:7c75ab32d7c9 166 static inline uint32_t align_down(uint64_t val, uint64_t size)
tvendov 2:7c75ab32d7c9 167 {
tvendov 2:7c75ab32d7c9 168 return (((val) / size)) * size;
tvendov 2:7c75ab32d7c9 169 }
tvendov 2:7c75ab32d7c9 170
tvendov 2:7c75ab32d7c9 171 int _calculate_blocksize_match_tdbstore(BlockDevice *bd)
tvendov 2:7c75ab32d7c9 172 {
tvendov 2:7c75ab32d7c9 173 bd_size_t size = bd->size();
tvendov 2:7c75ab32d7c9 174 bd_size_t erase_size = bd->get_erase_size();
tvendov 2:7c75ab32d7c9 175 bd_size_t number_of_sector = size / erase_size;
tvendov 2:7c75ab32d7c9 176
tvendov 2:7c75ab32d7c9 177 if (number_of_sector < 2) {
tvendov 2:7c75ab32d7c9 178 tr_warning("KV Config: There are less than two sectors - TDBStore will not work.");
tvendov 2:7c75ab32d7c9 179 return -1;
tvendov 2:7c75ab32d7c9 180 }
tvendov 2:7c75ab32d7c9 181
tvendov 2:7c75ab32d7c9 182
tvendov 2:7c75ab32d7c9 183 if (number_of_sector % 2 != 0) {
tvendov 2:7c75ab32d7c9 184 tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size");
tvendov 2:7c75ab32d7c9 185 }
tvendov 2:7c75ab32d7c9 186
tvendov 2:7c75ab32d7c9 187 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 188 }
tvendov 2:7c75ab32d7c9 189
tvendov 2:7c75ab32d7c9 190 int _get_addresses(BlockDevice *bd, bd_addr_t start_address, bd_size_t size, bd_addr_t *out_start_addr,
tvendov 2:7c75ab32d7c9 191 bd_addr_t *out_end_addr)
tvendov 2:7c75ab32d7c9 192 {
tvendov 2:7c75ab32d7c9 193 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 194 bd_addr_t end_address;
tvendov 2:7c75ab32d7c9 195 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 196
tvendov 2:7c75ab32d7c9 197 aligned_start_address = align_down(start_address, bd->get_erase_size(start_address));
tvendov 2:7c75ab32d7c9 198 if (aligned_start_address != start_address) {
tvendov 2:7c75ab32d7c9 199 tr_error("KV Config: Start address is not aligned. Better use %02llx", aligned_start_address);
tvendov 2:7c75ab32d7c9 200 return -1;
tvendov 2:7c75ab32d7c9 201 }
tvendov 2:7c75ab32d7c9 202
tvendov 2:7c75ab32d7c9 203 if (size == 0) {
tvendov 2:7c75ab32d7c9 204 (*out_start_addr) = aligned_start_address;
tvendov 2:7c75ab32d7c9 205 (*out_end_addr) = bd->size();
tvendov 2:7c75ab32d7c9 206 return 0;
tvendov 2:7c75ab32d7c9 207 }
tvendov 2:7c75ab32d7c9 208
tvendov 2:7c75ab32d7c9 209 end_address = start_address + size;
tvendov 2:7c75ab32d7c9 210 aligned_end_address = align_up(end_address, bd->get_erase_size(end_address));
tvendov 2:7c75ab32d7c9 211 if (aligned_end_address != end_address) {
tvendov 2:7c75ab32d7c9 212 tr_error("KV Config: End address is not aligned. Consider changing the size parameter.");
tvendov 2:7c75ab32d7c9 213 return -1;
tvendov 2:7c75ab32d7c9 214 }
tvendov 2:7c75ab32d7c9 215
tvendov 2:7c75ab32d7c9 216 if (aligned_end_address > bd->size()) {
tvendov 2:7c75ab32d7c9 217 tr_error("KV Config: End address is out of boundaries");
tvendov 2:7c75ab32d7c9 218 return -1;
tvendov 2:7c75ab32d7c9 219 }
tvendov 2:7c75ab32d7c9 220
tvendov 2:7c75ab32d7c9 221 (*out_start_addr) = aligned_start_address;
tvendov 2:7c75ab32d7c9 222 (*out_end_addr) = aligned_end_address;
tvendov 2:7c75ab32d7c9 223 return 0;
tvendov 2:7c75ab32d7c9 224 }
tvendov 2:7c75ab32d7c9 225
tvendov 2:7c75ab32d7c9 226 FileSystem *_get_filesystem_FAT(const char *mount)
tvendov 2:7c75ab32d7c9 227 {
tvendov 2:7c75ab32d7c9 228 static FATFileSystem sdcard(mount);
tvendov 2:7c75ab32d7c9 229 return &sdcard;
tvendov 2:7c75ab32d7c9 230
tvendov 2:7c75ab32d7c9 231 }
tvendov 2:7c75ab32d7c9 232
tvendov 2:7c75ab32d7c9 233 FileSystem *_get_filesystem_LITTLE(const char *mount)
tvendov 2:7c75ab32d7c9 234 {
tvendov 2:7c75ab32d7c9 235 static LittleFileSystem flash(mount);
tvendov 2:7c75ab32d7c9 236 return &flash;
tvendov 2:7c75ab32d7c9 237 }
tvendov 2:7c75ab32d7c9 238
tvendov 2:7c75ab32d7c9 239 FileSystemStore *_get_file_system_store(FileSystem *fs)
tvendov 2:7c75ab32d7c9 240 {
tvendov 2:7c75ab32d7c9 241 static FileSystemStore fss(fs);
tvendov 2:7c75ab32d7c9 242 return &fss;
tvendov 2:7c75ab32d7c9 243 }
tvendov 2:7c75ab32d7c9 244
tvendov 2:7c75ab32d7c9 245 FileSystem *_get_filesystem_default(const char *mount)
tvendov 2:7c75ab32d7c9 246 {
tvendov 2:7c75ab32d7c9 247 #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
tvendov 2:7c75ab32d7c9 248 return _get_filesystem_LITTLE(mount);
tvendov 2:7c75ab32d7c9 249 #elif (COMPONENT_SD || COMPONENT_RZ_SDHI)
tvendov 2:7c75ab32d7c9 250 return _get_filesystem_FAT(mount);
tvendov 2:7c75ab32d7c9 251 #else
tvendov 2:7c75ab32d7c9 252 return NULL;
tvendov 2:7c75ab32d7c9 253 #endif
tvendov 2:7c75ab32d7c9 254 }
tvendov 2:7c75ab32d7c9 255
tvendov 2:7c75ab32d7c9 256 //Calculates the start address of FLASHIAP block device for TDB_INTERNAL profile.
tvendov 2:7c75ab32d7c9 257 //If possible, the address will start 2 sectors after the end of code sector allowing
tvendov 2:7c75ab32d7c9 258 //some space for an application update.
tvendov 2:7c75ab32d7c9 259 int _get_flashiap_bd_default_addresses_tdb_internal(bd_addr_t *start_address, bd_size_t *size)
tvendov 2:7c75ab32d7c9 260 {
tvendov 2:7c75ab32d7c9 261 #if COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 262
tvendov 2:7c75ab32d7c9 263 FlashIAP flash;
tvendov 2:7c75ab32d7c9 264
tvendov 2:7c75ab32d7c9 265 if (*start_address != 0 || *size != 0) {
tvendov 2:7c75ab32d7c9 266 return MBED_ERROR_INVALID_ARGUMENT;
tvendov 2:7c75ab32d7c9 267 }
tvendov 2:7c75ab32d7c9 268
tvendov 2:7c75ab32d7c9 269 //If default values are set, we should get the maximum available size of internal bd.
tvendov 2:7c75ab32d7c9 270 if (flash.init() != 0) {
tvendov 2:7c75ab32d7c9 271 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 272 }
tvendov 2:7c75ab32d7c9 273
tvendov 2:7c75ab32d7c9 274 *start_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));
tvendov 2:7c75ab32d7c9 275
tvendov 2:7c75ab32d7c9 276 // Give the application a couple of spare sectors to grow (if there are such)
tvendov 2:7c75ab32d7c9 277 bd_size_t spare_size_for_app = 0;
tvendov 2:7c75ab32d7c9 278 bd_addr_t curr_addr = *start_address;
tvendov 2:7c75ab32d7c9 279 bd_addr_t flash_end_address = flash.get_flash_start() + flash.get_flash_size();
tvendov 2:7c75ab32d7c9 280
tvendov 2:7c75ab32d7c9 281 int spare_sectors_for_app = 2;
tvendov 2:7c75ab32d7c9 282 int min_sectors_for_storage = 2;
tvendov 2:7c75ab32d7c9 283 for (int i = 0; i < spare_sectors_for_app + min_sectors_for_storage - 1; i++) {
tvendov 2:7c75ab32d7c9 284 bd_size_t sector_size = flash.get_sector_size(curr_addr);
tvendov 2:7c75ab32d7c9 285 curr_addr += sector_size;
tvendov 2:7c75ab32d7c9 286 if (curr_addr >= flash_end_address) {
tvendov 2:7c75ab32d7c9 287 spare_size_for_app = 0;
tvendov 2:7c75ab32d7c9 288 break;
tvendov 2:7c75ab32d7c9 289 }
tvendov 2:7c75ab32d7c9 290
tvendov 2:7c75ab32d7c9 291 if (i < spare_sectors_for_app) {
tvendov 2:7c75ab32d7c9 292 spare_size_for_app += sector_size;
tvendov 2:7c75ab32d7c9 293 }
tvendov 2:7c75ab32d7c9 294 }
tvendov 2:7c75ab32d7c9 295 *start_address += spare_size_for_app;
tvendov 2:7c75ab32d7c9 296
tvendov 2:7c75ab32d7c9 297 flash.deinit();
tvendov 2:7c75ab32d7c9 298
tvendov 2:7c75ab32d7c9 299 #endif
tvendov 2:7c75ab32d7c9 300
tvendov 2:7c75ab32d7c9 301 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 302 }
tvendov 2:7c75ab32d7c9 303
tvendov 2:7c75ab32d7c9 304 //Calculates address and size for FLASHIAP block device in TDB_EXTERNAL and FILESYSTEM profiles.
tvendov 2:7c75ab32d7c9 305 //The size of the block device will be 2 sectors at the ends of the internal flash for
tvendov 2:7c75ab32d7c9 306 //the use of the rbp internal TDBStore.
tvendov 2:7c75ab32d7c9 307 int _get_flashiap_bd_default_addresses_rbp(bd_addr_t *start_address, bd_size_t *size)
tvendov 2:7c75ab32d7c9 308 {
tvendov 2:7c75ab32d7c9 309 #if COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 310
tvendov 2:7c75ab32d7c9 311 bd_addr_t flash_end_address;
tvendov 2:7c75ab32d7c9 312 bd_addr_t flash_start_address;
tvendov 2:7c75ab32d7c9 313 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 314 bd_addr_t flash_first_writable_sector_address;
tvendov 2:7c75ab32d7c9 315 FlashIAP flash;
tvendov 2:7c75ab32d7c9 316
tvendov 2:7c75ab32d7c9 317 if (*start_address != 0 || *size != 0) {
tvendov 2:7c75ab32d7c9 318 return MBED_ERROR_INVALID_ARGUMENT;
tvendov 2:7c75ab32d7c9 319 }
tvendov 2:7c75ab32d7c9 320
tvendov 2:7c75ab32d7c9 321 int ret = flash.init();
tvendov 2:7c75ab32d7c9 322 if (ret != 0) {
tvendov 2:7c75ab32d7c9 323 return MBED_ERROR_INITIALIZATION_FAILED;
tvendov 2:7c75ab32d7c9 324 }
tvendov 2:7c75ab32d7c9 325
tvendov 2:7c75ab32d7c9 326 flash_first_writable_sector_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));
tvendov 2:7c75ab32d7c9 327 flash_start_address = flash.get_flash_start();
tvendov 2:7c75ab32d7c9 328 flash_end_address = flash_start_address + flash.get_flash_size();;
tvendov 2:7c75ab32d7c9 329 *start_address = flash_end_address - 1;
tvendov 2:7c75ab32d7c9 330 aligned_start_address = align_down(*start_address, flash.get_sector_size(*start_address));
tvendov 2:7c75ab32d7c9 331 *size = (flash_end_address - aligned_start_address) * 2;
tvendov 2:7c75ab32d7c9 332 *start_address = (flash_end_address - *size);
tvendov 2:7c75ab32d7c9 333 aligned_start_address = align_down(*start_address, flash.get_sector_size(*start_address));
tvendov 2:7c75ab32d7c9 334
tvendov 2:7c75ab32d7c9 335 flash.deinit();
tvendov 2:7c75ab32d7c9 336
tvendov 2:7c75ab32d7c9 337 if (aligned_start_address < flash_first_writable_sector_address) {
tvendov 2:7c75ab32d7c9 338 tr_error("KV Config: Internal block device start address overlapped ROM address ");
tvendov 2:7c75ab32d7c9 339 return MBED_ERROR_INITIALIZATION_FAILED;
tvendov 2:7c75ab32d7c9 340 }
tvendov 2:7c75ab32d7c9 341
tvendov 2:7c75ab32d7c9 342 #endif
tvendov 2:7c75ab32d7c9 343
tvendov 2:7c75ab32d7c9 344 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 345
tvendov 2:7c75ab32d7c9 346 }
tvendov 2:7c75ab32d7c9 347
tvendov 2:7c75ab32d7c9 348 BlockDevice *_get_blockdevice_FLASHIAP(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 349 {
tvendov 2:7c75ab32d7c9 350 #if COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 351
tvendov 2:7c75ab32d7c9 352 bd_addr_t flash_end_address;
tvendov 2:7c75ab32d7c9 353 bd_addr_t flash_start_address;
tvendov 2:7c75ab32d7c9 354 bd_addr_t flash_first_writable_sector_address;
tvendov 2:7c75ab32d7c9 355 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 356 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 357 bd_addr_t end_address;
tvendov 2:7c75ab32d7c9 358 FlashIAP flash;
tvendov 2:7c75ab32d7c9 359
tvendov 2:7c75ab32d7c9 360 int ret = flash.init();
tvendov 2:7c75ab32d7c9 361 if (ret != 0) {
tvendov 2:7c75ab32d7c9 362 return NULL;
tvendov 2:7c75ab32d7c9 363 }
tvendov 2:7c75ab32d7c9 364
tvendov 2:7c75ab32d7c9 365 //Get flash parameters before starting
tvendov 2:7c75ab32d7c9 366 flash_first_writable_sector_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));
tvendov 2:7c75ab32d7c9 367 flash_start_address = flash.get_flash_start();
tvendov 2:7c75ab32d7c9 368 flash_end_address = flash_start_address + flash.get_flash_size();;
tvendov 2:7c75ab32d7c9 369
tvendov 2:7c75ab32d7c9 370 //Non default configuration
tvendov 2:7c75ab32d7c9 371 if (start_address != 0) {
tvendov 2:7c75ab32d7c9 372
tvendov 2:7c75ab32d7c9 373 aligned_start_address = align_down(start_address, flash.get_sector_size(start_address));
tvendov 2:7c75ab32d7c9 374 if (start_address != aligned_start_address) {
tvendov 2:7c75ab32d7c9 375 tr_error("KV Config: Internal block device start address is not aligned. Better use %02llx", aligned_start_address);
tvendov 2:7c75ab32d7c9 376 flash.deinit();
tvendov 2:7c75ab32d7c9 377 return NULL;
tvendov 2:7c75ab32d7c9 378 }
tvendov 2:7c75ab32d7c9 379
tvendov 2:7c75ab32d7c9 380 if (size == 0) {
tvendov 2:7c75ab32d7c9 381 //The block device will have all space form start address to the end of the flash
tvendov 2:7c75ab32d7c9 382 size = (flash_end_address - start_address);
tvendov 2:7c75ab32d7c9 383
tvendov 2:7c75ab32d7c9 384 static FlashIAPBlockDevice bd(start_address, size);
tvendov 2:7c75ab32d7c9 385 flash.deinit();
tvendov 2:7c75ab32d7c9 386 return &bd;
tvendov 2:7c75ab32d7c9 387 }
tvendov 2:7c75ab32d7c9 388
tvendov 2:7c75ab32d7c9 389 if (size != 0) {
tvendov 2:7c75ab32d7c9 390 end_address = start_address + size;
tvendov 2:7c75ab32d7c9 391 if (end_address > flash_end_address) {
tvendov 2:7c75ab32d7c9 392 tr_error("KV Config: Internal block device end address is out of boundaries");
tvendov 2:7c75ab32d7c9 393 flash.deinit();
tvendov 2:7c75ab32d7c9 394 return NULL;
tvendov 2:7c75ab32d7c9 395 }
tvendov 2:7c75ab32d7c9 396
tvendov 2:7c75ab32d7c9 397 aligned_end_address = align_up(end_address, flash.get_sector_size(end_address - 1));
tvendov 2:7c75ab32d7c9 398 if (end_address != aligned_end_address) {
tvendov 2:7c75ab32d7c9 399 tr_error("KV Config: Internal block device start address is not aligned. Consider changing the size parameter");
tvendov 2:7c75ab32d7c9 400 flash.deinit();
tvendov 2:7c75ab32d7c9 401 return NULL;
tvendov 2:7c75ab32d7c9 402 }
tvendov 2:7c75ab32d7c9 403
tvendov 2:7c75ab32d7c9 404 static FlashIAPBlockDevice bd(start_address, size);
tvendov 2:7c75ab32d7c9 405 flash.deinit();
tvendov 2:7c75ab32d7c9 406 return &bd;
tvendov 2:7c75ab32d7c9 407 }
tvendov 2:7c75ab32d7c9 408 }
tvendov 2:7c75ab32d7c9 409
tvendov 2:7c75ab32d7c9 410 //Non default configuration start_address = 0
tvendov 2:7c75ab32d7c9 411 start_address = flash_end_address - size;
tvendov 2:7c75ab32d7c9 412 aligned_start_address = align_down(start_address, flash.get_sector_size(start_address));
tvendov 2:7c75ab32d7c9 413 if (start_address != aligned_start_address) {
tvendov 2:7c75ab32d7c9 414 tr_error("KV Config: Internal block device start address is not aligned. Consider changing the size parameter");
tvendov 2:7c75ab32d7c9 415 flash.deinit();
tvendov 2:7c75ab32d7c9 416 return NULL;
tvendov 2:7c75ab32d7c9 417 }
tvendov 2:7c75ab32d7c9 418
tvendov 2:7c75ab32d7c9 419 flash.deinit();
tvendov 2:7c75ab32d7c9 420
tvendov 2:7c75ab32d7c9 421 if (aligned_start_address < flash_first_writable_sector_address) {
tvendov 2:7c75ab32d7c9 422 tr_error("KV Config: Internal block device start address overlapped ROM address ");
tvendov 2:7c75ab32d7c9 423 return NULL;
tvendov 2:7c75ab32d7c9 424 }
tvendov 2:7c75ab32d7c9 425 static FlashIAPBlockDevice bd(aligned_start_address, size);
tvendov 2:7c75ab32d7c9 426 return &bd;
tvendov 2:7c75ab32d7c9 427
tvendov 2:7c75ab32d7c9 428 #else
tvendov 2:7c75ab32d7c9 429 return NULL;
tvendov 2:7c75ab32d7c9 430 #endif
tvendov 2:7c75ab32d7c9 431 }
tvendov 2:7c75ab32d7c9 432
tvendov 2:7c75ab32d7c9 433 BlockDevice *_get_blockdevice_SPIF(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 434 {
tvendov 2:7c75ab32d7c9 435 #if COMPONENT_SPIF
tvendov 2:7c75ab32d7c9 436
tvendov 2:7c75ab32d7c9 437 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 438 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 439
tvendov 2:7c75ab32d7c9 440 static SPIFBlockDevice bd(
tvendov 2:7c75ab32d7c9 441 MBED_CONF_SPIF_DRIVER_SPI_MOSI,
tvendov 2:7c75ab32d7c9 442 MBED_CONF_SPIF_DRIVER_SPI_MISO,
tvendov 2:7c75ab32d7c9 443 MBED_CONF_SPIF_DRIVER_SPI_CLK,
tvendov 2:7c75ab32d7c9 444 MBED_CONF_SPIF_DRIVER_SPI_CS,
tvendov 2:7c75ab32d7c9 445 MBED_CONF_SPIF_DRIVER_SPI_FREQ
tvendov 2:7c75ab32d7c9 446 );
tvendov 2:7c75ab32d7c9 447
tvendov 2:7c75ab32d7c9 448 if (bd.init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 449 tr_error("KV Config: SPIFBlockDevice init fail");
tvendov 2:7c75ab32d7c9 450 return NULL;
tvendov 2:7c75ab32d7c9 451 }
tvendov 2:7c75ab32d7c9 452
tvendov 2:7c75ab32d7c9 453 if (start_address == 0 && size == 0) {
tvendov 2:7c75ab32d7c9 454 return &bd;
tvendov 2:7c75ab32d7c9 455 }
tvendov 2:7c75ab32d7c9 456
tvendov 2:7c75ab32d7c9 457 //If address and size were specified use SlicingBlockDevice to get the correct block device size and start address.
tvendov 2:7c75ab32d7c9 458 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 459 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 460 return NULL;
tvendov 2:7c75ab32d7c9 461 }
tvendov 2:7c75ab32d7c9 462
tvendov 2:7c75ab32d7c9 463 static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
tvendov 2:7c75ab32d7c9 464 return &sbd;
tvendov 2:7c75ab32d7c9 465
tvendov 2:7c75ab32d7c9 466 #else
tvendov 2:7c75ab32d7c9 467 return NULL;
tvendov 2:7c75ab32d7c9 468 #endif
tvendov 2:7c75ab32d7c9 469 }
tvendov 2:7c75ab32d7c9 470
tvendov 2:7c75ab32d7c9 471 BlockDevice *_get_blockdevice_QSPIF(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 472 {
tvendov 2:7c75ab32d7c9 473 #if COMPONENT_QSPIF
tvendov 2:7c75ab32d7c9 474
tvendov 2:7c75ab32d7c9 475 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 476 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 477
tvendov 2:7c75ab32d7c9 478 static QSPIFBlockDevice bd(
tvendov 2:7c75ab32d7c9 479 QSPI_FLASH1_IO0,
tvendov 2:7c75ab32d7c9 480 QSPI_FLASH1_IO1,
tvendov 2:7c75ab32d7c9 481 QSPI_FLASH1_IO2,
tvendov 2:7c75ab32d7c9 482 QSPI_FLASH1_IO3,
tvendov 2:7c75ab32d7c9 483 QSPI_FLASH1_SCK,
tvendov 2:7c75ab32d7c9 484 QSPI_FLASH1_CSN,
tvendov 2:7c75ab32d7c9 485 QSPIF_POLARITY_MODE_0,
tvendov 2:7c75ab32d7c9 486 MBED_CONF_QSPIF_QSPI_FREQ
tvendov 2:7c75ab32d7c9 487 );
tvendov 2:7c75ab32d7c9 488
tvendov 2:7c75ab32d7c9 489 if (bd.init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 490 tr_error("KV Config: QSPIFBlockDevice init fail");
tvendov 2:7c75ab32d7c9 491 return NULL;
tvendov 2:7c75ab32d7c9 492 }
tvendov 2:7c75ab32d7c9 493
tvendov 2:7c75ab32d7c9 494 if (start_address == 0 && size == 0) {
tvendov 2:7c75ab32d7c9 495 return &bd;
tvendov 2:7c75ab32d7c9 496 }
tvendov 2:7c75ab32d7c9 497
tvendov 2:7c75ab32d7c9 498 //If address and size were specified use SlicingBlockDevice to get the correct block device size and start address.
tvendov 2:7c75ab32d7c9 499 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 500 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 501 return NULL;
tvendov 2:7c75ab32d7c9 502 }
tvendov 2:7c75ab32d7c9 503
tvendov 2:7c75ab32d7c9 504 static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
tvendov 2:7c75ab32d7c9 505 return &sbd;
tvendov 2:7c75ab32d7c9 506
tvendov 2:7c75ab32d7c9 507 #else
tvendov 2:7c75ab32d7c9 508 return NULL;
tvendov 2:7c75ab32d7c9 509 #endif
tvendov 2:7c75ab32d7c9 510 }
tvendov 2:7c75ab32d7c9 511
tvendov 2:7c75ab32d7c9 512 BlockDevice *_get_blockdevice_DATAFLASH(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 513 {
tvendov 2:7c75ab32d7c9 514 #if COMPONENT_DATAFLASH
tvendov 2:7c75ab32d7c9 515
tvendov 2:7c75ab32d7c9 516 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 517 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 518
tvendov 2:7c75ab32d7c9 519 static DataFlashBlockDevice bd(
tvendov 2:7c75ab32d7c9 520 MBED_CONF_DATAFLASH_SPI_MOSI,
tvendov 2:7c75ab32d7c9 521 MBED_CONF_DATAFLASH_SPI_MISO,
tvendov 2:7c75ab32d7c9 522 MBED_CONF_DATAFLASH_SPI_CLK,
tvendov 2:7c75ab32d7c9 523 MBED_CONF_DATAFLASH_SPI_CS
tvendov 2:7c75ab32d7c9 524 );
tvendov 2:7c75ab32d7c9 525
tvendov 2:7c75ab32d7c9 526 if (bd.init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 527 tr_error("KV Config: DataFlashBlockDevice init fail");
tvendov 2:7c75ab32d7c9 528 return NULL;
tvendov 2:7c75ab32d7c9 529 }
tvendov 2:7c75ab32d7c9 530
tvendov 2:7c75ab32d7c9 531 if (start_address == 0 && size == 0) {
tvendov 2:7c75ab32d7c9 532 return &bd;
tvendov 2:7c75ab32d7c9 533 }
tvendov 2:7c75ab32d7c9 534
tvendov 2:7c75ab32d7c9 535 //If address and size were specified use SlicingBlockDevice to get the correct block device size and start address.
tvendov 2:7c75ab32d7c9 536 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 537 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 538 return NULL;
tvendov 2:7c75ab32d7c9 539 }
tvendov 2:7c75ab32d7c9 540
tvendov 2:7c75ab32d7c9 541 static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
tvendov 2:7c75ab32d7c9 542 return &sbd;
tvendov 2:7c75ab32d7c9 543
tvendov 2:7c75ab32d7c9 544
tvendov 2:7c75ab32d7c9 545 #else
tvendov 2:7c75ab32d7c9 546 return NULL;
tvendov 2:7c75ab32d7c9 547 #endif
tvendov 2:7c75ab32d7c9 548 }
tvendov 2:7c75ab32d7c9 549
tvendov 2:7c75ab32d7c9 550 BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 551 {
tvendov 2:7c75ab32d7c9 552 #if COMPONENT_SD
tvendov 2:7c75ab32d7c9 553
tvendov 2:7c75ab32d7c9 554 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 555 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 556
tvendov 2:7c75ab32d7c9 557 static SDBlockDevice bd(
tvendov 2:7c75ab32d7c9 558 MBED_CONF_SD_SPI_MOSI,
tvendov 2:7c75ab32d7c9 559 MBED_CONF_SD_SPI_MISO,
tvendov 2:7c75ab32d7c9 560 MBED_CONF_SD_SPI_CLK,
tvendov 2:7c75ab32d7c9 561 MBED_CONF_SD_SPI_CS
tvendov 2:7c75ab32d7c9 562 );
tvendov 2:7c75ab32d7c9 563
tvendov 2:7c75ab32d7c9 564 if (bd.init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 565 tr_error("KV Config: SDBlockDevice init fail");
tvendov 2:7c75ab32d7c9 566 return NULL;
tvendov 2:7c75ab32d7c9 567 }
tvendov 2:7c75ab32d7c9 568
tvendov 2:7c75ab32d7c9 569 if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 ||
tvendov 2:7c75ab32d7c9 570 strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
tvendov 2:7c75ab32d7c9 571 //In TDBStore profile, we have a constraint of 4GByte
tvendov 2:7c75ab32d7c9 572 if (start_address == 0 && size == 0 && bd.size() < (uint32_t)(-1)) {
tvendov 2:7c75ab32d7c9 573 return &bd;
tvendov 2:7c75ab32d7c9 574 }
tvendov 2:7c75ab32d7c9 575
tvendov 2:7c75ab32d7c9 576 //If the size of external storage is bigger than 4G we need to slice it.
tvendov 2:7c75ab32d7c9 577 size = size != 0 ? size : align_down(bd.size(), bd.get_erase_size(bd.size() - 1));
tvendov 2:7c75ab32d7c9 578
tvendov 2:7c75ab32d7c9 579 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 580 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 581 return NULL;
tvendov 2:7c75ab32d7c9 582 }
tvendov 2:7c75ab32d7c9 583
tvendov 2:7c75ab32d7c9 584 if (aligned_end_address - aligned_start_address != (uint32_t)(aligned_end_address - aligned_start_address)) {
tvendov 2:7c75ab32d7c9 585 aligned_end_address = aligned_start_address + (uint32_t)(-1);//Support up to 4G only
tvendov 2:7c75ab32d7c9 586 }
tvendov 2:7c75ab32d7c9 587 } else {
tvendov 2:7c75ab32d7c9 588 //For all other KVStore profiles beside TDBStore we take the entire external memory space.
tvendov 2:7c75ab32d7c9 589 if (start_address == 0 && size == 0) {
tvendov 2:7c75ab32d7c9 590 return &bd;
tvendov 2:7c75ab32d7c9 591 }
tvendov 2:7c75ab32d7c9 592
tvendov 2:7c75ab32d7c9 593 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 594 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 595 return NULL;
tvendov 2:7c75ab32d7c9 596 }
tvendov 2:7c75ab32d7c9 597 }
tvendov 2:7c75ab32d7c9 598
tvendov 2:7c75ab32d7c9 599 aligned_end_address = align_down(aligned_end_address, bd.get_erase_size(aligned_end_address));
tvendov 2:7c75ab32d7c9 600 static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
tvendov 2:7c75ab32d7c9 601 return &sbd;
tvendov 2:7c75ab32d7c9 602
tvendov 2:7c75ab32d7c9 603 #else
tvendov 2:7c75ab32d7c9 604 return NULL;
tvendov 2:7c75ab32d7c9 605 #endif
tvendov 2:7c75ab32d7c9 606 }
tvendov 2:7c75ab32d7c9 607
tvendov 2:7c75ab32d7c9 608 BlockDevice *_get_blockdevice_RZ_SDHI(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 609 {
tvendov 2:7c75ab32d7c9 610 #if COMPONENT_RZ_SDHI
tvendov 2:7c75ab32d7c9 611
tvendov 2:7c75ab32d7c9 612 bd_addr_t aligned_end_address;
tvendov 2:7c75ab32d7c9 613 bd_addr_t aligned_start_address;
tvendov 2:7c75ab32d7c9 614
tvendov 2:7c75ab32d7c9 615 static SDHIBlockDevice bd(MBED_CONF_RZ_SDHI_CH);
tvendov 2:7c75ab32d7c9 616
tvendov 2:7c75ab32d7c9 617 if (bd.init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 618 tr_error("KV Config: SDBlockDevice init fail");
tvendov 2:7c75ab32d7c9 619 return NULL;
tvendov 2:7c75ab32d7c9 620 }
tvendov 2:7c75ab32d7c9 621
tvendov 2:7c75ab32d7c9 622 if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 ||
tvendov 2:7c75ab32d7c9 623 strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
tvendov 2:7c75ab32d7c9 624 //In TDBStore profile, we have a constraint of 4GByte
tvendov 2:7c75ab32d7c9 625 if (start_address == 0 && size == 0 && bd.size() < (uint32_t)(-1)) {
tvendov 2:7c75ab32d7c9 626 return &bd;
tvendov 2:7c75ab32d7c9 627 }
tvendov 2:7c75ab32d7c9 628
tvendov 2:7c75ab32d7c9 629 //If the size of external storage is bigger than 4G we need to slice it.
tvendov 2:7c75ab32d7c9 630 size = size != 0 ? size : align_down(bd.size(), bd.get_erase_size(bd.size() - 1));
tvendov 2:7c75ab32d7c9 631
tvendov 2:7c75ab32d7c9 632 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 633 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 634 return NULL;
tvendov 2:7c75ab32d7c9 635 }
tvendov 2:7c75ab32d7c9 636
tvendov 2:7c75ab32d7c9 637 if (aligned_end_address - aligned_start_address != (uint32_t)(aligned_end_address - aligned_start_address)) {
tvendov 2:7c75ab32d7c9 638 aligned_end_address = aligned_start_address + (uint32_t)(-1);//Support up to 4G only
tvendov 2:7c75ab32d7c9 639 }
tvendov 2:7c75ab32d7c9 640 } else {
tvendov 2:7c75ab32d7c9 641 //For all other KVStore profiles beside TDBStore we take the entire external memory space.
tvendov 2:7c75ab32d7c9 642 if (start_address == 0 && size == 0) {
tvendov 2:7c75ab32d7c9 643 return &bd;
tvendov 2:7c75ab32d7c9 644 }
tvendov 2:7c75ab32d7c9 645
tvendov 2:7c75ab32d7c9 646 if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
tvendov 2:7c75ab32d7c9 647 tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
tvendov 2:7c75ab32d7c9 648 return NULL;
tvendov 2:7c75ab32d7c9 649 }
tvendov 2:7c75ab32d7c9 650 }
tvendov 2:7c75ab32d7c9 651
tvendov 2:7c75ab32d7c9 652 aligned_end_address = align_down(aligned_end_address, bd.get_erase_size(aligned_end_address));
tvendov 2:7c75ab32d7c9 653 static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
tvendov 2:7c75ab32d7c9 654 return &sbd;
tvendov 2:7c75ab32d7c9 655
tvendov 2:7c75ab32d7c9 656 #else
tvendov 2:7c75ab32d7c9 657 return NULL;
tvendov 2:7c75ab32d7c9 658 #endif
tvendov 2:7c75ab32d7c9 659 }
tvendov 2:7c75ab32d7c9 660
tvendov 2:7c75ab32d7c9 661 BlockDevice *_get_blockdevice_default(bd_addr_t start_address, bd_size_t size)
tvendov 2:7c75ab32d7c9 662 {
tvendov 2:7c75ab32d7c9 663 #if COMPONENT_QSPIF
tvendov 2:7c75ab32d7c9 664 return _get_blockdevice_QSPIF(start_address, size);
tvendov 2:7c75ab32d7c9 665 #elif COMPONENT_SPIF
tvendov 2:7c75ab32d7c9 666 return _get_blockdevice_SPIF(start_address, size);
tvendov 2:7c75ab32d7c9 667 #elif COMPONENT_DATAFLASH
tvendov 2:7c75ab32d7c9 668 return _get_blockdevice_DATAFLASH(start_address, size);
tvendov 2:7c75ab32d7c9 669 #elif COMPONENT_SD
tvendov 2:7c75ab32d7c9 670 return _get_blockdevice_SD(start_address, size);
tvendov 2:7c75ab32d7c9 671 #elif COMPONENT_RZ_SDHI
tvendov 2:7c75ab32d7c9 672 return _get_blockdevice_RZ_SDHI(start_address, size);
tvendov 2:7c75ab32d7c9 673 #else
tvendov 2:7c75ab32d7c9 674 tr_error("KV Config: No default component define in target.json for this target.");
tvendov 2:7c75ab32d7c9 675 return NULL;
tvendov 2:7c75ab32d7c9 676 #endif
tvendov 2:7c75ab32d7c9 677 }
tvendov 2:7c75ab32d7c9 678
tvendov 2:7c75ab32d7c9 679 int _storage_config_TDB_INTERNAL()
tvendov 2:7c75ab32d7c9 680 {
tvendov 2:7c75ab32d7c9 681 #if COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 682 bd_size_t internal_size = MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 683 bd_addr_t internal_start_address = MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 684
tvendov 2:7c75ab32d7c9 685 if (internal_size == 0 && internal_start_address == 0) {
tvendov 2:7c75ab32d7c9 686 //Calculate the block device size and start address in case default values are used.
tvendov 2:7c75ab32d7c9 687 if (_get_flashiap_bd_default_addresses_tdb_internal(&internal_start_address, &internal_size) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 688 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 689 }
tvendov 2:7c75ab32d7c9 690 }
tvendov 2:7c75ab32d7c9 691
tvendov 2:7c75ab32d7c9 692 //Get internal memory FLASHIAP block device.
tvendov 2:7c75ab32d7c9 693 kvstore_config.internal_bd = GET_BLOCKDEVICE(INTERNAL_BLOCKDEVICE_NAME, internal_start_address, internal_size);
tvendov 2:7c75ab32d7c9 694 if (kvstore_config.internal_bd == NULL) {
tvendov 2:7c75ab32d7c9 695 tr_error("KV Config: Fail to get internal BlockDevice.");
tvendov 2:7c75ab32d7c9 696 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 697 }
tvendov 2:7c75ab32d7c9 698
tvendov 2:7c75ab32d7c9 699
tvendov 2:7c75ab32d7c9 700 int ret = kvstore_config.internal_bd->init();
tvendov 2:7c75ab32d7c9 701 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 702 tr_error("KV Config: Fail to init internal BlockDevice.");
tvendov 2:7c75ab32d7c9 703 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 704 }
tvendov 2:7c75ab32d7c9 705
tvendov 2:7c75ab32d7c9 706 //Check that internal flash has 2 or more sectors
tvendov 2:7c75ab32d7c9 707 if (_calculate_blocksize_match_tdbstore(kvstore_config.internal_bd) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 708 tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
tvendov 2:7c75ab32d7c9 709 return MBED_ERROR_INVALID_ARGUMENT;
tvendov 2:7c75ab32d7c9 710 }
tvendov 2:7c75ab32d7c9 711
tvendov 2:7c75ab32d7c9 712 //Deinitialize internal block device and TDB will reinitialize and take control on it.
tvendov 2:7c75ab32d7c9 713 ret = kvstore_config.internal_bd->deinit();
tvendov 2:7c75ab32d7c9 714 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 715 tr_error("KV Config: Fail to deinit internal BlockDevice.");
tvendov 2:7c75ab32d7c9 716 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 717 }
tvendov 2:7c75ab32d7c9 718
tvendov 2:7c75ab32d7c9 719 //Create a TDBStore in the internal FLASHIAP block device.
tvendov 2:7c75ab32d7c9 720 static TDBStore tdb_internal(kvstore_config.internal_bd);
tvendov 2:7c75ab32d7c9 721 kvstore_config.internal_store = &tdb_internal;
tvendov 2:7c75ab32d7c9 722
tvendov 2:7c75ab32d7c9 723 ret = kvstore_config.internal_store->init();
tvendov 2:7c75ab32d7c9 724 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 725 tr_error("KV Config: Fail to init internal TDBStore.");
tvendov 2:7c75ab32d7c9 726 return ret;
tvendov 2:7c75ab32d7c9 727 }
tvendov 2:7c75ab32d7c9 728 kvstore_config.kvstore_main_instance =
tvendov 2:7c75ab32d7c9 729 kvstore_config.internal_store;
tvendov 2:7c75ab32d7c9 730
tvendov 2:7c75ab32d7c9 731 //Masking flag - Actually used to remove any KVStore flag which is not supported
tvendov 2:7c75ab32d7c9 732 //in the chosen KVStore profile.
tvendov 2:7c75ab32d7c9 733 kvstore_config.flags_mask = ~(KVStore::REQUIRE_CONFIDENTIALITY_FLAG |
tvendov 2:7c75ab32d7c9 734 KVStore::REQUIRE_REPLAY_PROTECTION_FLAG);
tvendov 2:7c75ab32d7c9 735
tvendov 2:7c75ab32d7c9 736 //Initialize kv_map and add the configuration struct to KVStore map.
tvendov 2:7c75ab32d7c9 737 KVMap &kv_map = KVMap::get_instance();
tvendov 2:7c75ab32d7c9 738 ret = kv_map.init();
tvendov 2:7c75ab32d7c9 739 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 740 tr_error("KV Config: Fail to init KVStore global API.");
tvendov 2:7c75ab32d7c9 741 return ret;
tvendov 2:7c75ab32d7c9 742 }
tvendov 2:7c75ab32d7c9 743
tvendov 2:7c75ab32d7c9 744 ret = kv_map.attach(STR(MBED_CONF_STORAGE_DEFAULT_KV), &kvstore_config);
tvendov 2:7c75ab32d7c9 745 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 746 tr_error("KV Config: Fail to attach KVStore main instance to KVStore global API.");
tvendov 2:7c75ab32d7c9 747 return ret;
tvendov 2:7c75ab32d7c9 748 }
tvendov 2:7c75ab32d7c9 749 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 750 #else
tvendov 2:7c75ab32d7c9 751 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 752 #endif
tvendov 2:7c75ab32d7c9 753
tvendov 2:7c75ab32d7c9 754 }
tvendov 2:7c75ab32d7c9 755
tvendov 2:7c75ab32d7c9 756 int _storage_config_TDB_EXTERNAL()
tvendov 2:7c75ab32d7c9 757 {
tvendov 2:7c75ab32d7c9 758 #if !SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 759 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 760 #endif
tvendov 2:7c75ab32d7c9 761
tvendov 2:7c75ab32d7c9 762 bd_size_t internal_rbp_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 763 bd_addr_t internal_start_address = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 764
tvendov 2:7c75ab32d7c9 765 //Get the default address and size for internal rbp TDBStore
tvendov 2:7c75ab32d7c9 766 if (internal_rbp_size == 0 && internal_start_address == 0) {
tvendov 2:7c75ab32d7c9 767 //Calculate the block device size and start address in case default values are used.
tvendov 2:7c75ab32d7c9 768 if (_get_flashiap_bd_default_addresses_rbp(&internal_start_address, &internal_rbp_size) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 769 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 770 }
tvendov 2:7c75ab32d7c9 771 }
tvendov 2:7c75ab32d7c9 772
tvendov 2:7c75ab32d7c9 773 //Create internal FLASHIAP block device
tvendov 2:7c75ab32d7c9 774 kvstore_config.internal_bd = GET_BLOCKDEVICE(INTERNAL_BLOCKDEVICE_NAME, internal_start_address, internal_rbp_size);
tvendov 2:7c75ab32d7c9 775 if (kvstore_config.internal_bd == NULL) {
tvendov 2:7c75ab32d7c9 776 tr_error("KV Config: Fail to get internal BlockDevice.");
tvendov 2:7c75ab32d7c9 777 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 778 }
tvendov 2:7c75ab32d7c9 779
tvendov 2:7c75ab32d7c9 780 int ret = kvstore_config.internal_bd->init();
tvendov 2:7c75ab32d7c9 781 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 782 tr_error("KV Config: Fail to init internal BlockDevice.");
tvendov 2:7c75ab32d7c9 783 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 784 }
tvendov 2:7c75ab32d7c9 785
tvendov 2:7c75ab32d7c9 786 //Check if TDBStore has at least 2 sector.
tvendov 2:7c75ab32d7c9 787 if (_calculate_blocksize_match_tdbstore(kvstore_config.internal_bd) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 788 tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
tvendov 2:7c75ab32d7c9 789 return MBED_ERROR_INVALID_ARGUMENT;
tvendov 2:7c75ab32d7c9 790 }
tvendov 2:7c75ab32d7c9 791
tvendov 2:7c75ab32d7c9 792 //Create internal TDBStore
tvendov 2:7c75ab32d7c9 793 static TDBStore tdb_internal(kvstore_config.internal_bd);
tvendov 2:7c75ab32d7c9 794 kvstore_config.internal_store = &tdb_internal;
tvendov 2:7c75ab32d7c9 795
tvendov 2:7c75ab32d7c9 796 ret = kvstore_config.internal_store->init();
tvendov 2:7c75ab32d7c9 797 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 798 tr_error("KV Config: Fail to init internal TDBStore.");
tvendov 2:7c75ab32d7c9 799 return ret;
tvendov 2:7c75ab32d7c9 800 }
tvendov 2:7c75ab32d7c9 801
tvendov 2:7c75ab32d7c9 802 bd_size_t size = MBED_CONF_STORAGE_TDB_EXTERNAL_EXTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 803 bd_addr_t address = MBED_CONF_STORAGE_TDB_EXTERNAL_EXTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 804
tvendov 2:7c75ab32d7c9 805 //Get external BlockDevice for TDBStore
tvendov 2:7c75ab32d7c9 806 BlockDevice *bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_TDB_EXTERNAL_BLOCKDEVICE, address, size);
tvendov 2:7c75ab32d7c9 807 if (bd == NULL) {
tvendov 2:7c75ab32d7c9 808 tr_error("KV Config: Fail to get external BlockDevice.");
tvendov 2:7c75ab32d7c9 809 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 810 }
tvendov 2:7c75ab32d7c9 811
tvendov 2:7c75ab32d7c9 812 //TDBStore needs a block device base on flash. so if this is SD block device or the default block device is SD
tvendov 2:7c75ab32d7c9 813 //add FlashSimBlockDevice on top of the SDBlockDevice
tvendov 2:7c75ab32d7c9 814 #if defined(COMPONENT_SD) || defined(COMPONENT_RZ_SDHI)
tvendov 2:7c75ab32d7c9 815 if (strcmp(STR(MBED_CONF_STORAGE_TDB_EXTERNAL_BLOCKDEVICE), "SD") == 0
tvendov 2:7c75ab32d7c9 816 #if (defined(COMPONENT_SD) || defined(COMPONENT_RZ_SDHI))&& !defined(COMPONENT_SPIF) && !defined(COMPONENT_QSPIF) && !defined(COMPONENT_DATAFLASH)
tvendov 2:7c75ab32d7c9 817 || strcmp(STR(MBED_CONF_STORAGE_TDB_EXTERNAL_BLOCKDEVICE), "default") == 0) {
tvendov 2:7c75ab32d7c9 818 #else
tvendov 2:7c75ab32d7c9 819 ) {
tvendov 2:7c75ab32d7c9 820
tvendov 2:7c75ab32d7c9 821 #endif
tvendov 2:7c75ab32d7c9 822 //TDBStore need FlashSimBlockDevice when working with SD block device
tvendov 2:7c75ab32d7c9 823 if (bd->init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 824 tr_error("KV Config: Fail to init external BlockDevice.");
tvendov 2:7c75ab32d7c9 825 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 826 }
tvendov 2:7c75ab32d7c9 827
tvendov 2:7c75ab32d7c9 828 static FlashSimBlockDevice flash_bd(bd);
tvendov 2:7c75ab32d7c9 829 kvstore_config.external_bd = &flash_bd;
tvendov 2:7c75ab32d7c9 830 } else {
tvendov 2:7c75ab32d7c9 831 kvstore_config.external_bd = bd;
tvendov 2:7c75ab32d7c9 832 }
tvendov 2:7c75ab32d7c9 833 #else
tvendov 2:7c75ab32d7c9 834 kvstore_config.external_bd = bd;
tvendov 2:7c75ab32d7c9 835 #endif
tvendov 2:7c75ab32d7c9 836
tvendov 2:7c75ab32d7c9 837 kvstore_config.flags_mask = ~(0);
tvendov 2:7c75ab32d7c9 838
tvendov 2:7c75ab32d7c9 839 return _storage_config_tdb_external_common();
tvendov 2:7c75ab32d7c9 840 }
tvendov 2:7c75ab32d7c9 841
tvendov 2:7c75ab32d7c9 842 int _storage_config_TDB_EXTERNAL_NO_RBP()
tvendov 2:7c75ab32d7c9 843 {
tvendov 2:7c75ab32d7c9 844 #if !SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 845 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 846 #endif
tvendov 2:7c75ab32d7c9 847 bd_size_t size = MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 848 bd_addr_t address = MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_EXTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 849
tvendov 2:7c75ab32d7c9 850 //Get external block device
tvendov 2:7c75ab32d7c9 851 BlockDevice *bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_BLOCKDEVICE, address, size);
tvendov 2:7c75ab32d7c9 852 if (bd == NULL) {
tvendov 2:7c75ab32d7c9 853 tr_error("KV Config: Fail to get external BlockDevice.");
tvendov 2:7c75ab32d7c9 854 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 855 }
tvendov 2:7c75ab32d7c9 856
tvendov 2:7c75ab32d7c9 857 //TDBStore needs a block device base on flash. so if this is SD block device or the default block device is SD
tvendov 2:7c75ab32d7c9 858 //add FlashSimBlockDevice on top of the SDBlockDevice
tvendov 2:7c75ab32d7c9 859 #if defined(COMPONENT_SD) || defined(COMPONENT_RZ_SDHI)
tvendov 2:7c75ab32d7c9 860 if (strcmp(STR(MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_BLOCKDEVICE), "SD") == 0
tvendov 2:7c75ab32d7c9 861 #if (defined(COMPONENT_SD) || defined(COMPONENT_RZ_SDHI)) && !defined(COMPONENT_SPIF) && !defined(COMPONENT_QSPIF) && !defined(COMPONENT_DATAFLASH)
tvendov 2:7c75ab32d7c9 862 || strcmp(STR(MBED_CONF_STORAGE_TDB_EXTERNAL_NO_RBP_BLOCKDEVICE), "default") == 0) {
tvendov 2:7c75ab32d7c9 863 #else
tvendov 2:7c75ab32d7c9 864 ) {
tvendov 2:7c75ab32d7c9 865
tvendov 2:7c75ab32d7c9 866 #endif
tvendov 2:7c75ab32d7c9 867 //TDBStore need FlashSimBlockDevice when working with SD block device
tvendov 2:7c75ab32d7c9 868 if (bd->init() != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 869 tr_error("KV Config: Fail to init external BlockDevice.");
tvendov 2:7c75ab32d7c9 870 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 871 }
tvendov 2:7c75ab32d7c9 872
tvendov 2:7c75ab32d7c9 873 static FlashSimBlockDevice flash_bd(bd);
tvendov 2:7c75ab32d7c9 874 kvstore_config.external_bd = &flash_bd;
tvendov 2:7c75ab32d7c9 875 } else {
tvendov 2:7c75ab32d7c9 876 kvstore_config.external_bd = bd;
tvendov 2:7c75ab32d7c9 877 }
tvendov 2:7c75ab32d7c9 878 #else
tvendov 2:7c75ab32d7c9 879 kvstore_config.external_bd = bd;
tvendov 2:7c75ab32d7c9 880 #endif
tvendov 2:7c75ab32d7c9 881
tvendov 2:7c75ab32d7c9 882 //Masking flag - Actually used to remove any KVStore flag which is not supported
tvendov 2:7c75ab32d7c9 883 //in the chosen KVStore profile.
tvendov 2:7c75ab32d7c9 884 kvstore_config.flags_mask = ~(KVStore::REQUIRE_REPLAY_PROTECTION_FLAG);
tvendov 2:7c75ab32d7c9 885
tvendov 2:7c75ab32d7c9 886 return _storage_config_tdb_external_common();
tvendov 2:7c75ab32d7c9 887 }
tvendov 2:7c75ab32d7c9 888
tvendov 2:7c75ab32d7c9 889 int _storage_config_tdb_external_common()
tvendov 2:7c75ab32d7c9 890 {
tvendov 2:7c75ab32d7c9 891 #if SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 892 //Initialize external block device
tvendov 2:7c75ab32d7c9 893 int ret = kvstore_config.external_bd->init();
tvendov 2:7c75ab32d7c9 894 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 895 tr_error("KV Config: Fail to init external BlockDevice.");
tvendov 2:7c75ab32d7c9 896 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 897 }
tvendov 2:7c75ab32d7c9 898
tvendov 2:7c75ab32d7c9 899 //Check that there is at least 2 sector for the external TDBStore
tvendov 2:7c75ab32d7c9 900 if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 901 tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
tvendov 2:7c75ab32d7c9 902 return MBED_ERROR_INVALID_SIZE;
tvendov 2:7c75ab32d7c9 903 }
tvendov 2:7c75ab32d7c9 904
tvendov 2:7c75ab32d7c9 905 //Create external TDBStore
tvendov 2:7c75ab32d7c9 906 static TDBStore tdb_external(kvstore_config.external_bd);
tvendov 2:7c75ab32d7c9 907 kvstore_config.external_store = &tdb_external;
tvendov 2:7c75ab32d7c9 908
tvendov 2:7c75ab32d7c9 909 //Create SecureStore and initialize it
tvendov 2:7c75ab32d7c9 910 static SecureStore secst(kvstore_config.external_store, kvstore_config.internal_store);
tvendov 2:7c75ab32d7c9 911
tvendov 2:7c75ab32d7c9 912 ret = secst.init();
tvendov 2:7c75ab32d7c9 913 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 914 tr_error("KV Config: Fail to init SecureStore.");
tvendov 2:7c75ab32d7c9 915 return ret ;
tvendov 2:7c75ab32d7c9 916 }
tvendov 2:7c75ab32d7c9 917
tvendov 2:7c75ab32d7c9 918 kvstore_config.kvstore_main_instance = &secst;
tvendov 2:7c75ab32d7c9 919
tvendov 2:7c75ab32d7c9 920 //Init kv_map and add the configuration struct to KVStore map.
tvendov 2:7c75ab32d7c9 921 KVMap &kv_map = KVMap::get_instance();
tvendov 2:7c75ab32d7c9 922 ret = kv_map.init();
tvendov 2:7c75ab32d7c9 923 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 924 tr_error("KV Config: Fail to init KVStore global API");
tvendov 2:7c75ab32d7c9 925 return ret;
tvendov 2:7c75ab32d7c9 926 }
tvendov 2:7c75ab32d7c9 927
tvendov 2:7c75ab32d7c9 928 ret = kv_map.attach(STR(MBED_CONF_STORAGE_DEFAULT_KV), &kvstore_config);
tvendov 2:7c75ab32d7c9 929 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 930 tr_error("KV Config: Fail to attach KvStore main instance to KVStore global API");
tvendov 2:7c75ab32d7c9 931 return ret;
tvendov 2:7c75ab32d7c9 932 }
tvendov 2:7c75ab32d7c9 933
tvendov 2:7c75ab32d7c9 934 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 935 #else
tvendov 2:7c75ab32d7c9 936 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 937 #endif
tvendov 2:7c75ab32d7c9 938 }
tvendov 2:7c75ab32d7c9 939
tvendov 2:7c75ab32d7c9 940 int _storage_config_FILESYSTEM()
tvendov 2:7c75ab32d7c9 941 {
tvendov 2:7c75ab32d7c9 942 #if !SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 943 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 944 #endif
tvendov 2:7c75ab32d7c9 945
tvendov 2:7c75ab32d7c9 946 filesystemstore_folder_path = STR(MBED_CONF_STORAGE_FILESYSTEM_FOLDER_PATH);
tvendov 2:7c75ab32d7c9 947
tvendov 2:7c75ab32d7c9 948 bd_size_t internal_rbp_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 949 bd_addr_t internal_start_address = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 950
tvendov 2:7c75ab32d7c9 951 //Get the default address and size for internal rbp TDBStore
tvendov 2:7c75ab32d7c9 952 if (internal_rbp_size == 0 && internal_start_address == 0) {
tvendov 2:7c75ab32d7c9 953 //Calculate the block device size and start address in case default values are used.
tvendov 2:7c75ab32d7c9 954 if (_get_flashiap_bd_default_addresses_rbp(&internal_start_address, &internal_rbp_size) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 955 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 956 }
tvendov 2:7c75ab32d7c9 957 }
tvendov 2:7c75ab32d7c9 958
tvendov 2:7c75ab32d7c9 959 //Get internal FLASHIAP block device
tvendov 2:7c75ab32d7c9 960 kvstore_config.internal_bd = GET_BLOCKDEVICE(INTERNAL_BLOCKDEVICE_NAME, internal_start_address, internal_rbp_size);
tvendov 2:7c75ab32d7c9 961 if (kvstore_config.internal_bd == NULL) {
tvendov 2:7c75ab32d7c9 962 tr_error("KV Config: Fail to get internal BlockDevice ");
tvendov 2:7c75ab32d7c9 963 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 964 }
tvendov 2:7c75ab32d7c9 965
tvendov 2:7c75ab32d7c9 966 int ret = kvstore_config.internal_bd->init();
tvendov 2:7c75ab32d7c9 967 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 968 tr_error("KV Config: Fail to init internal BlockDevice ");
tvendov 2:7c75ab32d7c9 969 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 970 }
tvendov 2:7c75ab32d7c9 971
tvendov 2:7c75ab32d7c9 972 //Check that internal flash has 2 or more sectors
tvendov 2:7c75ab32d7c9 973 if (_calculate_blocksize_match_tdbstore(kvstore_config.internal_bd) != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 974 tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
tvendov 2:7c75ab32d7c9 975 return MBED_ERROR_INVALID_ARGUMENT;
tvendov 2:7c75ab32d7c9 976 }
tvendov 2:7c75ab32d7c9 977
tvendov 2:7c75ab32d7c9 978 //Deinitialize internal block device and TDB will reinitialize and take control on it.
tvendov 2:7c75ab32d7c9 979 ret = kvstore_config.internal_bd->deinit();
tvendov 2:7c75ab32d7c9 980 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 981 tr_error("KV Config: Fail to deinit internal BlockDevice.");
tvendov 2:7c75ab32d7c9 982 return MBED_ERROR_FAILED_OPERATION;
tvendov 2:7c75ab32d7c9 983 }
tvendov 2:7c75ab32d7c9 984
tvendov 2:7c75ab32d7c9 985 //Create internal TDBStore for rbp
tvendov 2:7c75ab32d7c9 986 static TDBStore tdb_internal(kvstore_config.internal_bd);
tvendov 2:7c75ab32d7c9 987 kvstore_config.internal_store = &tdb_internal;
tvendov 2:7c75ab32d7c9 988
tvendov 2:7c75ab32d7c9 989 ret = kvstore_config.internal_store->init();
tvendov 2:7c75ab32d7c9 990 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 991 tr_error("KV Config: Fail to init internal TDBStore");
tvendov 2:7c75ab32d7c9 992 return ret;
tvendov 2:7c75ab32d7c9 993 }
tvendov 2:7c75ab32d7c9 994
tvendov 2:7c75ab32d7c9 995 bd_size_t size = MBED_CONF_STORAGE_FILESYSTEM_EXTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 996 bd_addr_t address = MBED_CONF_STORAGE_FILESYSTEM_EXTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 997 const char *mount_point = STR(MBED_CONF_STORAGE_FILESYSTEM_MOUNT_POINT);
tvendov 2:7c75ab32d7c9 998
tvendov 2:7c75ab32d7c9 999 //Get external block device for FileSystem.
tvendov 2:7c75ab32d7c9 1000 kvstore_config.external_bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_FILESYSTEM_BLOCKDEVICE, address, size);
tvendov 2:7c75ab32d7c9 1001 if (kvstore_config.external_bd == NULL) {
tvendov 2:7c75ab32d7c9 1002 tr_error("KV Config: Fail to get external BlockDevice ");
tvendov 2:7c75ab32d7c9 1003 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1004 }
tvendov 2:7c75ab32d7c9 1005
tvendov 2:7c75ab32d7c9 1006 ret = kvstore_config.external_bd->init();
tvendov 2:7c75ab32d7c9 1007 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 1008 tr_error("KV Config: Fail to init external BlockDevice ");
tvendov 2:7c75ab32d7c9 1009 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1010 }
tvendov 2:7c75ab32d7c9 1011
tvendov 2:7c75ab32d7c9 1012 //Get FileSystem. Can be FAT, LITTLE or default. in case of default, the type will be decided base on the default
tvendov 2:7c75ab32d7c9 1013 //component block device configured in the system. The priority is:
tvendov 2:7c75ab32d7c9 1014 //QSPI -> SPI -> DATAFLASH == LITTLE
tvendov 2:7c75ab32d7c9 1015 //SD == FAT
tvendov 2:7c75ab32d7c9 1016 kvstore_config.external_fs = GET_FILESYSTEM(MBED_CONF_STORAGE_FILESYSTEM_FILESYSTEM, mount_point);
tvendov 2:7c75ab32d7c9 1017 if (kvstore_config.external_fs == NULL) {
tvendov 2:7c75ab32d7c9 1018 tr_error("KV Config: Fail to get FileSystem");
tvendov 2:7c75ab32d7c9 1019 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1020 }
tvendov 2:7c75ab32d7c9 1021
tvendov 2:7c75ab32d7c9 1022 kvstore_config.flags_mask = ~(0);
tvendov 2:7c75ab32d7c9 1023
tvendov 2:7c75ab32d7c9 1024 return _storage_config_filesystem_common();
tvendov 2:7c75ab32d7c9 1025 }
tvendov 2:7c75ab32d7c9 1026
tvendov 2:7c75ab32d7c9 1027 int _storage_config_FILESYSTEM_NO_RBP()
tvendov 2:7c75ab32d7c9 1028 {
tvendov 2:7c75ab32d7c9 1029 #if !SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 1030 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 1031 #endif
tvendov 2:7c75ab32d7c9 1032
tvendov 2:7c75ab32d7c9 1033 filesystemstore_folder_path = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH);
tvendov 2:7c75ab32d7c9 1034
tvendov 2:7c75ab32d7c9 1035 bd_size_t size = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE;
tvendov 2:7c75ab32d7c9 1036 bd_addr_t address = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS;
tvendov 2:7c75ab32d7c9 1037 const char *mount_point = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT);
tvendov 2:7c75ab32d7c9 1038
tvendov 2:7c75ab32d7c9 1039 //Get external block device for FileSystem.
tvendov 2:7c75ab32d7c9 1040 kvstore_config.external_bd = GET_BLOCKDEVICE(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_BLOCKDEVICE, address, size);
tvendov 2:7c75ab32d7c9 1041 if (kvstore_config.external_bd == NULL) {
tvendov 2:7c75ab32d7c9 1042 tr_error("KV Config: Fail to get external BlockDevice ");
tvendov 2:7c75ab32d7c9 1043 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1044 }
tvendov 2:7c75ab32d7c9 1045
tvendov 2:7c75ab32d7c9 1046 int ret = kvstore_config.external_bd->init();
tvendov 2:7c75ab32d7c9 1047 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 1048 tr_error("KV Config: Fail to init external BlockDevice ");
tvendov 2:7c75ab32d7c9 1049 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1050 }
tvendov 2:7c75ab32d7c9 1051
tvendov 2:7c75ab32d7c9 1052 //Get FileSystem. Can be FAT, LITTLE or default. in case of default, the type will be decided base on the default
tvendov 2:7c75ab32d7c9 1053 //component block device configured in the system. The priority is:
tvendov 2:7c75ab32d7c9 1054 //QSPI -> SPI -> DATAFLASH == LITTLE
tvendov 2:7c75ab32d7c9 1055 //SD == FAT
tvendov 2:7c75ab32d7c9 1056 kvstore_config.external_fs = GET_FILESYSTEM(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FILESYSTEM, mount_point);
tvendov 2:7c75ab32d7c9 1057 if (kvstore_config.external_fs == NULL) {
tvendov 2:7c75ab32d7c9 1058 tr_error("KV Config: Fail to get FileSystem");
tvendov 2:7c75ab32d7c9 1059 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1060 }
tvendov 2:7c75ab32d7c9 1061
tvendov 2:7c75ab32d7c9 1062 //Masking flag - Actually used to remove any KVStore flag which is not supported
tvendov 2:7c75ab32d7c9 1063 //in the chosen KVStore profile.
tvendov 2:7c75ab32d7c9 1064 kvstore_config.flags_mask = ~(KVStore::REQUIRE_REPLAY_PROTECTION_FLAG);
tvendov 2:7c75ab32d7c9 1065
tvendov 2:7c75ab32d7c9 1066 return _storage_config_filesystem_common();
tvendov 2:7c75ab32d7c9 1067 }
tvendov 2:7c75ab32d7c9 1068
tvendov 2:7c75ab32d7c9 1069 int _storage_config_filesystem_common()
tvendov 2:7c75ab32d7c9 1070 {
tvendov 2:7c75ab32d7c9 1071 #if SECURESTORE_ENABLED
tvendov 2:7c75ab32d7c9 1072
tvendov 2:7c75ab32d7c9 1073 //Mount file system. if it fails, try to reformat
tvendov 2:7c75ab32d7c9 1074 int ret = kvstore_config.external_fs->mount(kvstore_config.external_bd);
tvendov 2:7c75ab32d7c9 1075 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 1076 ret = kvstore_config.external_fs->reformat(kvstore_config.external_bd);
tvendov 2:7c75ab32d7c9 1077 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 1078 tr_error("KV Config: Fail to mount FileSystem to %s",
tvendov 2:7c75ab32d7c9 1079 STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT));
tvendov 2:7c75ab32d7c9 1080 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1081 }
tvendov 2:7c75ab32d7c9 1082 }
tvendov 2:7c75ab32d7c9 1083
tvendov 2:7c75ab32d7c9 1084 //Create FileSystemStore
tvendov 2:7c75ab32d7c9 1085 kvstore_config.external_store = _get_file_system_store(kvstore_config.external_fs);
tvendov 2:7c75ab32d7c9 1086 if (kvstore_config.external_store == NULL) {
tvendov 2:7c75ab32d7c9 1087 tr_error("KV Config: Fail to get FileSystemStore");
tvendov 2:7c75ab32d7c9 1088 return MBED_ERROR_FAILED_OPERATION ;
tvendov 2:7c75ab32d7c9 1089 }
tvendov 2:7c75ab32d7c9 1090
tvendov 2:7c75ab32d7c9 1091 //Create SecureStore and set it as main KVStore
tvendov 2:7c75ab32d7c9 1092 static SecureStore secst(kvstore_config.external_store, kvstore_config.internal_store);
tvendov 2:7c75ab32d7c9 1093
tvendov 2:7c75ab32d7c9 1094 ret = secst.init();
tvendov 2:7c75ab32d7c9 1095 if (ret != MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 1096 tr_error("KV Config: Fail to init SecureStore.");
tvendov 2:7c75ab32d7c9 1097 return ret; ;
tvendov 2:7c75ab32d7c9 1098 }
tvendov 2:7c75ab32d7c9 1099
tvendov 2:7c75ab32d7c9 1100 kvstore_config.kvstore_main_instance = &secst;
tvendov 2:7c75ab32d7c9 1101
tvendov 2:7c75ab32d7c9 1102 //Init kv_map and add the configuration struct to KVStore map.
tvendov 2:7c75ab32d7c9 1103 KVMap &kv_map = KVMap::get_instance();
tvendov 2:7c75ab32d7c9 1104 ret = kv_map.init();
tvendov 2:7c75ab32d7c9 1105 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 1106 tr_error("KV Config: Fail to init KVStore global API");
tvendov 2:7c75ab32d7c9 1107 return ret;
tvendov 2:7c75ab32d7c9 1108 }
tvendov 2:7c75ab32d7c9 1109
tvendov 2:7c75ab32d7c9 1110 ret = kv_map.attach(STR(MBED_CONF_STORAGE_DEFAULT_KV), &kvstore_config);
tvendov 2:7c75ab32d7c9 1111 if (MBED_SUCCESS != ret) {
tvendov 2:7c75ab32d7c9 1112 tr_error("KV Config: Fail to attach KvStore main instance to KVStore global API");
tvendov 2:7c75ab32d7c9 1113 return ret;
tvendov 2:7c75ab32d7c9 1114 }
tvendov 2:7c75ab32d7c9 1115
tvendov 2:7c75ab32d7c9 1116 return MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 1117 #else
tvendov 2:7c75ab32d7c9 1118 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 1119 #endif
tvendov 2:7c75ab32d7c9 1120 }
tvendov 2:7c75ab32d7c9 1121
tvendov 2:7c75ab32d7c9 1122 int _storage_config_default()
tvendov 2:7c75ab32d7c9 1123 {
tvendov 2:7c75ab32d7c9 1124 #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
tvendov 2:7c75ab32d7c9 1125 return _storage_config_TDB_EXTERNAL();
tvendov 2:7c75ab32d7c9 1126 #elif (COMPONENT_SD || COMPONENT_RZ_SDHI)
tvendov 2:7c75ab32d7c9 1127 return _storage_config_FILESYSTEM();
tvendov 2:7c75ab32d7c9 1128 #elif COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 1129 return _storage_config_TDB_INTERNAL();
tvendov 2:7c75ab32d7c9 1130 #else
tvendov 2:7c75ab32d7c9 1131 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 1132 #endif
tvendov 2:7c75ab32d7c9 1133 }
tvendov 2:7c75ab32d7c9 1134
tvendov 2:7c75ab32d7c9 1135 const char *get_filesystemstore_folder_path()
tvendov 2:7c75ab32d7c9 1136 {
tvendov 2:7c75ab32d7c9 1137 return filesystemstore_folder_path;
tvendov 2:7c75ab32d7c9 1138 }
tvendov 2:7c75ab32d7c9 1139
tvendov 2:7c75ab32d7c9 1140 MBED_WEAK int kv_init_storage_config()
tvendov 2:7c75ab32d7c9 1141 {
tvendov 2:7c75ab32d7c9 1142
tvendov 2:7c75ab32d7c9 1143 int ret = MBED_SUCCESS;
tvendov 2:7c75ab32d7c9 1144
tvendov 2:7c75ab32d7c9 1145 // We currently have no supported configuration without internal storage
tvendov 2:7c75ab32d7c9 1146 #ifndef COMPONENT_FLASHIAP
tvendov 2:7c75ab32d7c9 1147 return MBED_ERROR_UNSUPPORTED;
tvendov 2:7c75ab32d7c9 1148 #endif
tvendov 2:7c75ab32d7c9 1149
tvendov 2:7c75ab32d7c9 1150 mutex->lock();
tvendov 2:7c75ab32d7c9 1151
tvendov 2:7c75ab32d7c9 1152 if (is_kv_config_initialize) {
tvendov 2:7c75ab32d7c9 1153 goto exit;
tvendov 2:7c75ab32d7c9 1154 }
tvendov 2:7c75ab32d7c9 1155
tvendov 2:7c75ab32d7c9 1156 memset(&kvstore_config, 0, sizeof(kvstore_config_t));
tvendov 2:7c75ab32d7c9 1157
tvendov 2:7c75ab32d7c9 1158 ret = _STORAGE_CONFIG(MBED_CONF_STORAGE_STORAGE_TYPE);
tvendov 2:7c75ab32d7c9 1159
tvendov 2:7c75ab32d7c9 1160 if (ret == MBED_SUCCESS) {
tvendov 2:7c75ab32d7c9 1161 is_kv_config_initialize = true;
tvendov 2:7c75ab32d7c9 1162 }
tvendov 2:7c75ab32d7c9 1163
tvendov 2:7c75ab32d7c9 1164 exit:
tvendov 2:7c75ab32d7c9 1165 mutex->unlock();
tvendov 2:7c75ab32d7c9 1166 return ret;
tvendov 2:7c75ab32d7c9 1167 }