What's the best method to write a image file to flash?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What's the best method to write a image file to flash?

Jump to solution
1,026 Views
danielchai
Senior Contributor I

Hi All,

I am trying to write a boot loader.

Every time, it checks the SD card if there is new image file, if yes, then write this image file to the flash.

Based on MQX4.0.2, what's the best way to write to flash? Is there any API to do this or I have to use the low level registers to write to flash?

Thank you.

-Daniel

1 Solution
390 Views
dereksnell
NXP Employee
NXP Employee

Hi Daniel,

MQX includes the flashX driver, which can erase and program the internal flash.  You can refer to the the flashX example in MQX, and the driver documentation installed at <MQX Installation path>\doc\mqx\MQXIOUG.pdf for help on how to use the driver.

The Kinetis device MK60FN1M0VLQ12 offers the program flash swap feature.  If you can take advantage of it and fit your application in the lower half of the flash, then your MQX application can re-program the upper half with the new image from the SD card.  Once the new image is programmed and verified, you can execute the flash swap command.  This will swap the upper flash with the lower flash in the address map, and when you reset you will now boot from the lower flash address range with the new image.  Appnote AN4533 has the details on using the swap feature

http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4533.pdf

If the program flash swap feature doesn't work for your needs, you can use a small bootloader at the lower end of flash to program the remaining flash with your application.  We have several example bootloaders for Kinetis below you can reference for this.  The closest to what you describe would be AN4368 bootloader.  This uses USB instead of an SD card, but it uses a file system to mount the USB flash drive.  Then the bootloader reads the new firmware image off the USB drive, and programs it to internal flash.

AN4379, Freescale USB Mass Storage Device Bootloader - Application Notes

Associated File: AN4379SW

AN4368, USB Mass Storage Device Host Bootloader - Application Notes 

Associated File: AN4368SW

AN4370, USB DFU Bootloader for MCUs - Application Notes

Associated File: AN4370SW

Developer's Serial Bootloader 

Associated File: AN2295SW

Thanks

View solution in original post

0 Kudos
1 Reply
391 Views
dereksnell
NXP Employee
NXP Employee

Hi Daniel,

MQX includes the flashX driver, which can erase and program the internal flash.  You can refer to the the flashX example in MQX, and the driver documentation installed at <MQX Installation path>\doc\mqx\MQXIOUG.pdf for help on how to use the driver.

The Kinetis device MK60FN1M0VLQ12 offers the program flash swap feature.  If you can take advantage of it and fit your application in the lower half of the flash, then your MQX application can re-program the upper half with the new image from the SD card.  Once the new image is programmed and verified, you can execute the flash swap command.  This will swap the upper flash with the lower flash in the address map, and when you reset you will now boot from the lower flash address range with the new image.  Appnote AN4533 has the details on using the swap feature

http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4533.pdf

If the program flash swap feature doesn't work for your needs, you can use a small bootloader at the lower end of flash to program the remaining flash with your application.  We have several example bootloaders for Kinetis below you can reference for this.  The closest to what you describe would be AN4368 bootloader.  This uses USB instead of an SD card, but it uses a file system to mount the USB flash drive.  Then the bootloader reads the new firmware image off the USB drive, and programs it to internal flash.

AN4379, Freescale USB Mass Storage Device Bootloader - Application Notes

Associated File: AN4379SW

AN4368, USB Mass Storage Device Host Bootloader - Application Notes 

Associated File: AN4368SW

AN4370, USB DFU Bootloader for MCUs - Application Notes

Associated File: AN4370SW

Developer's Serial Bootloader 

Associated File: AN2295SW

Thanks

0 Kudos