Dynamically load code into an embedded target

I have an application that runs on a bare metal object and has the following structure

  • main.c
  • service.c / .h

It is compiled into an executable ELF (system.elf) using standard sequence gcc -c, ld. I use the linker to create a map file with the addresses of all the characters.

Now, without flashing my system again, I need to add extra functionality with a custom runtime loader. Remember that this is bare metal without an OS.

I would like to

  • compile extra.c, which uses the APIs defined in service.h (and somehow a link to the existing service.o / system.elf)
  • copy the resulting executable to my sdram at runtime and navigate to it
  • loaded code should be able to run and access exported characters from service.c, as expected

I thought I could reuse the map file to associate extra.o with system.elf, but this did not work:

ld -o extraExe extra.o system.map

Does gcc or ld have any mode for this late binding procedure? If not, how can I achieve loading the dynamic code that I outlined above?

+6
source share
1 answer

ld -R '--just-symbols = _ ". , . , system.elf. (. ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html).

, filename "system.elf". extra.c GCC, services.h, "extra.o", ld, :

ld -R"system.elf" -o"extra.out" extra.o

"extra.out" . objdump "extra.out" "extra.o". , ld (, -defsym _TEXT_START_ADDR = 0xAAAA0123), , bss, data. (.. -Tbss, -Tdata)
, , "system.elf", ld . + + bss script system.elf, 'extra.o'.

+4
source

All Articles