Hi,
I use RT1021 and I'm testing mcuboot.
I want image to be at most 512kB, so in sblconfig.h I define:
#define CONFIG_MCUBOOT_MAX_IMG_SECTORS 128 /*4kB sector * 128 = 512kB */
and in flash_partitioning.h I have defined:
#define BOOT_FLASH_ACT_APP 0x60100000
#define BOOT_FLASH_CAND_APP 0x60180000
However, I get an error:
Failed reading sectors; BOOT_MAX_IMG_SECTORS=128 - too small?
I debugged and found the point where I think there is a bug.
https://github.com/nxp-mcuxpresso/mcuboot/blob/mcux_main/boot/nxp_mcux_sdk/flashapi/flash_api.c#L378
int flash_area_get_sectors(int fa_id, uint32_t *count, struct flash_sector *sectors)
{
const struct flash_area *fa;
uint32_t max_cnt = *count;
uint32_t rem_len;
int rc = -1;
if (flash_area_open(fa_id, &fa))
goto out;
if (*count < 1)
goto fa_close_out;
rem_len = fa->fa_size;
*count = 0;
while ((rem_len > 0) && (*count < max_cnt))
{
if (rem_len < MFLASH_SECTOR_SIZE)
{
goto fa_close_out;
}
sectors[*count].fs_off = MFLASH_SECTOR_SIZE * (*count);
sectors[*count].fs_size = MFLASH_SECTOR_SIZE;
*count = *count + 1;
rem_len -= MFLASH_SECTOR_SIZE;
}
if (*count >= max_cnt)
{
goto fa_close_out;
}
rc = 0;
fa_close_out:
flash_area_close(fa);
out:
return rc;
}
If slot size is equal to image size, the while loop iterate until both conditions are false, but it is not an error if rem_len is 0 at the end of loop, it means that I have used al entry in sectors array, but no other entry is required.
I think that the if condition should be changed in:
if (rem_len > 0)
{
goto fa_close_out;
}
what do you think about this?
best regards
Max
Hi @mastupristi,
Thanks for reporting this issue.
I will pass it on to the SDK team so they can investigate it further and provide a change if they see it necessary.
BR,
Edwin.