checking the CRC (checksum) of a program

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.

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 = + (<<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[i];
FlashPointer += 512;

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