Home > Electronics > Compiling avr-gcc toolchain from scratch

Compiling avr-gcc toolchain from scratch

Follow instructions here but some things needed fixing; summarised below.

Double hyphens: Options below such as –target=avr should be typed with two hyphens at the start. (WordPress converts a double-hyphen to a single but longer one by default.)

Install binutils
  • Download latest binutils (e.g. binutils-2.20.1.tar.bz2), untar and cd to top level
  • mkdir obj-avr; cd obj-avr
  • ../configure –prefix=/usr/local/avr –target=avr –disable-nls –disable-werror
  • make
  • sudo make install
  • Add /usr/local/avr/bin to PATH

Note: On Mac, a warning that stat64 is deprecated is given. The –disable-werror option prevents warnings from being treated as errors.

Install gcc
  • Download latest mpfr (e.g. mpfr-3.0.0.tar.bz2) and untar
  • Download patches for mpfr (e.g. cumulative patches) and apply
    • cd mpfr-3.0.0
    • patch -N -Z -p1 < ../allpatches_mpfr_3.0.0.txt
  • Download latest mpc (e.g. mpc-0.8.2.tar.gz) and untar
  • Download latest gmp (e.g. gmp-5.0.1.tar.bz2) and untar
  • Download latest avr architecture patches
    • [Without this step, avr-libc will fail to compile]
    • I used this patch but I had to add commas manually in the patch file first (because most of the entries in the patch file were missing commas)
    • Save the file as “changes.patch.txt”
  • Download latest gcc (e.g. gcc-core-4.5.1.tar.bz2), untar and cd to top level
  • patch -p0 < ../changes.patch.txt
  • Create links to mpc, gmp and mpfr
    • ln -s ../gmp-5.0.1 gmp
    • ln -s ../mpc-0.8.2 mpc
    • ln -s ../mpfr-3.0.0 mpfr
  • mkdir obj-avr; cd obj-avr
  • ../configure –target=avr –prefix=/usr/local/avr –disable-nls –enable-languages=c –disable-libssp
  • make
    • This failed with an error message about gmp-impl.h and longlong.h not being found (a known bug) therefore:
      • cp ../gmp/gmp-impl.h gmp
      • cp ../gmp/longlong.h gmp
      • make
  • sudo make install

Note: It appears that gcc would like the mathematics packages gmp, mpc and mpfr so that it can evaluate mathematical expressions at compile time such as initialisation of constants.

Note: Finding the right patch files for gcc was a challenge; there does not seem to be a central place to look. One could try going to the gcc patches mailing list and searching, or alternatively just try google directly.

Install avr-libc
  • Download latest avr-libc (e.g. avr-libc-1.7.0.tar.bz2), untar and cd to top level
  • mkdir obj-avr; cd obj-avr
  • ../configure –prefix=/usr/local/avr –build=`../config.guess` –host=avr
  • make
  • sudo make install

Note: The script config.guess simply returns the architecture of the computer you are on (e.g.  i686-apple-darwin10.4.0 in my case).

Install avrdude
  • Download latest avrdude (e.g. avrdude-5.10.tar.gz), untar and cd to top level
  • ./configure –prefix=/usr/local/avr
  • make
  • sudo make install
Advertisements
  1. Tom
    January 30, 2011 at 7:17 am

    Excellent howto! I was rebuilding my toolchain on a newly installed machine, and this has definately saved me quite a bit of work! thanks

  1. December 19, 2010 at 8:08 am

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: