problem: i want to make sure that every time the program is executed by the mcu, my code is as expected, and has not been changed (partially) or been corrupted in some part.
currently i'm thinking about storing checksum/crc value in some ROM place.
please recommend some of your methods for this problem and for code protection in general.
It's a common procedure using checksum/crc for the code program.
But what happens if the code which performs the CRC checking get corrupt and is not able to check further.
If that code is implemented in ROM rather than FLASH then it's OK. Very similar with microcontroller that has bootloader in ROM.
If the code memory size it's not an issue you can duplicate the code area like file allocation tables and use the other when first get corrupted.
what i intend to do is to have a checksum precalculated, and store it somewhere in the flash.
whenever the program starts, it will calculate the checksum again on its own code ((by reading out from the flash), and compare this with the precalculated value. if not equal, the program should stop.
one possible issue is that the time for calculating the checksum when startup may be quite long..