-
Notifications
You must be signed in to change notification settings - Fork 8
Installation: Cortex
|
Warning
|
You should complete the following installation process in one sitting in one terminal window. Failing to do so may cause serious issues. |
Before we begin make sure you have a relatively modern version of GCC installed for your architecture. All of the following commands should be entered into your terminal window without alteration, unless there are specific instructions otherwise. This guide was used to successfully build GCC with Newlib for the arm-none-eabi architecture in Mac OS X 10.6.6 and Ubuntu 10.10, but your milage may vary as building the ARM cross-compiler is a notoriously difficult task.
The remainder of this guide assumes the following three environmental variables are set:
export base="$HOME/arm-toolchain"
export prefix="/opt/mine"
export parallel=4where base contains the path to a temporary directory, prefix is the destination directory for the installed files, and parallel indicates how many threads should be used for compilation. As a general guideline, setting this to approximately twice the number of available CPU cores will greatly speed up build times. With the initial configuration complete, start by downloading and extracting the necessary source code:
mkdir $base && cd $base
curl -O ftp://aeneas.mit.edu/pub/gnu/gmp/gmp-5.0.1.tar.gz
curl -O ftp://aeneas.mit.edu/pub/gnu/mpfr/mpfr-2.4.2.tar.gz
curl -O ftp://aeneas.mit.edu/pub/gnu/binutils/binutils-2.21.tar.gz
curl -O ftp://aeneas.mit.edu/pub/gnu/gcc/gcc-4.4.4/gcc-4.4.4.tar.gz
curl -O ftp://sources.redhat.com/pub/newlib/newlib-1.19.0.tar.gz
tar -xf gmp-5.0.1.tar.gz
tar -xf mpfr-2.4.2.tar.gz
tar -xf binutils-2.21.tar.gz
tar -xf gcc-4.4.4.tar.gz
tar -xf newlib-1.19.0.tar.gz
export PATH="$prefix/bin:$PATH"
export CPATH="$prefix/include:$CPATH"
unset LIBRARY_PATH|
Note
|
If you changed prefix to a directory where you have write access you can (and should) omit sudo from each make install command. If you are using the default prefix of /opt/mine, you will need sudo.
|
cd $base
mkdir build-binutils && cd build-binutils
../binutils-2.21/configure --prefix="$prefix" --target=arm-none-eabi --with-cpu=cortex-m3
make -j$parallel
sudo make installTypically building GCC for an architecture requires a standard library for that architecture. Unfortunately, building the standard library for the ARM architecture (Newlib) requires a working compiler. To solve this chicken-and-the-egg problem, we will first compile an imcomplete version of GCC with no standard library, use it to build Newlib, and recompile GCC with Newlib. The first compilation of GCC is called a "bootstrap" and is done below:
|
Note
|
If installation fails with an error message about libiberty, run the command unset LIBRARY_PATH and try again.
|
cd $base
cp -r gmp-5.0.1 gcc-4.4.4/gmp
cp -r mpfr-2.4.2 gcc-4.4.4/mpfr
mkdir build-bootstrap && cd build-bootstrap
../gcc-4.4.4/configure --prefix="$prefix" --target=arm-none-eabi --with-cpu=cortex-m3 --enable-languages=c --with-newlib --without-headers
make -j$parallel all-gcc
sudo make install-gccUsing the bootstrap compiler, we now build a standard library for the ARM:
cd $base
mkdir build-newlib && cd build-newlib
../newlib-1.19.0/configure --prefix="$prefix" --target=arm-none-eabi --with-cpu=cortex-m3 --with-build-time-tools="$prefix"
make -j$parallel
sudo make installWith Newlib compiled and installed, we can now build the full version of GCC:
cd $base
mkdir build-gcc && cd build-gcc
../gcc-4.4.4/configure --prefix="$prefix" --target=arm-none-eabi --with-cpu=cortex-m3 --enable-languages=c --with-newlib
make -j$parallel
sudo make installAssuming the installation completed with no errors you can test you should recieve output that is similar to:
$ arm-none-eabi-gcc -v
Using built-in specs.
Target: arm-none-eabi
Configured with: ../gcc-4.4.4/configure --prefix="$prefix" --target=arm-none-eabi --with-cpu=cortex-m3 --enable-languages=c --with-newlib
Thread model: single
gcc version 4.4.4 (GCC) Finally, we’re going to add this installation directory to the necessary environmental variables by adding the following lines to .profile in your home directory:
export PATH="<<prefix>>/bin:$PATH"
export CPATH="<<prefix>>/include:$CPATH"
export LIBRARY_PATH="<<prefix>>/lib:$LIBRARY_PATH"
export MANPATH="<<prefix>>/man:$MANPATH"Note that you must manually replace each instance of <<prefix>> with the value you chose as the start of this guide. If you do not remember, you can check using the command echo $prefix.