How to Build Cross Compilers for Embedded Systems

The following steps explain how to build a cross compiler on your *nix machine:

Download the following sources

Set environment variables

Before setting the environment variables you have to choose your target: in this tutorial our target is powerpc-eabi (Embedded PowerPC system in big endian mode). Check here for other targets.


% export TARGET=powerpc-eabi
% export PREFIX=/usr/local/$TARGET #specify the PATH you want the cross-compiled binaries
% export PATH=$PATH:$PREFIX/bin

Compiling and installing binutils

% tar xzfv binutils-2.25.tar.gz
% mkdir build-binutils
% cd build-binutils
% ../binutils-2.25/configure --target=$TARGET --prefix=$PREFIX
% make all
% make install

Compiling and installing GCC

% tar xjfv gcc-4.8.4.tar.bz2
% mkdir build-gcc
% cd build-gcc
% ../gcc-4.8.4/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --with-gnu-as --with-gnu-ld
% make all-gcc
% make install-gcc

Compiling and installing newlib

% tar xzfv newlib-2.2.0-1.tar.gz
% mkdir build-newlib
% cd build-newlib
% ../newlib-2.2.0-1/configure --target=$TARGET --prefix=$PREFIX
% make all
% make install

Reconfigure GCC with newlib

% cd build-gcc
% ../gcc-4.8.4/configure --target=$TARGET --prefix=$PREFIX --with-newlib --with-gnu-as --with-gnu-ld --disable-shared --disable-libssp
% make all
% make install

Compiling and installing GDB with PSIM (Emulator of the PowerPC Architecture)

% tar xjfv gdb-7.8.2.tar.bz2
% mkdir build-gdb
% cd build-gdb
% ../gdb-7.8.2/configure --target=$TARGET --prefix=$PREFIX –enable-sim-powerpc --enable-sim-stdio
% make all
% make install

Done! Let’s test our tool chain (-m options here)

% powerpc-eabi-gcc -mcpu=440 hw.c -o hw -msim
% powerpc-eabi-run hello
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s