stm32 – calculate and embed crc of bin in bin

Sysprogs forums Forums VisualGDB stm32 – calculate and embed crc of bin in bin

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28250
    dabramson
    Participant

    I have a request to calculate a checksum of a binary file and embed that checksum as part of the firmware file that is flashed to the chip. Upon startup it the code would calculate the checksum and do a comparison to the one stored. The catch is that the checksum that is embedded in the firmware file is to be calculated and embedded in the build process. I’m at a loss for how to go about doing this, is there anything in VGDB that could help?

    #28258
    support
    Keymaster

    Hi,

    VisualGDB itself doesn’t provide any special tools for calculating checksums, however it should be relatively straight-forward to code a simple tool that would do that. You can use VisualGDB Project Properties -> Custom Build Steps page to invoke the custom tool that will patch the .bin file generated by VisualGDB.

    Then you can convert the .bin file back to ELF as shown below:

    arm-none-eabi-objcopy -I binary -O elf32-little --change-section-address .data=0x08000000 <file>.bin <file>-patched.elf

    Note that the new ELF file will not contain any debugging symbols, so it should not replace the original ELF file. Instead, please add the following command to Additional GDB Startup Commands (before connecting to target);

    exec-file <file>-patched.elf

    This will make sure that VisualGDB uses the contents of <file>-patched.elf to program the FLASH memory, but still uses the regular ELF file to load the symbols.

    #30978
    tajen
    Participant

    And how would I then access this checksum from the code?

    #30983
    support
    Keymaster

    Hi,

    You can use the same techniques that would work for any other IDE or a directly built project. VisualGDB does not change anything from that perspective.

    #32445
    lpancoast
    Participant

    Hi I have a similar request to calculate a checksum upon building. Are there any examples that make custom build steps? I’m unfamiliar with what sort of syntax is needed to access the built file and such.

    #32459
    support
    Keymaster

    Hi,

    You can use the $(TargetPath) expression to reference the built file path. Ultimately, the custom build steps are simply instructions to run custom command-line applications or scripts. The actual logic for editing the files would need to be done by the actual script.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.