8 years, 5 months ago.

Rewrite Flash first sectors on K64F

Hi all, I'm getting started with ARM programming on FRDM-K64F devboard + mbed classic, and i would like to use FreescaleIAP lib to perfrom something like "firmware updates" through microsd card, but i'm facing with some issues: when i try to erase flash sectors already used by existing code (in my case the first four sectors) it hangs and corrupts onboard firmware (usb reflash needed). What am I doing wrong? What's the best way to perform my task (if it exists)? Thank you!

Question relating to:

IAP code for Freescale platforms

1 Answer

8 years, 5 months ago.

That is kinda supposed to happen if you erase the code it is currently running ;).

You can have a look at: https://developer.mbed.org/users/Sissors/code/Bootloader_K64F/ as example for something like this. The important part is that the part which is doing the updating is not allowed to be deleted while the update process is running. With the compiler statements in that program you can place it in a specific area to make sure of that (there are also a few alternative ways to place it somewhere safe). In addition you also need to take care you aren't using any functions which are in the area you are deleting. Lets say you make a DigitalOut to blink an LED during the process. The DigitalOut code will reside somewhere in the middle of the program which you are deleting, so when it calls the function, it is gone.

So if you want to delete the first four sectors, make sure the code doing the deleting and the reprogramming is outside the first four sectors.

Accepted Answer

Great! From what i've read i should place SD lib + IAP lib + flasher code in a safe location using attribute directive, but what's the rule to follow to choose the right address for each function? How do you esitimate functions sizes?

posted by User Name 19 Nov 2015

One other option, which maybe you can find the discussion about I had with someone else on this site, is to first copy it from wherever you have it (in your case the SD card) to another place in your flash memory, and from there copy it to the beginning of your flash memory where it will actually be run. The advantage is that this way you don't need to place the SD lib code anywhere else. Especially since it uses the C standard lib, which you cannot (easily) move.

Or what might help is if you setup everything in your main code, and supply your flash function with the SD card sector it needs to start reading from. So the whole filesystem part is done outside the flash code.

Now regarding your question: You do it by estimating :P. Sorry, I don't have a better answer, you get a feeling for it. But don't worry about it: If you put it too small you will get an error. Just leave some headroom in functions which might change, so you can change them without moving all other functions.

posted by Erik - 19 Nov 2015

Thank you very much!

posted by User Name 19 Nov 2015