LPC Microcontroller flash checksum utility

Wrote an utility to fix something annoying in my micro-controller work-flow.

If you’re coding for the LPC17xx micro-controllers under Linux using OpenOCD and the GNU tool-chain you’re likely familiar with the following message during flashing:

Warn : Verification will fail since checksum in image (0x00000000) to be written to flash is different from calculated vector checksum …

This message won’t prevent you from flashing a working image because OpenOCD will calculate the checksum on the fly. It will however prevent you from doing a verify of the data because verification will be done to the unpatched binary.

If you’re working with mbed and the external compiler tool-chain you’ll likely have seen this output a thousand times:

*****
***** You must modify vector checksum value in *.bin and *.hex files.
*****

Here comes my lpcpatchelf utility into play:

It will process an ARM binary in ELF format and fix the checksum. This will get rid of the messages and allows OpenOCD to verify.

The source-code is up on my new github:

https://github.com/nPipen/lpcpatchelf

To use it, compile it and put it somewhere in your path. (You may have to install the libelf-dev package which I need to manipulate the elf files).

Once done you can process the files by just calling:

lpcpatchelf -f mybinary.elf

right after the linker call in your makefile.

This calculates the valid checksum and updates the elf file in place. Once done you can then use objcopy to get your .bin or .hex files if needed.

The utility will work for LPC17xx and most other LPC micro-controllers by default. Some LPC microc-controllers have a slightly different algorithm though. For example in the LPC20xx family the way the checksum is calculated is identical except that the checksum is placed at a different position.

You can define this position by explicitly setting it via the the -c option. For example this call will patch the elf file for the LPC20xx family.

lpcpatchelf -c 5 -f mybinary.elf

I hope you find it as useful as I do. If you have questions just drop a comment below..

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to LPC Microcontroller flash checksum utility

  1. zeze says:

    Hey there! I’ve been reading your weblog for a while now and finally got
    the bravery to go ahead and give you a shout out from Kingwood Tx!
    Just wanted to mention keep up the excellent work!

Leave a Reply

Your email address will not be published. Required fields are marked *