Skip to content

Commit 483561b

Browse files
committed
Remove global declaration of default_bd and logical_bd
1 parent 75947e2 commit 483561b

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

default_bd.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBE
4444
#endif
4545
#endif
4646

47-
#if MCUBOOT_AS_ENVIE
48-
static BlockDevice *default_bd = NULL;
49-
static MBRBlockDevice *logical_bd = NULL;
50-
#endif
51-
5247
/*
5348
* MCUBOOT_AS_ENVIE -> Secondary Block device defined by getOTAData [SDCARD, QSPI] Internal flash not supported
5449
* -> !!WARNING!! Scratch Block device by default on QSPI + MBR + FAT
@@ -66,35 +61,36 @@ BlockDevice *BlockDevice::get_default_instance()
6661
storageType storage_type;
6762
uint32_t data_offset;
6863
uint32_t update_size;
69-
BlockDevice *raw_bd = NULL;
7064

7165
getOTAData(&storage_type, &data_offset, &update_size);
7266

7367
//if (storage_type & INTERNAL_FLASH_FLAG) {
7468
// if (storage_type & (FATFS_FLAG | LITTLEFS_FLAG)) {
7569
// // have a filesystem, use offset as partition start
7670
// static FlashIAPBlockDevice flashIAP_bd(0x8000000 + data_offset, 2 * 1024 * 1024 - data_offset);
77-
// raw_bd = &flashIAP_bd;
71+
// return &flashIAP_bd;
7872
// } else {
7973
// // raw device, no offset
8074
// static FlashIAPBlockDevice flashIAP_bd(0x8000000, 2 * 1024 * 1024);
81-
// raw_bd = &flashIAP_bd;
75+
// return &flashIAP_bd;
8276
// }
8377
//}
8478

8579
#if MCUBOOT_ENVIE_SDCARD
8680
if (storage_type & SDCARD_FLAG) {
8781
static SDMMCBlockDevice SDMMC_bd;
88-
raw_bd = &SDMMC_bd;
82+
BOOT_LOG_INF("SDMMCBlockDevice");
83+
return &SDMMC_bd;
8984
}
9085
#endif
9186

9287
if (storage_type & QSPI_FLASH_FLAG) {
9388
static QSPIFBlockDevice QSPIF_bd(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
94-
raw_bd = &QSPIF_bd;
89+
BOOT_LOG_INF("QSPIFBlockDevice");
90+
return &QSPIF_bd;
9591
}
9692

97-
return raw_bd;
93+
return NULL;
9894
#else //MCUBOOT_AS_ENVIE
9995
#if COMPONENT_SPIF
10096

@@ -144,7 +140,8 @@ mbed::BlockDevice* get_secondary_bd(void) {
144140
// In this case, our flash is much larger than a single image so
145141
// slice it into the size of an image slot
146142
#if MCUBOOT_AS_ENVIE
147-
default_bd = mbed::BlockDevice::get_default_instance();
143+
mbed::BlockDevice* default_bd = mbed::BlockDevice::get_default_instance();
144+
mbed::BlockDevice* logical_bd;
148145
storageType storage_type;
149146
uint32_t data_offset;
150147
uint32_t update_size;
@@ -175,7 +172,7 @@ mbed::BlockDevice* get_secondary_bd(void) {
175172
}
176173
#endif
177174

178-
static mbed::FileBlockDevice file_bd(logical_bd, "/secondary/update.bin", "rb+", update_size);
175+
static mbed::FileBlockDevice file_bd("/secondary/update.bin", "rb+", update_size);
179176
return &file_bd;
180177
} else {
181178
int err = default_bd->init();
@@ -200,7 +197,7 @@ mbed::BlockDevice* get_secondary_bd(void) {
200197
}
201198
#endif
202199

203-
static mbed::FileBlockDevice file_bd(default_bd, "/secondary/update.bin", "rb+", update_size);
200+
static mbed::FileBlockDevice file_bd("/secondary/update.bin", "rb+", update_size);
204201
return &file_bd;
205202
}
206203

@@ -223,7 +220,7 @@ mbed::BlockDevice* get_secondary_bd(void) {
223220
if (err) {
224221
BOOT_LOG_ERR("Error mounting fatfs on secondary mbr device");
225222
}
226-
static mbed::FileBlockDevice file_bd(&mbr_bd, "/secondary/update.bin", "rb+", MCUBOOT_SLOT_SIZE);
223+
static mbed::FileBlockDevice file_bd("/secondary/update.bin", "rb+", MCUBOOT_SLOT_SIZE);
227224
return &file_bd;
228225
#endif
229226
#endif //MCUBOOT_AS_ENVIE
@@ -248,9 +245,9 @@ mbed::BlockDevice* get_scratch_bd(void) {
248245
*
249246
*/
250247

251-
if(!(storage_type & QSPI_FLASH_FLAG)) {
252-
default_bd = new QSPIFBlockDevice(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
253-
logical_bd = new MBRBlockDevice(default_bd, 2);
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);
254251

255252
int err = logical_bd->init();
256253
if (err) {
@@ -262,9 +259,9 @@ mbed::BlockDevice* get_scratch_bd(void) {
262259
if (err) {
263260
BOOT_LOG_ERR("Error mounting fatfs on scratch mbr device");
264261
}
265-
}
262+
//}
266263

267-
static mbed::FileBlockDevice file_bd(logical_bd, "/scratch/scratch.bin", "rb+", MCUBOOT_SCRATCH_SIZE);
264+
static mbed::FileBlockDevice file_bd("/scratch/scratch.bin", "rb+", MCUBOOT_SCRATCH_SIZE);
268265
return &file_bd;
269266
#else
270267
#if !defined MCUBOOT_USE_FILE_BD
@@ -284,7 +281,7 @@ mbed::BlockDevice* get_scratch_bd(void) {
284281
if (err) {
285282
BOOT_LOG_ERR("Error mounting fatfs on scratch mbr device");
286283
}
287-
static mbed::FileBlockDevice file_bd(&mbr_bd, "/scratch/scratch.bin", "rb+", MCUBOOT_SCRATCH_SIZE);
284+
static mbed::FileBlockDevice file_bd("/scratch/scratch.bin", "rb+", MCUBOOT_SCRATCH_SIZE);
288285
return &file_bd;
289286
#endif
290287
#endif //MCUBOOT_AS_ENVIE

0 commit comments

Comments
 (0)