Forum Discussion
Linux development environment
Does anyone know if the Nios II port of uClinux is available as a simple tarball (i.e. tar.gz or .tgz) that can be downloaded to a Linux machine and configured and built using the nios2-elf-gcc cross compiler?
I am actively attempting to rebuild the nios2-gnutools on my Linux box so I can develop the kernel and user applications on it. I will post the results if I am successful. However, if someone has already accomplished this I would be very interested in getting the source.26 Replies
- Altera_Forum
Honored Contributor
Just use the source supplied with the Windows "uClinux 2.6 Distribution for Nios II" posted in the forum.
Remove CRs from the source-files by using dos2unix or stripcr.c included at the end of this mail (have also included a script which calls this prog.). Build instructions: Installdir=/usr/local/nios2-gnutools (or whatever you want) Sourcedir contents: binutils gdb gcc make newlib Get rid of Cygwin inserted CRs: ./stripcr.sh In sourcedir do: [1] Binutils mkdir binutils-build cd binutils-build ../binutils/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [2] GCC export PATH=$PATH:$Installdir mkdir gcc-build cd gcc-build ../gcc/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir --with-newlib --with-headers=../newlib/newlib/libc/include -v make all make install [3] Make mkdir make-build cd make-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [4] Newlib cp newlib/newlib/configure.host.normalc newlib/newlib/configure.host mkdir newlib-build cd newlib-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [5] GDB mkdir gdb-build cd gdb-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install Hope this is helpful Regards Atle ---------------------------------------------- stripcr: ----------------------------------------------# include <stdio.h># include <string.h># include <errno.h> char strip_tmpfile[]="/tmp/stripCR.tmp"; int custom_copy (const char* in, const char* out, int stripCR); int main (argc, argv) int argc; char* argv[]; { int result; while (--argc > 0) { argv++; result = custom_copy (argv[0], strip_tmpfile, 1); if (result==1) { if (custom_copy (strip_tmpfile, argv[0], 0)) exit(-1); printf(" Stripping CR from file %s\n", argv[0]); }else { if (result!=0) exit(-1); } } return 0; } /* return value: 0: no strip, 1: file stripped, otherwise error */ int custom_copy (const char* in, const char* out, int stripCR) { FILE *ifp; /* input file pointer */ FILE *ofp; /* output file pointer */ char ch; int result=0; ifp = fopen (in, "rb"); ofp = fopen (out, "wb"); if (ifp == NULL) { printf ("Could not open %s for reading\n", in); return 0; } if (ofp == NULL) { printf ("Could not open %s for writing.\n", out); return -1; } while (!feof (ifp)) { if(fread ((void*) &ch, 1, 1, ifp)) { if (stripCR && (ch == (char) 0x0D)) { result=1; continue; } fwrite((void*) &ch, 1, 1, ofp); } } fclose (ifp); fclose (ofp); return result; } ------------------------------------------------------- stripcr.sh: -------------------------------------------------------# !/bin/bash# Strips CRs from all Makefiles and sourcefiles # stripcr binary STRIPCR=$PWD"/stripcr/stripcr" SRCDIR=$PWD"/src/" echo $PWD # Makefiles find $SRCDIR \( -name 'Makefile' -o -name 'Makefile.in' \) -exec $STRIPCR {} \; # Source files find $SRCDIR \( -name '*.c' -o -name '*.h' -o -name '*.S' \) -exec $STRIPCR {} \; # Linker scripts find $SRCDIR \( -name '*.ld' \) -exec $STRIPCR {} \; # Awk, sed and perl scripts find $SRCDIR \( -name '*.awk' -o -name '*.sed' -o -name '*.pl' \) -exec $STRIPCR {} \; # Config find $SRCDIR \( -name 'config.in' -o -name 'configure.in' -o -name 'configure' \) -exec $STRIPCR {} \; # Other find $SRCDIR \( -name '*.md' \) -exec $STRIPCR {} \; - Altera_Forum
Honored Contributor
Ooops. Sorry.. the tools are of course included with the Altera Nios kit.
- Altera_Forum
Honored Contributor
I am having some level of success following your instructions.
Your stripcr program and script has been very helpful. I did find that I had to change it so that instead of Makefile.in it looks in any Makefile.* and instead of config.in, it looks at any config.*. I also found that throughout the build I would have to run the script again to strip newly generated files of their carriage returns. Currently I am hung up on the newlib configuration/compile. It is having problems with the following directory of the install: nios2-gnutools/src/newlib-build/nios2-elf/mno-hw-mul/newlib/libc/sys/. The Makefile contains no definition for "sys_dir". Apparently this is where the specific system is called out. In looking at the nios2-gnutools/src/newlib/newlib/libc/sys directory, there are several systems listed. None of them are related to nios, but there is one for linux. I have tried to get the Makefile to use this directory, but it still has issues. Were you able to get your newlib/ items to build properly without any tweaking? If so, was your "sys_dir" variable defined? It was not defined in my setup. Thanks again for your help. - Altera_Forum
Honored Contributor
I have just tried to build the tools, and have not experienced any problems (newlib builds just fine). The only thing I've done different from the HOWTO I posted was to build only C and C++ for gcc by using: --enable-languages=c,c++. As you say you have to run stripcr() on autogenerated files, maybe that CRs is your problem. Here is an updated version of the stripcr.sh script:
# !/bin/bash# Strips CRs (Cygwin ......) from all Makefiles and sourcefiles # stripcr binary STRIPCR="/usr/local/bin/stripcr" SRCDIR=$PWD echo "Stripping CR in "$SRCDIR # Config find $SRCDIR \( -name 'config.*' -o -name 'configure.*' -o -name 'configure' \) -exec $STRIPCR {} \; # Scripts + templates find $SRCDIR \( -name '*.sc' -o -name '*.sh' \) -exec $STRIPCR {} \; # Makefiles find $SRCDIR \( -name 'Makefile' -o -name 'Makefile.*' \) -exec $STRIPCR {} \; # Source files find $SRCDIR \( -name '*.c' -o -name '*.h' -o -name '*.S' -o -name '*.s' \) -exec $STRIPCR {} \; # Linker scripts find $SRCDIR \( -name '*.ld' \) -exec $STRIPCR {} \; # Awk, sed and perl scripts find $SRCDIR \( -name '*.awk' -o -name '*.sed' -o -name '*.pl' \) -exec $STRIPCR {} \; # Other find $SRCDIR \( -name '*.md' \) -exec $STRIPCR {} \; - Altera_Forum
Honored Contributor
Thanks again for your help. I will untar a pristine tarball and try the process over.
I have assumed that for the newlib portion in step 4, you meant to have "../newlib/configure" instead of "../make/configure". Is this correct, or is this why I'm having problems? - Altera_Forum
Honored Contributor
Correct, it was just a little typo. And in step 5 it should be ../gdb/configure
- Altera_Forum
Honored Contributor
Success!
Thank you very much for your help. I followed your lead and used the c,c++ compiler options for newlib. I don't know if this fixed the problem. I tend to think that all along it was just more carriage returns getting in the way. Your new script worked great. I now have the tools all built on my Linux box. The next issue I'm facing is getting compiled programs to run on my nios2 development board. A couple of the programs are: "cpuload" and "uart_send". I've created a few small programs, but when I try to run them on the target I get the following errors: -------------------------------------# ./cpuload & BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) 27# ^ELF@@@^: not found # ./uart_send & BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) 29# ^ELF@@@^: not found ------------------------------------ I couldn't copy some of the symbols verbatim. The ^ is actually a triange and the @ is actually a smiley face. Anyway, they are just binary. I am going to try again but this time compile them statically so I'll know if it is a compiler or a library problem. - Altera_Forum
Honored Contributor
After compiling them statically, I just get a "cannot execute" error.
I get this same error if I try to run the program on my development machine. So, it wasn't compiled natively and the nios2-elf-gcc cross-compiler didn't seem build it for the nios2 architecture either. Am I missing something here? Shouldn't I just be able to use "nios2-elf-gcc" to compile a program and have it run on the nios2? I can understand if there are library issues. Perhaps the libraries on my target don't match the libraries for my development environment. But, if I compile the programs statically, it should just come down to a compiler issue. - Altera_Forum
Honored Contributor
<div class='quotetop'>QUOTE </div>
--- Quote Start --- Shouldn't I just be able to use "nios2-elf-gcc" to compile a program and have it run on the nios2?[/b] --- Quote End --- not if you run the program on uClinux. Under uClinux, we are using a FLAT binary format, not ELF (which could not run on uClinux). You need a tool, elf2flt, to convert ELF format to FLAT format. Please check the userland Rules.mak for details. You also need the source code of elf2flt (with Nios II support) so that you can rebuilt it on Linux. Regards, wentao Microtronix. - Altera_Forum
Honored Contributor
I want to know if it is built under RedHat9.
Thanks.