Fix for broken avr-size in Ubuntu 10.04 (Lucid Lynx)

If you have never used it before, avr-size is a very useful command that does a relatively simple thing – it tells you how large your compiled avr-gcc programs are.  This is very useful knowledge when you are trying to fit as much code as possible into a part with only a few K of flash memory.  Additionally, the actual flash footprint of an AVR program is not something you can easily distill from a .hex file.  Hex files are usually much larger than the actual compiled code due to the overhead of that file format.

avr-size comes with the binutils-avr package in Ubuntu (and is installed as part of WinAVR and CrossPack on Windows and OSX, respectively).  Unfortunately, Ubuntu 10.04 (Lucid Lynx) ships with a broken version of avr-size that doesn’t include the necessary patches to support the AVR.

To see if your avr-size is working, open a Terminal in Lucid and try executing this command on a compiled avr-gcc .elf file of your choice:

avr-size -C --mcu=attiny2313 main.elf

You’ll probably see something like this:

avr-size: invalid option -- 'C'
Usage: avr-size [option(s)] [file(s)]
Displays the sizes of sections inside binary files
If no input file(s) are specified, a.out is assumed
The options are:
-A|-B     --format={sysv|berkeley}  Select output style (default is berkeley)
-o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex
-t        --totals                  Display the total sizes (Berkeley only)
--common                  Display total size for *COM* syms
--target=<bfdname>        Set the binary file format
@<file>                   Read options from <file>
-h        --help                    Display this information
-v        --version                 Display the program's version
avr-size: supported targets: elf32-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex

Bad news, but it’s not surprising. You have the broken version of avr-size that comes with binutils-avr for Lucid.

The solution:

I was able to fix this issue by installing the binutils-avr package for Debian Squeeze, an approach I learned about from this Ubuntu bug report.

To download the Debian binutils-avr package, either go to the Debian package repository or execute this command:

wget "http://ftp.us.debian.org/debian/pool/main/b/binutils-avr/binutils-avr_2.20.1-1_amd64.deb"

Now install the package by double clicking on it or executing:

sudo dpkg -i binutils-avr_2.20.1-1_amd64.deb

If you tell Ubuntu to “hold” the package you just installed, it should stop trying to revert to the broken version in the Lucid repository every time you run a system update:

echo "binutils-avr hold" | sudo dpkg --set-selections

You can check the hold status by running

sudo dpkg --get-selections | grep binutils-avr

The status should be shown as “hold” (not “install”).

Now if you run avr-size, you should see the special AVR option ‘-C’ is now present.

jkeyzer@atom:~$ avr-size --help

Usage: avr-size [option(s)] [file(s)]
Displays the sizes of sections inside binary files
If no input file(s) are specified, a.out is assumed
The options are:
-A|-B|-C  --format={sysv|berkeley|avr}  Select output style (default is berkeley)
--mcu=<avrmcu>            MCU name for AVR format only
-o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex
-t        --totals                  Display the total sizes (Berkeley only)
--common                  Display total size for *COM* syms
--target=<bfdname>        Set the binary file format
@<file>                   Read options from <file>
-h        --help                    Display this information
-v        --version                 Display the program's version
avr-size: supported targets: elf32-avr coff-avr coff-ext-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex

Report bugs to <http://www.sourceware.org/bugzilla/>

You can also test it out on a compiled .elf file:

jkeyzer@atom:~$ avr-size -C --mcu=attiny2313 main.elf

AVR Memory Usage
----------------
Device: attiny2313

Program: 2008 bytes (98.0% Full)
(.text + .data + .bootloader)

Data: 23 bytes (18.0% Full)
(.data + .bss + .noinit)

It works!  You now have a working avr-size command for Ubuntu.

There is a good chance this package will eventually be fixed in the Lucid repository, but based on the bug report above, it could be a while (2012?) before we see an update.  Until then, installing the Debian package seems to be a good solution.

If anyone reading this is close to the Ubuntu package maintainers, can you please kick them about this issue?

8 thoughts on “Fix for broken avr-size in Ubuntu 10.04 (Lucid Lynx)”

  1. I think what they’re saying is that the bug will be fixed in Ubuntu 10.10, but not for 10.04. So anyone who wants to keep using LTS versions of Ubuntu will have to wait for the next LTS release in 2012.

    1. Randy,

      Thanks for pointing that out! My understanding of the Ubuntu release schedule is pretty poor, but I think that means we should see a fix sometime around October of this year?

      1. From the look of the changelog on binutils-avr for 10.10, the necessary patch is included in the 10.10 builds. So, yes, if you upgrade to 10.10 in October, avr-size will work fine with the standard Ubuntu package.

    1. Tom,

      Thanks for the link! I’ll take a look at that package.

      It is worth pointing out that by default, universe is not included in apt’s repository search list, so that package won’t be installed automatically via update-manager or apt-get.

      Edit: I take that back, universe is enabled in 9.04 and later. Why then isn’t the revised package being installed automatically?

  2. Ubuntu 10.10 (Maverick) ships with a working bintuils-avr, so this tutorial is no longer necessary on new installations.

    Package: binutils-avr
    Status: install ok installed
    Priority: extra
    Section: devel
    Installed-Size: 9720
    Maintainer: Ubuntu Developers
    Architecture: i386
    Version: 2.20.1-1ubuntu2
    Depends: libc6 (>= 2.11)
    Suggests: binutils (>= 2.20.1-1ubuntu2)
    Description: Binary utilities supporting Atmel’s AVR targets
    The programs in this package are used to manipulate binary and object
    files that may have been created for Atmel’s AVR architecture. This package
    is primarily for AVR developers and cross-compilers and is not needed
    by normal users or developers.
    Original-Maintainer: Hakan Ardo

Comments are closed.