I have an embedded system with internal and external flash. The controller is an MSP430F22x2, the external flash is connected using SPI. I can load data from external flash but the external flash isn't memory mapped. Since the internal flash is not big enough I want to add functions into external flash. So the external flash has to be copied into internal flash, so that the functions can be executed. It is essentially like poor mans paging.
To do all this I have a function, that loads the right part of flash and then calls the function. It manages an internal page stack, seperate to the 'real' stack. If I want to call a function on another page I have to jump to this function. The function then calls the function on the now loaded page. When the function returns the execution continues in the management function (because it was called from there) which then loads the right page and jumps back.
The problem is, that the functions are all at the same location in memory, since they are copied. But the data in ram can't overlap. My current solution is to use seperate linker scripts for each parts of external code and setting the addresses of the ram sections manually. This is of course time consuming and everything has to be changed if a part needs more ram etc.
The separate linker scripts look like this:
ENTRY(part)
SECTIONS
{
.data 0x2A4 :
{
. = ALIGN(2);
*(.data .rodata*)
}
.text 0x4000 :
{
*(.text)
}
}
Nothing fancy. Everything is set to specific addresses, no overflow is checked. To be able to call the functions I export the symbol table and add them to the main linker script. This is all automated using batch scripts.
So I need a linker script that essentially places multiple .text sections overlapping in the same address range and the .data sections continuosly.
I don't know if there is a way to do this. Really any solution (linker scripts, batch scripts etc.) would help me. The only thing I can't change is the hardware.
separate linker scripts
you are using? How are you manully setting the sections? What "external flash" are you using? How should others post a solution if they don't know what hardware and environment are you using?My code does keep track of all this
How does "keep track of this" exactly works? Please edit your question and add additional information. - KamilCuk