2019-01-31 01:52 AM
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.
Solved! Go to Solution.
2019-01-31 06:04 AM
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.
2019-01-31 02:03 AM
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.
2019-01-31 03:08 AM
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 ?
2019-01-31 03:33 AM
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.
2019-01-31 03:59 AM
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 :
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.
2019-01-31 06:04 AM
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.
2019-01-31 06:13 AM
Okay i see, thanks for your answer.
2019-01-31 06:14 AM
Okay i see, thanks for your answer.