How to add BLE DFU to a NCS firmware application?

Dear Nordic experts,
 
Considering a Bluetooth Mesh application based on NCS 1.7.1 and running on an nRF52832:
What steps need to be done to add DFU over Bluetooth LE? Is there a user guide somewhere?  
 
Although there's quite some information on Bootloaders and Device Firmware Updates available, I'm still lacking the bigger picture of what exactly needs to be done.
 
Bootloaders:
If I understand it correctly, (and please correct me if I'm wrong) MCUboot is required for DFU over BLE.

If MCUboot is used, is the nRF Secure Immutable Bootloader (NSIB) really needed? Or would MCUboot alone be sufficient?
Available flash space is already getting low, and considering that the device is not connected to the internet (but only controlled through our own smartphone app), the risk of getting compromised is not a concern. Hence the idea to skip NSIB completely in favor of some additional Flash space. Under that circumstance, what bootloader(s) would you choose?

Any advise is very much welcome,
Thank you,
Michael.

 
 

  • Hi Mike, 

    It's possible to update from nRF5 SDK based application to nRF Connect application. Of course it's not straight forward but feasible. You can have a look at this case. After the update the original bootloader will be replaced by mcuboot (obviously because the softdevice is replaced)

    To compile with prj_minimal.conf, what I did was to simply back up the original prj.conf and rename the minimal file to prj.conf, but you can also do that with the config macro when building, by using "-DCONF_FILE='prj_minimal.conf'" if you build mcuboot directly, I'm not so sure how you do it when the mcuboot is a child image. 

    Regarding minimize the BLE stack, you can have a look at the prj_minimal.conf in the peripheral_lbs exmaple. However it's not a mesh application, so please try: 

    CONFIG_WATCHDOG=n
    
    CONFIG_PINMUX=n
    
    CONFIG_MINIMAL_LIBC_MALLOC=n
    
    CONFIG_BT_DEBUG_NONE=y
    
    CONFIG_BT_GATT_CACHING=n
    
    CONFIG_BT_GATT_SERVICE_CHANGED=n
    
    CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
    
    CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
    
    CONFIG_BT_HCI_VS_EXT=n
    
    CONFIG_BT_CTLR_PHY_2M=n
    
    CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
    
    CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43
    
    CONFIG_BT_BUF_EVT_RX_COUNT=2
    
    CONFIG_BT_CONN_TX_MAX=2
    
    CONFIG_BT_BUF_ACL_TX_COUNT=3
    CONFIG_BT_BUF_ACL_TX_SIZE=27
    
    
    CONFIG_BT_DATA_LEN_UPDATE=n
    CONFIG_BT_PHY_UPDATE=n
    
    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    CONFIG_STDOUT_CONSOLE=n
    CONFIG_PRINTK=n
    CONFIG_EARLY_CONSOLE=n
    
    CONFIG_LOG=n
    CONFIG_ASSERT=n

  • Thanks... again...

    The application still exceeds available flash by 40K.

    What an ironic joke: The firmware works perfectly under non stop stress test for more than 14 days. Last feature to add is DFU - what can possibly go wrong?!?

    Hung, please make sure there's a BIG RED WARNING SIGN added at Creating a new model telling that there's no way to get a custom model with BLE DFU onto a 512kb flash soc.

    Case closed.

  • Hi Mike, 

    With the following configuration I can see the size of the chat application is down to about 239kB. But I haven't tested that with SMP_SVR included how much it would increase in the size of application's flash.

    I agree with you that it's currently a blocking issue for DFU update nRF52832 running mesh. 
    We don't have a solution as off now besides trying to reduce the functionality of the stack, but it can't guarantee that it would fit for your application. 

    #
    # Copyright (c) 2020 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    # General configuration
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    CONFIG_HWINFO=y
    CONFIG_DK_LIBRARY=y
    
    # Bluetooth configuration
    CONFIG_BT=y
    CONFIG_BT_COMPANY_ID=0x0059
    CONFIG_BT_DEVICE_NAME="Mesh Chat"
    CONFIG_BT_L2CAP_TX_MTU=69
    CONFIG_BT_L2CAP_TX_BUF_COUNT=8
    CONFIG_BT_OBSERVER=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_SETTINGS=y
    
    # Disable unused Bluetooth features
    CONFIG_BT_CTLR_DUP_FILTER_LEN=0
    CONFIG_BT_CTLR_LE_ENC=n
    CONFIG_BT_DATA_LEN_UPDATE=n
    CONFIG_BT_PHY_UPDATE=n
    CONFIG_BT_CTLR_CHAN_SEL_2=n
    CONFIG_BT_CTLR_MIN_USED_CHAN=n
    CONFIG_BT_CTLR_PRIVACY=n
    
    # Bluetooth Mesh configuration
    CONFIG_BT_MESH=y
    CONFIG_BT_MESH_RELAY=y
    CONFIG_BT_MESH_FRIEND=y
    CONFIG_BT_MESH_ADV_BUF_COUNT=13
    CONFIG_BT_MESH_RX_SEG_MAX=10
    CONFIG_BT_MESH_TX_SEG_MAX=10
    CONFIG_BT_MESH_PB_GATT=y
    CONFIG_BT_MESH_GATT_PROXY=y
    CONFIG_BT_MESH_DK_PROV=y
    
    # Enable Bluetooth mesh models debug logs
    #CONFIG_BT_DEBUG_LOG=y
    #CONFIG_BT_MESH_DEBUG=y
    #CONFIG_BT_MESH_DEBUG_MODEL=y
    
    # Enable Shell module and use UART as a backend
    CONFIG_SHELL=y
    CONFIG_SHELL_BACKEND_SERIAL=y
    CONFIG_WATCHDOG=n
    
    CONFIG_PINMUX=n
    
    CONFIG_MINIMAL_LIBC_MALLOC=n
    
    CONFIG_BT_DEBUG_NONE=y
    
    CONFIG_BT_GATT_CACHING=n
    
    #CONFIG_BT_GATT_SERVICE_CHANGED=n
    
    CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
    
    CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
    
    CONFIG_BT_HCI_VS_EXT=n
    
    CONFIG_BT_CTLR_PHY_2M=n
    
    CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
    
    CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43
    
    CONFIG_BT_BUF_EVT_RX_COUNT=2
    
    CONFIG_BT_CONN_TX_MAX=8
    
    CONFIG_BT_BUF_ACL_TX_COUNT=3
    CONFIG_BT_BUF_ACL_TX_SIZE=27
    
    
    CONFIG_BT_DATA_LEN_UPDATE=n
    CONFIG_BT_PHY_UPDATE=n
    
    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    CONFIG_STDOUT_CONSOLE=n
    CONFIG_PRINTK=n
    CONFIG_EARLY_CONSOLE=n
    
    CONFIG_LOG=n
    CONFIG_ASSERT=n
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_BT_ASSERT=n 
    CONFIG_BT_ASSERT_VERBOSE=n 
    

  • Hi Hung,

    Thank you very much for your help. I've given up on NCS and started porting the firmware back to the nrf5 sdk for mesh, which seems to be the more future proof approach... Perhaps we'll add some more features in a future update, and then we would face the same issue again.

    Kind of a pity, I like NCS very much and it was a pleasant experience using it. Anyway, maybe for the next project.

    Again, thanks for your help,
    Michael.

Related