Send dfu image between two nrf5340

Hi,

What is the best way to send image from one nrf5340 that is central to other nrf5340 that is peripheral in order to update him via 

MCUMGR
thanks
Parents
  • I added the echo command to my code.
    How to implement other commands?

    For example Reset or Upload the image?
    Where is an documentation for this(op,flags,id, payload types)?

    Thanks

  • I've now put the app_update.bin file into flash of the device running the central_smp_client sample, then I read out the first 32 bytes containing the image header and sends it to the device running the smp_svr sample. The smp_svr side sends an image upload response in return, with "rc"=0 and "off"=32.

  • Amazing.
    if it is ok i can also test it on my side, i have an image stored at the external flash that i downloaded and i can read data and send it.
    You can attach a code for this.


  • Check it out here: https://github.com/simon-iversen/ncs_samples/tree/master/central_smp_client_dfu 

    The code is really messy and not cleaned up at all. Sorry about that. I'm using nRF52840 DK on both sides by the way, but I don't think that should matter.

    1. Program the central_smp_client_dfu to one nRF5340 DK and the smp_svr sample to another nRF55340 DK (I used 52840 DK)
    2. Put the app_update.bin file into flash address 0xf6000 using jlink commander and loadbin
    3. Then press button 2 on the device running central_smp_client_dfu sample, to send the image upload command.

    Then you should receive 0x300c0101bf6272630636f66661820ff in response.

    You can see these bytes by adding the following piece of code to C:\v2.0.0\nrf\subsys\bluetooth\services\dfu_smp.c--notify_process()

    printk("Received %d amount of bytes\n", length);
    printk("Bytes: 0x");
    for(int x = 0;x < length; x++){
    	printk("%x", ((uint8_t *)data)[x]);
    }
    printk("\n");

    Currently I'm struggling to parse the response in the app itself (using this method). But using cbor.me I'm able to see that the received data corresponds to this:

    300c0101bf   â†’     ???

    627263          â†’      "rc"

    0                    â†’       0

    636f6666       â†’      "off"

    1820              â†’     32 (unsigned(32))

    ff                    â†’     end of packet I think

    So you can see that it contains rc=0 and off=32

    Let me know if you achieve any progress.

  • Now I'm able to parse the incoming image upload CBOR response in the central_smp_client sample. So to complete the image upload command, I just need to repeat the process and send all of image chunks.

  • Hi Guys, I need to integrate into my project an OTA update.
    I have a gateway (nrf52840) connected using UART to an external microcontroller to the cloud, and IoT nodes connected using BLE.

    I begin following one thread on devzone, and then the guys talk to me about your dev thread.
    I purpose to join together to make a def. guide as in Nordic Doc I always can't find the solutions to my problems Slight smile

    My idea was to get data from UART (as I connect the nordic to an ESP32 with AT commands for Wifi Connection) and then store them into flash, and after getting the file .hex from uart, restart the micro.

    Into the bootloader, pick up data from flash and store to the program memory zone, and after that, restart the micro and that's it.

    When the gateway is updated, the next step is to update also IoT node, but in this case, using the BLE and not the UART obviously.

    Using STM it's a child's play, using nordic everything seems to be impossible... is it the way you are proceding ?

Reply
  • Hi Guys, I need to integrate into my project an OTA update.
    I have a gateway (nrf52840) connected using UART to an external microcontroller to the cloud, and IoT nodes connected using BLE.

    I begin following one thread on devzone, and then the guys talk to me about your dev thread.
    I purpose to join together to make a def. guide as in Nordic Doc I always can't find the solutions to my problems Slight smile

    My idea was to get data from UART (as I connect the nordic to an ESP32 with AT commands for Wifi Connection) and then store them into flash, and after getting the file .hex from uart, restart the micro.

    Into the bootloader, pick up data from flash and store to the program memory zone, and after that, restart the micro and that's it.

    When the gateway is updated, the next step is to update also IoT node, but in this case, using the BLE and not the UART obviously.

    Using STM it's a child's play, using nordic everything seems to be impossible... is it the way you are proceding ?

Children
  • The solution I'm working on is intended for two chips running Zephyr/NCS, is that the case for you enpre

    MaximSh I was just able to successfully perform a dfu update using this central_smp_client_dfu and the smp_svr sample. I have not been able to implement the image list command, which is needed in order to get the hash of the new image, which is used to test and confirm the image.

    As a temporary workaround, I modifed the img_mgmt.c library in the following manner:

    diff --git a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c
    index 119906204c..e12bb3f0aa 100644
    --- a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c
    +++ b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c
    @@ -448,6 +448,10 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
     #endif
     		/* If this is the last chunk */
     		if (g_img_mgmt_state.off + req.img_data.len == g_img_mgmt_state.size) {
    +			rc = boot_set_pending_multi(0, false);
    +			if (rc != 0) {
    +				return rc;
    +			}
     			last = true;
     		}
     
    

    So on the smp_svr side, it will set the image as pending right after the update is complete. After doing this, after resetting the chip running the smp_svr sample, MCUboot saw the new update in the secondary slot and swapped it into the primary slot.

    In order for the update to not revert back, you should call boot_write_img_confirmed() from within the new updated image. Like it's done in the http application update sample

    I will continue to work with implementing the image list command.

    Best regards,

    Simon

  • Hey Simon, 

    Thank you for putting this together. Like @enpre, I was directed to this thread from another thread. 

    What Enpre and I are trying to do is download an image for nrf52840 over an LTE/WIFI chip (nrf9160 in my case) and then send it to the BLE chip over UART. I've been trying to follow this link to formulate a solution that works, but there's very little documentation that explains what's going on there. 

    So my question is - what modifications does your code need to be able to DFU over UART. I use a zephyr ncs code on my nrf9160 and an sdk17 based code on my NRF52840, but I am happy to port to ncs if it makes the OTA solution easier. 

    Also, thank you so much for helping out with this! 

  • Hi,
    Thanks. 
    Did you test it on sdk 1.9.1? 

  • I tested it on NCS v2.0.0.

    Yesterday I was able to receive and parse the image list response, which is required to run in order to get the image hash. I have not implemented it yet, but now it should be straigth forward to test/confirm the image from the app. What is needed to do next is to run the image list command after doing the update, then store the hash of the newly updated image, confirm/test the new update using the stored hash and eventually reset it using the reset command.

    After doing this + cleaning up the sample, the solution is complete

    Feel free to create a pull request on https://github.com/simon-iversen/ncs_samples/tree/master/central_smp_client_dfu 

Related