Zylin AS
Phone:
(+47) 51 63 25 00
Fax:
(+47) 51 88 00 29
Queries:
info@zylin.com
Sales:
sales@zylin.com
libstdc++ for eCos Nios2
This is a work-in-progress intended only for testing and discussion purposes.

Download binaries

Precompiled CygWin nios2-elf toolchain is available for downloading here:

POSIX multithreaded exception handling nios2gccbin-20060811.tar.bz2
NIOS2 GCC toolchain source. These files are modified somewhat from what is provided with Nios 5.0. Also note that the GCC source provided with Nios 5.0 is incomplete, so some of the files were copied over from the Nios 6.0 beta. Altera has since I cobbled together the source for the GCC toolchain made efforts to provide complete and tidy source for the GCC Nios2 toolchain. Not investigated
http://www.altera.com/support/ip/ processors/nios2/ide/ips- nios2-ide-tutorial.html
nios2gccsrc.tar.bz2

Background

These instructions are based on libstdc++.

Building GCC

These instructions are incomplete. Consider them working notes. Once all the problems have been solved, the idea is to write a build script that can be used by mortals.

You should know how to compile a basic GCC toolchain before attempting this.

Cygwin time machine

Altera has included a partial, old version of Cygwin with Nios 5.0/6.0 that will not run binaries created by the latest Cygwin.

The solution is to install a Cygwin via the "Cygwin Time Machine." Which version? Altera includes several cygwin1.dll (double shame on them!) and there is no snapshot for 1.3.23. The toolchain above was created using:

ftp://www.fruitbat.org/pub/cygwin/circa/2003/05/14/200002/index.html.

Building

  1. Compile binutils
    $ mkdir build
    $ cd build
    $ ../GnuSRC/gcc/src/binutils/configure --target=nios2-elf --prefix=`pwd`/../install
    $ make
    $ make install
    $ cd ..
  2. Add the fresh binutils to the FRONT of the path
    $ export PATH=`pwd`/install/bin:$PATH
  3. Create eCos header files
    $ mkdir ecos
    $ cd ecos
    $ ecosconfig new nios2_dev_board default
    $ ecosconfig add posix
    $ ecosconfig add fileio
  4. Also change ecos.ecc to:
    cdl_option CYGPKG_LIBC_I18N_NEWLIB_CTYPE {
    user_value 1
    };
  5. Build eCos headers:
    $ ecosconfig tree
    $ make headers
    $ cd ..
  6. Build GCC
    $ mkdir gccbuild
    $ cd gccbuild
    $ ../GnuSRC/gcc/src/gcc/configure --target=nios2-elf --prefix=`pwd`/../install --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --enable-threads=posix --without-headers --enable-libstdcxx-allocator=malloc --enable-cstdio=stdio --disable-shared --disable-libstdcxx-pch
    $ make
    $ make install
    $ cd ..
  7. GCC will fail to compile libstdc++ as configured above, because it can not find the POSIX pthreads include files. The solution is to replace the newlib include files with the eCos include files when compiling libstdc++.
    $ mkdir ../install/nios2-elf/include
    $ cp -r ../ecos/install/include/* ../install/nios2-elf/include
    # remove reference to in the file below, lest compilation fails.
    # ../install/nios2-elf/include/pkgconf/hal_nios2.h
  8. _NEWLIB_VERSION have not been defined by the eCos include files and hence testsuite_hooks.cc fails. Modify testsuite_hooks.cc and continue.

Known problems

Tips

  • Here are some test cases that reportedly work. nios2workspace.zip
  • pthread_mutex_lock and various other symbols are defined as weak. This can cause hard-to-track problems, since the linker can silently leave out pthread_mutex_lock if the linker options are not passed in correctly. The symptom is for example, a crash on startup as invoking pthread_mutex_lock jumps to address 0.

    To make sure that the pthread_mutex_lock is pulled in, add this linker option to the GCC command line: -Wl,--undefined=pthread_mutex_lock.

  • Regarding code size: consider disabling the verbose terminate handler by defining this function in your application code: namespace __gnu_cxx { /* tiny verbose terminate handler */ void __verbose_terminate_handler() { abort(); } }
  • Note that newlib is NOT compiled as part of the GCC compile in this example (in other words, newlib is not copied into gcc/newlib). This is not necessary, as eCos will provide the functions that newlib would have provided. The toolchain as compiled above is not useful for anything but eCos POSIX, anyway.