Cross-compiling NDN projects for home routers » History » Revision 1
Revision 1/15
| Next »
Mathias Gibbens, 05/12/2014 02:21 PM
Cross-compiling NDN projects for home routers¶
Contents¶
- Introduction
- Setting up the build host
- OpenWRT source and toolchain
- DD-WRT source and toolchain
- Compiling ndn-cxx
- Using the ndn-cxx library with other NDN projects
- Concluding remarks
Introduction¶
This page describes how to cross compile the NDN projects to run on wireless home routers that are supported by various open source firmwares, such as OpenWRT and DD-WRT. It's a fairly straight forward process, but it is assumed that you are familiar with basic software development in a Linux environment, have some familiarity with cross compilation in general, and aren't afraid to get your hands dirty! There are also a couple considerations that need to be addressed when targeting smaller/embedded devices, especially concerning the limited flash storage typically available on routers.
The process of setting up the build host and actually compiling the NDN project will be the same regardless of the hardware/firmware you wish to target. Follow the corresponding section that matches your firmware to get the proper cross compile environment.
Setting up the build host¶
Steps in this guide were tested on a system running Debian 7 (wheezy). Distribution specific commands, like installing packages, may have to be modified to suit your setup, but on the whole this guide should be applicable to any modern Linux system. All commands should be run as a normal user -- never run as root!
Make sure you have the needed packages on the host system to compile the cross compile toolchain, libraries, and resulting firmware:
sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk unzip
Finally, before we actually begin the compilation process, be aware that the paths given below which reference a specific build target (like "mipsel_mips32_uClibc-0.9.33.2") very well could be different for you. Make sure to make the appropriate adjustments to match your setup.
OpenWRT source and toolchain¶
Begin by fetching the current code for OpenWRT. Additional instructions are available on their wiki at OpenWrt Buildroot - Installation. This guide assumes you checked out the source to your home directory.
git clone git://git.openwrt.org/openwrt.git
cd ~/openwrt/
./scripts/feeds update -a
./scripts/feeds install -a
We need to fetch the current feed information, as that is where we get the boost, libcrypto++, and libsqlite3 libraries to run in OpenWRT.
Now, run the configuration interface and adjust the settings as you need to match your device, etc.
cd ~/openwrt/
make menuconfig
Additionally, make sure the following libraries are selected so we can compile the NDN software. (Additional libraries might be required for projects that go beyond ndn-cxx, like libpcap
for NDF.)
Libraries --->
SSL --->
libopenssl
database --->
libsqlite3
boost-chrono
boost-date_time
boost-filesystem
boost-iostreams
boost-program_options
boost-regex
boost-system
boost-test
libcryptoxx
After you have the configuration to your liking, we need to compile the toolchain and libraries. This will take a while.
make
Once the OpenWRT cross compile environment is compiled, we need to create two temporary symlinks so the later ./waf configure
stage will properly detect libcrypto++
: (Again, remember that the target part of the path names may be different for you.)
ln -s ~/openwrt/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/usr/include/crypto++ ~/openwrt/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/usr/include/cryptopp
ln -s ~/openwrt/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/usr/lib/libcrypto++.so ~/openwrt/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/usr/lib/libcryptopp.so
Now the cross compile environment is ready for you to use. Proceed to Compiling ndn-cxx.
DD-WRT source and toolchain¶
WIP
Compiling ndn-cxx¶
In this section we will compile the ndn-cxx code. Other NDN projects should compile in a similar manner.
As mentioned in the introduction, compiling for an embedded device can present issues not normally encountered. Chief among these for us is the very limited disk space to copy files to on the router. Normal compilation of NDN projects by default includes debug symbols. This can add an order of magnitude to the resulting binary size, making in infeasible to run on a router. Therefore we will overwrite the default compiler flags with the CXXFLAGS
variable. Additionally, the compilation process produces a statically linked library which is several megabytes in size. Unless it is specifically needed, there's no reason to copy it to the router where it will just waste space.
Begin by fetching the current release of ndn-cxx, 0.1.0 as of this writing:
cd
wget https://github.com/named-data/ndn-cxx/archive/ndn-cxx-0.1.0.tar.gz
tar xf ndn-cxx-0.1.0.tar.gz
cd ndn-cxx-ndn-cxx-0.1.0/
Now, set the needed environment variables so the configuration and compilation process use the cross compile environment we have setup.
FIXME this is currently specific to OpenWRT
export TOOLCHAIN_PATH=$HOME/openwrt/staging_dir/toolchain-mipsel_mips32_gcc-4.8-linaro_uClibc-0.9.33.2/bin
export CROSSCOMPILE_PATH=$HOME/openwrt/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/usr
export CXX=$TOOLCHAIN_PATH/mipsel-openwrt-linux-uclibc-g++
export AR=$TOOLCHAIN_PATH/mipsel-openwrt-linux-uclibc-ar
export CXXFLAGS="-O2"
export CFLAGS="-I$CROSSCOMPILE_PATH/include"
export LDFLAGS="-L$CROSSCOMPILE_PATH/lib -lz"
Finally, configure and build the library. We will install the resulting binaries and source files into a folder within our home directory so we don't accidentally contaminate our host system with non-native binaries.
./waf configure --prefix=/usr --sysconfdir=/etc --with-openssl=$CROSSCOMPILE_PATH --with-cryptopp=$CROSSCOMPILE_PATH --with-sqlite3=$CROSSCOMPILE_PATH --boost-includes=$CROSSCOMPILE_PATH/include --boost-libs=$CROSSCOMPILE_PATH/lib
./waf
DESTDIR=$HOME/ndn-cxx-crosscompile ./waf install
You can now find the cross compiled binaries in ~/ndn-cxx-crosscompile
.
Using the ndn-cxx library with other NDN projects¶
WIP
Concluding remarks¶
Updated by Mathias Gibbens over 10 years ago · 15 revisions