Installing AVR libc & gcc toolchain from source on Linux

Tutorial on setting up the AVR gcc tool chain on Linux

Introduction

Some basic instructions on how get yourself setup to build C/C++ programs for Atmel’s AVR micro-controllers.

The will install the following versions:

  • GNU Binutils version 2.26
  • GNU GCC for AVR version 5.2.0
  • AVR libC version 2.0.0

Before you start, you need to decide where you would like to install the tool-chain. The default is something like /usr/local which will require root access. If don’t have this, or prefer to install in a non-system location you will need to configure the build system as such. My preference is the later, I try to do as much as I can as my normal login user. To this end, I’ve decided to install the AVR libraries and AVR tool-chain under ~/opt/avr.

Whatever location you chose, it’s important that you’re consistent with its use. The simplest way to ensure this is to define a couple of environment variables as follows:

export AVR_PREFIX=$HOME/opt/avr
export PATH=$PATH:$AVR_PREFIX/bin

The 1st one, AVR_PREFIX defines where we want to install everything. You’re a free to use whatever you want here1. The 2nd, PATH appends the bin subdirectory of the tool-chain install location to the system path.

For future use, I would recommend adding the above two export statements to the end of the .profile or .bashrc in your home directory.

Right, with that out of they way, let’s get on with the actual install.

Install Instructions

Note: If you have defined AVR_PREFIX as a system directory, you will most likely need to run the make install steps below as root.

GNU Binutils

The following steps will obtain and install the binutils package.

mkdir /tmp/binutils
cd /tmp/binutils
wget http://ftp.gnu.org/gnu/binutils/binutils-2.29.tar.bz2
tar -xf binutils-2.29.tar.bz2
cd binutils-2.29
mkdir avr-obj
cd avr-obj
../configure --prefix=$AVR_PREFIX --target=avr --disable-nls
make
make install
cd
rm -rf /tmp/binutils

GNU AVR GCC

The following steps will obtain and install the gcc package.

mkdir /tmp/avrgcc
cd /tmp/avrgcc
wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz
tar -xf gcc-7.2.0.tar.bz2
mkdir bld_gcc
cd gcc-7.2.0
./contrib/download_prerequisites
cd ../bld_gcc
../gcc-7.2.0/configure --prefix=$AVR_PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
make
make install
cd
rm -rf /tmp/avrgcc

AVR LibC

The following steps will obtain and install the AVR libC package.

mkdir /tmp/avrlibc
cd /tmp/avrlibc
wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
tar -xf avr-libc-2.0.0.tar.bz2
cd avr-libc-2.0.0
./configure --prefix=$AVR_PREFIX --build=`./config.guess` --host=avr
make
make install
cd
rm -rf /tmp/avrlibc

Quick test

As a really quick test, run avr-gcc --version, you should get something similar to this:

tfh@hex64:~$ avr-gcc --version
avr-gcc (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

tfh@hex64:~$

Any problems, please leave a message in the comment section, and I’ll do my best to help..


  1. Unless you have a strong reason not to, I would suggest you use the location shown above, other guides in this blog will assume this plus it’s as good any other ;-) [return]
 
comments powered by Disqus