This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Flash Code protection

Other Parts Discussed in Thread: UNIFLASH

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.

  • Hello Galan

    There was a forum post where a user wanted to perform the same action. Can you use search to go through the forum posts: Key word "Flash Protect". I will also search for it.

    Regards
    Amit
  • Galan Ojaw said:
    please let me know what I am missing here?

    Two "majors" quickly come to mind:  (you're unlikely to be pleased...)

    • You are attempting to "secure" a dead, buried irreplaceable device.   Does that make sense?   (btw - yours IS an LX4Fxyz - NO LM4F were made!)
    • Just as on "Wall St." the regulators/law-makers (i.e. MCU vendors) are NEVER as smart, motivated, & well equipped/financed as those they (attempt) to regulate.   Those who want your code - will HAVE your code - of that there is NO DOUBT!

    MCU manual paints a, "too rosy picture" and neglects (entirely) the skill-level, funds, special equipment of those (paid) to defeat the ineffectual "bandaids" which this vendor (and others) employ to (try) to soothe their "less than fully aware" clients.

    The blocking attempt you've outlined (may) delay a novice hacker - but serious/skilled ones can "decap and/or x-ray" your device - your code then lies, "naked to the world."   And there are less costly methods - but perhaps the above gives you the sense of the "futility" of your (security) efforts.  

    In the past there were (perhaps still are) MCUs which were far more resistant to such invasive techniques - and their prices were (at minimum) an order of magnitude beyond what you pay here.

    As small tech firm owner I'm as vulnerable as you.   Best defense is to arrive in the marketplace EARLY - with sufficient, valued features - and price at the level which tends to discourage competition...