What are we compiling for?
I have a couple of very hackable routers that I have flashed with latest version of OpenWRT -Barrier Breaker 14.07:- TP-LINK TL-MR3020
(Pocket Router with USB Port | Install Instructions | Image: openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin | I use this device to build my Weather Station) - TP-LINK TL-MR3040
(Just like MR3020 but has a building battery | Install Instructions | Image: openwrt-ar71xx-generic-tl-mr3040-v1-squashfs-factory.bin) - Dragino MS14
(OpenWRT wiki | Product Page | Firmware installation and instruction | Change Log | Firmware Image)
All these routers have the AR9331 SoC in them which is MIPS and not MIPSel. MIPSel refers to a MIPS architecture using a little endian byte order. Since almost all MIPS microprocessors have the capability of operating with either little endian or big endian byte order, the term is used only for processors where little endian byte order has been pre-determined. So we want the mips toolchain and not mipsel toolchain. AR9331 is also used on Arduino Yún.
OpenWRT SDK is a collection of tools for cross compiling software for MIPS on an x86 PC
Installing it.
Here are the steps I executed to run OpenWRT on Ubuntu 64 bit. The latest version of OpenWRT SDK (corresponding to Barrier Breaker) needs a 64bit Linux to run on. I used a Ubuntu 64 bit virtual machine running on Windows to get this done
- Install VirtualBox
- Download Ubuntu 14.10 64-bit .vdi file from http://www.osboxes.org/ubuntu/
- Create a new 64 bit Ubuntu machine and while doing so, attach the downloaded and existing .VDI file to the Virtual Machine
- Get latest Ubuntu software lists:
sudo apt-get update - Installed guest editions, setup shared folders between Windows and Linux and set user group permissions (here is how)
- Install dependencies:
sudo apt-get install build-essential subversion libncurses5-dev zlib1g-dev gawk gcc-multilib flex git-core gettext libssl-dev
Otherwise you will get the following messages while compiling:
Build dependency: Please install ncurses. (Missing libncurses.so or ncurses.h)
Build dependency: Please install zlib. (Missing libz.so or zlib.h)
Build dependency: Please install GNU awk.
Build dependency: Please install git (git-core) v1.6.5 or later.
Build dependency: Please install the subversion client. - Download latest Barrier Breaker SDK which is a 64-bit SDK (i.e. MIPS cross compiler that runs on 64bit version of x86 PCs):
wget http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 - Extract 64-bit SDK:
bzcat OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 | tar -xvf - - Edit Config-build.in in ~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2 :
Change:
config CCACHE
bool
default y
bool
default y
to
config CCACHE
bool
default ""
bool
default ""
Hello World:
Create the source file and Makefile for the helloworld program. Create the appropriate folders and the following files in it (beware, there are two makefiles):~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/package/helloworld/src/helloworld.c
1 | /**************** |
------------ ------------ ------------
~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/package/helloworld/src/Makefile
1 | # build helloworld executable when user executes "make" |
------------ ------------ ------------
~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/package/helloworld/Makefile
1 | ############################################## |
You can download the above source files from here. Its a good idea to fetch the files rather than copying and pasting so as to retain the proper spaces and tabs and EOLs - these are important when Makefiles are parsed.
Compiling it, Installing it, Running it on your OpenWRT device:
- While in ~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2 run:
make V=99 - .ipkwill be placed in ~/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/bin/ar71xx/packages/base
- Copy the ipk to Windows using shared folders
- Use WinSCP to copy helloworld_1.0.0-1_ar71xx.ipk to your OpenWRT router. (To know how to use WinSCP, go through the "Copying the executable to the router" section here)
- Connect to OpenWRT device using PuTTY and install the package:
opkg install helloworld_1.0.0-1_ar71xx.ipk - Execute:
helloworld
![]() |
Running helloworld |
References:
- OpenWRT: Using the SDK http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk
- https://giovanni.wordpress.com/2011/01/23/how-to-cross-compile-a-c-program-for-openwrt/
- http://postwarrior.com/openwrt-please-fix-packagehelloworldmakefile-see-logspackagehelloworlddump-txt-for-details-solution/
- http://wiki.openwrt.org/doc/devel/packages
- http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 Will not work on 32bit Linux and needs 64 bit linux because the binaries in there are built to run on 64 bit. You will get an error like: find: syntax error: "(" unexpected
In case of 32-bit Ubuntu, use the older Attitude Adjustment SDK:
- Download SDK:
wget http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2 - Extract SDK:
bzcat OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2 | tar -xvf -
In case of the newer release of OpenWRT Chaos Calmer 15.05:
- Toolchain is at:
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 - MR3020 Image is at:
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/openwrt-15.05-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin - MR3040 Image is at:
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/openwrt-15.05-ar71xx-generic-tl-mr3040-v2-squashfs-factory.bin