4 Replies Latest reply on Aug 18, 2017 1:08 PM by brendan_merna_1545636

    Checksum Description


      I'm working on creating a custom bootloader host program. I need to compute the checksums of the .cyacd file and to verify against the checksum calculated by the PSoC. I've seen some mixed descriptions and implementations in calculating this checksum and wonder if anyone could help.

      To help guide the answers here is a list of what I'm confused about and what I understand.


      1. The .cyacd is in ASCII and has to be parsed into hex values. I've done this in my code using help from btldrutils.


      2. Format of the header in the .cyacd file is [4-byte silicon ID][1-byte Silicon Rev][1-byte checksum type]


      Format of row in the .cyacd file is [1-byte array ID][2-byte row number][2-byte data length][64 data bytes][1 byte checksum]


      3. The start of the program row is marked by a ':' and the end of the row is marked by '..'.


      4. I'm using the basic summation (type 00 in header) from the data sheet this adds up every byte sent (besides the checksum) and takes the 2's complement of this value. Note- App note AN86526 attaches example code to run a bootloader host on a PSoC kit board and in the code the checksum for each row is calculated without taking the 2's complement.




      My questions revolve around 4.


      1. Is the header included in the checksum calculation?


      2. Are the semi colons and periods part of this calculation?


      3. Is the checksum calculated for each row or is it a running checksum for the entire file?


      4. If its a running checksum do you take the 2's complement each row and then add it to the continuous checksum or do you take the 2's complement to verify that row and then add the number before you took the 2's complement to the continuous checksum?


      5. Do you just add everything up and check the data after each row?




      Any help or directions toward a file that would help me out would be great.

        • 1. Re: Checksum Description

          Hi Brendan,


          The header and semicolon is not included as part of the checksum computation. The header is only used for validating the properties of the device (whether we are trying to bootload to the correct device, done using Silicon ID match) and is done using CyBtldr_ParseHeader.


          Now, in the header itself - we specify the checksum type which indicates the type of checksum used in the packets sent between the bootloader and the bootloader host during the bootloading operation. If this byte is 0, the checksum is a basic summation. If it is 1, the checksum is CRC-16.


          Please refer to the implementation of CyBtldr_ComputeChecksum in cybtldr_commad.c file. Simple SUM checksum is implemented in two's complement form: (you can find "return (1 + ~sum);").


          Also, we validate if each row is correctly programmed. Hence we have a row checksum and check if the checksum received from bootloader matches the expected row checksum stored in cyacd file. If TRUE, then we conclude that the row is correctly programmed.

          • 2. Re: Checksum Description

            Is the the row checksum just the checksum for the data in that row? Or is it a combination of the rows before?

            • 3. Re: Checksum Description

              It is only for that row.

              • 4. Re: Checksum Description
                        One more small clarification on this: If you check the Host project, there is a variable called "checksum2". This is the final checksum of a particular row. This checksum2 is used for ensuring the validity of the row when CyBtldr_VerifyRow API is used (Device sends the flash row checksum). The checksum2 value will not have the headers (arrayId and Row Number) as part of the checksum. But, there is another variable called "checksum". This is the checksum which is obtained from the cyacd row and this includes the header as well (header means arrayId and Row Number). Now, to this checksum - we again add arrayId and rowNum to get checksum2. checksum2 will not have the arrayId and rowNum as part of it.