Menu

Build_From_Ubuntu_12.04_Precise_Pangolin_host Log in to Edit

Special notes for Debian

This guide also works on Debian GNU/Linux 7 Wheezy, when applying the following:
- replace 'sudo su -c' with 'su -c'
- replace 'sudo' with 'su -c'

Concerning the step 'Install native gnat-4.7', as the native Debian gcc does not contain ada, you will need to use gnatgcc instead, but doing the following

$ export CC=gnatgcc

Get ready

This is based on http://arduino.ada-language.com/building-avr-gnat-for-avr-ada.html and has been updated to match Ubuntu 12.04 and to avoid building software with root priviledge.

$ sudo apt-get install build-essential libc6-dev gnat gnat-4.6  libgmp-dev bison flex libmpfr-dev libmpc-dev git texinfo zlib1g-dev
$ mkdir avrada-build
$ cd avrada-build

create file native_build_env.sh containing the content above

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/sh
export HOST_SYSTEM_MULTIARCH_TYPE=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
export C_INCLUDE_PATH=/usr/include/$HOST_SYSTEM_MULTIARCH_TYPE
export LIBRARY_PATH=/usr/lib/$HOST_SYSTEM_MULTIARCH_TYPE
export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH && export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
export MULTIARCH_FLAGS="-B/usr/lib/${HOST_SYSTEM_MULTIARCH_TYPE} -I/usr/include/${HOST_SYSTEM_MULTIARCH_TYPE}"
export CFLAGS="-g -O2"
export CXXFLAGS="${CFLAGS}"
export CFLAGS_FOR_TARGET="${CFLAGS} ${MULTIARCH_FLAGS}"
export CXXFLAGS_FOR_TARGET="${CXXFLAGS} ${MULTIARCH_FLAGS}"
export FLAGS_FOR_TARGET="${FLAGS_FOR_TARGET} ${MULTIARCH_FLAGS}"
export DEST_GNAT_HOST=/opt/gnat-4.7
export DEST_GNAT_CROSS=/opt/avrada

create file cross_build_env.sh containing the content above

1
2
3
4
#!/bin/sh
export DEST_GNAT_HOST=/opt/gnat-4.7
export DEST_GNAT_CROSS=/opt/avrada
export PATH=$DEST_GNAT_CROSS/bin:$DEST_GNAT_HOST/bin:$PATH

make them executable

$ chmod +x native_build_env.sh cross_build_env.sh

Install native gnat-4.7

$ . ./native_build_env.sh
$ wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-4.7.0/gcc-4.7.0.tar.gz
$ tar zxf gcc-4.7.0.tar.gz
$ mkdir gcc-obj-470
$ cd gcc-obj-470
$ ../gcc-4.7.0/configure --enable-languages=c,ada --prefix=$DEST_GNAT_HOST --disable-multilib
$ make bootstrap
$ sudo su -c " . ../native_build_env.sh && make install"
$ cd ..

Create a /opt/gnat-4.7/bin/gcc-4.7 file containing the following. Replace i386-linux-gnu with the output of dpkg-architecture -qDEB_HOST_MULTIARCH

1
2
#!/bin/sh
exec /opt/gnat-4.7/bin/gcc -B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu "$@"

Create a /opt/gnat-4.7/bin/g++-4.7 file containing the following. Replace i386-linux-gnu with the output of dpkg-architecture -qDEB_HOST_MULTIARCH

1
2
#!/bin/sh
exec /opt/gnat-4.7/bin/g++ -B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu "$@"

Create a /opt/gnat-4.7/bin/c++-4.7 file containing the following. Replace i386-linux-gnu with the output of dpkg-architecture -qDEB_HOST_MULTIARCH

1
2
#!/bin/sh
exec /opt/gnat-4.7/bin/c++ -B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu "$@"

Create a /opt/gnat-4.7/bin/cpp-4.7 file containing the following. Replace i386-linux-gnu with the output of dpkg-architecture -qDEB_HOST_MULTIARCH

1
2
#!/bin/sh
exec /opt/gnat-4.7/bin/cpp -B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu "$@"

Add executable rights

$ sudo chmod +x /opt/gnat-4.7/bin/gcc-4.7 /opt/gnat-4.7/bin/g++-4.7 /opt/gnat-4.7/bin/c++-4.7 /opt/gnat-4.7/bin/cpp-4.7

Install avr-binutils

$ export CC="gcc-4.7" CXX="c++-4.7" CPP="cpp-4.7"
$ . ./cross_build_env.sh
$ wget http://ftp.uni-kl.de/pub/gnu/binutils/binutils-2.20.1a.tar.bz2
$ tar jxf binutils-2.20.1a.tar.bz2
$ git clone git://git.code.sf.net/p/avr-ada/code avr-ada-code
$ cd binutils-2.20.1
$ for a in ../avr-ada-code/patches/binutils/2.20.1/*.patch;do patch -p0 < $a || fail "avr-binutils: patch $a" ; done
$ cd ..
$ mkdir binutils-obj
$ cd binutils-obj
$ ../binutils-2.20.1/configure --target=avr --program-prefix=avr- --disable-shared --disable-nls --enable-commonbfdlib=no --disable-werror --prefix=$DEST_GNAT_CROSS
$ make
$ sudo su -c ". ../cross_build_env.sh && make install"
$ cd ..

Install cross gnat-4.7 for avr

$ . ./native_build_env.sh
$ . ./cross_build_env.sh
$ mv gcc-4.7.0 gcc-4.7.0-native
$ tar zxf gcc-4.7.0.tar.gz
$ cd gcc-4.7.0
$ for a in ../avr-ada-code/patches/gcc/4.7.0/*.patch;do patch -p0 < $a;done
$ cd ..
$ mkdir avr-gcc-obj
$ cd avr-gcc-obj
$ ../gcc-4.7.0/configure --target=avr --program-prefix=avr- --disable-shared --disable-nls --disable-libssp --with-system-zlib --disable-libada --enable-languages=ada,c,c++ --enable-cpp --with-dwarf2 --enable-version-specific-runtime-libs --prefix=$DEST_GNAT_CROSS
$ sed -i -e 's/$(STAMP)/echo timestamp >/' ../gcc-4.7.0/gcc/config/avr/t-avr
$ make
$ sudo su -c ". ../native_build_env.sh && . ../cross_build_env.sh && make install"
$ cd ..

Installing cross avr-libc

$ . ./cross_build_env.sh
$ unset CC ; unset CXX ; unset CPP
$ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.8.0.tar.bz2
$ tar jxf avr-libc-1.8.0.tar.bz2
$ cd avr-libc-1.8.0
$ ./configure --host=avr --prefix=$DEST_GNAT_CROSS
$ make
$ sudo su -c ". ../cross_build_env.sh && make install"
$ cd ..

Installing AVR-Ada

Update the path to your native gprconfig and gprbuild binaries on the corresponding make commands

$ cd avr-ada-code
$ ./configure
$ make GPRCONFIG=/opt/gnat2013/bin/gprconfig GPRBUILD=/opt/gnat2013/bin/gprbuild
$ sudo su -c ". ../native_build_env.sh && . ../cross_build_env.sh && make install_rts GPRCONFIG=/opt/gnat2013/bin/gprconfig GPRBUILD=/opt/gnat2013/bin/gprbuild"
$ cd avr/avr_lib
$ sed -i -e 's/stamp-libs: $(thread_libs)/stamp-libs:/' Makefile
$ make
$ cd ../..
$ sudo su -c ". ../cross_build_env.sh && make install_libs"

Note

Some errors can be found during make stage. Remove the "-Werror" (warnings treated as errors) flag in avr-ada-code/avr/threads_lib.gpr.

Testing

Building AVR examples

Execute the following to setup your cross build environment:

export PATH=/opt/avrada/bin:/opt/gnat-4.7/bin:$PATH
export ADA_PROJECT_PATH=/opt/avrada/avr/lib/gnat:$ADA_PROJECT_PATH

For Arduino 2009, make the following changes in all the avr examples Makefiles (see line numbers)

35      MCU := atmega328p
46      MFLAGS = -aL/opt/avrada/avr/lib/gnat/avr_lib/$(MCU)/lib -XMCU=$(MCU) -p -P$(GPR)
61      AVRDUDE_PROGRAMMER = stk500v1
65      AVRDUDE_PORT = /dev/ttyUSB0
85      AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b 57600

Uploading to the AVR device

Create the file /etc/udev/rules.d/99-avrdude-usb.rules containing the following

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403",  ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB0", GROUP="plugdev", MODE="0660"

then

$ sudo service udev restart

Make sure the current user is in the plugdev group

$ grep plugdev /etc/group

if the user is not listed, then add him

$ sudo addgroup user plugdev

Unplug (if needed), and plug the USB device, test it by doing :

$ ls -al /dev/ttyUSB0
crw-rw---- 1 root plugdev 188, 0 Aug  1 23:05 /dev/ttyUSB0

References

http://arduino.ada-language.com/building-avr-gnat-for-avr-ada.html

http://sourceforge.net/apps/mediawiki/avr-ada/index.php?title=Build_From_Ubuntu_Lucid_Or_Debian_Squeeze

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644986