This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to Calculate Checksum of hex file.

Hello All,

I am using LPC2364 controller and Keil uVision5 IDE.

I need to calculate checksum of Hex file each time when the device is powered on and should be compared with the pre calculated checksum. This is to make sure that the source code is unchanged.

I am newbie ... Please help me...

Parents
  • "Can you please give more details. I am not able to get the below mentioned point"

    10 + (-10) = 0.

    Or when doing unsigned computations without caring for overflow in a computer:

    0xffff + 0x0001 = 0x0000

    So if the 16-bitchecksum of all flash bytes except the last two in your flash ends up as 0x83f0
    then you can decide to store 0x7c10
    in the last two bytes of the flash

    So when the program does a 16-bit checksum of all the flash, it ends up with a sum that is zero 0x83f0 + 0x7c10 = 0x10000
    which after 16-bit overflow means 0x0000

    How to figure out the value 0x7c10? That's the 16-bit unsigned result of 0-0x83f0.

    Just note one thing - while you may send a hex file to your processor, your processor will not store any hex file. The processor stores the binary data that is represented in the hex file. A program in the PC - or a bootloader in the processor - will decode the hex file to extract this binary data.

    Next thing - the processor will normally store the value 0xff in all bytes that does not get any content from the hex file. And these 0xff bytes will also be part of the checksum that the program computes. So the PC side must remember this when it computes a checksum before programming the processor.

Reply
  • "Can you please give more details. I am not able to get the below mentioned point"

    10 + (-10) = 0.

    Or when doing unsigned computations without caring for overflow in a computer:

    0xffff + 0x0001 = 0x0000

    So if the 16-bitchecksum of all flash bytes except the last two in your flash ends up as 0x83f0
    then you can decide to store 0x7c10
    in the last two bytes of the flash

    So when the program does a 16-bit checksum of all the flash, it ends up with a sum that is zero 0x83f0 + 0x7c10 = 0x10000
    which after 16-bit overflow means 0x0000

    How to figure out the value 0x7c10? That's the 16-bit unsigned result of 0-0x83f0.

    Just note one thing - while you may send a hex file to your processor, your processor will not store any hex file. The processor stores the binary data that is represented in the hex file. A program in the PC - or a bootloader in the processor - will decode the hex file to extract this binary data.

    Next thing - the processor will normally store the value 0xff in all bytes that does not get any content from the hex file. And these 0xff bytes will also be part of the checksum that the program computes. So the PC side must remember this when it computes a checksum before programming the processor.

Children