8.2.3.12 Ck Hexmate Option
The -ck option calculates a hash value over data in the HEX file and stores this value into the HEX file at a nominated address.
-mchecksum option to control hash calculations performed by Hexmate.-ck=start-end@dest[+offset][wwidth][tcode[.base]][galgorithm][ppolynomial][rrevWidth][sskipWidth[.skipBytes]][oXORvalue]where:startandendspecify the inclusive hexadecimal address range over which the hash will be calculated. The interpretation of these addresses are based on the addressing value (see Addressing Hexmate Option). If these addresses are not a multiple of the data width for checksum and Fletcher algorithms, the value zero will be padded into the relevant input word locations that are missing.destis the hexadecimal address where the hash result will be stored. The interpretation of this address is based on the addressing value (see Addressing Hexmate Option). This address cannot be within the range of addresses over which the hash is calculated.offsetis an optional initial hexadecimal value to be used in the hash calculations. It is not used with SHA algorithms.widthis optional and specifies the decimal width of the result. It is specified in bytes for most algorithms, but in bits for SHA algorithms. See the Hexmate Hash Algorithm Selection table below for allowable widths. If a positive width is requested, the result will be stored in big-endian byte order. A negative width will cause the result to be stored in little-endian byte order. If the width is left unspecified, the result will be 2 bytes wide and stored in little-endian byte order. This width argument is not required with any Fletcher algorithm, as they have fixed widths, but it may be used to alter the default endianism of the result.codeis an optional hexadecimal code sequence that will trail each byte in the result. Use this feature if you need each byte of the hash result to be embedded within an instruction or if the hash value has to be padded to allow the device to read it at runtime. For example,t34will embed each byte of the result in aretlwinstruction (bit sequence 0x34xx) on Mid-range PIC devices. If the code sequence specifies multiple bytes, these are stored in big-endian order after the hash bytes, for exampletAABBwill append 0xAA immediately after the hash byte and 0xBB at the following address. The trailing code specificationt0000will store two 0x00 bytes after each byte of the hash. The code sequence argument can be optionally followed by.Base, whereBaseis the number of bytes of hash to be output before the trailing code sequence is appended. A specification oft11.2, for example, will output the byte 0x11 after each two bytes of the hash result.algorithmis a decimal integer to select which Hexmate hash algorithm to use to calculate the result. A list of selectable algorithms is provided in the table below. If unspecified, the default algorithm used is 8-bit checksum addition (algorithm 1).polynomialis a hexadecimal value which is the polynomial to be used if you have selected a CRC algorithm.revWidthis an optional reverse word width. If this is non-zero, then bytes within each word are read in reverse order when calculating a hash value. Words are aligned to the addresses in the HEX file. The width must be 0 or a value 2 or greater. Typical values would be 2 or 4, depending on the application. It is recommended that you do not exceed a width of 8. A zero width disables the reverse-byte feature, as if thersuboption was not present. This suboption is intended for situations when Hexmate is being used to match a CRC produced by a PIC hardware CRC module that uses the Scanner module to stream data to it. This feature will work with all hash types, but has no effect when using any checksum algorithm (algorithms -4 thru 4).skipWidthis an optional skip word width. If this is non-zero, then the byte at the highest address within each word is skipped for the purposes of calculating a hash value. Words are aligned to the addresses in the HEX file. At present, the width must be 0 (which disables the skip feature, as if thessuboption was not present) or greater than 1. This skip width argument can be optionally followed by.SkipBytes, whereSkipBytesis a number representing the number of bytes to skip in each word, for examples4.2will skip the two bytes at the highest addresses in each 4-byte word. In hash calculations, to avoid processing the 'phantom' 0x00 bytes added to HEX files for PIC24 and 24-bit instruction set dsPIC devices, uses4.XORvalueis a hexadecimal value that will be XORed with the hash result before it is stored.
| Selector | Algorithm description | Allowable hash width |
|---|---|---|
| -5 | Reflected cyclic redundancy check (CRC) | 1 - 8 bytes |
| -4 | Subtraction of 32 bit values from initial value | 1 - 8 bytes |
| -3 | Subtraction of 24 bit values from initial value | 1 - 8 bytes |
| -2 | Subtraction of 16 bit values from initial value | 1 - 8 bytes |
| -1 | Subtraction of 8 bit values from initial value | 1 - 8 bytes |
| 1 | Addition of 8 bit values from initial value | 1 - 8 bytes |
| 2 | Addition of 16 bit values from initial value | 1 - 8 bytes |
| 3 | Addition of 24 bit values from initial value | 1 - 8 bytes |
| 4 | Addition of 32 bit values from initial value | 1 - 8 bytes |
| 5 | Cyclic redundancy check (CRC) | 1 - 8 bytes |
| 7 | Fletcher’s checksum (8 bit calculation) | 2 bytes |
| 8 | Fletcher’s checksum (16 bit calculation) | 4 bytes |
| 10 | SHA-2 | 256 bits |
| 11 | SHA-1 | 160 bits |
The single letter argument tokens are case insensitive, so for example w2 and W2 are both valid width arguments to this option.
-ck=0-1FFF@2FFE+2100w-2g2If the addressing value is set to1, this option will calculate a checksum (16-bit addition) over the HEX file address range 0 to 0x1FFF(inclusive) and program the checksum result at address 0x2FFE. The checksum value will be offset by 0x2100. The result will be two bytes wide and stored in little-endian format.
start and end addresses specified in the -ck option. Consider this option:-ck=0-5@100w2g5p1021s2s2) over HEX addresses 0 through 5. If it is acting on the HEX record (data underlined)::1000000064002500030A750076007700780064001C
-ck=1-6@100w2g5p1021s2the hash will be calculated from the (hexadecimal) bytes 0x25, 0x03, and 0x75 (the same 0x00 bytes are skipped). These features attempt to mimic data read limitations of code running on the device, and thus the words they use are aligned with actual addresses.
skipWidth has been specified for algorithms that process 16 or 32 bits of data per iteration of the hash algorithm, then the skipped bytes are padded with 0 bytes. For example if the HEX record was (data underlined)::0400000012345678E8then employing a 16-bit additive checksum (algorithm 2) over this data would normally add 0x3412 and 0x7856. If a skipWidth of 2 was requested, the algorithm would add 0x0012 and 0x0056, since every second byte in the input was skipped. However, if the CRC (algorithm 5), which processes the input sequence one byte per iteration, had instead been selected, the bytes 0x12 and 0x56 will be processed by the CRC algorithm.Note that this option inserts data into the output HEX file, thus, to prevent a conflict, you must ensure that the locations where this data is to be placed are not already populated by other data from a HEX file or from another option.
See Hash Value Calculations for more details about the algorithms that are used to calculate hashes.
