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

How to make sure that the Bootloader starts in DFU mode if a valid app is not present?

Hi,

I am trying to implement a Single Bank DFU over Bluetooth for my nRF51822 (256KB / 16KB RAM) using SDK v7.1 and Softdevice 110. I am using GCC to compile the bootloader and in order to switch from dual bank (which I was doing previously before my application size did not allow it anymore) to single bank mode, I changed from dfu_dual_bank.c to dfu_single_bank.c in the Makefile. The complied bootloader works fine as I can upload new firmware onto the chip using FOTA. But, if however the process is interrupted, the chip bricks and has to be flashed again.

I figured out that upon load, the bootloader checks if the app present in the chip is valid by comparing its crc16 checksum with the checksum saved in the bootloader settings. I believe that here lies my problem because if this check failed after an unsuccessful FOTA attempt, the chip should remain in DFU mode but that is not the case. Can anybody shed some light into where the problem may lie?

Any response is much appreciated.

-ashakya

  • Hi Hung, thanks alot for your continued and patient support. I was able to find the part of the code (at least its equivalent in SDK 7) that you mentioned in the last comment. In dfu_single_bank.c I always assumed that lines 341 and 342 were actually calling the functions that were being assigned to the function pointers(?) leading me to believe that dfu_cleared_func_app which sets the bootloader settings bank0 =BANK_INVALID_APP was being called.

    Therefore, now I added m_function.cleared() in line 367 after m_functions.prepare() which erases bank 0. This gives me the functionality I desire as a failed DFU will always set the chip to DFU mode. I don't know how it affects the rest of the bootloader functionality, but for my purposes where I only need to update the app, it is working perfectly.

  • Line 341 and 342 only assign the address of the functions into .prepare and .cleared so it can be called later on.

    If you look at my code and look for SINGLEBANK PATCHyou can find that one more thing I added was to delay the notification of BLE_DFU_START_PROCEDURE until we finish clearing the flash. This way we can let the master to wait until we finish clearing bank0. Please have a look at dfu_clear_cb_handler() here

  • Thanks for the heads up. I made the changes and so far the bootloader is working great.

Related