_CHECKSUM_ADD_WORD method -> only works when all the addresses/sizes are a multiple of 2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_CHECKSUM_ADD_WORD method -> only works when all the addresses/sizes are a multiple of 2

1,398 Views
BasePointer
Contributor II
Hi to all,
 
I'm using _CHECKSUM_ADD_WORD method to verify program content.
It works nice unless the addresses/sizes of the segments are odd number.
I have to check and modify segments sizes(with additional NOPs) evertime I compile the application with some new codes.
 
I start feeling tired to do this. :smileysad:
 
Code:
/* _Checksum_CheckAreaWordAdd: word summation checksum of an aera */_CheckSum2ByteType _Checksum_CheckAreaWordAdd(_CHECKSUM_ConstMemBytePtr start, unsigned int len) {  _CheckSum2ByteType checkVal=0;  const _CheckSum2ByteType*...;  while (len > 0) { <-- problem is here, when len is odd, it is always being bigger than 0         checkVal = (_CheckSum2ByteType)(checkVal + (*ptr));    ptr++;        len-= sizeof(*ptr); <-- "len -= 2"  }  return checkVal;}

 
I tried to patch the function above in checksum.c. I couldn't succeed because the calculated checkVal value nerver match with linker's.

Please save me from this irritating process.
 
Thank you,
BP.
Labels (1)
0 Kudos
3 Replies

378 Views
BasePointer
Contributor II
 
Hi,
 
I patched the function to work at all condition like below:
 
Code:
  while (len > 1) { <-- patched         checkVal = (_CheckSum2ByteType)(checkVal + (*ptr));    ptr++;        len-= sizeof(*ptr); <-- "len -= 2"  }  return checkVal;

 
The return value checkVal doesn't match when len is odd. I think the linker uses different method to calculate checksum value than the function implemented in checksum.c when segment size is odd.
 
If I discover how linker calculate checksum value when segment size is odd, I believe we can patch the function in checksum.c.
For now, as an interim solution, I switched to CRC8 method that requires bigger flash area, needs more execution time, and less reliable than ADD_WORD method. These are three important parameters for my application.
 
Regards,
BP.
0 Kudos

378 Views
allawtterb
Contributor IV


BasePointer wrote:
Hi to all,
 
It works nice unless the addresses/sizes of the segments are odd number.
I have to check and modify segments sizes(with additional NOPs) evertime I compile the application with some new codes.

If you are doing a checksum with a size larger than a byte the address and number of bytes should be a multiple of this size. 
0 Kudos

378 Views
JimDon
Senior Contributor III
Try CRC_ADD_BYTE, CRC_8 or CRC_XOR_BYTE instead. The timings are within 1% of add word.

Since you have decided not to use one that has the required mathamatical theory behind it, I don't see that it much matters.





Message Edited by JimDon on 2008-04-14 12:27 PM
0 Kudos