We do have a product in which we program a bootloader on the target. It is remotely based on the ble_app_buttonless_dfu example. The bootloader is not actually used in the end product, i.e. There is usually no occasion on which the bootloader is activated from the application, except if instructed to do so via UART (which should not happen in the production version of the product) and the application does not activate and use the Softdevice. Instead we are using the application solely for proprietary RF communication. The project uses SDK 15.3.0 with Softdevice 6.1.1.
Nonetheless, we observed that once in a while at some point in the product life cycle, the device seems to keep hanging in the bootloader. In the one device I have available for examination, I was able to single-step through the bootloader using a debugger and noticed that it started the bootloader because the check (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP)in nrf_bootloader.c succeeds. On further investigation, I noticed that the entire DFU settings and settings backup pages are consisting of zeroes (0x00), except for the CRC (s_dfu_settings.crc, 0xAC871054), the version (s_dfu_settings.version, 0x00000001), the app validation type (s_dfu_settings.boot_validation_app.type, 0x01) and, curiously, (adv_name.name[1], 0x01).
Looking at nrf_dfu_settings_init(), line 262 in nrf_dfu_settings.c, it looks like the settings pages get zeroed if neither the settings page nor the settings backup page are valid - and when the settings page gets written, the above values should be generated and written, too. Now the question is: how and why do the settings get invalid in the first place?
I was able to get the production logs from the EMS who flashed the device and the device seems to have been properly flashed, containing the correct, valid settings pages. From my understanding, the settings pages should not be touched unless the bootloader is actually used, so I can't imagine under what circumstances the bootloader settings pages may get invalidated... Additionally it looks like this particular device never actually booted into the application, because if it had booted into the application, the first thing done there is activating Access Point protection, which would prevent me from being able to connect using the debugger.
I dumped the flash of the device exhibiting this behaviour and compared it to a freshly flashed device (that has not yet reset and thus did not have access point protection yet) and the differences are:
- on the working device, page at 0x7E000 (presumably the settings backup page) has not been written (all 0xFFFFFFFF)
- the faulty device has a copy of the faulty settings as described above there.
- The working device has the presumably correct bootloader settings at 0x7F000
- The faulty device has the faulty settings as described above in said page.
So finally my questions:
- So with the setup as described, under what circumstances could the bootloader settings page become invalid?
- Under what circumstances do the bootloader settings and backup pages get erased / written at all?
- (When) are the bootloader settings pages protected by the bootloader using the BPROT registers?