My K8x gets locked when programming. This is not a problem in a development environment, where I use Segger J-Link commands to unlock it. This is not viable in a production environment, with Over-The-Air (OTA) updates.
Flash_Config is unaltered from factory defaults - (FOPT = 0x3D, FSEC = 0xFE) - which I take to mean that the secure lock feature should not be in play. I do not use a mass erase because some data sections in internal flash may need to be preserved. To program the chip an OTA update package is sent to the device, and staged on external SPI NOR Flash. The package contains the target with a header - load address, length, and ECDSA (signature). The staged file is checked for integrity, and a RAM function erases sufficient 4K blocks, and then writes the target. The MCU is reset and the system reboots.
Except that sometimes it doesn't! Connecting J-Link I find the chip in a secure locked state.
What causes this, and how do I overcome it?