MCUBoot DFU OTA Best way to obtain actions ( Hooks ) also Android vs iOS discrepancies.

Hi There, 

Environment Description: 

 1. nRF Connect for VS Code v2023.1.44.

 1.  NCS Version v2.0.0. 

 2. Zephyr v3.0.99-ncs1.

 3. MCUBoot v1.9.99

 4. NRF52840.

 5. NRF Connect mobile app Android v 4.26.0 Mobile app IOS V 2.6.

I am currently working on the implementation of OTA DFU using BLE, I have successfully implemented this functionality after following the documentation here., However there are some questions and perhaps missing functionality to fulfill our product's requirements, taking into account that our product consists of an LCD which should display the state of the update as it goes along. 

By using these image management callbacks I am able to get the start of the DFU process as well as the DFU Pending event, nonetheless there is a discrepancy depending on which kind of device is used to perform for instance:

From an Android the workflow is as follows: 

1. DFU Started form mobile phone -> 2. Get DFU Started Callback. -> 3. ~ 30 Seconds transferring the image. -> 4. Device goes into MCUBoot .... -> 5. ~30-40 Seconds later, Device resets. -> 6. get the Image confirmed callback.

  

Question 1: Why does step 5 take that long ? ( After Jumping to the first Image slot ).

2. From an iPhone However the workflow changes slightly as the confirmed callback is never received by the application, Which makes it tricky to display user updates: 

Question 2: Why does the update from iPhone does generate the Confirmed callback ?

Question 3: Why are the swap types different (Android -> "Swap type: test", iPhone -> "Swap type: perm") ?

Finally, I would very much appreciate advise in regards to obtaining MCUBoot status actions in order to update the LCD accordingly while the bootloader is doing its magic, I did have a look online and found a couple of references to CONFIG_MCUBOOT_ACTION_HOOKS here, unfortunately it seems to be undefined when included in my child_image/mcuboot.conf file. 

Question 3: What is the best way to obtain MCUBoot actions to execute my own code ( is there a sample for this ) ? 

MCUBoot Configuration: 

Main project Configuration: 

Cheers !

Parents
  • Hi Felipe, 


    I will need help from our Mobile app team to answer most of your questions and get back to you. 

    I can try to answer question 1 though.

    At step 5 I would assume it's when the MCUBoot start the swapping process. The process involve erasing page by page of both Primary Slot and Secondary Slot and copy the image page by page from one slot to another slot. 
    This actually can take a lot of time considering erasing one page would require up to 90ms. And this is not include the calculation time needed to verify the hash of the image. The larger the image the longer it takes. 

    In the last question I assume you mean "your own code" not "won code" ?

Reply
  • Hi Felipe, 


    I will need help from our Mobile app team to answer most of your questions and get back to you. 

    I can try to answer question 1 though.

    At step 5 I would assume it's when the MCUBoot start the swapping process. The process involve erasing page by page of both Primary Slot and Secondary Slot and copy the image page by page from one slot to another slot. 
    This actually can take a lot of time considering erasing one page would require up to 90ms. And this is not include the calculation time needed to verify the hash of the image. The larger the image the longer it takes. 

    In the last question I assume you mean "your own code" not "won code" ?

Children
  • Hi Hung, 

    Thanks for your prompt response. 

    Awesome, So we should then wait for the mobile team to get back to us in regards to question 2 and 3. 

    In regards to the last question (Apologies for the typo) , since the answer in question 1 is that it may take reasonably long to perform these actions, I would want to be able to somehow ( Since at that instance the device will appear unresponsive to the user ) notify the user that the operation is happening i.e ( LCD Display  or a GPIO toggle etc. ) is this possible ? 


    Cheers,  

    Thanks

  • Hi Felipe, 
    I haven't implemented the hooks myself but what I can see from the code is that you would need to add your own function named  mcuboot_status_change() into mcuboot. 
    If you look into \bootloader\mcuboot\boot\zephyr\main.c you can find that it will call mcuboot_status_change() on each stage of the mcuboot process: 

    As far as I know this function should be implemented in mcuboot, not in your application because your application will not run when the Mcuboot is doing its job. 

  • Hi Hung, 

    I had a look at ncs/v2.0.0/bootloader/mcuboot/boot/zephyr/main.c and I find no references to mcuboot_status_change() also line numbers do not match as shown below, we must be looking ad different versions of ncs. 

    Also, Is there any way this might be achieved without having to modify the bootloader ? otherwise the whole idea of mcuboot hooks is lost. 

    What is Nordic's recommended way of achieving this indications from the bootloader ? 

    Cheers, 

  • Hi Felipe, 
    As far as I know mcuboot_status_change() and CONFIG_MCUBOOT_ACTION_HOOKS was only added from NCS v2.1.0 .

    You may want to consider upgrading to newer SDK.  

    I understand that you don't want to modify the bootloader. I'm checking internally if we have an example that doesn't need to do that. My understanding is that it should be possible to add the function in a file and then compile the mcuboot as childimage with the extra file. 

  • Hi again Felipe, 
    I got the suggestion from our colleague on how to do it (still you need to update to v2.1 or newer) 

    In CMakeLists.txt in boards/arm/your_board , you can add something like this:
    if(CONFIG_MCUBOOT)
    zephyr_library()
    zephyr_library_sources(my_mcuboot_hook.c)
    endif()
    Then place a my_mcuboot_hook.c, that has the mcuboot_status_change() function, in boards/arm/your_board

    By doing this you don't have to change mcuboot.