GCC linker is capable to generate elf file with a given value for UICR->APPROTECT register with a simple script:
/* Linker script with read back protection . */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
UICR (r) : ORIGIN = 0x10001000, LENGTH = 0x300
}
SECTIONS
{
.uicr : AT(0x10001208) ALIGN(4)
{
LONG(0xFFFFFF00)
} > UICR
} INSERT AFTER .text
INCLUDE "nrf52_ble_gcc.ld"
This feature allows generating "always protected firmware" in release configuration and unprotected in other configurations.
To use the script it should be refered in "-T" option of the linker step instead of the original script, e.g. -Tnrf52_ble_gcc_prot.ld
Perhaps, other toolchains have similar capabilities.
Please note, this example script is targeting nRF52 with SoftDevice. For other targets it may need some adjustments on the UICR addresses and the
