-deleted-
10 years, 7 months ago.

How to build a FOTA boot loader for FRDM-K22F or FRDM-K64F

Information

The following notebook page is documenting the discovery journey for how to implement a solution for basic wireless remote programming. http://developer.mbed.org/users/ebowles/notebook/freescale-bootloader-fota-firmware-over-the-air---/

I would like to build a solution for remotely updating the firmware for a FRDM-K22F or FRDM-K64F platform, in terms of a FOTA (Firmware Over The Air) boot loader, using IAP (In Application Programming), with XBee radios over serial UART.

A master FRDM mbed device will load the program bin file from an FTP server into its external SPI FRAM, perform CRC, and then transmit the program bin file over a serial XBee series 2 API mesh network to the remote FRDM XBee mbed device which saves the data into its external SPI FRAM or RAM. The remote program then performs a CRC check before the IAP routine executes, writing the new firmware program to flash memory, followed by a software reset. The XBee’s will use API mode to verify each transmitted packet.

I have found a commercial solution called http://utasker.com/, however I need something more specific to using serial XBee boot loading, with native mbed code, where the application and IAP is in one code base, so as to remove the need for an intermediate compiler. I realize there are risks of “bricking” when using this approach.

There are solutions that help me understand the basic code requirements, like: https://developer.mbed.org/cookbook/FirmwareUpdater https://developer.mbed.org/users/Sissors/code/FreescaleIAP/ http://developer.mbed.org/forum/mbed/topic/2112/?page=1#comment-10756 https://developer.mbed.org/users/WiredHome/code/SWUpdate/ https://developer.mbed.org/users/EmLa/code/CRC16/ http://developer.mbed.org/users/peterand/code/Sw_reset/

If this is possible, please would you provide some hints for how to use FreescaleIAP as a firmware bootloader, an FTP Client and transferring bin files using XBee serial in API mode.

The FreescaleIAP code example seems to suggest this is possible. https://developer.mbed.org/users/Sissors/code/FreescaleIAP/

My final solution will be a custom PCB with one K22F or K64F microcontroller chip..

I saw this only a couple of days ago, haven't tried it yet or looked into it a great detail. If I'm right in thinking the bootloader sits in a separate area outside user flash area and can be invoked via an external interrupt during reset or called within your code. I think you can modify the user code base address.

http://app.contact.freescale.com/e/es.aspx?s=1764&e=96405&elq=cd65043e062541d3904dbccd9e2ca98b

posted by Paul Staron 14 Mar 2015

This seems like the only option and the best solution..

posted by -deleted- 15 Mar 2015

I'm interesting in doing a similar operation and unfortunately that link is now dead. Would anyone in the know be able to update the link?

posted by Rupert Rutledge 22 Mar 2016

1 Answer

10 years, 7 months ago.

Grrr accidently went back, and everything is gone within mbed. So shorter version.

First of all, you assigned this to me, which I didn't know about until Martin mentioned it. The downside of this is that now I am only one able to answer with how the mbed questions work. This is not exactly trivial matter, so doubtful many would answer, but who knows.

Next, I have never used FreescaleIAP as bootloader, don't think anyone else has (but you never know). FTP client shouldn't be the limitting issue. Transferring bin files via xbee is also easy:

for (int i = 0; i<length; i++)
  xbee.putc(bin[i]);

The hard part is the bootloader, although some things seem to make it a bit easier for you. The main question is: Does it need to run at startup and be very robust? If that is the case, it needs to be located at flash address zero, meaning everything else in your program needs to have an offset, meaning they need special programming requirements, and you get crap with interrupt vector locations.

Otherwise you can put your bootloader in the last sector of your flash memory. From here it can happily overwrite your first sectors with your new program. However big downside of this: If you overwrite with a corrupt program which never calls your bootloader afterwards when there is a new program, it won't be able to enter bootloader mode again. So you always need to program it with the correct program.

So what are your requirements?

Accepted Answer

Thank you for your time to answer.

You make a good point. I agree that not many developers would answer this question because of the complexity. Thank you for the code on transferring bin files via xBee.

I like your idea of the bootloader being in the last sector of flash memory and overwriting the first sectors with the new program.

My requirements are one MCU chip using native mbed code with the native mbed compiler. I realize the associated risk of bricking, which is acceptable because the PCB will have a JTAG connector.

posted by -deleted- 10 Mar 2015

FYI I looked a bit at making a bootloader in the last section (or somewhere at the end). It is pretty easy to location your function there:

 __attribute__((section(".ARM.__at_0x10000"))) void bootloader(void) {
    led2 = !led2;
}

And then whatever memory location you want.

The major issue for the next step: You cannot use other functions. To use the FreescaleIAP library you need to make sure those functions are placed in the correct location too. Now that is still fairly easy to do by just modifying the library and adding attributes for them too (of course a bit a pain to figure out how large each function is, but it should work). But that also means no usage of mbed library functions in your bootloader. You cannot use any function which is not inlined or which is specifically placed by you in the bootloader section.

posted by Erik - 10 Mar 2015

Assigned to -deleted- 10 years, 7 months ago.

This means that the question has been accepted and is being worked on.