Oleg Skydan wrote:
I need to check the Flash checksum after the program start to be sure that
all is OK.
It is very simple to calculate the checksum, but the result should be stored
in the Flash
and this will result in checksum changes.
simply exclude the checksum from the sum. it is indirecly checked too as
you compare it to the sum.
e.g. for a 16 bit checksum/crc
int * expected = 0x1000;
sum = checksum(0x1002, 0xffff);
if (*expected != sum)
{
warn('i'm broken');
}
it's slightly different if it's not on the border of the available
flash. then you need a checksum function that can be called twice for
two parts of the flash around the checksum or it should skip the
location of the value.
the other question is, how do you get the checksum into the
elf/ihex/whatver file you download ;-)
several possibilities:
- firmware flashes it on first run (maybe not the prefered solution)
- production writes the value after flashing the firmware
- run the linker stage twice. 1st run with a dummy crc, then use a tool
to calcualte the crc of the file and then a 2nd link with the real
crc. you can define symbols for the linker with -D (or -Wl,-D...
when calling msp430-ld over msp430-gcc, which is prefered)
- have some tool that calcualtes the checksum of the object file and
patches it directly. patching an ihex file is easy (e.g. look at the
pyjtag tools, it contains code to read/write ihex)
chris