0

Is it possible to set the memory position a function start from? I want to know if it is possible to do so at compilation, linking or even in code.

Also I'm working with FreeRTOS, is it possible too?

jlanza
  • 1,208
  • 3
  • 23
  • 43
  • Why you need this? Put function pointer on a known location ? – Danijel Mar 22 '15 at 00:45
  • I want to compile the main program in one set, and then, include the code of some function in another part of the memory. This way if I want I will only reflash the function and not the main program. – jlanza Mar 23 '15 at 15:00
  • Function pointer could solve the problem, in program set void (*some_func)(int param1, int param2); some_funct foo = 0x34223 (exact memory location). But still full compile ithink it's better :). This problem could be solvable via some special mode like maintaince mode. Put device in mode, write flash -> reboot device from that flash, it's kinda update functionality. – Danijel Mar 23 '15 at 17:47
  • The problem is that OTA update should be the less possible in size in order to reduce network cost. This is why I want to just flash the function. From what @Dostojevski says I have to set in the binary creation configuration files the memory address. Is it correct? – jlanza Mar 23 '15 at 21:20

1 Answers1

0

What toolchain do you use? Some compilers have special syntax for this (e.g. with word "absolute"), but if you are using GCC you should edit a linker file (.ld). Its syntax is rather cryptic at first sight, but it have a docs where everything is explained. In short, you should mark your function that it belongs to a section like this:

__attribute__((section(".mysection"))) void reflashable_function(...

and then add following text to your MyProject.ld file after all existing sections:

.mysection 0xS0MEADDRESS:
{
  *(.mysection)
  *(.mysection*)
}

Also, add a key like "-Map=output.map" to your makefile to generate mapfile and then seek a name of your function in output.map to check if it has correct address. There may be additional difficulties with e.g. inlining a function or inlining something in it, so i suggest putting it to the separate .c file. You can also addg reflashable memory to MEMORY section of the .ld file, in that case you won't need to add address, but need to add memory name like this:

  .mysection:
{
  *(.mysection)
  *(.mysection*)
  ./sources/dir/reflashable_file.o(.text) /*this is to add a full file, not just one function */
  ./sources/dir/reflashable_file.o(.rodata)
} >BOOTFLASH

You can also add an EXCLUDE_FILE directive to other sections so it won't be included in other sections too. Check a .map file to see results.

kipar
  • 507
  • 3
  • 7
  • Thanks. Unfortunately I'm not working on that issue. I will pass this link to my colleagues to see if it suits – jlanza Dec 21 '15 at 17:01