Zephyr + Slot 0 & Slot 1 data write not working for bootloader DFU

Hello,

Dev board: nRF52840 development board.

OS: Zephyr (NCS v2.6.0).

My requirement and What I am using...

- I want to perform DFU for application core & bootloader.

- I am using NSIB+MCUBoot+Application.

- I have custom DFU characteristic in BLE peripheral to receive .bin file data in chunks from BLE central device.

What I have performed so far (for application DFU)...

- In application firmware:

- I am successfully able perform the DFU for application core by receiving the .bin file data (using app_update.bin) in chunk from BLE central device over custom DFU characteristic.

- Then I am able to write those chunks in secondary slot (PM_MCUBOOT_SECONDARY_ID) using following code...

struct flash_img_context fic;
flash_img_init_id(&fic, PM_MCUBOOT_SECONDARY_ID);
boot_erase_img_bank(PM_MCUBOOT_SECONDARY_ID);
flash_img_buffered_write(&fic, &data[0], FILE_SIZE, true);
boot_request_upgrade(BOOT_UPGRADE_PERMANENT);

- Then I soft reset the BLE peripheral device and MCUBoot will successfully validate & swap the new application image from secondary slot to primary slot and then new application image gets started onwards.

What I have performed so far (for bootloader DFU)...

- I know that, I should use *_b0_s1_image_update.bin file for slot1 and *_b0_s1_image_update.bin file for slot0.

- In application firmware:

- I am using signed_by_mcuboot_and_b0_s1_image_update.bin file and successfully able to receive the chunk of it from BLE central device over custom DFU characteristic.

- I am using following code to write those chunks in slot1 (PM_S1_ID)...

struct flash_img_context fic;
flash_img_init_id(&fic, PM_S1_ID);
boot_erase_img_bank(PM_S1_ID);
flash_img_buffered_write(&fic, &data[0], FILE_SIZE, true);

- Now the problem is, I get bus fault and BLE peripheral device gets restarted during the use of the function flash_img_buffered_write(&fic, &data[0], FILE_SIZE, true).

My question is, How can I successfully write .bin file data in slot1 using flash_img_buffered_write?. Is there any other way to do so?. Is there any other way to perform bootloader DFU?.

  • Hi,

    Thank you for the detailed description.

    - Now the problem is, I get bus fault and BLE peripheral device gets restarted during the use of the function flash_img_buffered_write(&fic, &data[0], FILE_SIZE, true).

    Could you post the device log showing the bus fault? Could you also post your partition map? (for instance partitions.yml located in your build folder) or use the partition_manager_report feature in VS Code

    Kind regards,
    Andreas

  • Hello,

    Thanks for your reply.

    - Meanwhile I was able to solve this bus fault issue that I did mention. Issue was due to the protection enabled for S0 (slot0) and S1 (slot1) from the MCUBoot using the function fprotect_area.

    - Now another problem gets generated while erasing the S1 (slot1) using the function boot_erase_img_bank.

    - I am using the following code to erase the S1 (slot1)...

    struct flash_img_context fic;
    flash_img_init_id(&fic, PM_S1_ID);
    boot_erase_img_bank(PM_S1_ID);

    - E: unaligned address: 0x00016000:49664 error was generated when boot_erase_img_bank function executed.

    - What could be the root cause of this error and how to solve it? Any help would be appreciated.

    Thanks & Regards

    Vivek Kaloliya

  • Hi Vivek,

    Vivek_Core said:
    Meanwhile I was able to solve this bus fault issue that I did mention. Issue was due to the protection enabled for S0 (slot0) and S1 (slot1) from the MCUBoot using the function fprotect_area.

    Glad to hear that, and also great that you let me know how you resolved it

    Vivek_Core said:
    - E: unaligned address: 0x00016000:49664 error was generated when boot_erase_img_bank function executed.

    The error message "E: unaligned address: 0x00016000:49664 error" typically indicates that the address you're trying to erase with the `boot_erase_img_bank` function is not aligned correctly. This could be due to the address not being a multiple of the flash erase block size, or it could be outside the valid range of addresses for the flash memory. Are you able to verify if the address is either outside of the valid range or if it is not a multiple of the flash erase block size?

    https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/doxygen/html/group__mcuboot__api.html#booteraseimgbank 

    Kind regards,
    Andreas

  • Hi Andreas,

    E: unaligned address: 0x00016000:49664 error

    Flash address that is 0x16000 in our case is valid & in range. Erase size 49664 bytes are also valid & multiple of 512 bytes (which is multiple of the flash erase block size).

    FYI: I tried to erase secondary slot (PM_MCUBOOT_SECONDARY_ID) using boot_erase_img_bank(PM_MCUBOOT_SECONDARY_ID) function. It didn't generate any error and secondary slot erased successfully.

    What could be the possible reason of unaligned address error and how can I solve it?

    Thanks & Regards

    Vivek Kaloliya

  • Thank you for verifying.

    If possible, could you share your partitioning map? If it is non-suited for public forums, could you create a private ticket, share it there and let me know when you've shared it? My guess is that the misalignment is caused due to padding or something else skewing the partition.

    Is there any numbered error codes associated with the error message? 

    Kind regards,
    Andreas

Related