Device is secure?


It is one of these long weekends which allow to catch up on many things. One thing I finally completed was the move to FreeRTOS V7.1.1. With this I did some tests using the Tower boards, including the Kinetis one. So I have rebuild my Kinetis K60 application and was ready to flash the device. But then to my surprise I got this dialog:

Device is secure. Erase to unsecure?

Device is secure. Erase to unsecure?

Strange, I do not remember that I have secured that device. Actually I’m very careful not to secure any devices as this might be a permanent thing.

Most microcontroller offer different levels of protection, usually with special configuration registers and settings:

  1. Protect: the device or parts of it are protected against programming the flash memory. This is typically used to protect a bootloader or any parts of the device to be overwritten either by the debugger or by the application itself. To unprotect usually a configuration register has to be reprogrammed or the flash memory needs a mass erase.
  2. Secure: Access to the flash memory with an external tool or debugger is not possible any more. This used to protect the software on the device to be inspected or to prevent reverse engineering. To recover the device a mass erase typically has to be applied.
  3. Disable Mass Erase: This is probably the most dangerous option a device can offer for a developer. With this configuration set, it will not be possible to do a mass erase of the device. So if I combine ‘secure’ with ‘disable mass erase’, I will not be able to recover my device any more.

Depending on the device/flash features, CodeWarrior provides Protect/Unprotect and Secure/Unsecure target task actions for the flash programmer.

For this I have the Target Tasks view open (menu Window > Show View > Other > Debug > Target Tasks). In that view, I can create a new Target Task with the ‘import’ button:

Import Target Task

Import Target Task

Then I go to  <installation path>\MCU\bin\plugins\support:

Flash_Programmer inside MCU\bin\plugins\support

Flash_Programmer inside MCU\bin\plugins\support

Then I go inside the Flash_Programmer folder and select the XML file matching my device:

Selecting flash file

Selecting flash file

Then I can double-click on the newly created Target Task and change/configure it:

Flash Programmer Task

Flash Programmer Task

And in that dialog I can add more actions:

Protect/Secure Target Task Actions

Protect/Secure Target Task Actions

The problem is that during development it can happen that I write wrong settings to my device, and with this accidentally secure it. And if my wrong settings as well include ‘disable mass erase’, I’m really doomed. And unsoldering a CPU from a board is not something easy if has >100 pins or is a ball grid array device type :-( .

Back to my dialog from the beginning:

Device is secure. Erase to unsecure?
Device is secure. Erase to unsecure?

So it looks I might have accidentally secured my device? I pressed ‘Yes’, but unsecuring failed again, resulting with the same dialog. Tried it again: same thing. Oh, oh! Could it be that the ‘disable mass erase’ bit is set as well? That would be really bad. I only have that single Kinetis K60 board. Wait! I have as well the Kinetis K60F (Kinetis K60 with floating point using an Cortex-M4F) on my desk. And here was my problem: the OSBDM debug cable was not connected to the TWR-K60N512, but instead to the TWR-K60F120M one!

Which board I'm debugging?

Which board I’m debugging?

Connecting the correct TWR-K60N512 one to my host machine, and I was able to download my application :-) .

Lessons learned, in priority order:

  1. Connecting to the wrong device might trigger a false alarm about the device being secured.
  2. Carefully check to which board/device I’m connecting.
  3. Cleanup my desk and reduce the number of boards, power supplies and USB cables on it.

Interestingly, my wife only agrees to point 3.

PS: My desk is still not close to the famous one of Jim Williams of Linear Technologies group. Or as commented in this EEtimes article : “A clean desk is a sign of empty mind”.

Happy Unsecuring, and Cleaning :-)

About these ads

20 thoughts on “Device is secure?

  1. Pingback: Killing Me Softly: Zombies and Debugger Engines | MCU on Eclipse

  2. Hi Erich

    I am getting this same problem. I can load a small program but cannot load my main program of 94k. I was working with trying to set up a bootldr and think something was changed incorrectly. Can you tell me where the options are you mention above. I have looked and can not find the flash programmer in cw10.3 with these options?

    Thanks

    Robert

  3. Hi Erich

    Thank you, that was very helpful, it also show more of about the plugins. I checked this but I do not see how to use the programmer. Is this this called automatically as part of a debug configuration, or is the programmer run separately.

    Also when I call up the protect/unsecure option for the k20dx256z, it shows that all the address’s are set to unsecure. But a windows comes up saying the device is secured, the consoles says that it is unsecuring the device, then fails on a write. This only happened after I tried implementing the bootldr apps, 4367,68,70.

    I have tried looking into the memory protect registers but don’t see anything different.

    Do you know of anyway just to reset/erase the device using the programmer plugin or any other way? I know if the disable mass erase is set, the game is over; that bit could have been set by a mistake in the lcf file build. I once had a system, now I don’t. The problem is this is a custom board and the only one that is/was working.

    Thanks

    Robert

    • Hi Robert,
      the target task is not used for Kinetis as part of the debugger download. It is used for ColdFire V2. You can run the target task independently of a debug session, as your probably have found out.

  4. I found the problem. Something became corrupted in the mqx installation. Even though my application and all the middleware components built without error. My quess is that the loader was loading memory incorrectly offset from the allowed boundaries, ie 32 byte boundaries. I restored mqx from my oct 15 backup, and it all worked again. But this was after I had changed out a 100 pin processor because of this error and now I have found this was not anything related to hardware or the memory protect registers. This is a bad design in the debug component loader; the error messages are inconsistent and misleading.

    But I would still like to know how to run the programmer plugin as a target task if possible. Mine is greyed out.

    Thanks

    Robert

  5. Pingback: Unsecuring the KL25Z Freedom Board | MCU on Eclipse

  6. Hi

    I have the same problem.. I have tried what you have written, but nothing works.. My board is TWR-K60F120M.
    But no matter what i do i get the message “Device is secure. Erase to unsecure?”
    I am just trying to get one of CW small example codes to work..

    Thanks

      • I have had the same thing, many, many times. What I have found that works sometimes (usually for me) is to create a new debug configuration. I think that the database/files for the configuration in Eclipse becomes corrupted. The debug system is a spawned process and a third party one as well, sometimes it just hangs, other times I get the ‘Device is secure’ message. Also you may need to go into Task Manager and delete the “DE” process on CW10.2 and “DE & DE monitor” on CW10.3.

        Robert

      • In case the P&E layer/debugger is not able to talk to the device (or better: if the device does not respond), then the ‘device is secure’ dialog comes up. Beside of having the device really secured :-( , it happened to me as well in case the power supply was somewhat flaky, or when I tried to debug the wrong device. That of course could happen as well in case the debug configuration is wrong/corrupted.

  7. Hi Erich, Can you provide any reference to where I can find instructions to apply security(read protect) to my KL15 MCU? As seen in one of the screenshots above, the secure/unsecure option is grayed out. Wondering why?
    Do I have to write a long word value to the .cfmprotect region declared in the linker file?
    I am not trying that method fearing i might lock out my MCU. What is a proper way to do it?

      • Thanks for the link. But I think the script is intended for unlocking secured devices. My query was regarding __securing__ the MCU. More specifically,
        “What is a good way of loading values in the Flash Configuration Field so that my MCU is secured and the flash is not readable”.

        I am guessing I have to write the values in an array and use the linker to place it at the Flash Configuration Field address. Something like this…

        const uint8_t FCF_Reg[]__attribute__((section(“.cfmprotect”)));

        is my understanding correct? Sorry to ask simple questions, but i dont want to try something wrong and lock up my MCU :)

      • Yes, I misread it the first time (sorry, had probably not enough coffee early this morning :-) ). Your thinking is correct, I would do it the same way.

    • Hi Safwat,
      the proper way to secure an application in my view is to have the security word programmed in the application binary (at least that’s how I do it). But there are other options, especially as securing only applies to production programming. Either the production programmer does support this (writing sepecial bytes), or the other way is to combine two S19 files into one: one S19 file contains the bytes for security enabled, plus the application S19 file.

      • Thanks Erich. I think i will have it in the application binary so that they only have to burn one binary during production.

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s