Multiple firmware images in internal flash memory

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

Multiple firmware images in internal flash memory

3,428 Views
renjithvamanan
Contributor III

Hi,

I would like to keep two firmware images(new and old) in internal memory and select the any of the two to execute at reset using  a boot loader.

Since I am specifying absolute addresses in Linker file (LCF), Its my assumption that I cannot place the firmware at some other location and execute from there (Jmp to the location from Bootloader).

So I have to copy the firmware to the linked location first before jumping to it, right ?

Is there any other option available for Kinetis to specify relative linking for an application, and place the firmware anywhere in the memory and execute from there?

Hope my question is clear.

Thanks,

Renjith

Labels (1)
12 Replies

1,935 Views
mehdikarimibiuk
Contributor V

Why don't you just use the flash block swap feature, available in Kinetis series?

Please refer to "Robust Over-the-Air Firmware Updates Using Program Flash Memory Swap on Kinetis Microcontrollers" (Document Number:AN4533)

It allows you to swap to new FW when loaded into your flash, then if it crashes, obviously, you have watchdog to revert to old FW and inspect the new FW fault!

Hope this helps!

Mehdi

0 Kudos

1,935 Views
renjithvamanan
Contributor III

Hi Mehdi,

I had gone through this before, and it was a good option. But my CPU, MK10DX128VLH7 doesn't support swap feature :smileysad:

Regards,

Renjith

0 Kudos

1,935 Views
mehdikarimibiuk
Contributor V

1- Ok, I see you are having the one with Flex for the second flash section! So yeah you cannot use swap because you don't have second flash section!

Mine is MK10DN512Z VLL10 so I have two flash sections and I can use the swap. I'm figuring this out at the moment.

But your question would be interesting to find out as well. I would like to know if there is a possibility to have two firmwares in flash and be able to tell the bootloader which one to start executing.

What is your bootloader by the way?

2- I also follow that apparently you should be using two linker files, one for each firmware, is that true? how did you do this? Did you make two different projects in CodeWarrior? Or is it possible to do this in one project?

3- If you do this in two different projects, you have a project for FW1 and another one for FW1"?

If so then how to load two different project files (S19) into one target flash?!

0 Kudos

1,935 Views
renjithvamanan
Contributor III

Hi  Mehdi,

1 - Botoloader also I am trying to make my own now. The actual firmware will be receiving the new firmware and updating the internal flash.

So the role of the bootloader is just to execute the new firmware when a new version is found in the flash memory.

2- No I am planning to use only one linker file. Also  have no two separate projects for firmwares 1 and 1", 1" is just the new version of 1.

Best regards,

Renjith

1,935 Views
mehdikarimibiuk
Contributor V

Hi Renjith,

1- My bootloader is getting new FW from SPI bus. Do you know how to do a soft reset and jump to the new FW, once it is donwloeded into flash?

2- But you are having two srec files, one for bootloader and one for your FW. How would you manage to put them in one target flash?

0 Kudos

1,935 Views
renjithvamanan
Contributor III

Hi Mehdi,

1. Refer to any of the bootloader related app notes like AN4370, AN4379, AN2295. These will help.

2. You are right. For Bootloader I will be using a different linker file from my application firmware. And I will be having two SREC files. Bottloader SREC file, I will write with a flash programmer (OSBDM JTAG interface for Towerboard now). Then in your case, bootloader must be able to recieve S19 file through SPI, parse it and write it to the flash.  If you want to write both Bootloader and application firmware at once with a flash programmer, you may have to combine both S19 files. In the AN2295, Freescale has mention about a program to combine S19 files. Hope this may help in this case. I am also planning to try.

1,935 Views
thomasgrieger
Contributor III

Hi Renjith,

could you describe your use case for this question or at least how the second firmware image is loaded into the µC?

A general answer for you question would be that you don't have to use relative linking. For every firmware image (firmware + vector table) you need some space in the flash memory which means you have to define a memory layout (on paper or in your head) containing all 3 parts (bootloader, firmware 1, firmware 2). For every part a project and a separate linker file is needed. After flashing all of them separately the bootloader starts up, chooses one changes the value of the VTOR register in the µC and performs a jump.

Hope this helps.

Best regards,

Thomas

1,935 Views
renjithvamanan
Contributor III

Hi Thomas

Thanks for the reply.

I will make it more clear.

My requirement is firmware update over USB, cloud etc.

I have a boot loader and Firmware 1 in the memory. When a new version of the Firmware 1 is released ( let's call it Firmware 1"), Firmware 1 will receive the image of Firmware 1" and flash it to some location in  the internal flash memory and make some bit in the flash high to indicate to the boot loader that there is a new firmware available. Boot loader during the next reset need to check this bit and execute Firmware 1"(new version) instead of Firmware 1.

I understand that using separate linker file for Firmware 1 and 1", my bootloader can jump directly to Firmware 1" image. But keeping multiple linker files for version upgrade of same firmware would make it unmanageable. So the option I have left in my mind is to copy the Firmware 1" image to the location of Firmware 1 (since both will use same linker file) and execute from there.

Other option would be if possible, specify relative linking in linker file and with in the boot loader just change the base address to Firmwar 1" image and jump to Firmware 1" location.

I would like to know if such an option is available.

Hope this is clear.

Thanks ,

Renjith

0 Kudos

1,935 Views
thomasgrieger
Contributor III

Hi Renjith,

you are correct. Flashing the new firmware to the location of the actual one is the normal procedure, at least for automotive ECUs. The main problem of this approach is that if flashing fails the device has to stop at the bootloader and will show no functional behaviour.

Regarding the multiple linker files, you need 3 of them but they should not change during development as the sections one uses for the firmware images do not change. Let's suppose you define 3 sections in your flash:

0x00000 - 0xFFFF -> bootloader

0x10000 - 0x2FFFF -> firmware 1

0x30000 - 0x4FFFF -> firmware 1"

This definition is independent of the actual size of firmware 1 and firmware 1". This means that there is some empty code if the firmware does not use all available space in the section but ...

Best Regards,

Thomas

0 Kudos

1,935 Views
renjithvamanan
Contributor III

Hi,

Did you mean that I have to use two separate linker files for firmware 1 and 1".

Could you please make it more clear.

Thanks,

Renjith

0 Kudos

1,935 Views
thomasgrieger
Contributor III

Hi Renjith,

actually one needs one linker file for every independent application or firmware part as this is the only was to tell the linker how to link and which addresses shall be used.

Therefor if you refer to the example above you need 3 linker files, one for the bootloader, one for the firmware 1 and one for the firmware 1".

This could be reduced to two linker files if you don't have two copies of the firmware in the flash but the bootloader writes the new one to the position of the old one.

Do you have DDRAM on your device?

Best regards,

Thomas

0 Kudos

1,935 Views
renjithvamanan
Contributor III

hi Thomas,

Yes. I understand that every application needs a linker file. In my case Firmware 1", is the new version of Firmware 1. So both Firmware 1 and 1" will be using same linker file for the build.

So I was thinking if there is any alternative option to place the Firmware 1 " in some arbitrary position in flash in the run time and execute from there. Do you think that this is possible with some settings in linker specification?

Regarding DDRAM, I don't have. Otherwise I understand that I can copy the firmwares to DDRAM before execution and start from there.

Regards,

Renjith

0 Kudos