renesas / fsp

Flexible Software Package (FSP) for Renesas RA MCU Family
https://renesas.github.io/fsp/
Other
182 stars 82 forks source link

Crash when calling RM_VEE_FLASH_Open #347

Open sytsereitsma opened 4 months ago

sytsereitsma commented 4 months ago

Hi,

We have the following scenario:

When opening the flash from the bootloader (RM_VEE_FLASH_Open) we sometimes get a crash, which I narrowed down to the record offset assignment in rm_vee_load_record_table (ra\fsp\src\rm_vee_flash\rm_vee_flash.c line 1055 on v5.2.0):

        /* Save record offset if complete record found (reset may have occurred during a write) */
        if (RM_VEE_FLASH_VALID_CODE == p_end->valid_code)
        {
            // This line may assign an offset out of bounds of the rec_offset array
            p_ctrl->p_cfg->rec_offset[p_end->id] = (uint16_t) (addr - p_ctrl->active_seg_addr);

            /* Save for statusGet */
            p_ctrl->last_id = p_end->id;
        }

When parsing all records sometimes record ids (p_end->id) are greater than 32 resulting in an out of bounds write to the p_ctrl->p_cfg->rec_offset array.

A quick fix would be:

        /* Save record offset if complete record found (reset may have occurred during a write) */
        if (RM_VEE_FLASH_VALID_CODE == p_end->valid_code)
        {
            uint16_t rec_id = p_end->id;
            if (rec_id <= p_ctrl->p_cfg->record_max_id)
            {
                p_ctrl->p_cfg->rec_offset[p_end->id] = (uint16_t) (addr - p_ctrl->active_seg_addr);

                /* Save for statusGet */
                // Not sure if this should be inside, or outside the if
                p_ctrl->last_id = p_end->id;
            }
        }
renesas-brandon-hussey commented 4 months ago

This is being internally tracked using FSPRA-2635.

renesas-billgesner commented 3 months ago

Hi @sytsereitsma, opening a volume with RM_VEE_Open with a configuration that does not match what is reflected in the volume is not currently supported. Is there a reason you cannot open the volume using the same configuration in both the bootloader and the application?

sytsereitsma commented 3 months ago

At present we have no means to field-update our bootloader. In the beginning we thought 32 records 'ought to be enough for anybody', so now we're stuck with that number. Meanwhile the application has evolved and now uses a max record id of 64 entries.