This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf9160: DFU of user application over serial

Hi

I am looking for a ways to perform DFU over serial, surprisingly i dont find any ways except this thread with no answers

https://devzone.nordicsemi.com/f/nordic-q-a/48154/9160---from-bootloader-updating-flashing-new-application-and-modem-firmware---how

This requirement is very critical for product where my device should be capable of performing firmware upgrade over serial.

Team NORDIC can you please elevate this case?

regards

KK

Parents
  • Hi again, Martin informed me you would like some more information on how to perform DFU over serial on the nRF9160 DK. 

    I just tried this and here's what I did. 

    Make a file called "nrf9160_pca10090.conf" and place it in /path_to-ncs/bootloader/mcuboot/boot/zephyr/boards/, and add the following lines to the file. 

    # Disable Zephyr console
    CONFIG_CONSOLE=n
    CONFIG_CONSOLE_HANDLER=n
    CONFIG_UART_CONSOLE=n
    
    # MCUBoot settings
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    
    # MCUboot serial recovery
    CONFIG_MCUBOOT_SERIAL=y
    CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_0"
    CONFIG_BOOT_SERIAL_DETECT_PIN=6
    CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=0
    

    Then to load the bootloader configurations to the nRF9160 flash any application with the following config enabled to the chip. 

    CONFIG_BOOTLOADER_MCUBOOT=y

    Now, to put the device in serial recovery mode push button 1 on the device, while turning it on. 

    It is the config BOOT_SERIAL_DETECT_PIN that determines which pin puts it in serial recovery mode and the default is pin 6 which corresponds to button 1 on the DK. This can be changed by changing the configurations in the "nrf9160_pca10090.conf" file.

    For prerequisites, make sure you have the following installed on your computer:

    1. Download, install and make sure Go Language (1.7 or later) is in your system path.
    2. Install mcumgr command-line tool by issuing the following go get command:
      go get github.com/apache/mynewt-mcumgr-cli/mcumgr

    Now to flash the application to the device, just follow the steps under Updating FW in this tutorial,

     

    For reference, here is what I ran: 

    mcumgr --conntype=serial --connstring=COM23 image upload nrf9160_asset_tracker_dfu.bin
    mcumgr --conntype=serial --connstring=COM23 reset

    One thing to note is that when you connect the nRF9160 DK, three COM ports will show up. Make sure to use the COM port that is connected to the nRF9160 DK. To find out which one that is, just open a terminal emulator and see which COM port spits out debug info for the application running on the nRF9160. 

    For what images to use: you can either download precompiled binaries here and use the files in images_dfu_bin. Or compile your own application (making sure CONFIG_BOOTLOADER_MCUBOOT=y is set) and find the file to use in /build_folder/zephyr/app_update.bin.

    Let me know if you have any further questions! 

    Best regards,

    Heidi

Reply
  • Hi again, Martin informed me you would like some more information on how to perform DFU over serial on the nRF9160 DK. 

    I just tried this and here's what I did. 

    Make a file called "nrf9160_pca10090.conf" and place it in /path_to-ncs/bootloader/mcuboot/boot/zephyr/boards/, and add the following lines to the file. 

    # Disable Zephyr console
    CONFIG_CONSOLE=n
    CONFIG_CONSOLE_HANDLER=n
    CONFIG_UART_CONSOLE=n
    
    # MCUBoot settings
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    
    # MCUboot serial recovery
    CONFIG_MCUBOOT_SERIAL=y
    CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_0"
    CONFIG_BOOT_SERIAL_DETECT_PIN=6
    CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=0
    

    Then to load the bootloader configurations to the nRF9160 flash any application with the following config enabled to the chip. 

    CONFIG_BOOTLOADER_MCUBOOT=y

    Now, to put the device in serial recovery mode push button 1 on the device, while turning it on. 

    It is the config BOOT_SERIAL_DETECT_PIN that determines which pin puts it in serial recovery mode and the default is pin 6 which corresponds to button 1 on the DK. This can be changed by changing the configurations in the "nrf9160_pca10090.conf" file.

    For prerequisites, make sure you have the following installed on your computer:

    1. Download, install and make sure Go Language (1.7 or later) is in your system path.
    2. Install mcumgr command-line tool by issuing the following go get command:
      go get github.com/apache/mynewt-mcumgr-cli/mcumgr

    Now to flash the application to the device, just follow the steps under Updating FW in this tutorial,

     

    For reference, here is what I ran: 

    mcumgr --conntype=serial --connstring=COM23 image upload nrf9160_asset_tracker_dfu.bin
    mcumgr --conntype=serial --connstring=COM23 reset

    One thing to note is that when you connect the nRF9160 DK, three COM ports will show up. Make sure to use the COM port that is connected to the nRF9160 DK. To find out which one that is, just open a terminal emulator and see which COM port spits out debug info for the application running on the nRF9160. 

    For what images to use: you can either download precompiled binaries here and use the files in images_dfu_bin. Or compile your own application (making sure CONFIG_BOOTLOADER_MCUBOOT=y is set) and find the file to use in /build_folder/zephyr/app_update.bin.

    Let me know if you have any further questions! 

    Best regards,

    Heidi

Children
  • Hi Heidi,

    Thanks for the information, able to upgrade the firmware with above mentioned steps, i have following questions:

    • The new image is directly downloaded to slot0 as a result, if the download is interrupted the device doesn't have any valid image, so is there a way to boot old image if flashing fails?
    • Is there a way to trigger DFU from application rather putting the device to recovery mode physically and then pass control to MCUboot to swap the image to primary slot?

    Regards

    KK

  • Hi,

    kk2mkk said:
    The new image is directly downloaded to slot0 as a result, if the download is interrupted the device doesn't have any valid image, so is there a way to boot old image if flashing fails?

     If the download is interrupted, and the application is not able to mark itself as successfully booted it will revert back to the old application.

     

    kk2mkk said:
    Is there a way to trigger DFU from application rather putting the device to recovery mode physically and then pass control to MCUboot to swap the image to primary slot?

     Yes, this is possible but we don't have any sample code available to show you how. You could for example write a variable to flash that is read out by MCUBoot and makes it put itself in serial recovery. 

    Best regards,

    Heidi

  •  If the download is interrupted, and the application is not able to mark itself as successfully booted it will revert back to the old application.

    No, i tried couple of times its always struck in MCUboot, need to re initiate the download, but never boots old image.

    Yes, this is possible but we don't have any sample code available to show you how. You could for example write a variable to flash that is read out by MCUBoot and makes it put itself in serial recovery.

    No, my requirement is bit different, its like download the image to slot2 when my app is running, then pass control to MCUboot to perform the sanity/signature check and swap the image to slot0, is it doable?

    regards

    KK

  • Hi, 

    What I said below isn't correct for serial DFU, only DFU OTA. Sorry about that.

    For a serial DFU, if the download gets interrupted, the application on the device just won't work and you will have to start MCUBoot and reinitiate the process like you said.

    Do you have your own slot 2 to use as the secondary slot - or do you mean slot 1? If yes, and you're asking about a switch from the primary to the secondary slot, then what you describe is possible.

    I would also recommend using swap type BOOT_SWAP_TYPE_TEST, so you can revert back to the old image if the swap is unsuccessful. 

    If you aren't using dfu_target, remember to call 

    err = boot_request_upgrade(BOOT_UPGRADE_TEST);

    in zephyr/include/dfu/mcuboot.h

     
  • I tried to put "nrf9160dk_nrf9160.conf" in /path_to-ncs/bootloader/mcuboot/boot/zephyr/boards/ then DFU over UART works.

Related