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

Using Zephyr NVS with mcuboot - losing configuration on firmware update

I've got my application wrapped in mcuboot for HTTP-based firmware updates which is working fine.  In the past couple days I've enabled CONFIG_NVS using the code in zephyr/samples/subsys/nvs for guidance.  The basic ability to save/load settings works fine, and values are retained around power cycles as expected.  However, I've not been able to save NVS settings around firmware updates, either locally via nrfjprog or remotely via mcuboot.

I am using the default partition manager settings for the nrf9160_pac10090/nrf9160_pac10090ns board, and am building my application targeting nrf9160_pac10090ns.

I double-checked the parameters I'm passing to nvs_init(), and I am using an offset of DT_FLASH_AREA_STORAGE_OFFSET (1024000) with 3 sectors of size 0x1000.  These values all seem to safely align with the FLASH offset/size ranges I'm finding in the generated DTS files in my build output directory, both for mcuboot and my application.

My libraries are all checked matching the manifest in NRF at tag v0.4.0.

I've noticed that the fs_nvs log shows slightly different values on reboot after a mcuboot swap, which makes me think mcuboot is touching the storage flash.

For example, after a full device erase, with nothing stored, I see this on bootup:

[00:00:01.819,976] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:01.825,744] <inf> fs_nvs: alloc wra: 0, ff0
[00:00:01.830,993] <inf> fs_nvs: data wra: 0, 0

After writing one value to NVS, I see this on bootup:

[00:00:00.457,641] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.463,409] <inf> fs_nvs: alloc wra: 0, fe8
[00:00:00.468,658] <inf> fs_nvs: data wra: 0, 5

And then, after mcuboot swap, I see this on bootup:

[00:00:00.453,277] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.459,045] <inf> fs_nvs: alloc wra: 1, ff0
[00:00:00.464,263] <inf> fs_nvs: data wra: 1, 348

Any suggestions on what I might be doing wrong or where to look next?

Related