cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader and binary file format of a new application (memory areas)

francois06
Associate II

Hello,

I'm currently working on a STM32F411 MCU project which includes a BlueNRG-MS module and a bootloader for reprograming OTA purpose. The bootloader is at address 0x08000000.

I would like to program, by the MCU application (not the bootloader) into the flash, a binary file sent over the air at an address determined by the MCU app.

But it looks like the binary file can't be programmed anywhere into the flash but only at the address specified by the linker.

For exemple, if I program a binary file with the ST Link at address 0x0800C000 with the following memory areas in the linker, the bootloader jumps to this new app and it works :

MEMORY

{

RAM (xrw)   : ORIGIN = 0x20000000, LENGTH = 128K

FLASH (rx)   : ORIGIN = 0x800C000, LENGTH = 512K - 48k

}

But if I change the FLASH origin to address 0x08000000 but still program it at address 0x0800C000, the bootloader doesn't jump to this new application.

I thought binary file didn't have any metadata and could be programed anywhere in the flash whithout considering the linker origin.

Am I doing something wrong ? Is there a solution ?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

You'd need to use a format that conveys fixup addresses, and then apply those fixes to accommodate a different base address. The ELF file format could be used, I'd probably optimize the content. If you can use address independent code you'd just need to modify​ the content of the vector table as it contains absolute addresses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

7 REPLIES 7

The binary file contains addresses fixed by the linker. The vector table contains absolute addresses. You can place the binary at any location you want, but it will only function properly at the location you told the linker that it should reside at.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois06
Associate II

Okay thanks for your answer.

So if I understand you well, when I proceed flash programing of the binary file with my MCU, I need to change the value (of the vector table ?) from the binary file, corresponding to the location address of the new app, before putting it in flash.

Am I right ? Is it feasable ? or should I just accept the fact that I won't be able to have a custom address ?

You tell the linker where you want/plan to place the code.

You tell the microcontroller where the vector table is via SCB->VTOR which is often done in the SystemInit code.

The addresses need to be on 512 byte boundaries, you get to choose where, and ensure the​ tools and the microcontroller have a consistent and coherent understanding of where that is.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois06
Associate II

Thanks but what you say is already done in my code and it works.

I'm probably not enough clear in my explanation, so here is a step by step exemple of what I would like to do :

  1. I generate a binary file with a certain origin, let's say 0x0800C000, specified in the linker.
  2. I send to the MCU via Bluetooth Low Energy using the OTA protocole of ST (via a phone or computer for exemple), that I want to program the new binary file in flash at address 0x0800C000.
  3. Before receiving the binary file, the MCU decides to change the origin address because there is some protected data (or whatever) at this typical address. The new address determied by the MCU would be 0x08010000 for exemple.
  4. The MCU receives the binary data and modify it before flashing in order to make the new app functional at the new origin address 0x08010000

So my question is : is there a way, from the MCU, to modify this origin address of the binary file, before putting it in flash ?

I hope it will be clearer.

You'd need to use a format that conveys fixup addresses, and then apply those fixes to accommodate a different base address. The ELF file format could be used, I'd probably optimize the content. If you can use address independent code you'd just need to modify​ the content of the vector table as it contains absolute addresses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois06
Associate II

Okay i see, thanks for your answer.

Okay i see, thanks for your answer.