Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LPC checksum in .bin file #25

Closed
maxgerhardt opened this issue Jul 19, 2021 · 3 comments
Closed

Add LPC checksum in .bin file #25

maxgerhardt opened this issue Jul 19, 2021 · 3 comments

Comments

@maxgerhardt
Copy link

Per this community topic (and related), the .bin file PlatformIO creates does not include the "LPC Image cheksum", as e.g. documented here. The first 7 entries of the vector table, interpreted as 4-byte little-endian integers, must be summed up (modulo 2^32), then the value ~summed_value + 1 must be written at offset 0x1c.

See

for code examples.

Without this checksum in the .bin file, if one takes that file and drag-and-drops it unto the virtual USB disk of the microcontroller for flashing, the firmware will refuse to run. It only works via OpenOCD flashing because OpenOCD detects that the checksum is missing and calculates and injects it last-minute before flashing.

Code should be added into the build logic of this platform to calculate and write the checksum into all .bin files for NXP LPC microcontrollers.

Note: This was already noticed in

#6 (comment)

But wasn't fixed in the platform code.

@valeros
Copy link
Member

valeros commented Jul 23, 2021

Thanks for pointing it out. Any idea what MCUs (or more generally CPUs) require this checksum? In the links I only found this line:

The reserved Cortex-M3 exception vector location 7

I tried to search for something similar where M0, M4 are mentioned, but to no avail.

@maxgerhardt
Copy link
Author

The original source https://www.nxp.com/docs/en/user-guide/UM10360.pdf (page 627) talks about this checksum in reference to "LPC176x/5x Flash memory interface and programming", further in OpenOCD when searching for checksum, it reaveals that there are reference to a flash checksum in lpc2xxx.cfg and lpc1xxx.cfg.

Looking closer at what mbed-os does, it uses the patch() function in this code, where it is invoked for LPC4088 directly, but also referenced in here which thus executes the patch logic for all targets in the targets.json inheriting from LPCTarget, so that is the LPC1114, LPC1768, ARCH_PRO (LPC1768 based), LPC54114.

When I read the first link correctly it states

NXP LPC parts use a word in the vector table of the processor to store a checksum that is examined by the bootloader to identify a valid image. For ARM7/ARM9 based parts this checksum word is stored at offset 0x14, for Cortex-M based parts it is stored at offset 0x1C

So by that I read that as "every NXP LPC" part.

@valeros
Copy link
Member

valeros commented Jul 23, 2021

Many thanks for the research. Added as a post action to the final binary image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants