* [U-Boot-Users] How to specify the starting function of a U-boot standalone application.
@ 2008-06-24 21:45 richardretanubun
2008-06-25 5:44 ` Jens Gehrlein
0 siblings, 1 reply; 5+ messages in thread
From: richardretanubun @ 2008-06-24 21:45 UTC (permalink / raw)
To: u-boot
Hi Guys,
I am writing a u-boot standalone application and are having difficulty
understanding how it decides the function to execute when
I used to "go <start addr>+4" command.
In my application I have something like this...
the filename is my_test.c
/* Function prototypes */
int main (int argc, char *argv[]);
void do_func_a (int argc, char *argv[]);
void do_func_info (void);
int main (int argc, char *argv[])
{
app_startup (argv);
....
do_func_info();
do_func_a(argc, argv);
return(0);
}
void do_func_a(int argc, char *argv[])
{
....
}
void do_func_info(void)
{
}
When I go go <start addr>, the execution jumps straight to
do_func_info() and the application finishes. (which is just a bunch of
printf).
How do I ensure that when compiled, the my_test.bin places the main
function at the "go" point?
I have tried re-ordering the function bodies around, moving main as the
last function and thus removing all the function prototypes.
I tried name matching the "main" function to the file name, none seems
to help.
Thank you so much for all your help.
Richard Retanubun.
^ permalink raw reply [flat|nested] 5+ messages in thread* [U-Boot-Users] How to specify the starting function of a U-boot standalone application.
2008-06-24 21:45 [U-Boot-Users] How to specify the starting function of a U-boot standalone application richardretanubun
@ 2008-06-25 5:44 ` Jens Gehrlein
2008-06-25 13:42 ` [U-Boot-Users] How to specify the starting function of aU-boot " McMullan, Jason
0 siblings, 1 reply; 5+ messages in thread
From: Jens Gehrlein @ 2008-06-25 5:44 UTC (permalink / raw)
To: u-boot
Hi all,
richardretanubun schrieb:
> When I go go <start addr>, the execution jumps straight to
> do_func_info() and the application finishes. (which is just a bunch of
> printf).
>
> How do I ensure that when compiled, the my_test.bin places the main
> function at the "go" point?
>
> I have tried re-ordering the function bodies around, moving main as the
> last function and thus removing all the function prototypes.
> I tried name matching the "main" function to the file name, none seems
> to help.
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?
My temporary solution:
Because I had to patch the U-Boot code, especially the API, anyway for
my purposes, I decided to implement my test function as U-Boot command
instead as standalone application.
Best Regards,
Jens
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot-Users] How to specify the starting function of aU-boot standalone application.
2008-06-25 5:44 ` Jens Gehrlein
@ 2008-06-25 13:42 ` McMullan, Jason
2008-06-25 13:57 ` Jens Gehrlein
0 siblings, 1 reply; 5+ messages in thread
From: McMullan, Jason @ 2008-06-25 13:42 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply [flat|nested] 5+ messages in thread* [U-Boot-Users] How to specify the starting function of aU-boot standalone application.
2008-06-25 13:42 ` [U-Boot-Users] How to specify the starting function of aU-boot " McMullan, Jason
@ 2008-06-25 13:57 ` Jens Gehrlein
2008-06-27 16:08 ` richardretanubun
0 siblings, 1 reply; 5+ messages in thread
From: Jens Gehrlein @ 2008-06-25 13:57 UTC (permalink / raw)
To: u-boot
Hi Jason,
McMullan, Jason schrieb:
> 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.
Very nice. Thank you for this tip!
Best Regards,
Jens
^ permalink raw reply [flat|nested] 5+ messages in thread* [U-Boot-Users] How to specify the starting function of aU-boot standalone application.
2008-06-25 13:57 ` Jens Gehrlein
@ 2008-06-27 16:08 ` richardretanubun
0 siblings, 0 replies; 5+ messages in thread
From: richardretanubun @ 2008-06-27 16:08 UTC (permalink / raw)
To: u-boot
Hi Guys,
I found this in the u-boot FAQ (is there anything that thing can't
answer? :D)
http://www.denx.de/wiki/view/DULG/MyStandaloneProgramDoesNotWork
Of course, Jason's solution is also nice. Thanks for that!
Regards,
- Richard Retanubun
Jens Gehrlein wrote:
> Hi Jason,
>
> McMullan, Jason schrieb:
>> 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.
>
> Very nice. Thank you for this tip!
>
> Best Regards,
> Jens
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-06-27 16:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-24 21:45 [U-Boot-Users] How to specify the starting function of a U-boot standalone application richardretanubun
2008-06-25 5:44 ` Jens Gehrlein
2008-06-25 13:42 ` [U-Boot-Users] How to specify the starting function of aU-boot " McMullan, Jason
2008-06-25 13:57 ` Jens Gehrlein
2008-06-27 16:08 ` richardretanubun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox