Hello,
I would like to protect the embedded code in the micro controller, (LM4F211H5QR), from being read (executable only). I followed an application (Application Report SPMA044A – August 2012 ), and first thing was to place literals and other constants in a specific flash address with read/executable properties, and place .text in another section with executable only property. I Am using CCS and here is what I changed in the linker command file:
#define APP_BASE 0x00000000
#define RAM_BASE 0x20000000
MEMORY
{
FLASH_VEC (RX) : origin = APP_BASE, length = 0x0000800
FLASH (X) : origin = 0x00000800, length = 0x00010000
FLASH_CON (RX) : origin = 0x00010800, length = 0x0002F800
SRAM (RWX) : origin = 0x20000000, length = 0x00007FFF
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > FLASH_VEC
.text : > FLASH
.const : > FLASH_CON
.cinit : > FLASH_CON
.pinit : > FLASH_CON
.vtable : > RAM_BASE
.data : > SRAM
.bss : > SRAM
.sysmem : > SRAM
.stack : > SRAM
}
Also in main.c I created the following function:
void vProtectFlashSectors(void)
{
int protect_pages = 31; // 31 * 0x800
uint32_t Code_base = 0x00000800;
unsigned char ucI;
for (ucI = 0; ucI < protect_pages; ucI++)
{
FlashProtectSet((Code_base+(0x800*ucI)),FlashExecuteOnly);
}
// FlashProtectSave();
}
The questions I have are the following:
Where should this function be called from? in main.c or need another application that calls this routine?
I tried it from main.c at run time, and the application hung. Found out it was stuck in the hard fault ISR forever loop. Tried power cycling device but it remained locked.
Used UniFlash application to erase flash and recover device.
Could anyone please let me know what I am missing here and how to do the code protection? This seems an easy problem, but haven't found any literature showing the steps clearly and producing functional result.
Thanks in advance for your time and consideration.