Home/Support/Support Forum/checking the CRC (checksum) of a program
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

checking the CRC (checksum) of a program

0 votes
UL requires that we verify our software at runtime-- this means calculating the checksum of the section of memory that contains the program, and comparing it to a known value. Trouble is, including this known value anywhere in the source changes the resulting binary file/image in memory. A thread from 2003 (see bottom) suggests it's possible to manually append a checksum to a .bin file, then access that value from within the program. This seems like my best bet, but there are a few problems:

I'd have to use the RFU to upload the .bin, which means no debugging (big minus)

It's unclear how to calculate exactly where the appended value will end up in memory (prepending a 'magic string' to the value, then searching for that string, helps with this)

The value is difficult to obtain-- it must be recalculated every time the software is rebuilt, and I don't know how to get it simply by looking at the .bin file. It seems to me I'd have to run the code on the Rabbit and have it spit out the correct checksum over the serial port, then append that value to the .bin file

Is there a better way? Perhaps the .bin file already has a checksum built into it. Is there some document that specifiest the format of the .bin? Any documentation on the final/intermediate output of the Rabbit compiler, or tools that can manipulate such, might be useful here.

http://osdir.com/ml/hardware.rabbit-semiconductor/2003-04/msg00178.html
asked Feb 18, 2014 in Embedded Devices by machbaker New to the Community (1 point)

Please log in or register to answer this question.

2 Answers

0 votes
I have attached a short program which calculates a 16 bit checksum for an entire program in flash. You can use it as a basis for your requirement.

int ChkSumBuffer[256];
main ()
{
long TopOfProgram;
long FlashPointer;
int CheckSum, i,j;

TopOfProgram = prog_param.HPA.aaa.a.addr + (prog_param.HPA.aaa.a.base<<12);
CheckSum = 0; // init checksum value
FlashPointer = 0; // point to start of flash
while ( FlashPointer < TopOfProgram )
{ j = xmem2root ( ChkSumBuffer, FlashPointer, 512 );
for (i=0; i<256; i++) CheckSum += ChkSumBuffer;
FlashPointer += 512;
}
}
answered Feb 20, 2014 by MargaretK Veteran of the Digi Community (545 points)
0 votes
Another problem I was having, is that the checksum of the binary was changing every time I recompiled. I was able to resolve this by navigating to
options->project options->defines

and creating a new entry that says

_FIRMWARE_TIMESTAMP_=0x00

Cheers
answered Feb 28, 2014 by machbaker New to the Community (1 point)
...