[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!

Related