In order to start deploying and debugging your bare-metal code into this little cute board, you need to do some homework.
First, you need to have a working Linux distribution. Generally speaking, Windows or MacOS should be fine either. However, the experience will be different, and some tweaks will be necessary to use the tools ported. The Linux distribution should have working C/C++ compiler, make, linker, and development packages (headers + libraries) installed. I suggest to use package manager (i.e. apt-get) for installing missing components during the process. Hope, you are familiar with Linux command line and command line tools.
In your home folder (/home/foo) create folder 'work/toolchain'. Two subfolders 'build' and 'install' will be holding binaries for the toolbox.
foo@foo-home:~$ cd ~ foo@foo-home:~$ mkdir work/toolchain/build -p foo@foo-home:~$ mkdir work/toolchain/install foo@foo-home:~$ cd work/toolchain/
I also suggest placing a small script 'settings.sh' in the 'work' folder, which will be common for all future build scipts. This script should have 0755 mode.
#! /bin/sh export ARMTOOLS=/home/${USER}/work/toolchain/install export PATH="$PATH:$ARMTOOLS/bin"
Binutils will provide a cross-assembler, linker, and necessary image manipulating tools. First, we need to download and unpack the source tarball
foo@foo-home:~/work/toolchain$ wget http://ftp.gnu.org/gnu/binutils/binutils-2.23.tar.gz foo@foo-home:~/work/toolchain$ tar -xzf binutils-2.23.tar.gz foo@foo-home:~/work/toolchain$ mkdir -p build/binutils-2.23
Then, configure and build the tools for arm-none-eabi, which will be the best option for bare metal ARM platform.
foo@foo-home:~/work/toolchain$ cd build/binutils-2.23 foo@foo-home:~/work/toolchain/build/binutils-2.23$
A script to build:
#! /bin/sh . ../../../settings.sh ../../binutils-2.23/configure --target=arm-none-eabi --prefix=$ARMTOOLS --enable-interwork --enable-multilib make all install
When it's completed, you should have a minimal toolset installed in your local folder. This should be enough for building small assembler programs for uploading into RSPi.
I am using gcc-4.8.0 for cross compiling C and C++ code for bare Raspberry PI.
Gnu C Compiler (gcc) will require the following stuff to be installed. This list may be not complete as your default system configuration
m4 : 'sudo apt-get install m4'
gmplib : gmp-5.1.2
GNU mpfr library : mpfr-3.1.2 'sudo apt-get install libmpfr-dev'
Multiprecision : mpc-1.0.1 'sudo apt-get install libmpc-dev'
g++ matching installed host gcc : 'sudo apt-get install g++'
libz (zlib) development package
texinfo : 'sudo apt-get install texinfo'
Do not forget to run 'ldconfig' as root to rebuild library cache.
ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2
ftp://sourceware.org/pub/newlib/newlib-2.0.0.tar.gz
Once those packages are either compiled or installed from binaries, we can go ahead and prepare the cross compiler. Unpack gcc and newlib sources to ~/work/toolchain folder. Then, pre-compile the C compiler itself:
foo@foo-home:~/work/toolchain$ mkdir -p build/gcc-4.8.0 foo@foo-home:~/work/toolchain$ cd build/gcc-4.8.0 foo@foo-home:~/work/toolchain/build/gcc-4.8.0$ ../../gcc-4.8.0/configure --target=arm-none-eabi --prefix=/home/${USER}/work/toolchain/install --enable-interwork \
--enable-multilib --enable-languages="c,c++" --with-newlib --with-headers=../../newlib-2.0.0/newlib/libc/include --with-system-zlib foo@foo-home:~/work/toolchain/build/gcc-4.8.0$ make all-gcc install-gcc
Next step is building newlib for arm using our fresh cross compiler. Newlib will be serving as C-library, which will be linked in future binaries produced for the Raspberry PI. In few words, it contains a runtime required to execute compiled code on target platform including your favourite printf(...) function.
foo@foo-home:~/work/toolchain/build/gcc-4.8.0$ cd ../newlib-2.0.0 foo@foo-home:~/work/toolchain/build/newlib-2.0.0$ ../../newlib-2.0.0/configure --target=arm-none-eabi \ --prefix=/home/${USER}/work/toolchain/install --enable-interwork --enable-multilib foo@foo-home:~/work/toolchain/build/newlib-2.0.0$ make all install
At the end, we are going back building gcc:
foo@foo-home:~/work/toolchain/build/newlib-2.0.0$ cd ../gcc-4.8.0 foo@foo-home:~/work/toolchain/build/gcc-4.8.0$ make all install
Next, we need to compile cross-debugger.
libexpat-dev for XML support. Some GDB servers may require it. However, OpenOCD gdb server is not using it, so this library is not mandatory.
http://ftp.gnu.org/gnu/gdb/gdb-7.6.tar.bz2
Please use build-gdb.sh script provided on this page. Place this script in ~/work/toolchain/build/gdb-7.6 folder and execute.