Example
Dependencies: FXAS21002 FXOS8700Q
simple-mbed-cloud-client/storage-helper/storage-helper.cpp@0:11cc2b7889af, 2019-11-19 (annotated)
- Committer:
- maygup01
- Date:
- Tue Nov 19 09:49:38 2019 +0000
- Revision:
- 0:11cc2b7889af
Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maygup01 | 0:11cc2b7889af | 1 | // ---------------------------------------------------------------------------- |
maygup01 | 0:11cc2b7889af | 2 | // Copyright 2016-2018 ARM Ltd. |
maygup01 | 0:11cc2b7889af | 3 | // |
maygup01 | 0:11cc2b7889af | 4 | // SPDX-License-Identifier: Apache-2.0 |
maygup01 | 0:11cc2b7889af | 5 | // |
maygup01 | 0:11cc2b7889af | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
maygup01 | 0:11cc2b7889af | 7 | // you may not use this file except in compliance with the License. |
maygup01 | 0:11cc2b7889af | 8 | // You may obtain a copy of the License at |
maygup01 | 0:11cc2b7889af | 9 | // |
maygup01 | 0:11cc2b7889af | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
maygup01 | 0:11cc2b7889af | 11 | // |
maygup01 | 0:11cc2b7889af | 12 | // Unless required by applicable law or agreed to in writing, software |
maygup01 | 0:11cc2b7889af | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
maygup01 | 0:11cc2b7889af | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
maygup01 | 0:11cc2b7889af | 15 | // See the License for the specific language governing permissions and |
maygup01 | 0:11cc2b7889af | 16 | // limitations under the License. |
maygup01 | 0:11cc2b7889af | 17 | // ---------------------------------------------------------------------------- |
maygup01 | 0:11cc2b7889af | 18 | |
maygup01 | 0:11cc2b7889af | 19 | #include "storage-helper/storage-helper.h" |
maygup01 | 0:11cc2b7889af | 20 | #include "mbed_trace.h" |
maygup01 | 0:11cc2b7889af | 21 | |
maygup01 | 0:11cc2b7889af | 22 | #define TRACE_GROUP "SMCS" |
maygup01 | 0:11cc2b7889af | 23 | |
maygup01 | 0:11cc2b7889af | 24 | StorageHelper::StorageHelper(BlockDevice *bd, FileSystem *fs) |
maygup01 | 0:11cc2b7889af | 25 | : _bd(bd), _fs(fs), fs1(NULL), fs2(NULL), part1(NULL), part2(NULL) |
maygup01 | 0:11cc2b7889af | 26 | { |
maygup01 | 0:11cc2b7889af | 27 | } |
maygup01 | 0:11cc2b7889af | 28 | |
maygup01 | 0:11cc2b7889af | 29 | int StorageHelper::init() { |
maygup01 | 0:11cc2b7889af | 30 | static bool init_done = false; |
maygup01 | 0:11cc2b7889af | 31 | int status = 0; |
maygup01 | 0:11cc2b7889af | 32 | |
maygup01 | 0:11cc2b7889af | 33 | if(!init_done) { |
maygup01 | 0:11cc2b7889af | 34 | if (_bd) { |
maygup01 | 0:11cc2b7889af | 35 | status = _bd->init(); |
maygup01 | 0:11cc2b7889af | 36 | |
maygup01 | 0:11cc2b7889af | 37 | if (status != BD_ERROR_OK) { |
maygup01 | 0:11cc2b7889af | 38 | tr_warn("bd->init() failed with %d", status); |
maygup01 | 0:11cc2b7889af | 39 | return -1; |
maygup01 | 0:11cc2b7889af | 40 | } |
maygup01 | 0:11cc2b7889af | 41 | |
maygup01 | 0:11cc2b7889af | 42 | #if (MCC_PLATFORM_PARTITION_MODE == 1) |
maygup01 | 0:11cc2b7889af | 43 | // store partition size |
maygup01 | 0:11cc2b7889af | 44 | mcc_platform_storage_size = _bd->size(); |
maygup01 | 0:11cc2b7889af | 45 | tr_debug("init() - BlockDevice init OK, bd->size() = %llu", mcc_platform_storage_size); |
maygup01 | 0:11cc2b7889af | 46 | #else |
maygup01 | 0:11cc2b7889af | 47 | tr_debug("init() - BlockDevice init OK, bd->size() = %llu", _bd->size()); |
maygup01 | 0:11cc2b7889af | 48 | #endif |
maygup01 | 0:11cc2b7889af | 49 | |
maygup01 | 0:11cc2b7889af | 50 | } |
maygup01 | 0:11cc2b7889af | 51 | |
maygup01 | 0:11cc2b7889af | 52 | #if (MCC_PLATFORM_PARTITION_MODE == 1) |
maygup01 | 0:11cc2b7889af | 53 | #if (NUMBER_OF_PARTITIONS > 0) |
maygup01 | 0:11cc2b7889af | 54 | status = init_and_mount_partition(&fs1, &part1, PRIMARY_PARTITION_NUMBER, ((const char*) MOUNT_POINT_PRIMARY+1)); |
maygup01 | 0:11cc2b7889af | 55 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 56 | #if (MCC_PLATFORM_AUTO_PARTITION == 1) |
maygup01 | 0:11cc2b7889af | 57 | status = create_partitions(); |
maygup01 | 0:11cc2b7889af | 58 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 59 | return status; |
maygup01 | 0:11cc2b7889af | 60 | } |
maygup01 | 0:11cc2b7889af | 61 | #else |
maygup01 | 0:11cc2b7889af | 62 | tr_warn("primary partition init failed"); |
maygup01 | 0:11cc2b7889af | 63 | return status; |
maygup01 | 0:11cc2b7889af | 64 | #endif |
maygup01 | 0:11cc2b7889af | 65 | } |
maygup01 | 0:11cc2b7889af | 66 | |
maygup01 | 0:11cc2b7889af | 67 | #if (NUMBER_OF_PARTITIONS == 2) |
maygup01 | 0:11cc2b7889af | 68 | status = init_and_mount_partition(&fs2, &part2, SECONDARY_PARTITION_NUMBER, ((const char*) MOUNT_POINT_SECONDARY+1)); |
maygup01 | 0:11cc2b7889af | 69 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 70 | #if (MCC_PLATFORM_AUTO_PARTITION == 1) |
maygup01 | 0:11cc2b7889af | 71 | status = create_partitions(); |
maygup01 | 0:11cc2b7889af | 72 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 73 | return status; |
maygup01 | 0:11cc2b7889af | 74 | } |
maygup01 | 0:11cc2b7889af | 75 | #else |
maygup01 | 0:11cc2b7889af | 76 | tr_warn("secondary partition init failed"); |
maygup01 | 0:11cc2b7889af | 77 | return status; |
maygup01 | 0:11cc2b7889af | 78 | #endif |
maygup01 | 0:11cc2b7889af | 79 | } |
maygup01 | 0:11cc2b7889af | 80 | #endif // (NUMBER_OF_PARTITIONS == 2) |
maygup01 | 0:11cc2b7889af | 81 | #if (NUMBER_OF_PARTITIONS > 2) |
maygup01 | 0:11cc2b7889af | 82 | #error "Invalid number of partitions!!!" |
maygup01 | 0:11cc2b7889af | 83 | #endif |
maygup01 | 0:11cc2b7889af | 84 | #endif // (NUMBER_OF_PARTITIONS > 0) |
maygup01 | 0:11cc2b7889af | 85 | #else // Else for #if (MCC_PLATFORM_PARTITION_MODE == 1) |
maygup01 | 0:11cc2b7889af | 86 | |
maygup01 | 0:11cc2b7889af | 87 | fs1 = _fs; |
maygup01 | 0:11cc2b7889af | 88 | part1 = _bd; /* required for mcc_platform_reformat_storage */ |
maygup01 | 0:11cc2b7889af | 89 | status = test_filesystem(fs1, _bd); |
maygup01 | 0:11cc2b7889af | 90 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 91 | tr_info("Formatting..."); |
maygup01 | 0:11cc2b7889af | 92 | status = reformat_partition(fs1, _bd); |
maygup01 | 0:11cc2b7889af | 93 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 94 | tr_warn("Formatting failed with 0x%X", status); |
maygup01 | 0:11cc2b7889af | 95 | return status; |
maygup01 | 0:11cc2b7889af | 96 | } |
maygup01 | 0:11cc2b7889af | 97 | } |
maygup01 | 0:11cc2b7889af | 98 | #endif // MCC_PLATFORM_PARTITION_MODE |
maygup01 | 0:11cc2b7889af | 99 | init_done = true; |
maygup01 | 0:11cc2b7889af | 100 | } |
maygup01 | 0:11cc2b7889af | 101 | else { |
maygup01 | 0:11cc2b7889af | 102 | tr_debug("init already done"); |
maygup01 | 0:11cc2b7889af | 103 | } |
maygup01 | 0:11cc2b7889af | 104 | |
maygup01 | 0:11cc2b7889af | 105 | return status; |
maygup01 | 0:11cc2b7889af | 106 | } |
maygup01 | 0:11cc2b7889af | 107 | |
maygup01 | 0:11cc2b7889af | 108 | int StorageHelper::sotp_init(void) |
maygup01 | 0:11cc2b7889af | 109 | { |
maygup01 | 0:11cc2b7889af | 110 | int status = FCC_STATUS_SUCCESS; |
maygup01 | 0:11cc2b7889af | 111 | // Include this only for Developer mode and a device which doesn't have in-built TRNG support. |
maygup01 | 0:11cc2b7889af | 112 | #if MBED_CONF_DEVICE_MANAGEMENT_DEVELOPER_MODE == 1 |
maygup01 | 0:11cc2b7889af | 113 | #ifdef PAL_USER_DEFINED_CONFIGURATION |
maygup01 | 0:11cc2b7889af | 114 | #if !PAL_USE_HW_TRNG |
maygup01 | 0:11cc2b7889af | 115 | status = fcc_entropy_set(MBED_CLOUD_DEV_ENTROPY, FCC_ENTROPY_SIZE); |
maygup01 | 0:11cc2b7889af | 116 | |
maygup01 | 0:11cc2b7889af | 117 | if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ENTROPY_ERROR) { |
maygup01 | 0:11cc2b7889af | 118 | tr_error("fcc_entropy_set failed with status %d", status); |
maygup01 | 0:11cc2b7889af | 119 | fcc_finalize(); |
maygup01 | 0:11cc2b7889af | 120 | return status; |
maygup01 | 0:11cc2b7889af | 121 | } |
maygup01 | 0:11cc2b7889af | 122 | #endif // PAL_USE_HW_TRNG = 0 |
maygup01 | 0:11cc2b7889af | 123 | /* Include this only for Developer mode. The application will use fixed RoT to simplify user-experience with the application. |
maygup01 | 0:11cc2b7889af | 124 | * With this change the application be reflashed/SOTP can be erased safely without invalidating the application credentials. |
maygup01 | 0:11cc2b7889af | 125 | */ |
maygup01 | 0:11cc2b7889af | 126 | status = fcc_rot_set(MBED_CLOUD_DEV_ROT, FCC_ROT_SIZE); |
maygup01 | 0:11cc2b7889af | 127 | |
maygup01 | 0:11cc2b7889af | 128 | if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ROT_ERROR) { |
maygup01 | 0:11cc2b7889af | 129 | tr_error("fcc_rot_set failed with status %d", status); |
maygup01 | 0:11cc2b7889af | 130 | fcc_finalize(); |
maygup01 | 0:11cc2b7889af | 131 | } else { |
maygup01 | 0:11cc2b7889af | 132 | // We can return SUCCESS here as preexisting RoT/Entropy is expected flow. |
maygup01 | 0:11cc2b7889af | 133 | tr_info("Using hardcoded Root of Trust, not suitable for production use"); |
maygup01 | 0:11cc2b7889af | 134 | status = FCC_STATUS_SUCCESS; |
maygup01 | 0:11cc2b7889af | 135 | } |
maygup01 | 0:11cc2b7889af | 136 | #endif // PAL_USER_DEFINED_CONFIGURATION |
maygup01 | 0:11cc2b7889af | 137 | #endif // #if MBED_CONF_DEVICE_MANAGEMENT_DEVELOPER_MODE == 1 |
maygup01 | 0:11cc2b7889af | 138 | return status; |
maygup01 | 0:11cc2b7889af | 139 | } |
maygup01 | 0:11cc2b7889af | 140 | |
maygup01 | 0:11cc2b7889af | 141 | |
maygup01 | 0:11cc2b7889af | 142 | int StorageHelper::reformat_storage(void) { |
maygup01 | 0:11cc2b7889af | 143 | int status = -1; |
maygup01 | 0:11cc2b7889af | 144 | |
maygup01 | 0:11cc2b7889af | 145 | if (_bd) { |
maygup01 | 0:11cc2b7889af | 146 | #if (NUMBER_OF_PARTITIONS > 0) |
maygup01 | 0:11cc2b7889af | 147 | status = reformat_partition(fs1, part1); |
maygup01 | 0:11cc2b7889af | 148 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 149 | tr_warn("Formatting primary partition failed with 0x%X", status); |
maygup01 | 0:11cc2b7889af | 150 | return status; |
maygup01 | 0:11cc2b7889af | 151 | } |
maygup01 | 0:11cc2b7889af | 152 | #if (NUMBER_OF_PARTITIONS == 2) |
maygup01 | 0:11cc2b7889af | 153 | status = reformat_partition(fs2, part2); |
maygup01 | 0:11cc2b7889af | 154 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 155 | tr_warn("Formatting secondary partition failed with 0x%X", status); |
maygup01 | 0:11cc2b7889af | 156 | return status; |
maygup01 | 0:11cc2b7889af | 157 | } |
maygup01 | 0:11cc2b7889af | 158 | #endif |
maygup01 | 0:11cc2b7889af | 159 | #if (NUMBER_OF_PARTITIONS > 2) |
maygup01 | 0:11cc2b7889af | 160 | #error "Invalid number of partitions!!!" |
maygup01 | 0:11cc2b7889af | 161 | #endif |
maygup01 | 0:11cc2b7889af | 162 | #endif |
maygup01 | 0:11cc2b7889af | 163 | |
maygup01 | 0:11cc2b7889af | 164 | #if NUMBER_OF_PARTITIONS == 0 |
maygup01 | 0:11cc2b7889af | 165 | status = StorageHelper::format(_fs, _bd); |
maygup01 | 0:11cc2b7889af | 166 | #endif |
maygup01 | 0:11cc2b7889af | 167 | } |
maygup01 | 0:11cc2b7889af | 168 | |
maygup01 | 0:11cc2b7889af | 169 | tr_info("Storage reformatted (%d)", status); |
maygup01 | 0:11cc2b7889af | 170 | |
maygup01 | 0:11cc2b7889af | 171 | return status; |
maygup01 | 0:11cc2b7889af | 172 | } |
maygup01 | 0:11cc2b7889af | 173 | |
maygup01 | 0:11cc2b7889af | 174 | int StorageHelper::format(FileSystem *fs, BlockDevice *bd) { |
maygup01 | 0:11cc2b7889af | 175 | if (!fs || !bd) return -1; |
maygup01 | 0:11cc2b7889af | 176 | |
maygup01 | 0:11cc2b7889af | 177 | int status; |
maygup01 | 0:11cc2b7889af | 178 | |
maygup01 | 0:11cc2b7889af | 179 | status = bd->init(); |
maygup01 | 0:11cc2b7889af | 180 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 181 | return status; |
maygup01 | 0:11cc2b7889af | 182 | } |
maygup01 | 0:11cc2b7889af | 183 | |
maygup01 | 0:11cc2b7889af | 184 | status = fs->mount(bd); |
maygup01 | 0:11cc2b7889af | 185 | // might fail because already mounted, so ignore |
maygup01 | 0:11cc2b7889af | 186 | |
maygup01 | 0:11cc2b7889af | 187 | status = fs->reformat(bd); |
maygup01 | 0:11cc2b7889af | 188 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 189 | if (bd->erase(0, bd->size()) == 0) { |
maygup01 | 0:11cc2b7889af | 190 | if (fs->reformat(bd) == 0) { |
maygup01 | 0:11cc2b7889af | 191 | status = 0; |
maygup01 | 0:11cc2b7889af | 192 | printf("The storage reformatted successfully.\n"); |
maygup01 | 0:11cc2b7889af | 193 | } |
maygup01 | 0:11cc2b7889af | 194 | } |
maygup01 | 0:11cc2b7889af | 195 | } |
maygup01 | 0:11cc2b7889af | 196 | |
maygup01 | 0:11cc2b7889af | 197 | return status; |
maygup01 | 0:11cc2b7889af | 198 | } |
maygup01 | 0:11cc2b7889af | 199 | |
maygup01 | 0:11cc2b7889af | 200 | #if (MCC_PLATFORM_PARTITION_MODE == 1) |
maygup01 | 0:11cc2b7889af | 201 | // bd must be initialized before calling this function. |
maygup01 | 0:11cc2b7889af | 202 | int StorageHelper::init_and_mount_partition(FileSystem **fs, BlockDevice** part, int number_of_partition, const char* mount_point) { |
maygup01 | 0:11cc2b7889af | 203 | int status; |
maygup01 | 0:11cc2b7889af | 204 | |
maygup01 | 0:11cc2b7889af | 205 | // Init fs only once. |
maygup01 | 0:11cc2b7889af | 206 | if (&(**fs) == NULL) { |
maygup01 | 0:11cc2b7889af | 207 | if (&(**part) == NULL) { |
maygup01 | 0:11cc2b7889af | 208 | *part = new MBRBlockDevice(_bd, number_of_partition); |
maygup01 | 0:11cc2b7889af | 209 | } |
maygup01 | 0:11cc2b7889af | 210 | status = (**part).init(); |
maygup01 | 0:11cc2b7889af | 211 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 212 | (**part).deinit(); |
maygup01 | 0:11cc2b7889af | 213 | tr_warn("Init of partition %d fail", number_of_partition); |
maygup01 | 0:11cc2b7889af | 214 | return status; |
maygup01 | 0:11cc2b7889af | 215 | } |
maygup01 | 0:11cc2b7889af | 216 | /* This next change mean that filesystem will be FAT. */ |
maygup01 | 0:11cc2b7889af | 217 | *fs = new FATFileSystem(mount_point, &(**part)); /* this also mount fs. */ |
maygup01 | 0:11cc2b7889af | 218 | } |
maygup01 | 0:11cc2b7889af | 219 | // re-init and format. |
maygup01 | 0:11cc2b7889af | 220 | else { |
maygup01 | 0:11cc2b7889af | 221 | status = (**part).init(); |
maygup01 | 0:11cc2b7889af | 222 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 223 | (**part).deinit(); |
maygup01 | 0:11cc2b7889af | 224 | tr_warn("Init of partition %d fail", number_of_partition); |
maygup01 | 0:11cc2b7889af | 225 | return status; |
maygup01 | 0:11cc2b7889af | 226 | } |
maygup01 | 0:11cc2b7889af | 227 | |
maygup01 | 0:11cc2b7889af | 228 | tr_debug("Formatting partition %d ...", number_of_partition); |
maygup01 | 0:11cc2b7889af | 229 | status = reformat_partition(&(**fs), &(**part)); |
maygup01 | 0:11cc2b7889af | 230 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 231 | tr_warn("Formatting partition %d failed with 0x%X", number_of_partition, status); |
maygup01 | 0:11cc2b7889af | 232 | return status; |
maygup01 | 0:11cc2b7889af | 233 | } |
maygup01 | 0:11cc2b7889af | 234 | } |
maygup01 | 0:11cc2b7889af | 235 | |
maygup01 | 0:11cc2b7889af | 236 | status = test_filesystem(&(**fs), &(**part)); |
maygup01 | 0:11cc2b7889af | 237 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 238 | tr_debug("Formatting partition %d ...", number_of_partition); |
maygup01 | 0:11cc2b7889af | 239 | status = reformat_partition(&(**fs), &(**part)); |
maygup01 | 0:11cc2b7889af | 240 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 241 | tr_warn("Formatting partition %d failed with 0x%X", number_of_partition, status); |
maygup01 | 0:11cc2b7889af | 242 | return status; |
maygup01 | 0:11cc2b7889af | 243 | } |
maygup01 | 0:11cc2b7889af | 244 | } |
maygup01 | 0:11cc2b7889af | 245 | |
maygup01 | 0:11cc2b7889af | 246 | return status; |
maygup01 | 0:11cc2b7889af | 247 | } |
maygup01 | 0:11cc2b7889af | 248 | #endif |
maygup01 | 0:11cc2b7889af | 249 | |
maygup01 | 0:11cc2b7889af | 250 | int StorageHelper::reformat_partition(FileSystem *fs, BlockDevice* part) { |
maygup01 | 0:11cc2b7889af | 251 | return fs->reformat(part); |
maygup01 | 0:11cc2b7889af | 252 | } |
maygup01 | 0:11cc2b7889af | 253 | |
maygup01 | 0:11cc2b7889af | 254 | /* help function for testing filesystem availbility by umount and |
maygup01 | 0:11cc2b7889af | 255 | * mount filesystem again. |
maygup01 | 0:11cc2b7889af | 256 | * */ |
maygup01 | 0:11cc2b7889af | 257 | int StorageHelper::test_filesystem(FileSystem *fs, BlockDevice* part) { |
maygup01 | 0:11cc2b7889af | 258 | // unmount |
maygup01 | 0:11cc2b7889af | 259 | int status = fs->unmount(); |
maygup01 | 0:11cc2b7889af | 260 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 261 | tr_info("test_filesystem() - unmount fail %d", status); |
maygup01 | 0:11cc2b7889af | 262 | // should be OK, maybe not mounted... |
maygup01 | 0:11cc2b7889af | 263 | } |
maygup01 | 0:11cc2b7889af | 264 | // mount again |
maygup01 | 0:11cc2b7889af | 265 | status = fs->mount(part); |
maygup01 | 0:11cc2b7889af | 266 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 267 | tr_info("test_filesystem() - mount fail %d", status); |
maygup01 | 0:11cc2b7889af | 268 | return -1; |
maygup01 | 0:11cc2b7889af | 269 | } |
maygup01 | 0:11cc2b7889af | 270 | return status; |
maygup01 | 0:11cc2b7889af | 271 | } |
maygup01 | 0:11cc2b7889af | 272 | |
maygup01 | 0:11cc2b7889af | 273 | // create partitions, initialize and mount partitions |
maygup01 | 0:11cc2b7889af | 274 | #if ((MCC_PLATFORM_PARTITION_MODE == 1) && (MCC_PLATFORM_AUTO_PARTITION == 1)) |
maygup01 | 0:11cc2b7889af | 275 | int StorageHelper::create_partitions(void) { |
maygup01 | 0:11cc2b7889af | 276 | int status; |
maygup01 | 0:11cc2b7889af | 277 | |
maygup01 | 0:11cc2b7889af | 278 | #if (NUMBER_OF_PARTITIONS > 0) |
maygup01 | 0:11cc2b7889af | 279 | if (mcc_platform_storage_size < PRIMARY_PARTITION_SIZE) { |
maygup01 | 0:11cc2b7889af | 280 | tr_error("create_partitions PRIMARY_PARTITION_SIZE too large!!! Storage's size is %" PRIu64 \ |
maygup01 | 0:11cc2b7889af | 281 | " and PRIMARY_PARTITION_SIZE is %" PRIu64, |
maygup01 | 0:11cc2b7889af | 282 | (uint64_t)mcc_platform_storage_size, (uint64_t)PRIMARY_PARTITION_SIZE); |
maygup01 | 0:11cc2b7889af | 283 | assert(0); |
maygup01 | 0:11cc2b7889af | 284 | } |
maygup01 | 0:11cc2b7889af | 285 | |
maygup01 | 0:11cc2b7889af | 286 | status = MBRBlockDevice::partition(_bd, PRIMARY_PARTITION_NUMBER, 0x83, PRIMARY_PARTITION_START, PRIMARY_PARTITION_START + PRIMARY_PARTITION_SIZE); |
maygup01 | 0:11cc2b7889af | 287 | tr_debug("Creating primary partition ..."); |
maygup01 | 0:11cc2b7889af | 288 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 289 | tr_warn("Creating primary partition failed 0x%X", status); |
maygup01 | 0:11cc2b7889af | 290 | return status; |
maygup01 | 0:11cc2b7889af | 291 | } |
maygup01 | 0:11cc2b7889af | 292 | tr_debug("Created primary partition"); |
maygup01 | 0:11cc2b7889af | 293 | |
maygup01 | 0:11cc2b7889af | 294 | // init and format partition 1 |
maygup01 | 0:11cc2b7889af | 295 | status = init_and_mount_partition(&fs1, &part1, PRIMARY_PARTITION_NUMBER, ((const char*) MOUNT_POINT_PRIMARY+1)); |
maygup01 | 0:11cc2b7889af | 296 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 297 | return status; |
maygup01 | 0:11cc2b7889af | 298 | } |
maygup01 | 0:11cc2b7889af | 299 | tr_debug("Mounted primary partition"); |
maygup01 | 0:11cc2b7889af | 300 | |
maygup01 | 0:11cc2b7889af | 301 | #if (NUMBER_OF_PARTITIONS == 2) |
maygup01 | 0:11cc2b7889af | 302 | // use cast (uint64_t) for fixing compile warning. |
maygup01 | 0:11cc2b7889af | 303 | if (mcc_platform_storage_size < ((uint64_t)PRIMARY_PARTITION_SIZE + (uint64_t)SECONDARY_PARTITION_SIZE)) { |
maygup01 | 0:11cc2b7889af | 304 | tr_error("create_partitions (PRIMARY_PARTITION_SIZE+SECONDARY_PARTITION_SIZE) too large!!! Storage's size is %" PRIu64 \ |
maygup01 | 0:11cc2b7889af | 305 | " and (PRIMARY_PARTITION_SIZE+SECONDARY_PARTITION_SIZE) %" PRIu64, |
maygup01 | 0:11cc2b7889af | 306 | (uint64_t)mcc_platform_storage_size, (uint64_t)(PRIMARY_PARTITION_SIZE+SECONDARY_PARTITION_SIZE)); |
maygup01 | 0:11cc2b7889af | 307 | assert(0); |
maygup01 | 0:11cc2b7889af | 308 | } |
maygup01 | 0:11cc2b7889af | 309 | |
maygup01 | 0:11cc2b7889af | 310 | // use cast (uint64_t) for fixing compile warning. |
maygup01 | 0:11cc2b7889af | 311 | status = MBRBlockDevice::partition(_bd, SECONDARY_PARTITION_NUMBER, 0x83, SECONDARY_PARTITION_START, (uint64_t) SECONDARY_PARTITION_START + (uint64_t) SECONDARY_PARTITION_SIZE); |
maygup01 | 0:11cc2b7889af | 312 | tr_debug("Creating secondary partition ..."); |
maygup01 | 0:11cc2b7889af | 313 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 314 | tr_warn("Creating secondary partition failed 0x%X", status); |
maygup01 | 0:11cc2b7889af | 315 | return status; |
maygup01 | 0:11cc2b7889af | 316 | } |
maygup01 | 0:11cc2b7889af | 317 | tr_debug("Created secondary partition"); |
maygup01 | 0:11cc2b7889af | 318 | |
maygup01 | 0:11cc2b7889af | 319 | // init and format partition 2 |
maygup01 | 0:11cc2b7889af | 320 | status = init_and_mount_partition(&fs2, &part2, SECONDARY_PARTITION_NUMBER, ((const char*) MOUNT_POINT_SECONDARY+1)); |
maygup01 | 0:11cc2b7889af | 321 | if (status != 0) { |
maygup01 | 0:11cc2b7889af | 322 | return status; |
maygup01 | 0:11cc2b7889af | 323 | } |
maygup01 | 0:11cc2b7889af | 324 | tr_debug("Mounted secondary partition"); |
maygup01 | 0:11cc2b7889af | 325 | #endif |
maygup01 | 0:11cc2b7889af | 326 | #if (NUMBER_OF_PARTITIONS > 2) |
maygup01 | 0:11cc2b7889af | 327 | #error "Invalid number of partitions!!!" |
maygup01 | 0:11cc2b7889af | 328 | #endif |
maygup01 | 0:11cc2b7889af | 329 | #endif // (NUMBER_OF_PARTITIONS > 0) |
maygup01 | 0:11cc2b7889af | 330 | return status; |
maygup01 | 0:11cc2b7889af | 331 | } |
maygup01 | 0:11cc2b7889af | 332 | #endif // ((MCC_PLATFORM_PARTITION_MODE == 1) && (MCC_PLATFORM_AUTO_PARTITION == 1)) |