Hot!Checksum calculation of hex file

Author
patni.gaurav
Starting Member
  • Total Posts : 40
  • Reward points : 0
  • Joined: 2015/03/16 21:11:29
  • Location: 0
  • Status: offline
2016/05/31 05:00:49 (permalink)
0

Checksum calculation of hex file

 
Dear All Forum members ,
 
I have implemented Bootloader for PIC32MX device.
For error handling I have checked checksum of each row of Hex row received from PC software.
But I want to calculate Checksum of " complete hexfile "  similar to MPLABX IDE .
 
Following is the plan :
 
PC based software will calculate checksum & display on screen so that user can crosscheck with correct checksum before starting Bootloader application
OR
User can enter corrected checksum on UI & software will automatically compare this with calculated checksum .
 
If anyone knows method for calculating checksum of hexfile please reply.
 
Thanks,
Gaurav
#1

17 Replies Related Threads

    GlennP
    Super Member
    • Total Posts : 710
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Checksum calculation of hex file 2016/05/31 05:29:22 (permalink)
    4 (1)
    I have some code to generate CRC-32s of the entire HEX file (Pgm Flash + EEProm + Config) as specified in a control file.  It doesn't work line-by-line but with a 32 bit CRC I didn't feel that was necessary.
     
    It's in C#.  It's somewhat advanced in the sense that it uses reflection and a lot of inheritance, but if all you want is CRC code I could cut out one case sometime this week.
     
    Do you know which CRC you'd want to use if you used this?  See Koofman's CRC stuff: https://users.ece.cmu.edu/~koopman/crc/
     
    GlennP
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 16995
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Checksum calculation of hex file 2016/05/31 05:45:45 (permalink)
    4 (2)
    A simple checksum is the sum of all the data bytes. A better test whould be a Crc ( available as 8,16,32 bits)
    Even better are hashes. Which can be preformed using the pic32 cryptographic peripheral
    #3
    GlennP
    Super Member
    • Total Posts : 710
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Checksum calculation of hex file 2016/05/31 05:47:46 (permalink)
    3 (1)
    It's "Koopman", not "Koofman".  %&#*(@ Forum S/W did not allow me to edit.
    #4
    GlennP
    Super Member
    • Total Posts : 710
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Checksum calculation of hex file 2016/05/31 05:52:23 (permalink)
    4 (2)
    Agree w/ NK:

    Checksums are very weak.  CRC (32 bits) is decent, Hashes are best.
     
    In a similar case, I used .NET's SHA512Managed class for my Hash function.  I think there are better ones now though.
     
    G.
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 16995
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Checksum calculation of hex file 2016/05/31 11:04:14 (permalink)
    4 (2)
    glennp17321
    Agree w/ NK:

    Checksums are very weak.  CRC (32 bits) is decent, Hashes are best.
     
    In a similar case, I used .NET's SHA512Managed class for my Hash function.  I think there are better ones now though.
     
    G.


    Better is relative.  Stronger Hashes resist purposeful Attempts to break them.  Protection against communication errors need not be that strong, mathematically.
    Intel Hex is still getting away with a lame 8 bit additive checksum.
    #6
    patni.gaurav
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2015/03/16 21:11:29
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2016/05/31 21:04:25 (permalink)
    0
    Thanks NKurzman & GlennP for your valuable suggestions .
     
    Actually I want method to calculate Checksum which is used by MPLABX IDE / IPE while we build our project . Please refer attached screenshot for more details.
     
    Because when we release any code to production, checksum displayed my MPLABX IDE is the only key for them to ensure that hexfile is not corrupt .
     
    Same is applicable when we update firmware on field using serial / USB bootloader .
     
    So I want to implement method to calculate checksum exactly same as that of displayed by MPLABX IDE / IPE while we build our project in my PC based Bootloader software.
     
    Thnaks,
    Gaurav
     
    post edited by patni.gaurav - 2016/05/31 21:22:54

    Attached Image(s)

    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 16995
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Checksum calculation of hex file 2016/05/31 21:28:42 (permalink)
    3 (2)
    You should have lead with that.
    I think there is an app note on the subject.
    #8
    patni.gaurav
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2015/03/16 21:11:29
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2016/05/31 21:51:26 (permalink)
    0
     

     
    post edited by patni.gaurav - 2016/05/31 21:53:49
    #9
    patni.gaurav
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2015/03/16 21:11:29
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/01 05:21:47 (permalink)
    0
    Dear NKurzman,
     
    can you please mention that application note no ?
     
    Thanks,
    Gaurav
    #10
    GlennP
    Super Member
    • Total Posts : 710
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/01 06:02:51 (permalink)
    4 (1)
    Gaurav: Image is too small for me to read.  Just FYI.  GP
    #11
    patni.gaurav
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2015/03/16 21:11:29
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/01 09:47:58 (permalink)
    4 (1)
     
    Hi GlennP
     
    I have uploaded full screen image but i dont know why it gets shrink after upload ???
     
    please download image from following link
     
    app.box.com/s/by4c41lm92slzd2g15w6yo7q3azm69id
     
    thanks
    Gaurav
    #12
    patni.gaurav
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2015/03/16 21:11:29
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/03 23:41:51 (permalink)
    0
    HI ,
     
    any solution ?
     
    Thanks,
    Gaurav
    #13
    newfound
    Super Member
    • Total Posts : 1814
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/04 01:44:48 (permalink)
    #14
    NorthGuy
    Super Member
    • Total Posts : 5254
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/04 05:47:49 (permalink)
    4 (2)
    For every chip, Microchip publishes "Programming Specifications". This document describes how to calculate checksum. There's a list of rules and masks on what to include into the checksum and how. IMHO, it is too complicated to use outside of Microchip tools.
     
    Search for the chip, then when you get to the chip main page, expand "Documents" and download the programming specifications from there.
    #15
    aschen0866
    Super Member
    • Total Posts : 4396
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Checksum calculation of hex file 2016/06/04 07:27:01 (permalink)
    3 (1)
    patni.gaurav
     
    So I want to implement method to calculate checksum exactly same as that of displayed by MPLABX IDE / IPE while we build our project in my PC based Bootloader software.
     

    The MPLABX IDE/IPE style checksum is useful for production to verify hex file integrity to some degree. However, as people have already pointed out, this kind of checksum, just like using a simple checksum for communication, is weak.

    Your PC based bootloading software should only be concerned with the application checksum, which you can calculate using MPLABX's hexmate tool and inject the checksum directly into the application hex file at a known location. It is your bootloader's job to verify the application checksum is valid before even letting the application run. In this case, a simple checksum is as good as any other error detection algorithm. This is because Flash programming requires a page erase and row write. If there is a failure on a page erase or a row write, a simple checksum will detect the failure.
     
     
    #16
    lankep
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2019/01/15 07:57:05
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2019/01/18 12:17:44 (permalink)
    0
    As you mentioned in question that you want PC based software to calculate CRC of hex file.
    You can use SREC tool for the same.
    Using srecord tool you can calculate CRC of file and append it to hex file

    Things you need to do is.

    1. Write down your own routine to calculate CRC of p flash with an algorithm (CRC-16 or CRC-32).

    2. Calculate CRC of hex file using srec tool using same algorithm (CRC-16 or CRC-32). Append CRC at particular address in hex file. (You can place calculated CRC at unused p flash area )

    3. Now at run time your own routine will calculate CRC of p flash. You should have added a logic to compare calcilated CRC with stored CRC.


    For more details (how to use srec tool) please refer below link.
    https://embdsysbasics.blo...culator-using.html?m=1
    #17
    bastl
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: Checksum calculation of hex file 2019/01/27 05:43:14 (permalink)
    0
    You asked for a formula for calculation.
    I think most used is the checksum md5 like in MPLAP X because it can easily be verified by hardware circuits.
    MD5 is exactly explained on the wiki pages look here:
    https://de.wikipedia.org/...lgorithm_5#Algorithmus
    And c code called md5sum included in the coreutils can be downloaded here:
    ftp://ftp.gnu.org/gnu/coreutils/
    There you have also checksum rutines and all stuff you want, also sha1.
     
    #18
    Jump to:
    © 2019 APG vNext Commercial Version 4.5