Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

unable to link an executable image

Altera_Forum
Honored Contributor II
1,619 Views

Hi, 

I'm jus triying to compile and link a simple "hello world" application with gcc  

nios2-linux-gnu-gcc (version 4.1.2) 

but gcc does not reconize -elf2flt parameter as we can see in the compiler output: 

 

jordi@debian:$ nios2-linux-gnu-gcc hello.c -o hello.exe -elf2flt 

/home/jordi/projects/vdm-1/system/current/nios2-linux/toolchain-mmu/x86-linux2/bin/../lib/gcc/nios2-linux-gnu/4.1.2/../../../../nios2-linux-gnu/bin/ld: warning: cannot find entry symbol lf2flt; defaulting to 0000137c 

 

The output file remains in elf format instead of desired flat. 

 

please help, I'm realy stuck at this point :( 

 

thanks
0 Kudos
12 Replies
Altera_Forum
Honored Contributor II
563 Views

You need to use objcopy to convert the file format.

0 Kudos
Altera_Forum
Honored Contributor II
563 Views

thanks dsl 

 

I've tried $nios2-linux-gnu-objcopy -i srec hello -o binary hello.exe -s 

 

And I've got hello.exe file that heads with: 

 

00000000 2F6C 6962 2F6C 642E 736F 2E31 0000 0000 /lib/ld.so.1.... 

00000010 0400 0000 1000 0000 0100 0000 474E 5500 ............GNU. 

00000020 0000 0000 0200 0000 0600 0000 1500 0000 ................ 

00000030 0300 0000 0800 0000 0700 0000 0600 0000 ............... 

..... 

 

It doesn't seem a binary flat executable file. 

So where is the trick ? 

Did I a mistake using objcopy ?  

 

thanks
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

You've told objcopy the input file is 'S-records' - not surprising it doesn't DTRT! 

Your elf file probably contains multiple sections (depending on what is in the linker script) that get loaded to different addresses. You'll need to extract these separately. 'objdump -p' will list the program sections (which are the ones you probably want), use the -j parameter to objcopy to select the section.
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

thanks dsl 

I found that a little complicated. 

I think, I've better to use an older toolchain (gcc version 3.4.6) 

that accept -elf2flt parameter. 

I run nios2-linux-gnu-gcc hello.c -o hello2 -elf2flt and it works. 

I wonder why gcc 4.1.2 doesn't accept that. 

 

thanks
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

I can't see where gcc 3.4.6 supports it, the copy I have doesn't. 

Possibly something is using that parameter to set the OUTPUT_FORMAT outside the linker script - but I can't see a command line parameter to ld that would do that. 

 

For flexibility (and to know what is actually being done) it is best to run objcopy yourself.
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

OK dsl 

I'll follow this way 

Thankyou
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

 

--- Quote Start ---  

thanks dsl 

I found that a little complicated. 

I think, I've better to use an older toolchain (gcc version 3.4.6) 

that accept -elf2flt parameter. 

I run nios2-linux-gnu-gcc hello.c -o hello2 -elf2flt and it works. 

I wonder why gcc 4.1.2 doesn't accept that. 

 

thanks 

--- Quote End ---  

 

 

Hi, I am experiencing same problem.. I see that you have switch to older version of GCC. could you give me some instruction how safely remove the GCC and install the older one?.. I have tried this before but was not able to.. Sorry I have still much to learn in this linux
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

Hi, Lanzones 

I finally opted for using and old uClinux distribution (Linux version 2.6.19-uc1 from www.uclinux.org) and using also an old toolchain gcc version 3.4.6. You can get the tool from  

http://www.alterawiki.com/wiki/binarytoolchain 

you can decompress the archive http://www.niosftp.com/pub/gnutools/nios2gcc-20080203.tar.bz2 in any place you wish (i.e /opt/nios2-toolchain) 

You have to put in the 'path' the path to binaries in your bashrc file 

i.e: 

PATH_TOOLCHAIN_NIOS2=/opt/nios2-toolchain/build_nios2/staging_dir/bin/ 

PATH=$PATH:$PATH_TOOLCHAIN_NIOS2 

export PATH 

 

to compile my old version of linux I have to do something like this: 

 

M_ARCH=nios2nommu 

M_SYSPTF=$M_DIR_BASE/ptf/NIOS.ptf 

# toolchain (builroot) 

M_TOOLCHAIN=/opt/nios2-toolchain/build_nios2/staging_dir/bin/nios2-linux- 

# hardware assign 

make ARCH=${M_ARCH} CROSS_COMPILE=${M_TOOLCHAIN} vendor_hwselect SYSPTF=${M_SYSPTF} 

# compile 

make ARCH=${M_ARCH} CROSS_COMPILE=${M_TOOLCHAIN} 

 

This is valid for old uClinux dist so you will have to tune for your distribution. 

good luck
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

Thanks jofasa, 

 

got it... 

 

with this solution, the elf2flt function will work properly.I try to do the DEBUG Apps " nios2-linux-uclibc-gcc -g hello.c -o hello -elf2flt" again and it should work this time.. 

 

do you think this is also the reason why I couldnt run properly the  

make gcc elf2flt gdb-host on building the toolchain? 

 

some clarification.. ALL of below should be all in my .bash_profile.. correct? 

 

/******************************* 

PATH_TOOLCHAIN_NIOS2=/opt/nios2-toolchain/build_nios2/staging_dir/bin/ 

PATH=$PATH:$PATH_TOOLCHAIN_NIOS2 

export PATH 

 

M_ARCH=nios2nommu 

M_SYSPTF=$M_DIR_BASE/ptf/NIOS.ptf 

 

 

M_TOOLCHAIN=/opt/nios2-toolchain/build_nios2/staging_dir/bin/nios2-linux- 

 

make ARCH=${M_ARCH} CROSS_COMPILE=${M_TOOLCHAIN} vendor_hwselect SYSPTF=${M_SYSPTF} 

 

make ARCH=${M_ARCH} CROSS_COMPILE=${M_TOOLCHAIN}
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

Hi Lanzones 

In .bashrc you have to put only the path to binaries toolchain 

all the rest is just a script stuff to compile the kernel. 

You have to keep on mind the toolchain prefix, in my case is "nios2-linux-", 

so the compiler call is nios2-linux-gcc. In your case it seems to be "nios2-linux-uclibc-". We have different toolchains, so you should modify the path I give you as exemple in order to have correct binaries path in your toolchain.
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

thanks.. I have it working.. 

 

just for curiosity,, I have downloaded the toolchain and I gone in each directory coz I am trying to find /build_nios2/staging_dir/bin/ from your setting.. Couldnt find it... 

 

Is this something that you have put or generated?. BTW do I need to make the toolchain by MAKE?...
0 Kudos
Altera_Forum
Honored Contributor II
563 Views

Hi, 

I've got the my toolchain yet compiled from a colleague, so I didn't to make it. 

So, if you can't find the binaries, you should first make the toolchain project.
0 Kudos
Reply