EmbDev.net

Forum: ARM programming with GCC/GNU tools Reload an ELF File


von Andreas K. (halma)


Rate this post
useful
not useful
Hy!

I would like to know if somebody has any experience with elf files.

My problem is: I have a program which i compile with a gcc Compiler and 
this program runs on a Cortex A9 Prozessor.

In the program there is a pointer to a dummy function. During the 
program the user should be able to load a function to a specific space 
in RAM with all neccessary initialize things.
After loading this program the pointer should be set to the new function 
and this function should run.

The reload of the function should take place without stopping the main 
program.
I found something like Dynamik kinking with ELF files, but I Need some 
help with this Topic please.

Ülease ask if you Need more Information to this Topic

Best regards
Andi

von Dr. Summer (Guest)


Rate this post
useful
not useful
Use the exec() family of functions to replace the current process image 
with a new one from another executable file.
You can instead load library files using dlopen() and call functions 
from them using dlsym(). If your kernel/loader supports ELF, these files 
can be im ELF format.

von Karl Käfer (Guest)


Rate this post
useful
not useful
Hi Andreas,

Andreas Klettner wrote:
> I would like to know if somebody has any experience with elf files.
>
> My problem is: I have a program which i compile with a gcc Compiler and
> this program runs on a Cortex A9 Prozessor.
>
> In the program there is a pointer to a dummy function. During the
> program the user should be able to load a function to a specific space
> in RAM with all neccessary initialize things.
> After loading this program the pointer should be set to the new function
> and this function should run.
>
> The reload of the function should take place without stopping the main
> program.
> I found something like Dynamik kinking with ELF files, but I Need some
> help with this Topic please.

If you have an operating system with a dynamic linker (like, for 
example, Linux), then you could try the dl{open,error,sym,close}(3) 
functions from dlfcn.h. These provide dynamic loading as well as 
resolving the symbols of shared object files.

HTH,
Karl

von Andreas K. (halma)


Rate this post
useful
not useful
Hi,

thx for your answers, but I do not have the dlfcn.h file on my pc.
I can not find it in my gcc Settings.

Do you know what to do?

Thx

von Markus F. (mfro)


Rate this post
useful
not useful
what I have (successfully) done in the past (on another platform) was 
having the bootloader read S-record files from SD-card into memory, 
transform to binary and execute them.

This basically just needs two suitable linker scripts (they must agree 
on the entry point which is just a function without parameters returning 
an int), the SD-card read routines and an S-record parser.

I think that should work as well for ELF files.

von Karl Käfer (Guest)


Rate this post
useful
not useful
Hi Andreas,

Andreas Klettner wrote:
> thx for your answers, but I do not have the dlfcn.h file on my pc.
> I can not find it in my gcc Settings.
>
> Do you know what to do?

dlfcn.h is Linux-specific, thus if you work on a Windows PC you won't 
have it. Maybe you'd try and compile on the target?

HTH,
Karl

von Andreas K. (halma)


Rate this post
useful
not useful
I have another question:

What is about writting my own elf loader? Is this a very complicated 
thing or is it more like straight forward?

I do not know but I am looking in the internet for this thing but I do 
not really found some helpfull things. Only the CONTIKI System seems do 
be something I need.

Would be cool if you could help me again.

von Dr. Summer (Guest)


Rate this post
useful
not useful
Maybe you could finally tell us what Operating System you are using on 
your Cortex-A9. Linux supports dlopen(), others might have their own 
functions for loading ELF's.

von halma (Guest)


Rate this post
useful
not useful
Hey,

thank you for your interesst in my problem.
I do not use an operating system. We have written our own bootloader to 
start the processor and init the ram and flash.

Then we load our basic program down with the dummy function. And during 
the runtime I want to download another function to replace the dummy 
function without stopping the old program.

So I do not have and I also do not want to use Linux.
I think I will have to write my own elf loader to solve my problem, or 
do you have another idea?

von Rolf Magnus (Guest)


Rate this post
useful
not useful
halma wrote:
> I think I will have to write my own elf loader to solve my problem, or
> do you have another idea?

Yes, if you don't have an operating system, you can obviously not use 
any operating system services and have to do everything on your own.
So you have to implement your own dynamic linking system. Maybe you can 
get some ideas on how to do that from the linux kernel and its support 
for loadable kernel modules.

von Markus F. (mfro)


Rate this post
useful
not useful
Rolf Magnus wrote:
> implement your own dynamic linking system

I wouldn't call that "dynamic linking system". As far as I understand, 
what's needed is more like old style "overlays" and that should be 
pretty easy to implement.

If you know the load address upfront (at least that's what I 
understood), you can link your executable to a fixed address and do not 
need to relocate anything. The "overlay" loading process then just boils 
down to reading an ELF file (probably easiest with using one of the 
freely available libelf's that are around), finding the relevant 
section(s), extract them from the file and copy to destination. If you 
set up your linker scripts accordingly, you can even use common areas in 
the data and bss section to exchange data ("poor man's shared memory").

Do not forget to flush cache(s) if you have any since you copied code.

Then just cross fingers and call it.

: Edited by User
von Andreas K. (halma)


Rate this post
useful
not useful
Thank you very much for your answer, but I am a real noob in using elf 
files. Could you post me a link which elf file reader you would use, or 
do you have an idea which one is the best?

To explain my Problem again a litte bit more in Detail:
I have two projects in Eclipse and I am able to compile the two 
projects. I also have the adress where the new function should start in 
memory, for example at: 0x17600000
If I download the file with Eclipse to this location everything works 
fine, but now I want to automatic this process.

Thanks for help again.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.