[U-Boot-Users] Setting entry point in u-boot standalone apps

I have a U-boot standalone app which runs on the Gumstix boards. It's based on the /u-boot-1.2.0/examples/ folder. The problem I have is that my entry function - lets call it app_entry() - isn't at the load address, it's somewhere in the middle. I'm using the output from objdump -d <elf file> > <elf file>.dis to determine where in the address range the functions are located.
When I originally built the hello_world.c examples, the hello_world() function was located at the load address and everything worked fine. I would do issue the following commands to run it:
loadb a0000000 <send the .bin file> go a0000000
However I discovered that as I made changes to this file the hello_world() function was moved around within the address range (ie. it was no longer at the start of the range) - this was discovered when the app no longer worked. After investigating I found that I needed to disassemble the file, locate where the entry function is now located, and do the following commands:
loadb a0000000 <send the .bin file> go a0000948 (or whatever the address of my entry function was)
This then worked every time.
My problem is that I wish to avoid this as every time I change any of the functions located before my entry function, this address changes. It would be far nicer, and easier, to just have my entry function always located at the start of the range and I can then always execute my app by doing 'go a0000000' irrespective of any changes I make to the code..
I'm using a slightly modified version of the Makefile in the examples folder, the particular interesting part (I think) which I've not changed is:
$(ELF): $(obj)%: $(obj)%.o $(LIB) $(LD) -g $(EX_LDFLAGS) -Ttext $(LOAD_ADDR) \ -o $@ -e $(notdir $(<:.o=)) $< $(LIB) \ -L$(gcclibdir) -lgcc
The -e part should be specifying the entry point of the ELF file, however outputting the result of the $(notdir) part shows it's empty. When I've replaced it with just the entry function's name, it makes no difference either.
As I understand it (taken from: http://sourceware.org/binutils/docs-2.17/ld/Entry-Point.html):
"There are several ways to set the entry point. The linker will set the entry point by trying each of the following methods in order, and stopping when one of them succeeds:
* the `-e' entry command-line option; * the |ENTRY(|symbol|)| command in a linker script; * the value of the symbol |start|, if defined; * the address of the first byte of the `.text' section, if present; * The address |0|."
Unfortunately, the examples don't use linker scripts, and I don't want to start messing with these as it interacts with u-boot to some extent (certainly built within u-boot's makefile), and it's all working as it is. From what I understand though, the -e option should be sufficient.
Has anyone else experienced this problem, and can give any advice as to how to solve it?
Thanks
David

Hi David,
u-boot-users-bounces@lists.sourceforge.net wrote on :
I have a U-boot standalone app which runs on the Gumstix boards. It's based on the /u-boot-1.2.0/examples/ folder. The problem I have is that my entry function - lets call it app_entry() - isn't at the load address, it's somewhere in the middle. I'm using the output from objdump -d <elf
This is a known issue, please look at: http://www.denx.de/wiki/view/DULG/MyStandaloneProgramDoesNotWork
app no longer worked. After investigating I found that I needed to disassemble the file, locate where the entry function is now located, and do the following commands:
loadb a0000000 <send the .bin file> go a0000948 (or whatever the address of my entry function was)
This then worked every time.
Yes, it should :-)
The -e part should be specifying the entry point of the ELF file,
Yes, it specifies the entry point (= entry function) - but not at which address the entry point is placed by the linker. So the entry option does not, what you are looking for.
Unfortunately, the examples don't use linker scripts, and I don't want to start messing with these as it interacts with u-boot to some extent (certainly built within u-boot's makefile), and it's all working as it is. From what I understand though, the -e option should be sufficient.
No, see comments above.
Has anyone else experienced this problem, and can give any advice as to how to solve it?
You have to change your linker script. Tell the linker where it should place your entry point function (I'm no linker expert, so I couldn't give you advice at this ...)
Regards,
Martin Krause
-- TQ-Systems GmbH Muehlstrasse 2, Gut Delling, D-82229 Seefeld Amtsgericht Muenchen, HRB 105 018, UST-IdNr. DE 811 607 913 Geschaeftsfuehrer: Dipl.-Ing. (FH) Detlef Schneider, Dipl.-Ing. (FH) Ruediger Stahl http://www.tq-group.com

Martin Krause wrote:
Hi David,
u-boot-users-bounces@lists.sourceforge.net wrote on :
I have a U-boot standalone app which runs on the Gumstix boards. It's based on the /u-boot-1.2.0/examples/ folder. The problem I have is that my entry function - lets call it app_entry() - isn't at the load address, it's somewhere in the middle. I'm using the output from objdump -d <elf
This is a known issue, please look at: http://www.denx.de/wiki/view/DULG/MyStandaloneProgramDoesNotWork
Very helpful - thanks for pointing that out.
Has anyone else experienced this problem, and can give any advice as to how to solve it?
You have to change your linker script. Tell the linker where it should place your entry point function (I'm no linker expert, so I couldn't give you advice at this ...)
Regards,
Martin Krause
I've now started using a linker script which does the job. The way I did it was to create a separate object file which just contained a single wrapper function which called my 'main' function. This function would always be at the start of the resulting .o file, and this .o file was then specified as the first entry in the .text section. Consequently this wrapper function is now always at the start of my final binary file.
Thanks for the pointers, and the explanations regarding entry points and link locations.
David

In message 46EF92C1.5050309@swampie.org.uk you wrote:
Unfortunately, the examples don't use linker scripts, and I don't want to start messing with these as it interacts with u-boot to some extent
You canhave only one or the other...
(certainly built within u-boot's makefile), and it's all working as it is. From what I understand though, the -e option should be sufficient.
-e is sufficient to specify the entry point, but it is not sufficient to force the linker to place specific objects at specific locations in your image. For that you need alinker script.
Best regards,
Wolfgang Denk

Wolfgang Denk wrote:
In message 46EF92C1.5050309@swampie.org.uk you wrote:
Unfortunately, the examples don't use linker scripts, and I don't want to start messing with these as it interacts with u-boot to some extent
You canhave only one or the other...
(certainly built within u-boot's makefile), and it's all working as it is. From what I understand though, the -e option should be sufficient.
-e is sufficient to specify the entry point, but it is not sufficient to force the linker to place specific objects at specific locations in your image. For that you need alinker script.
Understood, implemented and now working.
David
participants (3)
-
David Hearn
-
Martin Krause
-
Wolfgang Denk