Hello all,
I am developing a custom application on a Ruuvi tag with nrf52830 ic. I am using the latest sdk17 and softdevice s132 7.0.1. I am having problems updating the bootloader/sd/app from the original stock ruuvi fw that is based on sdk12.3 and has sd 3.1.0.
I have built my own bootloader using the dfu/secure_bootloader/pca10040_s132_ble_debug example with only minimal modifications. My application is based on the ble_peripheral/ble_app_template example.
I have tested the bootloader+sd+app combo by using mergehex and flashing via them all via the nrf52dk + nrfjprog.
This does not work when updating BL+SD+APP via DFU. I have managed to update the stock Ruuvi tag bootloader with the secure_bootloader example over DFU (BL + SD), and I have managed to also flash my application over the DFU using the new bootloader, however, the application fails to start with the following error:
<error> peer_manager_pds: Could not initialize flash storage. fds_init() returned 0x860A. <error> peer_manager: pm_init failed because pds_init() returned NRF_ERROR_STORAGE_FULL.
And here is where it fails exactly in fds.c:
fds_init_opts_t init_opts = pages_init(); switch (init_opts) { case NO_PAGES: case NO_SWAP: return FDS_ERR_NO_PAGES; <...>
After reading through many posts with related fds page issues, I have come to the understanding that the reason fds_init() fails is that it cannot find any flash pages marked as empty/unused (as, i assume, nrfjprog --eraseall marks everything with some magic values). I am unable to find good information on how to erase the application data memory when updating via DFU.
The discussion here https://devzone.nordicsemi.com/f/nordic-q-a/28076/sdk-13-0-fds_init-causes-errors-unless-doing-a-full-flash-erase hints that the NVMC driver can be used to erase the flash data pages before running fds_init().
I have also added #define DFU_APP_DATA_RESERVED (CODE_PAGE_SIZE * 3) (as mentioned here https://devzone.nordicsemi.com/f/nordic-q-a/52581/fds_err_no_pages-problem) to my bootloader's sdk_config, which did not change anything.
My view is that there are two solutions for this, 1) have the flash be erased when doing an update via DFU (something similar to a partial nrfjprog --eraseall), or 2) Erase all application data from flash on first boot (or when the error occurs). I cant find definitive answers on how to do either of these. I believe no. 2 would be fairly straightforward, but im not quite sure what SDK funcitons to use for erasing flash, nor how to exactly find the bounds of the app data.
I would really appreciate any help and guidance with this issue.