[U-Boot] Can't get sprintf to work in standalone program

Martin Hejnfelt mh at newtec.dk
Wed Jul 8 16:12:39 CEST 2009


Hi,

I'm trying to use the sprintf function in a C program written for
U-boot. As far as I understand, to get the function I have to add it to
the exports.h, _exports.h and exports.c file as per the
README.Standalone file in /doc (the function is declared in common.h). 
Now if I do this, the program compiles fine, and all is dandy, until I
actually start using the function. It generates garbage. printf and
alike works fine, and the program runs like it should, except the places
where sprintf is used, I get garbage (meaning some environment variables
are looking pretty nasty since the result of the sprintf functions are
used for these). 
When compiling I link to the examples/libstubs.a file and
lib_generic/libgeneric.a where the code I'm using should be present. 
Can anyone give me a clue to what the problem could be or if I
misunderstood the concept completely?
I searched the lists and in my frustration I tried to use some code from
an earlier post where some guy had problems with sprintf. Here Wolfgang
Denk wrote a small piece of code that used the function, and this was
what I then put in my own code, just to see if I could get *anything*
working with sprintf. The code I used was this:
...
unsigned char buf[128];
unsigned char a[6] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, };
int i;
...
printf ("Before: "); for (i=0; i<6; ++i) printf (" %02X",a[i]); putc
('\n');
sprintf (buf, "%02X:%02X:%02X:%02X:%02X:%02X", a[0], a[1], a[2], a[3],
a[4], a[5]);
printf ("After:  "); for (i=0; i<6; ++i) printf (" %02X",a[i]); putc
('\n');
printf ("buf=\"%s\"\n", buf);
...
When I do this, the line that defines the a[6] thing generates a
compiler error stating an undefined reference to memcpy. Since this
error is present every time I try to initialize a string (char*) or char
array I'm guessing this might be the problem, but I'm not sure...

The platform is ARM (AT91RM9200)... U-boot version is 2009.06.

I'm new to standalone programming for U-boot so this might surely be the
problem, so any help is appreciated :)

Kind regards,
Martin Hejnfelt



More information about the U-Boot mailing list