We want to lock the top half of our flash contains some NMV RO config information, the bootloader and CCFG. Everything from 0x0009 C000 to 0x000B 0000.
I am using FlashProtectionSet() to first set the FLASH_WRITE_PROTECT (read it back with FlashProtectionGet()) and then FlashProtectionSave() to save it to CCFG. The FlashProtectionSet and FlashProtectionGet both seem to work, after Setting, the Getting shows its locked. Obviously it does not persist over a reset.
However, I then pass the same offset to FlashProtectionSave and sometimes it returns successful and sometimes error. The CCFG reflects the returned value.
Sector 0x4e (0x0009c000) is RO
Sector 0x4e (0x0009c000) save success
Sector 0x4f (0x0009e000) is RO
Sector 0x4f (0x0009e000) save success
Sector 0x50 (0x000a0000) is RO
Sector 0x50 (0x000a0000) save success
Sector 0x51 (0x000a2000) is RO
Sector 0x51 (0x000a2000) save success
Sector 0x52 (0x000a4000) is RO
Sector 0x52 (0x000a4000) save fail
Sector 0x53 (0x000a6000) is RO
Sector 0x53 (0x000a6000) save fail
Sector 0x54 (0x000a8000) is RO
Sector 0x54 (0x000a8000) save fail
Sector 0x55 (0x000aa000) is RO
Sector 0x55 (0x000aa000) save success
Sector 0x56 (0x000ac000) is RO
Sector 0x56 (0x000ac000) save success
Sector 0x57 (0x000ae000) is RO
Sector 0x57 (0x000ae000) save fail
Sector 0x58 (0x000b0000) is RW
Sector 0x58 (0x000b0000) save success
I also have tried disabling the HWI and it is using the ROM functions in driverlib so I cannot walk through the code easily. Trying to the ROM debug define was unsuccessful and the program did not boot.
Code below:
// lock the RO NVS up to and including CCFG
// 0x9C000 - 0xB2000
for (sector = (MEM_NVS_RO_START / FlashSectorSizeGet()); sector < sectorCount; sector++)
{
uint32_t offset = sector * FlashSectorSizeGet();
FlashProtectionSet(offset, FLASH_WRI TE_PROTECT);
Hwi_disable();
cmd_printf("\tSector 0x%02x (0x%08x) is %s\n", sector, offset,
(FlashProtectionGet(offset) == FLASH_WRITE_PROTECT) ? "RO" : "RW");
uint32_t result = FlashProtectionSave(offset);
cmd_printf("\tSector 0x%02x (0x%08x) save %s (%u)\n", sector, offset,
(result == FAPI_STATUS_SUCCESS) ? "success" : "fail", result);
Hwi_enable();
}
cmd_printf("Bootloader and NVM RO locked\n");
Side question, to lock the CCFG memory I need to lock Sector 0x58, (0xB0000 - 0xB2000) correct? That is the sector above the end of the flash. Or do I need to lock the last available sector possible, which is sector 127 in CCFG? Should I just try to lock all sectors from 0x4e to 0xff even if they are not valid flash locations?