Hi,
One year ago, I started a projet on a MCF52259 processor running MQX3.4 and neded the same thing than you : update my application software running from the internal flash. The USB bootloader provided by Freescale was nice for a demo purpose, but was unusable for a remote equipment without any operator closed to it, and where only an internet connection to the system is available.
So I decided to find-out a way to update the MQX image from MQX itself. With this method, MQX can be used to download the new image from FTP or serial line (srecord or binary format) to a buffer. This can be done while the system is running.
Then an MQX command can be run to copy a small bootstrap code to internal SRAM and run it from SRAM to copy this buffer to the flash and restart the board on the new image.
As my MQX application code was less than half the size of the flash, I used the second half of the flash as a buffer.
I developped a buffer driver creating a "buffer:" device that can be used as target device when downloading with existing MQX applications such as FTP (for example : get filename buffer
.
The buffer driver also does an on-the-fly srecord to binary conversion, if required, and the final binary image is stored in the second half of flash. The buffer driver uses the MQX flashx: driver to write data to the flash.
Then the only remaining step was to implement an "update" command to copy the second half of the flash to the first half and reset. This is done as follows
- allocate some memory in stack (SRAM) to copy a do_update() function from flash to SRAM. This can be done simply by declaring a local variable : char stackmem[size]; The do_update() function is the function doing the real copy.
- copy do_update() code from flash to SRAM (address=stackmem) using memcpy()
- declare a pointer to the function in SRAM and set it to stackmem
- call the function through this pointer.
Limitations on do_update() :
- must be self contained : do not call any other function. So a simple flash erase / write code must be written for this function.
- must not return once the flash has been altered bacause MQX application image has changed, so write to the required register to reset the board when done
- must not make use of some data stored in flash (= constant data). Only non constant data or stack data can be used from this function as it is stored in SRAM
- passing arguments to the function is allowed (through stack or registers)
This works fine. The only drawback compared to a bootloader if that the power must not be removed while do_update() is running to prevent from having a non functional system. Fortunately the update takes only 2 seconds on my system sothe risk is reduced to the minimum. I also added a checksum verification on the image before using it for the update.
I you are interested in that, I can give you more info or sample code.