This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use nrfutil dfu ble with the DFU buttonless example?

I have some questions on using the nrfutil dfu ble with the buttonless example.

Should both devices (central and peripheral) be already bonded before starting the DFU process via nrfutil dfu ble?. Looks like they should not be bonded because the peripheral is reporting a Connection security failed message on the serial terminal. If I erase the bonds on the nRF52840DK by pressing one of push buttons and reset, and then issue the nrfutil dfu command, I see that the connection is secured on the peripheral. However, the nrfutil fails with the message below (see screenshot)

The nrfutil command I am using is

nrfutil dfu ble -p COM14 -pkg C:\Nordic\nRF5_SDK\nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_dfu_test_images\ble\nrf52840\softdevice_s140.zip -ic NRF52 -cd 0 -mtu 131 -a "DE9B5D58F3A7"

And the peripheral nRF52840DK is running the firmware ble_app_buttonless_dfu_with_bonds_s140_with_setting_page.hex

Parents
  • Hello,

    If you have not already, I suggest that you go through this guide. It is old, but still very useful. 

    I believe that the issues are related to bonding. If you follow the guide, you will see how to get started without bonding, and you can add bonding later, if you like. 

    I suggest that you do not use the precompiled .hex files, but compile and flash the examples, like it is described in the guide from the link.

    Apart from that, the nrfutil command that you used look good, but you can't use bonding if you use nrfutil directly (because nrfutil doesn't support bonding). However, you can do it from nRF Connect for Desktop -> Bluetooth Low Energy if you want to test that later when you have everything up and running without bonding. 

    Best regards,

    Edvin

  • Hi Edvin,

    I have the buttonless example working without bonding. I also have the same example working with bonding, but via the nRF connect desktop application.

    You had mentioned in your earlier response 

    Apart from that, the nrfutil command that you used look good, but you can't use bonding if you use nrfutil directly (because nrfutil doesn't support bonding).

    Does this mean that nRF Connect Desktop is the only way to perform DFU with bonding enabled?

    I know that nrfutil does not provide a way to pair/bond, but can you clarify whether it is possible to bond via nRFConnect desktop and then use the nrfutil to perform the DFU?

    I tried bonding with nRFConnect and then issued the nrfutil command, but I received an error below:

    nrfutil dfu ble -ic NRF52 -p COM14 -cd 0 -mtu 131 -n "Nordic_Buttonless" -pkg C:\Users\irtxxx\Desktop\buttonless_dfu_image_bonds.zip
    [------------------------------------] 0%2021-12-14 10:39:43,448 Exception: on_gap_evt_auth_status() got an unexpected keyword argument 'error_src'
    2021-12-14 10:39:43,450 <FrameSummary file c:\python\lib\site-packages\pc_ble_driver_py\ble_driver.py, line 2787 in ble_event_handler_sync>
    2021-12-14 10:39:43,450

    Traceback (most recent call last):
    File "C:\Python\Scripts\nrfutil-script.py", line 11, in <module>
    load_entry_point('nrfutil===6.1.X', 'console_scripts', 'nrfutil')()
    File "c:\python\lib\site-packages\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
    File "c:\python\lib\site-packages\click\core.py", line 1062, in main
    rv = self.invoke(ctx)
    File "c:\python\lib\site-packages\click\core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\python\lib\site-packages\click\core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\python\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "c:\python\lib\site-packages\click\core.py", line 763, in invoke
    return __callback(*args, **kwargs)
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\__main__.py", line 1205, in ble
    dfu.dfu_send_images()
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu.py", line 127, in dfu_send_images
    self._dfu_send_image(self.manifest.application)
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu.py", line 88, in _dfu_send_image
    self.dfu_transport.open()
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu_transport_ble.py", line 475, in open
    self.target_device_name, self.target_device_addr = self.dfu_adapter.connect(
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu_transport_ble.py", line 164, in connect
    self.jump_from_buttonless_mode_to_bootloader(DFUAdapter.BLE_DFU_BUTTONLESS_BONDED_CHAR_UUID)
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu_transport_ble.py", line 199, in jump_from_buttonless_mode_to_bootloader
    self.bond()
    File "c:\python\lib\site-packages\nrfutil-6.1.x-py3.8.egg\nordicsemi\dfu\dfu_transport_ble.py", line 327, in bond
    self.adapter.driver.ble_gap_sec_params_reply(self.conn_handle,
    File "c:\python\lib\site-packages\pc_ble_driver_py\ble_driver.py", line 106, in wrapper
    raise NordicSemiException(
    pc_ble_driver_py.exceptions.NordicSemiException: Failed to ble_gap_sec_params_reply. Error code: NRF_ERROR_INVALID_STATE

  • Hello,

    No, nrfutil has no way of fetching bonding data. Both nrfutil and nRF Connect are built on top of something called pc-ble-driver, which supports bonding, but you have to implement the part where you store the bonding data on the computer yourself. This is done in nRF Connect, but not in nrfutil. Since the data is stored on the computer (in the application) and not on the nRF, then the bonding data will not carry on from nRF Connect for Desktop to nrfutil. 

    I remember writing the previous answer in this ticket, asking myself whether to include a section/warning on bonding in bootloaders, so I'll throw it in now.

    If you require bonding in the bootloader, and something happens during the DFU process, so that the end users decides to delete the bonding information while the nRF has deleted the previous application, the device is bricked, because the bootloader requires bonding, but there are no devices that has bonding data for the nRF stored. Of course, normally, a DFU error can be restored, but if you have 10 000 devices, and say 100 fails on the first attempt of the DFU either due to a battery brown out, or an out of range issue, then it is not unlikely that one out of those 100 decides to delete bonding info to get a "clean start". Just keep that in mind.

    Another approach is to require bonding to write to the buttonless DFU characteristic. In that case, only bonded devices can put the nRF in DFU mode, and the bootloader is secure, so it is impossible to upload malicious FW. The worst case is that someone else connects when the device advertises as a DFU target, and tries to upload something, but in that case the bootloader will reject the wrong image because it is not signed correctly. So worst case you can keep trying until you get connected to the correct device.

    Now, that doesn't solve your bonding issue. If you require bonding on the nRF, you can't use nrfutil as-is. You need to write your own application that handles the bonding data.

    Best regards,

    Edvin

Reply
  • Hello,

    No, nrfutil has no way of fetching bonding data. Both nrfutil and nRF Connect are built on top of something called pc-ble-driver, which supports bonding, but you have to implement the part where you store the bonding data on the computer yourself. This is done in nRF Connect, but not in nrfutil. Since the data is stored on the computer (in the application) and not on the nRF, then the bonding data will not carry on from nRF Connect for Desktop to nrfutil. 

    I remember writing the previous answer in this ticket, asking myself whether to include a section/warning on bonding in bootloaders, so I'll throw it in now.

    If you require bonding in the bootloader, and something happens during the DFU process, so that the end users decides to delete the bonding information while the nRF has deleted the previous application, the device is bricked, because the bootloader requires bonding, but there are no devices that has bonding data for the nRF stored. Of course, normally, a DFU error can be restored, but if you have 10 000 devices, and say 100 fails on the first attempt of the DFU either due to a battery brown out, or an out of range issue, then it is not unlikely that one out of those 100 decides to delete bonding info to get a "clean start". Just keep that in mind.

    Another approach is to require bonding to write to the buttonless DFU characteristic. In that case, only bonded devices can put the nRF in DFU mode, and the bootloader is secure, so it is impossible to upload malicious FW. The worst case is that someone else connects when the device advertises as a DFU target, and tries to upload something, but in that case the bootloader will reject the wrong image because it is not signed correctly. So worst case you can keep trying until you get connected to the correct device.

    Now, that doesn't solve your bonding issue. If you require bonding on the nRF, you can't use nrfutil as-is. You need to write your own application that handles the bonding data.

    Best regards,

    Edvin

Children
No Data
Related