[U-Boot-Users] How to specify the starting function of aU-boot standalone application.

McMullan, Jason mcmullan at netapp.com
Wed Jun 25 15:42:01 CEST 2008


On Wed, 2008-06-25 at 07:44 +0200, Jens Gehrlein wrote:
> I have the same problem. When I modify the source code the compiler may 
> or may not rearrange the functions. It is not guaranteed, that the main 
> function always starts at the same address.
> 
> How can this be solved? Is it possible/meaningful to put the main 
> function into a separate linker segment? Any suggestions?

The simplest way I've found is to make the following C file:

--- _start.c ---
void _start(void)
{
    extern int main(int argc, char **argv);
    char *args[] = { "myprogramname", "-foo", "bar", /* etc. etc. */ };
    main(sizeof(args)/sizeof(args[0]), args);
    /* Wait forever after the program ends */
    for (;;);
}
-----------------

Then, link '_start.o' before *any* other objects in your link step.

Voila! The text entry should be _start!

Feel free to add BSS initialization, etc. in _start as needed.

Jason McMullan
MTS SW
System Firmware

NetApp
724.741.5011    Fax
724.741.5166    Direct
412.656.3519    Mobile
jason.mcmullan at netapp.com
www.netapp.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.denx.de/pipermail/u-boot/attachments/20080625/ea02247f/attachment.pgp 


More information about the U-Boot mailing list