Easy Build for OpenWrt On Ubuntu/Debian

I just got a TP-Link TL-MR3040 a few days ago, and successfully set it up as a PirateBox, which involved refreshing the firmware with OpenWrt rather than a stock image. This is actually a pretty cool little device for the $35, it’ll run Linux, and with OpenWrt, not only can it function as a router, it can act as a tiny server running off a file system attached via USB.

I’ve tried this build on multiple platforms, and documented some of that in a previous version of this posting. While I’ve successfully gotten the core of OpenWrt to build on OS X, and a number of things to build on CentOS, I’ve only gotten consistent and reliable results overall on Debian-like systems, so that’s what I’m going to be sticking to here.

In particular, I’ve had nothing but trouble trying to build an OpenWrt image for a Raspberry Pi anywhere other than on Debian or a Debian derivative. I have verified working builds for both the TL-MR3040 and the Raspberry Pi on Mint 17.

The instructions for building a firmware image on the OpenWrt wiki are a version or more out of date — they’re for building Attitude Adjustment, rather than Barrier Breaker.

The procedure for building top-of-trunk for OpenWrt developers is better documented than the Attitude Adjustment build seems to have been, but still a little bit scattered.

Additionally, the guide for setting up a build environment on OS X relies on MacPorts, and I prefer Homebrew, is similarly outdated, and there are a wrinkle or two along the way, so I figured I should document what I’ve done. I’m not recommending, at this point, that you try building this stuff directly on OS X. Use a VM running Debian or Mint instead, that’s my recommendation.

Set Up the Prerequisites

On Ubuntu 14.04 LTS “Trusty Tahr”/Debian 7.7.0/Mint 17

sudo apt-get install subversion build-essential libncurses5-dev zlib1g-dev gawk git ccache gettext libssl-dev xsltproc zip

On OS X 10.10 “Yosemite”

On OS X, we’ll want to specifically set up a case-sensitive file system to work on. We can create a .dmg file that we can use for our development with the following commands. Twenty gig is plenty of space.

hdiutil create -size 20g -fs "Case-sensitive HFS+" -volname OpenWrt OpenWrt.dmg
hdiutil attach OpenWrt.dmg

Getting the build environment set up right here is a little more ornate. If you don’t have Homebrew (and you should), you’ll need to get that installed first. You’ll also need to install Xcode and the Xcode Command Line Tools.

brew update
brew upgrade
brew install coreutils e2fsprogs ossp-uuid asciidoc binutils fastjar gtk+ gnu-getopt gnu-tar intltool openssl subversion rsync sdcc gawk wget findutils

When brew installs the gnu toolset, it doesn’t automatically link it into your path, and the build wants to use gnu-compatible tools. However, brew does create an auxiliary directory of gnu-compatible aliases at /usr/local/opt/coreutils/libexec/gnubin, and for the purposes of the build, we can set our path to preference those tools temporarily.

ln -s /usr/local/Cellar/gnu-getopt/1.1.5/bin/getopt /usr/local/opt/coreutils/libexec/gnubin/getopt
ln -s /usr/local/bin/gtar /usr/local/opt/coreutils/libexec/gnubin/tar
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH

Get the Sources

Get the Barrier Breaker sources from the upstream repo to build the current stable release:

git clone git://git.openwrt.org/14.07/openwrt.git

Or pull down the latest OpenWrt “Chaos Calmer” sources to build the “bleeding edge” top-of-trunk version:

git clone git://git.openwrt.org/openwrt.git

Prepare For the Build

Connect to the source directory, and update and install all the feeds. These represents the build schemes for all of the optional components that you can add to your OpenWrt system.

cd ~/openwrt
./scripts/feeds update -a
./scripts/feeds install -a

Configure the build.

make prereq

This sets up prerequisites for the build and then takes you into menuconfig, a screen-driven configuration utility based on the one used to set up builds for the Linux kernel.

For starts, you simply want to pick an appropriate “Target system” and “Target profile”. For the TP-Link TL-MR3040, the target system is “Atheros AR7xxx/9xxx”, subtarget “generic”. For a Raspberry Pi, the target system is “BRCOM947xx/953xx”, the only profile is “Raspberry Pi”.

build5

For an initial build, I’d suggest simply picking the correct target and leaving it at that. You can start adding other options once you’ve verified that you can produce a working build and have an idea how much free space you’ve got to play with on the system. You want to start out minimal, the MR3040 only has 4MB (!) of available flash memory.

When you’re done here, select “Exit”, and save your configuration file as .config when prompted to do so.

Build that sucker!

All it takes is a make at this point. I like to use make V=s because I like to watch it do its thing.

make

Results will be in the bin/ folder, in a subfolder corresponding to the architecture you’ve built for — in my case “ar71xx”.

18 thoughts on “Easy Build for OpenWrt On Ubuntu/Debian”

    1. I’ve run into the same problem — I’m posting on that thread as “mcfate”. I haven’t really dug into a build for the Raspberry Pi on any platform, other than giving it a shot and having it fail on me, as I’ve documented. I’ve just set up a Pi with Raspbian, I may give a build a shot on a different platform (e.g. Mint 17).

    2. I’ve updated this posting to reflect increased familiarity and better understanding. The Raspberry Pi image builds without problems on a Debian-based system, I’ve revised this posting to just cut to the chase where things demonstrably work.

  1. Hey, thanks for the guide!
    I would like to point out that you can make use of multiple cores while building by adding -jX flag, where X is number of cores you want to use.

  2. How can I make development on OpenWRT???
    Means I want to write my own code in openWRT and want execute there. In which language it allows me to write code??

      1. If I write simple hello.c file to print “hello world” on openWRT itself using vi, Can I run it on openWRT without cross compiling???

        1. No, certainly not. You’ve (somehow) got to compile it for whatever platform you hope to run it on, unless you’re using some sort of an interpreted language. Whether you’re cross-compiling or not depends on where you do it, that’s all.

  3. When I follow your directions and get to the end of the “make prereq” operation I do not get the menuconfig screen.

    I am loading it locally on a pi2, with Raspian, and ignoring the OSX/Brew portion for setting up your Mac.

    Can I open it manually or is Raspbian the issue?

    Thanks,

    Rick

  4. Hello and thanks for writing this up. It should be integrated to the OpenWRT Wiki.

    I already had brew installed and I was checking the prerequisite packages against the OpenWRT wiki, so your guide came in handy 🙂

    I’m successfully building x86 images for an old netbook of mine.

  5. osX v10.11.1

    I have still some errors:
    Undefined symbols for architecture x86_64:
    “_ERR_remove_thread_state”, referenced from:
    _rsa_sign in rsa-sign.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    1. Yeah, I actually wouldn’t try this build on OS X at this point. I should update the posting to note that there are probably problems there. Use some Debian derivative, I build on Mint 17 with no issues.

    2. Actually, I already noted that: “While I’ve successfully gotten the core of OpenWrt to build on OS X, and a number of things to build on CentOS, I’ve only gotten consistent and reliable results overall on Debian-like systems, so that’s what I’m going to be sticking to here.” I’d recommend you do likewise, the build seems dead reliable on Debian-ish systems.

    3. I find this solution:
      http://mehmetalierturk.com/2015/09/29/openwrt-15-05-chaos-calmer-on-mac-os-x-el-capitan-10-11/

      After make modofocations now I receive these errors:
      make[3]: Entering directory `/Volumes/OpenWrt/chaos_calmer/tools/mkimage’
      Makefile:50: *** commands commence before first target. Stop.
      make[3]: Leaving directory `/Volumes/OpenWrt/chaos_calmer/tools/mkimage’
      make[2]: *** [tools/mkimage/compile] Error 2
      make[2]: Leaving directory `/Volumes/OpenWrt/chaos_calmer’
      make[1]: *** [/Volumes/OpenWrt/chaos_calmer/staging_dir/target-mips_34kc_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyyyyyyyyyyyynyyyyynnyyynyyynnnyy] Error 2
      make[1]: Leaving directory `/Volumes/OpenWrt/chaos_calmer’
      make: *** [world] Error 2

      1. I’m not really sure what to tell you, other than that I don’t really try to build this stuff on OS X any more. It’s an exercise in yak-shaving, and since CC builds painlessly on Mint, so why work harder to get worse results…?

  6. Worked great on El Capitan. gnu grep was missing but you can install it with homebrew.

    Either:

    brew install grep –with-default-names

    which will replace the default BSD grep or symlink it instead:

    ln -s /usr/local/Cellar/grep/2.22/bin/ggrep /usr/local/opt/coreutils/libexec/gnubin/grep

    Before linking make sure it is actually the version you installed (same with gnu-getopt, which changed to 1.1.6). If you have problems with openssl read:

    brew info openssl

Leave a Reply

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