6.3 Checksum
The bootloader will verify program status by calculating and comparing a 16-bit checksum on the program data bytes.
Overview
Checksum verification is a method used to validate the integrity of the bytes present in a given memory range through a direct mathematical analysis. A memory range is given to a checksum function, where a special value, called a checksum, is calculated from the data present in the given memory range, and then that value is compared to the checksum calculated by the bootloader during the programming step. If both checksum values match, then there is a high probability the data has not been accidentally altered or corrupted. This method is only capable of detecting errors in transmission or storage and it is unable to perform authenticity checks on the data’s source.
Verification Flow
Checksum verification begins with the bootloader performing a checksum calculation on the program memory space and comparing that value to the precalculated checksum that resides in the bootloader from the original calculation that occurred when the application was compiled. In this method, the only way to get the application back to Boot mode is to first erase the checksum location and then perform a device reset. This will force a failure in the verification step which is then caught by the bootloader. From there, the bootloader starts the device programming process and will again reset once the new image has been programmed. After the device programming has finished, the bootloader will calculate another checksum on the application memory space and compare that new value to the precalculated one from the application compilation. If the checksum values match, it is verified that the data present in the program memory is the valid hex file from the application code and the data’s integrity has not been compromised during transmission. This method is unable to perform authenticity checks of the sender of the image data.