Checksum Help

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

Checksum Help

1,807 Views
rhb3
Contributor II
I'm trying to create a "firmware integrity" check by using the __CHECKSUM_IS_OK macro like the following:
 
Code:
    while (__CHECKSUM_IS_OK == FALSE) {        disp.dig[0] = '6';        disp.dig[1] = '0';        disp.dig[2] = 'R';        disp.dig[3] = 'E';        disp.led_q = 0x00;        disp.led_t = 0x00;        /* Keep machines running during delay! */        run_machine();    }

 
To test this, I use PROG12Z to corrupt (read change) the flash in a certain byte/word.  I then run verify to ensure it fails to ensure I've changed some flash.  My prm file is:
 
Code:
/* This is a linker parameter file for the MC9S12E128 */NAMESENDSECTIONS      /* List of all sections specified on the "Build options" tab */      RAM        = READ_WRITE 0x002000 TO 0x003FFF FILL 0xAA 0x55;   /* unbanked FLASH ROM */      ROM_FLASH  = READ_ONLY  0x3E8000 TO 0x3E83FF FILL 0x00 NO_CHECKSUM;      ROM_4400   = READ_ONLY  0x004400 TO 0x007FFF FILL 0x3F;      ROM_C000   = READ_ONLY  0x00C000 TO 0x00FEFF FILL 0x3F;   /* banked FLASH ROM */      PAGE_38    = READ_ONLY  0x388000 TO 0x38BFFF FILL 0x3F;      PAGE_39    = READ_ONLY  0x398000 TO 0x39BFFF FILL 0x3F;      PAGE_3A    = READ_ONLY  0x3A8000 TO 0x3ABFFF FILL 0x3F;      PAGE_3B    = READ_ONLY  0x3B8000 TO 0x3BBFFF FILL 0x3F;      PAGE_3C    = READ_ONLY  0x3C8000 TO 0x3CBFFF FILL 0x3F;      PAGE_3D    = READ_ONLY  0x3D8000 TO 0x3DBFFF FILL 0x3F;ENDPLACEMENT      SSTACK, DEFAULT_RAM             INTO RAM;      CHIMERA_FLASH                   INTO ROM_FLASH;      DEFAULT_ROM                     INTO ROM_4400, PAGE_3C, PAGE_3D, PAGE_38, PAGE_39, PAGE_3A, PAGE_3B;      RTOS, _PRESTART, STARTUP,      ROM_VAR, STRINGS,      NON_BANKED, COPY, .checksum     INTO ROM_C000;ENDINIT _EntryPoint   /* The entry point of the application. This function is generated into the CPU module. */STACKSIZE 0x0200

 
So I surmise the linker will check every used portion of flash (not 0x3A fill areas but actual code) except ROM_FLASH.  This never works!  I know the code is actually changing because I start to have erratic behavior so clearly I'm not understanding how the auto checksum calculation works.  Any ides/thoughts would be much appreciated!
 
Thanks!
Labels (1)
0 Kudos
2 Replies

389 Views
CompilerGuru
NXP Employee
NXP Employee
Hmm. I wonder if you main loop should not just have the inverse condition.
You are stopping the loop once the checksum is correct....
It should be like this
   while (__CHECKSUM_IS_OK) {
      work();
   }
   BadThingsAreHappening();


This of course raises the question why your checksum computation does always fail...

Does it work if you are just checking the non banked code?
I think there is some preprocessor define you can use to get the checking working for banked code too (not 100% sure).
Anyway, you should have the code to see how the computation is done at runtime and which areas are tested, and which not.
Do you get any link time warnings?
Check the
CodeWarrior\(CodeWarrior_Examples)\HC12\Checksums
samples


Daniel
0 Kudos

389 Views
rhb3
Contributor II
Just to close this out...

I noticed I was receiving a L1827 in regards to the startup structure. I contacted tech support and to fix this, they sent me a new start12.h

Thanks
0 Kudos