Topic : I want to write procedure

Forum : ARM

Original Post
Post Information Post
January 27, 2012 - 1:52pm

I want to write procedure that upgrades code in internal flash (gcc Ride-7 enviroment). It will be full upgrade of flash with executing mass erase command, so I should copy upgrade procedure to ram, execute it from ram and upgrade program.
And I have questions:
1. when I copying function to RAM, i copying data from flash address to ram address, but how detect size of function (it will not be only one function but more functions, so I want collect them...)
2. how to execute program from RAm after copy ? simple jump ?
3. how tell the linker to locate pocedures in flash at specified address ? (I want them to be inside first page of flash)
4. how tell the linker to locate some constants at special flash address ? (for veryfing flash contents)

with best regards,

Post Information Post
January 27, 2012 - 2:57pm
Raisonance Support Team


1) the easiest way to do this is to place the functions you want to preserve in a specific linker section using the gcc __attribute__ ((section(".myflashsection"))). Then instruct the linker to place this section at a specific address in Flash. You will then be able to copy it to RAM.
Warning: On Cortex cores, an executable address pointer (such as a function address) is internally represented with its lowest bit set. So if you are handling a function address (which MUST be word aligned), always mask out the lowest bit. You've been warned!

2) Simple jump is fine. However you have to ensure that your code is position-independent using the -fpie compiler option.

3) Refer to Other threads on our forum can help concerning linker sections handling.

4) Same as 3. GCC links in a very organized (I mean "squared") way, and its process is extremely simple. So what it does for RAM is the same as for Flash, constants, strings or whatever it links.

Best Regards,