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

While programming lpc21isp adds garbage data at the end of program in flash memory #8

Open
swarzynski opened this issue Aug 30, 2013 · 4 comments

Comments

@swarzynski
Copy link

Hello!

While programming lpc21isp adds garbage data at the end of program in the flash memory. It is a problem when CRC value is calculated by the code from whole flash memory - CRC will differ when chip will be programmed by in example "Flash Magic" or "lpc21isp". Look at attached picture to see the details.
bug
I would be glad if someone try to fix it or point me where to look for the function which is responsible for writing this data.

Regards

@jamesmarkchan
Copy link

@swarzynski did you ever restore this issue? This might explain some of the behavior we're seeing.

@cmcqueen
Copy link

I've been caught out by this bug in version 1.97. Is this bug still present?

@ArcolaJasper
Copy link

ArcolaJasper commented May 9, 2018

I see the same thing, only it crashes lpc21isp.

It's caused by lpc21isp not coping with files that are not a multiple of the block size.

In NxpDownload here: https://github.com/capiman/lpc21isp/blob/master/lpcprog.c#L1263

There is no check that the access to IspEnvironment->BinaryContent is less than IspEnvironment->BinaryLength so it over reads BinaryContent and you either end up flashing rubbish to the mcu, or crashing as you hit unallocated memory.

I added a check around it:

                              if ((Pos + Block * 45 + BlockOffset) > IspEnvironment->BinaryLength) {
                                printf("padding with 0\n");
                                c = 0;
                              } else {
                                c = IspEnvironment->BinaryContent[Pos + Block * 45 + BlockOffset];
                              }

That pads the last block with 0's. Not a real fix cos verifying still fails as well. But it stops it crashing for me at least.

(This is with an lpc1768)

@cmcqueen
Copy link

cmcqueen commented Mar 1, 2019

if ((Pos + Block * 45 + BlockOffset) > IspEnvironment->BinaryLength)

Should that > be >=?

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

No branches or pull requests

4 participants