Buttonless BLE DFU - nrf_fstorage_write() failed with error 0x4

In our product we have implemented buttonless DFU over BLE with the secure boot-loader (unbonded) on SDK 15.2. The bootloader is unmodified except for the addition of PA/LNA control.

We are undertaking pre-production testing of our product and have been using the Nordic DFU libraries for iOS/Android to push firmware updates to our beta testers. Most of the time DFU process completes fine but occasionally (maybe 1 time in 10) the DFU process is failing.

We've managed to replicate this in nRFConnect by repeatedly performing DFU until it fails - here's a screenshot of nRFConnect showing the same error we see reported in our app logs:

After the error the device remains in DFU mode until timeout. This is a problem as the user experience is terrible - as the device remains stuck in DFU mode the user has to wait two minutes (for the DFU timeout) until the application starts again and we can re-establish a connection from the app to the product. We do the firmware version check/update when the user opens our app to interact with the product so asking them to wait two minutes for the product to reset is far from ideal.

I enabled logging on the bootloader and managed to replicate the problem with the product attached to the debugger, here is what gets logged:

 app: Entering DFU mode.
 nrf_dfu_validation: Signature required. Checking signature.
 nrf_dfu_validation: Calculating init packet hash (init packet len: 58)
 nrf_dfu_validation: Verify signature
 nrf_dfu_validation: Image verified
 nrf_dfu_settings: Backing up settings page to address 0xFE000.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_dfu_flash: nrf_fstorage_write() failed with error 0x4.
 nrf_bootloader_wdt: Internal feed
 app: Inactivity timeout.

I think error code 4 means no memory which seems like an odd error to be occurring in the bootloader....

Any suggestions as to what might be causing the issue and how to mitigate it would be appreciated.

Parents
  • Hi,

    According to the documentation for nrf_fstorage_write(), when using the SoftDevice API for writing flash you get NRF_ERROR_NO_MEM if the internal queue of operations is full.

    I will try to explain what that means. The flash storage module puts all flash operations in a queue, and operations are initiated from that queue when the SoftDevice is ready for executing a new flash operation. If you get NRF_ERROR_NO_MEM a lot (as you do) you can increase the size of the queue, by increasing NRF_FSTORAGE_SD_QUEUE_SIZE in sdk_config.h.

    Note that flash operations halts the CPU, and so the SoftDevice must have available time slots for scheduling the operation. Erase operations in particular take long time to complete and so are hard to schedule. This means depending on SoftDevice operation (for instance short connection interval), executing the pending flash operations may take quite some time. The bootloader example is tuned for working well, but if you make changes to SoftDevice operation you may end up in a situation where flash operations cannot be executed and the operation queue fills up faster than operations are handled.

    Regards,
    Terje

Reply Children