[nRF52840df] Protect Specific UICR Registers from OTA Overwrites Without Modifying Bootloader Code

I’m currently working on a project where I need to protect specific registers in the UICR (User Information Configuration Registers) from being overwritten or erased during an OTA update. These registers contain important configuration data, and I need to ensure they remain intact throughout the update process.
Specifically, I want to protect the following UICR registers:

  • NRF_UICR->CUSTOMER[0]
  • NRF_UICR->CUSTOMER[1]
  • NRF_UICR->CUSTOMER[2]


I have made it work by modifying the nrf_dfu_settings_additional_erase() function:


ret_code_t nrf_dfu_settings_additional_erase(void)
{
ret_code_t ret_code = NRF_SUCCESS;
static uint32_t settings_backup[DFU_SETTINGS_PEER_DATA_OFFSET / 4];     // ADDED

// Check CRC for both types.
if ( (s_dfu_settings.peer_data.crc != 0xFFFFFFFF)
|| (s_dfu_settings.adv_name.crc != 0xFFFFFFFF))
{
NRF_LOG_DEBUG("Erasing settings page additional data.");
memcpy(settings_backup, (uint32_t const *)BOOTLOADER_SETTINGS_ADDRESS, sizeof(settings_backup));     // ADDED
// Erasing and resetting the settings page without the peer data/adv data
nrf_nvmc_page_erase(BOOTLOADER_SETTINGS_ADDRESS);
nrf_nvmc_write_words(BOOTLOADER_SETTINGS_ADDRESS, (uint32_t const *)&s_dfu_settings, DFU_SETTINGS_PEER_DATA_OFFSET / 4);     // ADDED
}

return ret_code;
}


But I do not want to modify neither any Nordic library code nor the bootloader, as I have several products already in the field and changing the bootloader could cause compatibility issues. My goal is to find a way to ensure these UICR registers are protected after an OTA update, without affecting the rest of the bootloader or other configurations.
I’ve considered using the NRF_NVMC functions to configure write protection, but I want to confirm if there’s a configuration in the SDK that allows this, or if it’s only achievable by modifying the bootloader itself.
Has anyone worked with this scenario before? Is there a way to protect just the specified UICR registers without impacting the bootloader or the OTA process? All that I found here seems outdated or deprecated. Maybe I’m struggling with the search, but I couldn’t find any recent or relevant information on this topic.
Any guidance or suggestions would be greatly appreciated!

Parents Reply Children
  • Thanks for the reply! But for some reason, the UICR information on my devices is being erased after OTA, and I cannot modify any bootloader settings on devices that are already with clients.. The only solution I found was making the changes I showed above, and after these changes, the problem stopped occurring. In theory, the UICR should remain unchanged after an OTA update, but that hasn’t been the case for me, as it keeps getting erased. I would prefer not to modify any Nordic libraries to work around this issue. Is there any other alternative?

  • Hi!

    We don't see how your changes affect the UICR registers.

    Pedro Arthur said:
    the UICR information on my devices is being erased after OTA

    Our bootloader won't do it.

    And if you enable APPROTECT, uicrerase is not possible.

    Maybe you have done some modifications in your code that deletes the UICR.

     

Related