- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am working on a custom board with Nios2. I am facing a weird problem with printf. When I do any printf I am getting an inversed output. i.e. If I do printf("Hello World"); I get eHll ooWlrd. Take 2 chars from H and reverse. U get the o/p I am getting. All this is happening in vsprintf which is called by printf for formatting. Below I will give the code snippet where things are going wrong. int vsprintf(char *buf, const char *fmt, va_list args) { ................... char * str; ................... for (temp=str=buf ; *fmt ; ++fmt) { if (*fmt != '%') { *str++ = *fmt; continue; } ..................... case 's': s = va_arg(args, char *); if (!s) s = "<NULL>"; len = strnlen(s, precision); if (!(flags & LEFT)) while (len < field_width--) *str++ = ' '; for (i = 0; i < len ; ++i) *str++ = *s++; while (len < field_width--) *str++ = ' '; continue; .................... } for (i = 0; i < len ; ++i) *str++ = *s++; This is where every thing goes wrong. suppose s="Hello from NiosII!" it coppies correctly to str but it appears as mentioned above in buf i.e "eHll oofmoN oiIsI. Clue: For loop which is suppose to incerement from 0 to len, actually decrements from len to 0. I beleive it is compiler optimization.Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by shakthi@Mar 28 2006, 03:12 AM hi,
i am working on a custom board with nios2. i am facing a weird problem with printf.
when i do any printf i am getting an inversed output.
i.e. if i do printf("hello world"); i get ehll oowlrd. take 2 chars from h and reverse. u get the o/p i am getting.
all this is happening in vsprintf which is called by printf for formatting.
below i will give the code snippet where things are going wrong.
int vsprintf(char *buf, const char *fmt, va_list args)
{
...................
char * str;
...................
for (temp=str=buf ; *fmt ; ++fmt) {
if (*fmt != '%') {
*str++ = *fmt;
continue;
}
.....................
case 's':
s = va_arg(args, char *);
if (!s)
s = "<null>";
len = strnlen(s, precision);
if (!(flags & left))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len ; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
....................
}
for (i = 0; i < len ; ++i)
*str++ = *s++;
this is where every thing goes wrong.
suppose s="hello from niosii!" it coppies correctly to str but it appears as mentioned above in buf i.e "ehll oofmon oiisi.
clue:
for loop which is suppose to incerement from 0 to len, actually decrements from len to 0. i beleive it is compiler optimization.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13861)
--- quote end ---
--- Quote End --- Looks like it's byte swapped to me...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi shakthi,
> When I do any printf I am getting an inversed output. Ok, this is the same problem you posted WRT u-boot. Are you now using the system library and seeing the same problems? And the big question: are you using a custom memory component, or a custom bridge between your system module and an on/off-chip memory? --Scott- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by fmcmurra+mar 28 2006, 10:41 pm--><div class='quotetop'>quote (fmcmurra @ mar 28 2006, 10:41 pm)</div>
--- quote start ---
<!--quotebegin-shakthi@Mar 28 2006, 03:12 AM hi,
i am working on a custom board with nios2. i am facing a weird problem with printf.
when i do any printf i am getting an inversed output.
i.e. if i do printf("hello world"); i get ehll oowlrd. take 2 chars from h and reverse. u get the o/p i am getting.
all this is happening in vsprintf which is called by printf for formatting.
below i will give the code snippet where things are going wrong.
int vsprintf(char *buf, const char *fmt, va_list args)
{
...................
char * str;
...................
for (temp=str=buf ; *fmt ; ++fmt) {
if (*fmt != '%') {
*str++ = *fmt;
continue;
}
.....................
case 's':
s = va_arg(args, char *);
if (!s)
s = "<null>";
len = strnlen(s, precision);
if (!(flags & left))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len ; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
....................
}
for (i = 0; i < len ; ++i)
*str++ = *s++;
this is where every thing goes wrong.
suppose s="hello from niosii!" it coppies correctly to str but it appears as mentioned above in buf i.e "ehll oofmon oiisi.
clue:
for loop which is suppose to incerement from 0 to len, actually decrements from len to 0. i beleive it is compiler optimization.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13861)
--- quote end ---
--- Quote End --- Looks like it's byte swapped to me... <div align='right'><{post_snapback}> (index.php?act=findpost&pid=13873)</div> [/b] --- Quote End --- <div class='quotetop'>QUOTE </div> --- Quote Start --- Yappppp its a byte swap[/b] --- Quote End ---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. I had posted the same wrt U-Boot.
It is a custom board with Nios II, Intel strata flash and Samsung SDRAM and few more components. Off chip SDRAM is connected to Nios directly through Avalon switch fabric and no tristate bridge is used in between. While configuring SDRAM controller in SOPC since samsung memory is available in dropdown list of the controller wizard the SDRAM controller is generated for custom memory. We are using SDRAM controller and Avalon switch fabric from SOPC builder. Here is what exactly happens: Assume I am trying to write 'a' at 0x0 using a char *. It puts 'a' at 0x0. When I put 'b' at 0x1, It moves 'a' from 0x0 to 0x1 and puts 'b' at 0x0. I have tested It with Nios II IDE's sample programs, I get the same result. I could even port linux kernel to the board, but got the same result. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/unsure.gif- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi shakthi,
> I have tested It with Nios II IDE's sample programs, I get the same result. I did not think it was a u-boot problem. > It puts 'a' at 0x0. When I put 'b' at 0x1, It moves 'a' from 0x0 to 0x1 and puts 'b' > at 0x0. Your hardware is broken -- you need to fix it and stop wasting time looking for problems in software that has been stable for years. Your byte enable signals are probably reversed, maybe shorted -- and check your SDRAM configuration in SOPCBuilder as well. Regards, --Scott- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yapp. Now I know its not a problem in U-Boot or Nios II programs or the kernel.
Its a problem of byte swap due to some wrong hardware configuration. We are trying to figure out the problem in the hardware. We have already checked the configuration data for SDRAM and looks correct. We are trying with different phase shifts. Now we have noticed that there is swapping in nibbles too. Thanks for your help. Looking forward for more support. Regards, Shakthi
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page