How to create custom MCUBOOT for DFU

Hello!

I am creating a DFU application and want to customize the bootloader code.

I used this example: https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/ncs-dfu

How can you include a custom MCUBOOT when doing this example?

Parents Reply Children
  • Hi Markus, 
    The main purpose of SMP_SVR is to integrate with your application and can receive the image when the application is running. It will write the new image into flash. 
    The test and swap is handled by MCUBoot, not SMP_SVR. 
    You can choose to modify SMP_SVR to do the decompression instead of MCUBoot. This way the MCUBoot will not need to be modified. 

  • Oh ok I see :)

    That seems like a very good option. So the decompressed image file would then end up in the image slot correct?

    Do you have a recommendation for where to put the decompression in the SMP_SVR example?

  • Hi Markus, 

    I haven't looked deep into the code of smp_svr. So I can't point you to the exact place of the flash writing when receiving new image. 

    But as far as I know the flash handling is in fs_mgmt.c in \zephyr\subsys\mgmt\mcumgr\lib\cmd\fs_mgmt\src. And the image management is in \zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt. 

    Also, pay attention to the smp.c file, it's when the SMP request is handled. 

  • Hi again!

    We have looked into the files.

    It seems like img_mgmt.c is an appropriate file to modify. There is a function at line 392 called img_mgmt_upload(struct mgmt_ctxt *ctxt). Also check Line 522 ("/* Write the image data to flash. */")

    We believe this could be a good location to include decompress. What do you think? Or should it be "deeper" in the data sending.

  • Hi Markus, 


    I have to admit that I haven't tried to modify the img_mgmt library myself. But it looks to me that it's where the flash write actually happened. So the function img_mgmt_impl_write_image_data() will write the data it get from cbor_read_object() to flash. The decompression can happens here. I'm not sure how you do decompress but what the code here is doing is to write to flash chunk by chunk, until the /* If this is the last chunk */ . 
    So if your decompression would work with each chunk then you can do it on the fly, or you will do it when it's the last chunk and the whole image has been received. It depends on how you will do decompression. 

Related