The toolchain
Now we have necessary hardware, but still the only thing we can do is to login into the RasPi in a slightly different way. Now we need some software tools to convert our program sources into binaries for RasPi.
I'm aware that there are some instructions floating around on how to acquire a toolchain more quickly, but I think the most correct way is to build one ourselves.
Since I'm using Debian as my primary desktop operating system for years, I'll provide instructions for it, but the same principle should be valid for any Linux-based OS. Tip for Windows users: you can run Linux inside VirtualBox.
First thing we have to ensure that our host system has all the necessary tools. Open your terminal and run:
It should either tell, that you have all the newest versions or ask your confirmation to download and install some packages.
We also need to prepare a location in our file system, where the toolchain will be located:
I did just created a directory and made it writable by me (of course replace velko with your username). You could, of course, choose a different path and not change it's owning user. But then you must already know what you're doing and should be able to adjust following commands accordingly.
Next it would be a good idea to adjust the Linux environment variables accordingly. So run:
and append :/usr/local/cross/bin to every line starting with PATH=.
Hit Ctrl-O and Ctrl-X to save and exit. Now you should log off and log back in before continuing.
If you absolutely refuse to re-login, you also can execute:
First thing we need is software package called GNU Binutils. As name suggests, it contains set of tools to deal with compiled binaries. Go to download site and look for a newest ones. Download them (2.22 for the moment of writing this, adjust following commands if there are newer versions available):
It will download several megabytes of source code. Now we should unpack it:
Create temporary directory for compilation process:
Now go into that directory, configure, compile and install:
Next we continue with GNU GCC. It's a set of compilers for turning source code of various programming languages into compiled binaries. Go to mirror selection site, choose one closest to you and download newest sources (for the moment of writing this):
Go into that directory, configure, compile and install:
We now have most essential tools ready for bare-metal development. Next we need to learn how to use them.
In the meantime you may try out David Welch's examples.
I'm aware that there are some instructions floating around on how to acquire a toolchain more quickly, but I think the most correct way is to build one ourselves.
Since I'm using Debian as my primary desktop operating system for years, I'll provide instructions for it, but the same principle should be valid for any Linux-based OS. Tip for Windows users: you can run Linux inside VirtualBox.
First thing we have to ensure that our host system has all the necessary tools. Open your terminal and run:
Note that, instead of using sudo, you could also log in as root and execute the commands without it. In this tutorial I'll however prepend sudo to every command that requires elevated privileges.sudo apt-get install build-essential wget
It should either tell, that you have all the newest versions or ask your confirmation to download and install some packages.
We also need to prepare a location in our file system, where the toolchain will be located:
sudo mkdir /usr/local/crosssudo chown velko /usr/local/cross
I did just created a directory and made it writable by me (of course replace velko with your username). You could, of course, choose a different path and not change it's owning user. But then you must already know what you're doing and should be able to adjust following commands accordingly.
Next it would be a good idea to adjust the Linux environment variables accordingly. So run:
sudo nano /etc/profile
and append :/usr/local/cross/bin to every line starting with PATH=.
Hit Ctrl-O and Ctrl-X to save and exit. Now you should log off and log back in before continuing.
If you absolutely refuse to re-login, you also can execute:
in your terminal, but bear in mind that in this case following commands must also be issued in the same terminal.export PATH=$PATH:/usr/local/cross/bin
First thing we need is software package called GNU Binutils. As name suggests, it contains set of tools to deal with compiled binaries. Go to download site and look for a newest ones. Download them (2.22 for the moment of writing this, adjust following commands if there are newer versions available):
wget http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.gz
It will download several megabytes of source code. Now we should unpack it:
tar -xzf binutils-2.22.tar.gz
Create temporary directory for compilation process:
mkdir build-binutils
Now go into that directory, configure, compile and install:
cd build-binutilsThe 3rd command can take some time to complete. You may also want to adjust the -j5 setting. For the fastest compilation, as a general rule of a thumb it should be the number of CPUs (or cores) your computer (or virtual machine) possesses + 1. But nothing will fail if you set it wrong, it will just take more time to complete. For my (quad core) Core i5 it took less than 1 minute to complete, but your mileage may vary.
../binutils-2.22/configure --prefix=/usr/local/cross \
--target=arm-none-eabi
make -j5
make install
cd ..
Next we continue with GNU GCC. It's a set of compilers for turning source code of various programming languages into compiled binaries. Go to mirror selection site, choose one closest to you and download newest sources (for the moment of writing this):
It will also download several tens of megabytes. Next we unpack it.wget http://mirrors.webhostinggeeks.com/gcc/releases/gcc-4.7.1/gcc-4.7.1.tar.bz2
GCC requires a few additional libraries, which may not be present on your system. We'll download, and move them into GCC's tree (also watch if there are newer versions available):tar -xjf gcc-4.7.1.tar.bz2
Similarly as with Binutils, create temporary directory for compilation:wget ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.5.tar.bz2wget http://www.mpfr.org/mpfr-current/mpfr-3.1.1.tar.bz2wget http://www.multiprecision.org/mpc/download/mpc-1.0.tar.gzmkdir gcc-4.7.1/gmp
tar -xjf gmp-5.0.5.tar.bz2 --strip-components=1 -C gcc-4.7.1/gmpmkdir gcc-4.7.1/mpfr
tar -xjf mpfr-3.1.1.tar.bz2 --strip-components=1 -C gcc-4.7.1/mpfrmkdir gcc-4.7.1/mpctar -xzf mpc-1.0.tar.gz --strip-components=1 -C gcc-4.7.1/mpc
mkdir build-gcc
Go into that directory, configure, compile and install:
Again, some commands may take some time (up to half of an hour, on slower computers) to complete. Note that we built compiler for C programming language only. You may delete downloaded source code and temporary directories now.cd build-gcc../gcc-4.7.1/configure --prefix=/usr/local/cross \--target=arm-none-eabi --disable-nls --enable-languages=cmake -j5 all-gccmake install-gccmake -j5 all-target-libgccmake install-target-libgcc
We now have most essential tools ready for bare-metal development. Next we need to learn how to use them.
In the meantime you may try out David Welch's examples.
Comments
Post a Comment