Building an Ada Toolchain for AVR (Arduino) on Ubuntu 14.04 LTS x64

This is an adventure! I kept all of my stupid failures in here in case someone else is also lazy and stupid. Behold, the Internet age!

A post on reddit regarding the aerospace industry’s use of Ada got me interested in the language. I’ve programmed enough in C to know the dangers inherent in the freedom it gives you, and I still have a lot to learn about “undefined behaviour”. I like that Ada is a trusted language for embedded environments, so I thought I’d try it out on my Arduino (ATMEGA-328P).

The toolchain isn’t available in the base apt repositories, unfortunately. There are two posts online that I found that both recommend building it yourself to ensure you have the latest patches and detail how to do it.

There’s this post by Tero Koskinen at the site which seems to be the primary reference for building a toolchain for Ada programming on AVR platforms. Tero’s post is a couple years out of date now though, so I’ll be building against the latest versions of everything involved.

Another post is this one by rolf_ebert on the AVR-ada sourceforge site. That post specifically targets Debian-based environments, which is useful for me. Again, it is quite out of date.

The version of gcc used in the second link is 4.7.0, whereas the latest available stable release is 4.9.1. The changelog is available here, and you can see that one change is that it defaults to Ada 2012 instead of 2005. The 4.8 changelog doesn’t reference Ada at all, and the 4.7 changelog mentions that a change was made that reduces debugger overhead and slightly reduces compilation time, by default. It looks like not much has changed, really. Regardless, I proceed in my blind march for progress!

I followed the build procedure for GCC to the letter for the second link, including the “export CC=gnatgcc” line at the top which is required to run the configure script.

The installation phase is where things went wrong. I thought I was a brilliant mastermind of the all-science and decided that the decimal at the beginning of the commands executing the and were superfluous. They are not. Executing them directly does nothing, you have to “source” them. Presumably the decimal is an alias for source. I tested it separately and learned that it was true, yay learning.

I renamed the directory from /opt/gnat-4.7 to /opt/gnat-4.9, should have done that in the environment setup scripts. Following along with the second link, I replaced all references to 4.7 to 4.9. I also changed any references to i386-linux-gnu to my architecture of x86_64-linux-gnu, as reported by “dpkg-architecture -qDEB_HOST_MULTIARCH”.

I had to eventually edit the environment building files to reflect my new directory, I should have done it before my first make install.

In my blind march for progress I downloaded the latest available binutils, but the latest patches from the avr-ada-code project are for 2.20.1. This is the point where I realized I had the same problem with gcc. I applied the 4.7.2 patches successfully on gcc 4.9.1 with no errors, but I am a little concerned at this point that I’m missing something. The binutils patches failed, and so I reverted to the latest version that had the patches, 2.20.1.

I’ve had to fix patch files in the past before, but I decided against trying for this, as compilers and toolchains are basically magic to me still and I don’t want to introduce bugs.

I had these fun binutil make errors greet me halfway through the process:

../../../binutils-2.20.1/bfd/doc/bfd.texinfo:326: unknown command `colophon'
../../../binutils-2.20.1/bfd/doc/bfd.texinfo:337: unknown command `cygnus'
make[3]: *** [] Error 1

Here’s a thread that seems relevant, but its about a more recent version. I just went into the relevant file and added an extra @ sign next to @colophon and @cygnus (@@colophon, @@cygnus) as I saw in the patch. This IRC conversation seems to indicate that this is an issue with texinfo 5 incompatibility with texinfo 4 targets, yay.

I downgraded to texinfo 4 by blindly accepting the advice of this Github issue post. A little apt-get remove texinfo here and a little dpkg -i there and I was done that bit. I ran “make install” again and it proceeded successfully. Awesome! In hindsight, my editing of the previous error was unnecessary. What I really needed to do was downgrade texinfo.

I had a build error when making gcc on file gcc-4.9.1/gcc/ada/switch-c.adb. The case/switch structure seemed to duplicate the ‘t’ switch, so I commented out the second one because it was shorter. Clearly, I am on a path of great success here. It compiled fine after that, but maybe I’m missing a command line argument. Whatever!

The next step for me was avr-libc, which has a slightly newer version available, 1.8.1 versus 1.8.0. Onward to progress!

On my first attempt I neglected to unset CC, CXX, and CPP. This gave me an error: “Wrong C compiler found; check the PATH!”. After actually following the instructions, it was smooth sailing for avr-libc.

For AVR-Ada I did not have gprbuild installed natively which is required. I apt-get install’ed gprbuild, and encountered a few errors on build:

no matching compiler found for --config=blablabla

After updating my path (which the instructions mention but I I didn’t understand until now) with export PATH=$PATH:/opt/gnat-4.9/bin it compiled without error. “make install” didn’t work after that, but that’s because I was supposed to “make install_libs”. All built, all installed! Woot! I don’t seem to have any examples to try and build yet, but this post is long enough anyway!

Sadly, the ultimate result is that code does not compile. Instead, I am greeted with the following:

$> make
avr-gnatmake -aL/opt/avrada/avr/lib/gnat/avr_lib/atmega328p/lib -XMCU=atmega328p -p -Pblink.gpr -XAVRADA_MAIN=blink_rel
avr-gnatmake: cannot find RTS rts/avr5
make: *** [blink_rel.elf] Error 4

I found this post on the avr-ada-devel mailing list by Rolf Ebert who wrote the main document I’ve been following, it seems he’s found the same problem.

Synology DS416j – From Stock to pycurl

I got a Synology DS416j NAS and wanted to use it for some basic network infrastructure tasks on top of data storage. One of these network infrastructure tasks involves updating a DNS record with my service provider, which requires a python script that uses curl, and therefore pycurl. You can install python with the package manager, but it doesn’t come with much. If you pip install pycurl, it’ll complain about curl-config not existing. To fix that, you need to go down a rabbit hole into a messy world of missing dependancies; proceed at your own discretion.

First, you’ll need the community package manager “ipkg” that’ll let you install most of what you need. It’s called a bootstraper, and there’s an easy installer available here.

Dump that on your NAS, go to the package manager, and “manually install” it. You’ll also need to enable SSH.

By default the new “ipkg” binaries and associated bits will not be in your path, so you’ll have to modify your path to include it. I did this with a PATH=$PATH:/usr/opt in a .bashrc.

You can then “ipkg install” several packages as root. You’ll need a bunch:

  • busybox
  • binutils
  • diffutils
  • gawk
  • gcc
  • libc-dev
  • libcurl
  • libcurl-dev
  • make
  • openssl
  • openssl-dev
  • patch
  • sed

This is what I needed for pycurl, anyway.

Next, you need the python headers, which you are not going to be able to get via ipkg. You have to go to and get the appropriate source tarball for the version you have (python –version). Dump that in /tmp, extract it, run ./configure to produce pythonconfig.h. I had to modify pythonconfig.h so that Py_UNICODE_SIZE was 4, not 2, as it seems the binary I have installed was compiled with that. If you don’t change this you’ll get some undefined references to a symbol “PyUnicodeUCS2_Decode”.

Make a directory /opt/lib/python, dump everything in your extracted tarballs Include directory in there, and also put your modified pythonconfig.h in there.

Now you can pip install pycurl, except that won’t work. Run it with “pip install –no-clean pycurl” so you can manually complete it. It’ll leave a directory in “/tmp/pip-build-something/pycurl”, go there. is going to look for gcc in the wrong place. There’s probably a good way to fix that, but it was really quick to just symlink the wrong place to the right one:

ln -s /opt/bin/gcc /usr/local/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ccache-gcc

It’s also not going to know where to find those python includes we just collected. There’s probably a proper way to do that too, but I just modified so that:

self.include_dirs = [‘/opt/include/python’]

Under the instantiation definition for the class ExtensionConfiguration.

Now, you can make and make install and you’ll have pycurl.

Aruba 620 Password Reset

If you forget your password to an Aruba 620, you can perform a password reset it using the RS232 (serial) console port with some magic words.

Connect to the Aruba 620 using an RS232 DB9-to-RJ45 cable. This cable is pretty standard, and is also used for a lot of Cisco equipment.

The default serial settings are as follows:

9600 baud
8 data bits
no parity bit
1 stop bit
no flow control

At the user: prompt, enter “password”. As a password, enter “forgetme!”.

Type “enable” to enter a more privileged mode that will allow you to make changes.

Enter the system configuration menu with “configure terminal”. Then, you can use “mgmt-user admin PASSWORD” to set the password.

You’ve set the password, but it doesn’t actually matter yet. You have to write the new settings to make them stick. Use “write memory” to accomplish that.

That’s it!

Dell Laptop Stuck In Airplane Mode on Windows 10 Following Driver Update

After updating the drivers for my Dell laptop, it was stuck in airplane mode permanently. The specific model I have is Latitude E6540. The standard solution you can find online is to hold Fn + Print Screen, or Fn + F2 to toggle airplane mode. However, that didn’t do anything for me. Here’s what I did, which did work:

  1. Under Human Interface Devices, uninstall Dell’s airplane mode switch driver
  2. Yes, you want it to delete the driver files
  3. Reboot
  4. Press F2 frantically to trigger the BIOS setup menu
  5. Under Wireless, disable everything under Wireless Switch
  6. Under the other Wireless menu, disable everything. Apply, re-enable everything.
  7. Exit BIOS menu.

This worked for me, maybe it’ll work for you. Some of these steps may have been unnecessary.

Mezzanine Media Library 404, Solution!

I have been fighting with Mezzanine’s Media Library for the past hour. I love Mezzanine, but the damn Media Library (filebrowser_safe) wouldn’t load. I’d be greeted with my site’s 404 page when I’d try to reach that page. Google didn’t help much, so I had to turn my brain on and look at the code. The URL for the Media Library link in my admin panel was “/browse”. This is wrong. Add the following to your site’s main and all will be well:

urlpatterns += patterns('',
    ("^admin/media-library/", include("filebrowser_safe.urls")),

Dwarf Fortress 0.40.03 on Ubuntu 14.04 LTS x64

I wanted to run the latest and recently updated Dwarf Fortress on Ubuntu (14.04 LTS), but it’s a 32-bit binary and therefore depends on lots of other 32-bit binaries to be installed, which I don’t have on a x86_64 or 64-bit installation. If you try to run it, you’ll see this:

$> ./df
./libs/Dwarf_Fortress: error while loading shared libraries: cannot open shared object file: No such file or directory

Which you’ll find confusing if you definitely have libSDL 1.2 installed, as I do. Here’s a little hint:

$> file libs/Dwarf_Fortress && uname -a
libs/Dwarf_Fortress: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, stripped
Linux sleipnir 3.13.0-30-generic #55-Ubuntu SMP Fri Jul 4 21:40:53 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Your immediate thought, like mine, if you had not run into this before would be to just find and install the library, easy-peazy!

$> apt-cache search libsdl 1.2
libsdl1.2-dbg - Simple DirectMedia Layer debug files
libsdl1.2-dev - Simple DirectMedia Layer development files
libsdl1.2debian - Simple DirectMedia Layer

$> sudo apt-get install libsdl1.2debian
Reading package lists… Done
Building dependency tree
Reading state information… Done
libsdl1.2debian is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

What the heck?

$> ldconfig -p | grep (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/
$> apt-cache showpkg libsdl1.2debian
Package: libsdl1.2debian
1.2.15-8ubuntu1.1 (/var/lib/apt/lists/ca.archive.ubuntu.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages) (/var/lib/dpkg/status)

Ah. That explains it, doesn’t it!

I had run into this problem on Debian previously many moons ago, and as Ubuntu is Debian-based, I followed their excellent documentation on adding multi-arch support to Debian.

Essentially, I had to execute these commands:

$> sudo dpkg --add-architecture i386
$> sudo apt-get update
$> sudo apt-get install libsdl1.2debian:i386

Following this, I was excited to get started!

$> ./df
./libs/Dwarf_Fortress: error while loading shared libraries: cannot open shared object file: No such file or directory

Great, here we go down the dependency rabbit hole. What is this, Red Hat? When you stray from your package management system, you run into nasty problems like this. However, thanks to the Internet you can benefit from my work if you are having the same problem. Here’s what you need to install:

libsdl1.2debian:i386 libgtk2.0-0:i386 libsdl-image1.2:i386 libsdl-ttf2.0-0:i386

If you don’t care about sound, you’re done! If you do (thanks to Keilaron on the bay12forums):

sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/
sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/
sudo ldconfig

Since Dwarf Fortress expects the libraries to be called exactly “” and ““, which they are not.

I found that on first execution it took several seconds for the game to start, but following that it was quick and fully working, as far as I can tell! I don’t know what those broken keycode errors are about, but maybe that’ll be for another post.

Let me know if your case was a bit different or if you’re still stuck!

Dwarf Fortress 0.40.03 Running on Ubuntu 14.04 LTS