5
5
* Author: gdbeckstein
6
6
*/
7
7
8
+ #if !MCUBOOT_AS_ENVIE
9
+
8
10
#include " BlockDevice.h"
9
11
#include " SlicingBlockDevice.h"
10
- #include " FlashIAPBlockDevice.h"
11
- #include " bootutil/bootutil_log.h"
12
-
13
- #if MCUBOOT_AS_ENVIE || MCUBOOT_USE_FILE_BD
14
- #include " MBRBlockDevice.h"
15
- #include " FileBlockDevice.h"
16
- #include " FATFileSystem.h"
17
- #endif
18
-
19
- #if MCUBOOT_AS_ENVIE
20
- #include " SDMMCBlockDevice.h"
21
- #if MCUBOOT_ENVIE_LITTLEFS
22
- #include " LittleFileSystem.h"
23
- #endif
24
- #include " ota.h"
25
- #endif
26
12
27
13
#if COMPONENT_SPIF
28
14
#include " SPIFBlockDevice.h"
@@ -44,54 +30,8 @@ const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBE
44
30
#endif
45
31
#endif
46
32
47
- /*
48
- * MCUBOOT_AS_ENVIE -> Secondary Block device defined by getOTAData [SDCARD, QSPI] Internal flash not supported
49
- * -> !!WARNING!! Scratch Block device by default on QSPI + MBR + FAT
50
- *
51
- * MCUBOOT_USE_FILE_BD -> Secondary Block device on QSPI + MBR + FAT
52
- * -> Scratch Block device on QSPI + MBR + FAT
53
- *
54
- * -> Secondary Block device on RAW QSPI @0x0000000
55
- * -> Scratch Block device on Internal flash @MCUBOOT_SCRATCH_START_ADDR
56
- */
57
-
58
33
BlockDevice *BlockDevice::get_default_instance ()
59
34
{
60
- #if MCUBOOT_AS_ENVIE
61
- storageType storage_type;
62
- uint32_t data_offset;
63
- uint32_t update_size;
64
-
65
- getOTAData (&storage_type, &data_offset, &update_size);
66
-
67
- // if (storage_type & INTERNAL_FLASH_FLAG) {
68
- // if (storage_type & (FATFS_FLAG | LITTLEFS_FLAG)) {
69
- // // have a filesystem, use offset as partition start
70
- // static FlashIAPBlockDevice flashIAP_bd(0x8000000 + data_offset, 2 * 1024 * 1024 - data_offset);
71
- // return &flashIAP_bd;
72
- // } else {
73
- // // raw device, no offset
74
- // static FlashIAPBlockDevice flashIAP_bd(0x8000000, 2 * 1024 * 1024);
75
- // return &flashIAP_bd;
76
- // }
77
- // }
78
-
79
- #if MCUBOOT_ENVIE_SDCARD
80
- if (storage_type & SDCARD_FLAG) {
81
- static SDMMCBlockDevice SDMMC_bd;
82
- BOOT_LOG_INF (" SDMMCBlockDevice" );
83
- return &SDMMC_bd;
84
- }
85
- #endif
86
-
87
- if (storage_type & QSPI_FLASH_FLAG) {
88
- static QSPIFBlockDevice QSPIF_bd (PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000 );
89
- BOOT_LOG_INF (" QSPIFBlockDevice" );
90
- return &QSPIF_bd;
91
- }
92
-
93
- return NULL ;
94
- #else // MCUBOOT_AS_ENVIE
95
35
#if COMPONENT_SPIF
96
36
97
37
static SPIFBlockDevice default_bd;
@@ -128,8 +68,6 @@ BlockDevice *BlockDevice::get_default_instance()
128
68
return NULL ;
129
69
130
70
#endif
131
-
132
- #endif // MCUBOOT_AS_ENVIE
133
71
}
134
72
135
73
/* *
@@ -139,151 +77,15 @@ BlockDevice *BlockDevice::get_default_instance()
139
77
mbed::BlockDevice* get_secondary_bd (void ) {
140
78
// In this case, our flash is much larger than a single image so
141
79
// slice it into the size of an image slot
142
- #if MCUBOOT_AS_ENVIE
143
80
mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance ();
144
- mbed::BlockDevice* logical_bd;
145
- storageType storage_type;
146
- uint32_t data_offset;
147
- uint32_t update_size;
148
-
149
- getOTAData (&storage_type, &data_offset, &update_size);
150
-
151
- if (storage_type & MBR_FLAG) {
152
- logical_bd = new MBRBlockDevice (default_bd, data_offset);
153
- int err = logical_bd->init ();
154
- if (err) {
155
- BOOT_LOG_ERR (" Error initializing secondary mbr device" );
156
- }
157
- #if MCUBOOT_ENVIE_LITTLEFS
158
- if ((storage_type & LITTLEFS_FLAG)) {
159
- static LittleFileSystem secondary_bd_fs (" secondary" );
160
- err = secondary_bd_fs.mount (logical_bd);
161
- if (err) {
162
- BOOT_LOG_ERR (" Error mounting littlefs on secondary mbr device" );
163
- }
164
- } else {
165
- #endif
166
- static FATFileSystem secondary_bd_fs (" secondary" );
167
- err = secondary_bd_fs.mount (logical_bd);
168
- if (err) {
169
- BOOT_LOG_ERR (" Error mounting fatfs on secondary mbr device" );
170
- }
171
- #if MCUBOOT_ENVIE_LITTLEFS
172
- }
173
- #endif
174
-
175
- static mbed::FileBlockDevice file_bd (" /secondary/update.bin" , " rb+" , update_size);
176
- return &file_bd;
177
- } else {
178
- int err = default_bd->init ();
179
- if (err) {
180
- BOOT_LOG_ERR (" Error initializing secondary raw device" );
181
- }
182
- #if MCUBOOT_ENVIE_LITTLEFS
183
- if ((storage_type & LITTLEFS_FLAG)) {
184
- static LittleFileSystem secondary_bd_fs (" secondary" );
185
- err = secondary_bd_fs.mount (default_bd);
186
- if (err) {
187
- BOOT_LOG_ERR (" Error mounting littlefs on secondary raw device" );
188
- }
189
- } else {
190
- #endif
191
- static FATFileSystem secondary_bd_fs (" secondary" );
192
- err = secondary_bd_fs.mount (default_bd);
193
- if (err) {
194
- BOOT_LOG_ERR (" Error mounting fatfs on secondary raw device" );
195
- }
196
- #if MCUBOOT_ENVIE_LITTLEFS
197
- }
198
- #endif
199
-
200
- static mbed::FileBlockDevice file_bd (" /secondary/update.bin" , " rb+" , update_size);
201
- return &file_bd;
202
- }
203
-
204
- return NULL ;
205
- #else
206
- mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance ();
207
- #if !defined MCUBOOT_USE_FILE_BD
208
81
static mbed::SlicingBlockDevice sliced_bd (default_bd, 0x0 , MCUBOOT_SLOT_SIZE);
209
82
return &sliced_bd;
210
- #else
211
- static mbed::MBRBlockDevice mbr_bd (default_bd, 2 );
212
-
213
- int err = mbr_bd.init ();
214
- if (err) {
215
- BOOT_LOG_ERR (" Error initializing secondary mbr device" );
216
- }
217
-
218
- static mbed::FATFileSystem secondary_bd_fs (" secondary" );
219
- err = secondary_bd_fs.mount (&mbr_bd);
220
- if (err) {
221
- BOOT_LOG_ERR (" Error mounting fatfs on secondary mbr device" );
222
- }
223
- static mbed::FileBlockDevice file_bd (" /secondary/update.bin" , " rb+" , MCUBOOT_SLOT_SIZE);
224
- return &file_bd;
225
- #endif
226
- #endif // MCUBOOT_AS_ENVIE
227
-
228
-
229
83
}
230
84
231
85
mbed::BlockDevice* get_scratch_bd (void ) {
232
-
233
- #if MCUBOOT_AS_ENVIE
234
- storageType storage_type;
235
- uint32_t data_offset;
236
- uint32_t update_size;
237
-
238
- getOTAData (&storage_type, &data_offset, &update_size);
239
-
240
- /*
241
- * If the secondary slot is not into the internal QSPI flash, i.e. SDMCC; initialize
242
- * QSPI storage and mount the filesystem.
243
- *
244
- * WARNING: by default we are assuming the QSPI flash is formatted as MBR device with FAT
245
- *
246
- */
247
-
248
- // if(!(storage_type & QSPI_FLASH_FLAG)) {
249
- mbed::BlockDevice* default_bd = new QSPIFBlockDevice (PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000 );
250
- mbed::BlockDevice* logical_bd = new MBRBlockDevice (default_bd, 2 );
251
-
252
- int err = logical_bd->init ();
253
- if (err) {
254
- BOOT_LOG_ERR (" Error initializing scratch mbr device" );
255
- }
256
-
257
- static mbed::FATFileSystem secondary_bd_fs (" scratch" );
258
- err = secondary_bd_fs.mount (logical_bd);
259
- if (err) {
260
- BOOT_LOG_ERR (" Error mounting fatfs on scratch mbr device" );
261
- }
262
- // }
263
-
264
- static mbed::FileBlockDevice file_bd (" /scratch/scratch.bin" , " rb+" , MCUBOOT_SCRATCH_SIZE);
265
- return &file_bd;
266
- #else
267
- #if !defined MCUBOOT_USE_FILE_BD
268
86
static FlashIAPBlockDevice scratch_bd (MCUBOOT_SCRATCH_START_ADDR, MCUBOOT_SCRATCH_SIZE);
269
87
return &scratch_bd;
270
- #else
271
- mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance ();
272
- static mbed::MBRBlockDevice mbr_bd (default_bd, 2 );
273
-
274
- int err = mbr_bd.init ();
275
- if (err) {
276
- BOOT_LOG_ERR (" Error initializing scratch mbr device" );
277
- }
278
-
279
- static mbed::FATFileSystem secondary_bd_fs (" scratch" );
280
- err = secondary_bd_fs.mount (&mbr_bd);
281
- if (err) {
282
- BOOT_LOG_ERR (" Error mounting fatfs on scratch mbr device" );
283
- }
284
- static mbed::FileBlockDevice file_bd (" /scratch/scratch.bin" , " rb+" , MCUBOOT_SCRATCH_SIZE);
285
- return &file_bd;
286
- #endif
287
- #endif // MCUBOOT_AS_ENVIE
288
88
}
89
+ #endif // MCUBOOT_AS_ENVIE
90
+
289
91
0 commit comments