sketch self-delete in runtime

skylight

New member
Hi guys

I am working with teensy 4.0 and I programmed it with my sketch. A functionality of my project, is to detect tamper on a specific signal and then take action after that. Basically I want my current sketch (that is programmed on the board), to get deleted (or overwritten with dummy data or new empty sketch, etc) due to security reasons. Maybe like a self program, and of course the result would be a crash.
All I know is that my current programmed sketch is written somewhere in the flash memory of the board, but don't know where it is, if I have access to it, or how I can modify it this way.
Is there any way I can implement this in runtime?
I must also mention that lockable teensy is being used for the sketch.


Thank you.
 
for having more security. In general I am wondering if it's possible. If not, why and if so, how.

Thanks Paul
Yes, I think it is possible. Your programs have access to the program flash, which begins at address 0x6000'0000. If you look in cores\Teensy4\eeprom.c, you will find a function to erase a sector. If you erase the sector at the base address and then do a soft reboot, I think that would hang the Teensy, with the only way to recover to reprogram via the bootloader.
 
Yes, I think it is possible. Your programs have access to the program flash, which begins at address 0x6000'0000. If you look in cores\Teensy4\eeprom.c, you will find a function to erase a sector. If you erase the sector at the base address and then do a soft reboot, I think that would hang the Teensy, with the only way to recover to reprogram via the bootloader.
I'll see what I can do. Thanks a lot!
 
Use FASTRUN on your erase function, so it's allocated in RAM. Hopefully that can prevent the inevitable crash long enough to allow accomplishing all the memory erase you want.

After erasing, remember the CPU caches will still hold some info. You can do special low level stuff to delete the cache, or just soft reboot (which will fail to boot up). If you erase the flash so no valid program is found, keep in mind you will need to press the pushbutton on Teensy to recover. Automatic upload only works if a previously loaded program is still successfully implementing USB communication. Without USB working, your PC can't ask Teensy to go into programming mode. You will need to press the pushbutton.
 
Back
Top