As part of a broader organisational restructure, data networking research at Swinburne University of Technology has moved from the Centre for Advanced Internet Architecture (CAIA) to the Internet For Things (I4T) Research Lab.

Although CAIA no longer exists, this website reflects CAIA's activities and outputs between March 2002 and February 2017, and is being maintained as a service to the broader data networking research community.

Building OpenWRT under FreeBSD

As part of our research into using OpenWRT for traffic classification and other tasks on embedded devices, our group is documenting an approach to building OpenWRT images natively under FreeBSD. This approach has been confirmed to work inside a FreeBSD 8.x jail and a PCBSD 9.1 jail.

OpenWRT

OpenWRT is a Linux distribution for embedded devices. It is commonly used to replace the factory firmware found on residential Internet routers. By replacing the factory firmware, users gain access to additional configuration options and are able to extend the functionality of the router by installing new software. Our "Diffuse for OpenWRT" project released an Ubuntu-based VirtualBox VM suitable for building OpenWRT, but we also wanted to build OpenWRT natively under FreeBSD. The challenge is to install the GNU tools required by OpenWRT's  build system.

Configuring FreeBSD to build OpenWRT

The key is this script, which installs any required-but-missing FreeBSD utilities (building each one from source using the Ports system) and creates a set of symlinks to ensure OpenWRT utilises GNU utilities in preference to their BSD cousins where required.

The following example assumes we are installing OpenWRT's trunk branch into local directory /usr/home/openwrt. The steps are:
  • As your regular user, download and install OpenWRT trunk to /usr/home/openwrt (you will need subversion)
    • e.g. svn co svn://svn.openwrt.org/openwrt/trunk/
  • Change directory to /usr/home/openwrt/trunk
      • A number of FreeBSD Ports will most likely be built and installed, including GNU versions of a number of tools
      • Symlinks will added under ./bin-gnu
      • You will be told to pre-pend your environment's PATH variable with /usr/home/openwrt/trunk/bin-gnu before trying to build OpenWRT in the next step as a regular user
Assuming everthing has run smoothly, you should now have a functional OpenWRT build system able to run natively under FreeBSD.
  • As your regular user, from within /usr/home/openwrt/trunk
    • Pre-pend your environment's PATH variable with /usr/home/openwrt/trunk/bin-gnu
    • Run 'gmake menuconfig' to launch OpenWRT's build system configuration menu
    • Run 'gmake' to start building OpenWRT (tools, toolchain and then your desired release image)

Tested cases

We have successfully created OpenWRT trunk (r35515), attitude_adjustment (r35400) under a PCBSD 9.1 x64 Jail and a FreeBSD 8-STABLE x64 ezjail jail (using the Ports tree as of late January 2013 in each case), and then built default sets of packages and working images for the following Target Systems & Profiles:
  • Cavium CNS21XX (e.g. for the NS-K330)  [squashfs image, OpenWRT trunk only]
  • Cavium CNS3XXX  [squashfs image]
  • Atheros AR7xxx/AR9xxx (TP-Link WR1043ND & WR703N)  [squashfs image]
  • ARM Ltd. Realview board (qemu)  [elf image]

Notes

We came across at least one OpenWRT package (package/mac80211) that is hardwired to assume bash exists at /bin/bash. Our script assumes this is not generally true in a FreeBSD host, and thus installs bash from Ports and symlinks /bin/bash to /usr/local/bin/bash.

When installing inside a FreeBSD jail, check whether you have write permission to /bin -- some jail tools (like ezjail) initially create /bin as a symlink to a read-only /basejail/bin directory tree. You'll need to remove the symlink, copy /basejail/bin to a new /bin, then restart our script to instantiate the bash symlink.

Our script also prevents OpenWRT from compiling its own e2fsprogs and mtd-utils build tools (they currently don't compile properly under FreeBSD). These are different to any similarly-named packages that might be added to an OpenWRT image, and their absence means you cannot build ext4 root filesystem images. (This is an acceptable limitation for our purposes, as we only want squashfs or ramdisk images.)

Authors

Grenville Armitage and Chris Holman


Last Updated: Friday 22-Feb-2013 19:55:48 AEDT | No longer maintained. Pre-2018 was maintained and authorised by Grenville Armitage, garmitage@swin.edu.au