2024-02-23 06:48 PM
I have an STM32H745 (Dual Core).. I'd like to verify the integrity of the M7 Core's Flash memory.
Is there any built in way of getting the checksum (perhaps something that St-Link Cube Programmer uses), or is the only way to write my own function?
2024-02-23 08:37 PM
There is no standard functionality for this. The only way is to write your own function.
2024-02-23 10:04 PM
Nothing built in, nothing used on debugger.
You could set some sectors on MCU flash to R/O (to avoid it is overwritten): via debugger you could remove the "write locks" before you program again a new image. But anybody can still do (knowing the "trick").
You can generate a checksum after the BIN/EFL was created. And you can append this checksum to the BIN/ELF file. When you flash it into MCU - the checksum is also stored there.
In order to find the checksum easier (it would be always on a different address): you can decide to store such a cheksum on a reserved and dedicated address location.
But:
What you are potentially looking for is "Trust Zone" support. Check out MCUs with Trust Zone (e.g. STM32U5A5 and others). Or at least, check if you can set "Flash Lock Bits" via debugger (not really "secure": anybody can also remove again the lock bits).
Or: check if MCU has CRC features, e.g. to "protect" memory content via CRC checksums (and ability to correct bit errors). You would enable to use CRC and potentially you can query the MCU internal registers "if there was an CRC error correction needed". But you cannot repair the entire memory: if too many address locations are corrupted - nothing will work anymore as expected.
You are looking for "Trust Zone" and maybe "Tamper Protection": make it impossible that anybody can reflash or even read the flash content ("Secure Flash") or if somebody tries to "break in", e.g. via a debugger, tracing your code, reading your data in memory - you can let erase all data so that an intruder cannot find anything.
Check out the STM32U5x MCUs - they have all these "security" features.
2024-02-24 01:23 AM
STM32H7 have a special command in the flash controller that calculates CRC of selected flash range. But IIRC there's some errata rendering it unusable. See HAL_FLASHEx_ComputeCRC