possible bug in mcuboot/boot/nxp_mcux_sdk/flashapi/flash_api.c

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

possible bug in mcuboot/boot/nxp_mcux_sdk/flashapi/flash_api.c

408件の閲覧回数
mastupristi
Senior Contributor I

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

タグ(2)
0 件の賞賛
返信
1 返信

389件の閲覧回数
EdwinHz
NXP TechSupport
NXP TechSupport

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.

0 件の賞賛
返信
%3CLINGO-SUB%20id%3D%22lingo-sub-2159996%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Emcuboot%2Fboot%2Fnxp_mcux_sdk%2Fflashapi%2Fflash_api.c%20%E3%81%AB%E3%83%90%E3%82%B0%E3%81%8C%E3%81%82%E3%82%8B%E5%8F%AF%E8%83%BD%E6%80%A7%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2159996%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E3%80%81%3C%2FP%3E%3CP%3ERT1021%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%80%81mcuboot%20%E3%82%92%E3%83%86%E3%82%B9%E3%83%88%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%E7%94%BB%E5%83%8F%E3%82%92%E6%9C%80%E5%A4%A7512kB%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84%E3%80%82SO%E3%80%81sblconfig.h%E3%81%A7%E7%A7%81%E3%81%AF%E6%AC%A1%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E5%AE%9A%E7%BE%A9%E3%81%97%E3%81%BE%E3%81%99%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3E%23define%20CONFIG_MCUBOOT_MAX_IMG_SECTORS%20128%20%2F*4kB%20sector%20*%20128%20%3D%20512kB%20*%2F%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3Eflash_partitioning.h%20%E5%86%85%E7%A7%81%E3%81%AF%E6%AC%A1%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E5%AE%9A%E7%BE%A9%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3E%23define%20BOOT_FLASH_ACT_APP%20%20%20%20%20%20%20%20%20%20%20%20%20%200x60100000%0A%23define%20BOOT_FLASH_CAND_APP%20%20%20%20%20%20%20%20%20%20%20%20%200x60180000%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%E3%81%9F%E3%81%A0%E3%81%97%E3%80%81%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%97%E3%81%BE%E3%81%99%3A%3C%2FP%3E%3CPRE%20translate%3D%22no%22%3EFailed%20reading%20sectors%3B%20BOOT_MAX_IMG_SECTORS%3D128%20-%20too%20small%3F%3C%2FPRE%3E%3CP%3E%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E3%81%97%E3%81%A6%E3%83%90%E3%82%B0%E3%81%8C%E3%81%82%E3%82%8B%E3%81%A8%E6%80%9D%E3%82%8F%E3%82%8C%E3%82%8B%E7%AE%87%E6%89%80%E3%82%92%E8%A6%8B%E3%81%A4%E3%81%91%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fnxp-mcuxpresso%2Fmcuboot%2Fblob%2Fmcux_main%2Fboot%2Fnxp_mcux_sdk%2Fflashapi%2Fflash_api.c%23L378%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fnxp-mcuxpresso%2Fmcuboot%2Fblob%2Fmcux_main%2Fboot%2Fnxp_mcux_sdk%2Fflashapi%2Fflash_api.c%23L378%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3Eint%20flash_area_get_sectors(int%20fa_id%2C%20uint32_t%20*count%2C%20struct%20flash_sector%20*sectors)%0A%7B%0A%20%20%20%20const%20struct%20flash_area%20*fa%3B%0A%20%20%20%20uint32_t%20max_cnt%20%3D%20*count%3B%0A%20%20%20%20uint32_t%20rem_len%3B%0A%20%20%20%20int%20rc%20%3D%20-1%3B%0A%0A%20%20%20%20if%20(flash_area_open(fa_id%2C%20%26amp%3Bfa))%0A%20%20%20%20%20%20%20%20goto%20out%3B%0A%0A%20%20%20%20if%20(*count%20%26lt%3B%201)%0A%20%20%20%20%20%20%20%20goto%20fa_close_out%3B%0A%0A%20%20%20%20rem_len%20%3D%20fa-%26gt%3Bfa_size%3B%0A%20%20%20%20*count%20%20%3D%200%3B%0A%20%20%20%20while%20((rem_len%20%26gt%3B%200)%20%26amp%3B%26amp%3B%20(*count%20%26lt%3B%20max_cnt))%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20if%20(rem_len%20%26lt%3B%20MFLASH_SECTOR_SIZE)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20goto%20fa_close_out%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20sectors%5B*count%5D.fs_off%20%20%3D%20MFLASH_SECTOR_SIZE%20*%20(*count)%3B%0A%20%20%20%20%20%20%20%20sectors%5B*count%5D.fs_size%20%3D%20MFLASH_SECTOR_SIZE%3B%0A%20%20%20%20%20%20%20%20*count%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20*count%20%2B%201%3B%0A%20%20%20%20%20%20%20%20rem_len%20-%3D%20MFLASH_SECTOR_SIZE%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20if%20(*count%20%26gt%3B%3D%20max_cnt)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20goto%20fa_close_out%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20rc%20%3D%200%3B%0A%0Afa_close_out%3A%0A%20%20%20%20flash_area_close(fa)%3B%0Aout%3A%0A%20%20%20%20return%20rc%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%E3%82%B9%E3%83%AD%E3%83%83%E3%83%88%20%E3%82%B5%E3%82%A4%E3%82%BA%E3%81%8C%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%20%E3%82%B5%E3%82%A4%E3%82%BA%E3%81%A8%E7%AD%89%E3%81%97%E3%81%84%E5%A0%B4%E5%90%88%E3%80%81while%20%E3%83%AB%E3%83%BC%E3%83%97%E3%81%AF%E4%B8%A1%E6%96%B9%E3%81%AE%E6%9D%A1%E4%BB%B6%E3%81%8C%20false%20%E3%81%AB%E3%81%AA%E3%82%8B%E3%81%BE%E3%81%A7%E5%8F%8D%E5%BE%A9%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%81%8C%E3%80%81%E3%83%AB%E3%83%BC%E3%83%97%E3%81%AE%E7%B5%82%E4%BA%86%E6%99%82%E3%81%AB%20rem_len%20%E3%81%8C%200%20%E3%81%A7%E3%81%82%E3%81%A3%E3%81%A6%E3%82%82%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%AB%E3%81%AF%E3%81%AA%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%E3%81%93%E3%82%8C%E3%81%AF%E3%80%81%E3%82%BB%E3%82%AF%E3%82%BF%E3%83%BC%E9%85%8D%E5%88%97%E3%81%AE%E3%81%99%E3%81%B9%E3%81%A6%E3%81%AE%E3%82%A8%E3%83%B3%E3%83%88%E3%83%AA%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F%E3%81%8C%E3%80%81%E4%BB%96%E3%81%AE%E3%82%A8%E3%83%B3%E3%83%88%E3%83%AA%E3%81%AF%E5%BF%85%E8%A6%81%E3%81%AA%E3%81%84%E3%81%A8%E3%81%84%E3%81%86%E3%81%93%E3%81%A8%E3%82%92%E6%84%8F%E5%91%B3%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3Eif%20%E6%9D%A1%E4%BB%B6%E3%82%92%E6%AC%A1%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B%E5%BF%85%E8%A6%81%E3%81%8C%E3%81%82%E3%82%8B%E3%81%A8%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3E%20%20%20%20if%20(rem_len%20%26gt%3B%200)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20goto%20fa_close_out%3B%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%E3%81%93%E3%82%8C%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%81%A9%E3%81%86%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%E3%81%8B%EF%BC%9F%3C%2FP%3E%3CP%3E%E3%82%88%E3%82%8D%E3%81%97%E3%81%8F%E3%81%8A%E9%A1%98%E3%81%84%E3%81%84%E3%81%9F%E3%81%97%E3%81%BE%E3%81%99%3C%2FP%3E%3CP%3E%E6%9C%80%E5%A4%A7%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2160180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20possible%20bug%20in%20mcuboot%2Fboot%2Fnxp_mcux_sdk%2Fflashapi%2Fflash_api.c%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2160180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F124967%22%20target%3D%22_blank%22%3E%40mastupristi%3C%2FA%3E%20%E3%80%81%3C%2FP%3E%0A%3CP%3E%E3%81%93%E3%81%AE%E5%95%8F%E9%A1%8C%E3%82%92%E5%A0%B1%E5%91%8A%E3%81%97%E3%81%A6%E3%81%84%E3%81%9F%E3%81%A0%E3%81%8D%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%81%94%E3%81%96%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%0A%3CP%3E%E3%81%93%E3%82%8C%E3%82%92%20SDK%20%E3%83%81%E3%83%BC%E3%83%A0%E3%81%AB%E6%B8%A1%E3%81%97%E3%81%A6%E3%80%81%E3%81%95%E3%82%89%E3%81%AB%E8%AA%BF%E6%9F%BB%E3%81%97%E3%80%81%E5%BF%85%E8%A6%81%E3%81%A7%E3%81%82%E3%82%8C%E3%81%B0%E5%A4%89%E6%9B%B4%E3%81%97%E3%81%A6%E3%82%82%E3%82%89%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%0A%3CP%3EBR%E3%80%81%3CBR%20%2F%3E%E3%82%A8%E3%83%89%E3%82%A6%E3%82%A3%E3%83%B3%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E