Hexmate - How can I calculate checksum for my code, and store the result at a particular location?

Hexmate can be used to manipulate a generated hex file, calculate a checksum for a specific memory range, and store the result at a specific address in the hex file.
The tool can be found in the bin folder of MPLAB® X IDE or MPLAB XC8 compiler installation directory. It can also be used with hex files generated for 8-, 16- or 32-bit devices.
If you are using the MPLAB XC8 compiler, you can use the '–CHECKSUM' option which directly invokes Hexmate. Parameters provided to the '–CHECKSUM' option are used for calculating the checksum and storing the result at a particular address in the hex file. You can refer to below link for more on this:
http://microchipdeveloper.com/xc8:hexmate-crc-xc8

For other compilers, Hexmate can be used in the post-build step with the -CK option.
The generic format of the -CK option is:
-CK=start-end@destination [+offset][wWidth][tCode][gAlgorithm][pPoly]

where:
=start-end specify the address range over which the checksum will be calculated.
@destination is the address where the checksum result will be stored. This value cannot be within the range of calculation.
+offset is an optional initial value to add to the checksum result.
wWidth is optional and specifies the byte-width of the checksum result.
tCode is optional and is a hexadecimal code that will trail each byte in the checksum result.
gAlgorithm is an integer to select which Hexmate algorithm to use to calculate the checksum result.
pPoly is a polynomial value used for Cyclic Redundancy Check algorithms.

Hexmate can be invoked in the post-build step of MPLAB X IDE, under Project Properties>Building>Execute this command after the build.
For example:
"C:\Program Files (x86)\Microchip\MPLABX\v4.05\mplab_ide\bin\hexmate" —edf="C:\Program Files (x86)\Microchip\MPLABX\v4.05\mplab_ide\dat\en_msgs.txt" ${ImagePath} -o${ImagePath} –CK=0x200-0x1000@0x2000+0x0100w2g7 –ADDRESSING=2

The above command calculates the checksum for program memory range 0x200 - 0x1000 using the 8-bit Fletcher’s checksum. The two-byte result is stored at 0x2000.
The -ADDRESSING option indicates native addressing format. For PIC24 MCUs, word addressing is used, so -ADDRESSING=2. For PIC18 MCUs, ADDRESSING=1.

To learn more about Hexmate, Hexmate options, and the supported checksum algorithms, refer to the "Utilities" chapter in the "MPLAB XC8 C Compiler User’s Guide".

© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.