Skip to content

Commit f926c2d

Browse files
committed
Moved default block device code in ota files
1 parent d989ce5 commit f926c2d

File tree

2 files changed

+196
-228
lines changed

2 files changed

+196
-228
lines changed

default_bd.cpp

Lines changed: 4 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,10 @@
55
* Author: gdbeckstein
66
*/
77

8+
#if !MCUBOOT_AS_ENVIE
9+
810
#include "BlockDevice.h"
911
#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
2612

2713
#if COMPONENT_SPIF
2814
#include "SPIFBlockDevice.h"
@@ -44,54 +30,8 @@ const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBE
4430
#endif
4531
#endif
4632

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-
5833
BlockDevice *BlockDevice::get_default_instance()
5934
{
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
9535
#if COMPONENT_SPIF
9636

9737
static SPIFBlockDevice default_bd;
@@ -128,8 +68,6 @@ BlockDevice *BlockDevice::get_default_instance()
12868
return NULL;
12969

13070
#endif
131-
132-
#endif //MCUBOOT_AS_ENVIE
13371
}
13472

13573
/**
@@ -139,151 +77,15 @@ BlockDevice *BlockDevice::get_default_instance()
13977
mbed::BlockDevice* get_secondary_bd(void) {
14078
// In this case, our flash is much larger than a single image so
14179
// slice it into the size of an image slot
142-
#if MCUBOOT_AS_ENVIE
14380
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
20881
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
20982
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-
22983
}
23084

23185
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
26886
static FlashIAPBlockDevice scratch_bd(MCUBOOT_SCRATCH_START_ADDR, MCUBOOT_SCRATCH_SIZE);
26987
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
28888
}
89+
#endif //MCUBOOT_AS_ENVIE
90+
28991

0 commit comments

Comments
 (0)