DNS-323 Toolchain

I’ve been wanting to be able to compile software for my NAS, the DNS-323 from D-Link, and I found instructions at a couple of different places on the internet.  In order to do this, you’ll need a cross compilation toolchain, which you can either download or build yourself.

I found some good information on the dns 323 wiki, but ultimately those instructions didn’t work for me, on firmware 1.08.  Which incidentally, can be downloaded from D-Link’s website, ftp://gpl.dlink.com/DNS-323/dns323_GPL_v1.08_12182009.tgz.  The pre-built toolchain provided on the wiki, didn’t have libstdc++, and the instructions for building your own failed for me (couldn’t get binutils to build).

I found very good instructions here for how to build the toolchain, complete with modifications to enable dynamic linking of libraries.  Binaries are provided on that site, but they were for x86-64, and I’m on a 32-bit host.

So, I used Ubuntu Hardy Heron running in a VirtualBox VM to build it for myself.  You can download a toolchain for a 32-bit host below, or read on for instructions on how to build it on your machine.

DNS-323 cross compile toolchain for a 32-bit Host

Cross Compile Instructions

First you’ll need to set up some build dependencies.  The toolchain requires an older (3.x) gcc in order to build.  gcc 4.x may work, but most of what I’ve read seems to indicate that it probably does not.  You can set the /usr/bin/gcc symlink back to it’s original when you’re done.

$ sudo apt-get install gcc-3.4 g++-3.4 bison flex gettext make bzip2 libncurses5-dev patch git-core
$ cd /usr/bin
$ sudo mv gcc gcc-orig
$ sudo ln -s gcc-3.4 gcc
$ sudo mv g++ g++-orig
$ sudo ln -s g++-3.4 g++

Next you’ll need to clone the git repository containing the toolchain source.  Note that when you run ‘make’ a number of packages will be downloaded and then built.

$ git clone git://github.com/juergh/toolchain_arm.git 
$ cd toolchain_arm
$ make

The resulting toolchain files are in the toolchain_arm directory.

Using the Toolchain

Test minimum cross compiler functionality, by building a hello world app.  Save the following to hello.cpp

#include <iostream>

int main(int argc, char* argv[])
    std::cout << "the toolchain worked!" << std::endl;
    return 0;

Now compile it with the toolchain

$ source toolchain_arm/build-env
$ ${CXX} hello.cpp -o hello

Verify that the resulting file is an ARM executable

$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), not stripped

Now you can just copy the executable to your device and run it to see if it works.

Building Autotools style projects

You’ll probably have some open source software that you want to compile for your device. Here an example using curl.

$ wget http://curl.haxx.se/download/curl-7.26.0.tar.gz
$ tar -zxvf curl-7.26.0.tar.gz
$ cd curl-7.26.0
$ source ~/toolchain_arm/build-env #or wherever you decided to save your toolchain
$ ./configure --host=arm-linux-uclibc 
$ make


Leave a Reply

Your email address will not be published. Required fields are marked *