keep Settings Data and existing bonds during OTA update - nRF Connect SDK

Hi,

SoC: nrf52840
Environment: nRF Connect SDK v2.4.1

When performing OTA app upgrade all settings and bonds are gone.
Settings subsystem seems to be working fine. Settings are corrently loaded at startup and data is preserved during MCU reboot. Data is also preserved when flashing app via SWD.
Is there any configuration that I am missing, which can preserve at least Settings during OTA?

prj.conf:
# Settings
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y

#MCUMGR
CONFIG_MCUMGR=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_SECURE_BOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP=y

code:
settings_subsys_init();
settings_load();

Regards,
Simon

Parents
  • Hi, 
    Please provide the partitions.yml in the build folder or the pm_static.yml if you are using static partitions. Please provide the file for both the old project and the new project that you are updating to. 
    I suspect that the partition was changed and somehow overlapping the setting partition. 

    Do you change anything that may change the partition allocation ? 
    How do you receive the image ? Did you use the smp_svr ? 

  • Hi,

    here is partitions.yml content. I don't use static one. Content of the partitions.yml is the same between the builds. There is basically no difference between the "old" and the "new" project as I am testing update proces just between the builds.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    EMPTY_0:
    address: 0x15200
    end_address: 0x16000
    placement:
    before:
    - s1_pad
    region: flash_primary
    size: 0xe00
    EMPTY_1:
    address: 0x22200
    end_address: 0x23000
    placement:
    before:
    - mcuboot_pad
    region: flash_primary
    size: 0xe00
    EMPTY_2:
    address: 0xfd000
    end_address: 0xfe000
    placement:
    after:
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Do you change anything that may change the partition allocation ? 

    This is hard to answer. I might changed something unintentionaly.

    How do you receive the image ?

    Image is generated with default build task, generated by nRF Connect vscode plugin.

    For OTA update I used "app_update.bin" file from build/zephyr/ directory.

    Did you use the smp_svr ? 

    I am using mcumgr SMP:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #include <zephyr/mgmt/mcumgr/transport/smp_bt.h>
    ...
    int main(void)
    {
    ...
    smp_bt_register();
    ...
    }
    # sleep/shutdown
    smp_bt_unregister();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Maybe it's worth mentioning that I also tried to enable Direct XIP without success. I get similar issue as described here:

    https://devzone.nordicsemi.com/f/nordic-q-a/102186/partition-manager-error-w-direct-xip-and-mcuboot-enabled

  • Hi Simon, 
    If you have an identical partitions.yml then the partition may not be the culprit here. 

    I suspect that there could be change in the setting module that may change the layout of the setting data. Causing the data mismatch. 
    Have you tried to read the setting flash area out before the settings_subsys_init() is called in the new firmware (maybe putting an infinite loop there, then read flash using nrfjprog.exe --memrd or nrfjprog --readcode). You would need to read flash at address 0xfe000. 

    You may want to compare the flash before and after DFU update to see if the setting area is overwritten or not. If the content doesn't change, then it must be something changed in the settings layout causing it not able to read the bond information. 

  • Hi,

    I saved settings area before upgrade and then added hardcoded asm breakpoint instruction at the beggining of int main(void). With this image I made DFU update and read the same settings area after the update. It seems that DFU erased "settings_storage" section completely. 

  • Hi Simon, 

    I think I know why that happens. 
    Are you using nRF Device Manager for updating ? 
    There is an option which is enabled by default that erase the application settings: 

    If you click on the small arrow button in Firmware Upgrade , you will find the option to not to Erase application settings. 
    In nRF Connect app this setting is hidden in Settings/Mcu Manager options/Erase application settings

    Could you please disable it and try again? 

Reply
  • Hi Simon, 

    I think I know why that happens. 
    Are you using nRF Device Manager for updating ? 
    There is an option which is enabled by default that erase the application settings: 

    If you click on the small arrow button in Firmware Upgrade , you will find the option to not to Erase application settings. 
    In nRF Connect app this setting is hidden in Settings/Mcu Manager options/Erase application settings

    Could you please disable it and try again? 

Children
  • Hi,

    I am using nRF Connect mobile app and I was not aware of this setting as nothing is shown during DFU update process.

    I can confirm that everything works fine if I disable this option.

    Thanks for your support!

  • Hello, I have the same problem and the workaround works for me.
    But can't you protect the settings from being deleted via the OTA update?

  • I have now found a solution to prevent deletion via BLE directly in the firmware.

    You can disable support for this by switching off the function via CONFIG_MCUMGR_GRP_ZBASIC_STORAGE_ERASE=n or the entire SMP group 63 "Zephyr Management Group" via CONFIG_MCUMGR_GRP_ZBASIC=n (erase storage is currently the only function in the group anyway).

    Notes: I had originally tried to solve the problem with MGMT_EVT_OP_SETTINGS... hooks, spent a lot of time and recorded BLE via Wireshark to find out that the SMP group 3 "Settings (Config) Management Group" not used.

    I also found when looking through the source code that there are no hooks for the SMP group 63 "Zephyr Management Group" where you could intervene in the process.