CrossGcc

cancel
Showing results for 
Search instead for 
Did you mean: 

CrossGcc

CrossGcc



The following instructions explain how to build a gcc cross compiler for the Nios II using newlib.

This is for Altera's nios2-elf toolchain using newlib, not for Linux or uClinux toolchains using eglibc or uclibc.

Contents

 [hide

History

(..contributed by Scott)

Updated for release 9.0, 9.1 and 10.0 by dsl.

Release 9.1 contains an identical gcc, gas has support for 'rdprs' and 'wrprs' instructions, r30 (ta) has another alias of 'sstatus'.

Release 10.0 contains both gcc3 and gcc4, the gcc3 is identical to that in 9.1. The gcc4.1.2 sources didn't build!

Updated for release 9.0 and then 11.0 by bjb (see below)

The code generated by gcc4 is somewhat worse than that generated by gcc3 (at least for by code), YMMV.

GCC and binutils patches

There are some patches that improve the generated code elsewhere on this wiki: GCC_Patches

The gcc patches apply the gcc3 and gcc4 trees. The gcc4 sources need extra TLC to even build!

- gcc 4.3.2 correctly detected an array subscript error in gas/app.c line 561 (change UNGET('\n'); to *fromend++ = '\n'; ) .

- The regexp used to to check the version of 'makeinfo' in the binutils and gcc 'configure' files don't allow for version 4.11, add 4\.[1-9][0-9] to the regexps.

- gcc/config/nios2/nios2.h may need some changes undone/fixed:

   Change the value of JUMP_TABLES_IN_TEXT_SECTION from "1" to "flag_pic".

   Remove "!SYMBOL_REF_EXTERNAL_P(RTX) &&" from the definition of SYMBOL_REF_IN_NIOS2_SMALL_DATA_P(RTX).


Multilib options

Some instructions below recommend using multilib. This is the GCC/Newlib feature that precompiles variations of your libraries using combinations of popular options for your processor. In the case of NIOS2, as of gcc-4.1 (shipped with the 10.1 Altera package) the number of options produces a large number of multilib combinations (and so takes hours to build and lots of disk). In the gcc-4.1/gcc/config/nios2 directory there is a file called t-nios2 that controls the options available to build these libraries. You may need to edit this file, or there is a stripped version provided (as of gcc-4.1) called t-nios2dpx. Move t-nios2 to t-nios2.old and move t-nios2dpx to t-nios2 before compile if you want to use this stripped down version.

Basic setup

You can do either a local install or a system install. In most cases, you'll probably want to do a system install so the cross tools are available to everyone on the system.

If your're planning on building cross tools for more than one architecture, you need to make sure you don't have "tool collisions." That's what happens, for example, when you build cross tools for arm-elf and then powerpc -- some of the arm files may be overwritten with the powerpc files. For this reason, it's always best to use a "prefix" when building. The prefix is basically the path where the tools get installed.

In the following instructions we'll assume that you setup a prefix environment variable to point to the correct directory. Let's put everything in /usr/local/nios2-elf:

$ export PREFIX='/usr/local/nios2-elf'

If you would rather do a local install, you can do the following:

Insted of: $ export PREFIX='/usr/local/nios2-elf' use: $ export PREFIX=$HOME/nios2-elf

We also need to make sure that the tools we build will be available in our path. Don't forget to do this -- if you don't you'll have trouble when building gcc.

$ export PATH=$PATH:$PREFIX/bin

You should also put this in your .bash_profle file so you'll have the tools available when you login. That is, your shell needs to know where all of the available applications are. Add the following to ~/.bash_profile:

For a system install:

export PATH=$PATH:/usr/local/nios2-elf/bin

or for a local install:

export PATH=$PATH:$HOME/nios2-elf/bin

As an alternative, you can add a profile script on some linux distros (such as Fedora). For example, on my FC10 machine the file /etc/profile.d/nios2-elf.sh contains the following:

TOOLPATH=/usr/local/nios2-elf/bin

if ! echo ${PATH} | /bin/grep -q ${TOOLPATH} ; then

PATH=${TOOLPATH}:${PATH}

fi

Create a directory where you will build the cross tools.

For simplicity we'll use the directory 'cross' to build everything. Just create the directory at the top level of your user account. The 'archive' directory will be used to store the tarballs, dissertation and the 'build' directory will be used to build the tools.

$ mkdir -p cross/archive

$ mkdir -p cross/build

Download the source tarballs into your archive directory

Change your directory to cross/archive and download the source tarball:

$ wget ftp://ftp.altera.com/outgoing/download/support/ip/processors/nios2/gnu/nios2-gnutools-9.0-SRC.tgz

Build and install the binary utilities

a Change your directory to the 'cross' directory and extract the binary utilities code.

$ cd ~/cross

$ tar -zvxf archive/nios2-gnutools-9.0-SRC.tgz

 

b Configure the binary utilties

$ cd build

$ ../binutils/configure --target=nios2-elf --disable-nls --prefix=$PREFIX


c Make and install the binary utilities

$ make

NOTE: You will need to be root when you execute 'make install' in order to have permission to install files to /usr/local. If you're doing a local install you don't need to be root.

NOTE: If you install as root, don't forget to set your path to include /usr/local/nios2-elf/bin, otherwise the install will fail.

E.g.: $ export PATH=$PATH:/usr/local/nios2-elf/bin

$ make install

Cleanup the binutils

You don't need to keep the sources or other build artifacts after installing:

$ cd ~/cross/build

$ rm -rf *

Note: If you choose not to delete * within cross/build then you must remove every config.cache file from it (suggest using a find command) or the configuration fails at the next step.

Setup the compiler source tree

NB: This doesn't seem to be necessary any more, I'm not sure which library is built by default.

a We have to include newlib in the gcc tree. We'll do this by creating a few symlinks:

$ cd gcc

$ ln -s ../newlib/newlib newlib

$ ln -s ../newlib/libgloss libgloss

b Then we have to select small or normal library using this brain damaged technique:

For small:

$ rm -r configure.host

$ ln -s configure.host.smallc configure.host

For large:

$ rm -r configure.host

$ ln -s configure.host.normalc configure.host

Build and install the cross compiler

NOTE: The binutils above must be available in $PATH when building gcc, otherwise it will try to run the system's native assembler and linker.

a Change to the build directory and configure the compiler.

$ cd ~/cross/build

$ ../gcc/configure --target=nios2-elf --with-newlib --disable-threads \

--disable-multilib --disable-nls --enable-languages=c,c++ \

--prefix=$PREFIX --with-gnu-as --with-gnu-ld

For a smaller compiler for embedded applications remove the 'c++' and add: '--disable-shared --disable-cpp --disable-libssp'.

b Now make and install.

NOTE: You will need to be root when you execute 'make install' in order to have permission to install files to /usr/local. If you're doing a local install you don't need to be root.

$ make

$ make install

You're done!

You can now blow away the entire ~/cross directory. Some final notes:

a. The compiler was built with newlib so you can actually write hello world and it will successfully compile and link.

b. If you are a newbie and want to develop uClinux applications, don't use this one; use the prebuilt nios2gcc from the nios2 uClinux wiki.

c. For embedded use, you probably want to use -no-stdinc and -no-stdlib. This will prevent the tools from looking for headers and including libraries from the "standard" places. For highly embedded applications where all of the sources are in your build tree (e.g. you have your own linker script, your own startup code, and don't want to link against standard libraries) this is probably what you want.

<fck:hr>


A Set of Build Instructions [BJB]

The above set didn't really work for me. I kept getting compile errors during the process, I think due to cache.config problems with building in the same directory in each step. I was building the 9.0 toolkit on Solaris 10. These worked better (instructions cribbed from the arm-elf build instructions):


The following steps and configuration switches were used in the compilation process. NOTE that in the below the [xxx-source] directories will not appear by that name in your .tar.gz file. You may have to move source directories and/or rename to get this structure. Also the [xxx-build] directories will not be in the .tar.gz archive. They have to be created before entering this set of directions.

$ cd [binutils-build]

$ [binutils-source]/configure --target=nios2-elf --prefix=[install-directory] --enable-interwork --enable-multilib

$ make all install

$ (setenv or) export PATH="$PATH:[install-directory]/bin"


$ cd [gcc-build]

$ [gcc-source]/configure --target=nios2-elf --prefix=[install-directory] --enable-interwork --enable-multilib --enable-languages="c,c++" --with-newlib --with-headers=[newlib-source]/newlib/libc/include

$ make all-gcc install-gcc

$ cd [newlib-build]

$ [newlib-source]/configure --target=nios2-elf --prefix=[install-directory] --enable-interwork --enable-multilib

$ make all install

$ cd [gcc-build]


$ make all install

$ cd [gdb-build]

$ [gdb-source]/configure --target=nios2-elf --prefix=[install-directory] --enable-interwork --enable-multilib


$ make all install

For me this builds clean - no errors. BJB

Old info below - kept for historic purposes only ...

The nios2-elf gcc toolchains will be installed in /usr/local/bin and /usr/local/nios2-elf.

This gcc uses newlib, and will need a lot of effort to build UClinux applications.

If you are a newbie and want to develop uClinux applications, don't use this one; use the prebuilt nios2gcc from the nios2 uClinux wiki.

Download the source.

NOTE: You cannot use gcc4 to compile binutils 2.15. You must use gcc3, (gcc32 on Fedora Core 4, gcc34 on Fedora Core 6).

Enable the wheel group in sudoers and add yourself to group wheel, so that you can use the sudo command to install the tools. As root, run visudo:

# Uncomment to allow people in group wheel to run all commands

%wheel ALL=(ALL) ALL

Save the file with ESC :wq

Then add yourself to the wheel group:

usermod -aG wheel username

If you don't have usermod, edit /etc/group, and add yourself to wheel group:

wheel:x:10:root,hippo

You may need to logout and login again for the group change to take effect. Check that you are in the wheel group by running the id command:

$ id

Now, as a user, start the build. It may take a long time.

# Unpack

mkdir ~/nios2 cd ~/nios2 tar zxf niosii-gnutools-src-6.1.gz cp src/newlib/newlib/configure.host.smallc src/newlib/newlib/configure.host # Select small library set of newlib zip -r src.zip src rm -rf src unzip -a src.zip # convert the CRLF mkdir build cd build mkdir binutils gcc newlib gcc2 gdb

# Binutils

cd binutils ../../src/binutils/configure --target=nios2-elf make sudo make install cd ..

# GCC (C only, first pass)

cd gcc ../../src/gcc/configure --target=nios2-elf --enable-languages=c make sudo make install cd ..

# Newlib

cd newlib ../../src/newlib/configure --target=nios2-elf make sudo make install cd ..

# GCC (C and C++, second pass)

cd gcc2 ../../src/gcc/configure --target=nios2-elf --enable-languages=c,c++ --with-newlib make sudo make install cd ..

# GDB

cd gdb ../../src/gdb/configure --target=nios2-elf make sudo make install

Check the new gcc:

$ nios2-elf-gcc -v

Reading specs from /usr/local/lib/gcc/nios2-elf/3.4.1/specs Configured with: ../../src/gcc/configure --target=nios2-elf --enable-languages=c,c++ --with-newlib Thread model: single gcc version 3.4.1 (Altera Nios II 5.1 b93)

This is the same as in v6.0 and some earlier IDE releases. The only changes in the v6.1 source distribution since v6.0 are whitespace and proper inclusion of some files which were missing in v6.0 (in directories gcc/config/nios2 and newlib).

Download

CategoriesEmbedded ProcessingEmbedded Software and Software Tools


Version history
Last update:
‎06-25-2019 03:39 PM
Updated by:
Contributors