mbed: Fix calling to BlockDevice::size before initialization
These changes fixes a bug that can cause an uninitialized BlockDevice to be queried for its size. In some cases, this can return unexpected results (eg: 0). Move setting block device size after its initialization. Co-created: @AGlass0fMilk - George Beckstein Signed-off-by: Artur Tynecki <artur.tynecki@mobica.com> Signed-off-by: George Beckstein <george.beckstein@gmail.com>
This commit is contained in:
parent
6822365ecb
commit
a3cf3f8041
|
@ -91,15 +91,22 @@ int flash_area_open(uint8_t id, const struct flash_area** fapp) {
|
||||||
fap->fa_device_id = 0; // not relevant
|
fap->fa_device_id = 0; // not relevant
|
||||||
|
|
||||||
mbed::BlockDevice* bd = flash_map_bd[id];
|
mbed::BlockDevice* bd = flash_map_bd[id];
|
||||||
fap->fa_size = (uint32_t) bd->size();
|
|
||||||
|
|
||||||
/* Only initialize if this isn't a nested call to open the flash area */
|
/* Only initialize if this isn't a nested call to open the flash area */
|
||||||
if (open_count[id] == 1) {
|
if (open_count[id] == 1) {
|
||||||
MCUBOOT_LOG_DBG("initializing flash area %d...", id);
|
MCUBOOT_LOG_DBG("initializing flash area %d...", id);
|
||||||
return bd->init();
|
int ret = bd->init();
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
MCUBOOT_LOG_ERR("initializing flash area failed %d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fap->fa_size = (uint32_t) bd->size();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void flash_area_close(const struct flash_area* fap) {
|
void flash_area_close(const struct flash_area* fap) {
|
||||||
|
|
Loading…
Reference in New Issue