Saturday, April 26, 2014

Compiling custom firmware for wireless router with OpenWRT (Barrier Breaker from trunk) and OpenFlow

Environment: Ubuntu 12.04 with 30 GB HD and 1 GB RAM on VirtualBox (On I5 MacBook pro).
Hardware: Tested TP-LINK TL-WR740N v4.27 and TP-LINK TL-WR1043ND v2.1

1. Install prerequisite packages:
sudo apt-get update
sudo apt-get install autoconf binutils bison build-essential ccache flex gawk gettext git libncurses5-dev libssl-dev ncurses-term quilt sharutils subversion texinfo xsltproc zlib1g-dev 

2. Prepare directory and download OpenWRT source
mkdir ~/openwrt
cd ~/openwrt
svn co svn://svn.openwrt.org/openwrt/trunk/

3. Update and install feeds
cd ~/openwrt/trunk
./scripts/feeds update -a
./scripts/feeds install -a

4. Configure the build and verify prerequisites
cd ~/openwrt/trunk
make menuconfig
select 'Target System': Atheros AR71xxx/Ar9xxx
select 'Target Profile': TP-LINK TL-WR740N/ND        OR      TP-LINK TL-WR1043ND
make prereq
make (if only OpenWRT trunk version is desired. Following steps can be finished to include Openflow package, but running make at this point won't hurt and first compilation takes long time, but second time it will be faster)

5. Prepare directory, download openflow source for openwrt and link to OpenWRT for compilation
cd ~/openwrt

--------For OpenFlow 1.0--------
git clone git://gitosis.stanford.edu/openflow-openwrt
cd openflow-openwrt
git checkout -b openflow-1.0/tplink origin/openflow-1.0/tplink

cd ~/openwrt/trunk/package/
ln -s ~/openwrt/openflow-openwrt/openflow-1.0/
cd ~/openwrt/trunk/
ln -s ~/openwrt/openflow-openwrt/openflow-1.0/files
----------------------------------------
--------For OpenFlow 1.3--------
git clone https://github.com/CPqD/openflow-openwrt.git
cd ~/openwrt/trunk/package/
ln -s ~/openwrt/openflow-openwrt/openflow-1.3/
cd ~/openwrt/trunk/
ln -s ~/openwrt/openflow-openwrt/openflow-1.3/files
----------------------------------------
6. Configure the build with openflow
cd ~/openwrt/trunk
make menuconfig

select <*> 'openflow' package under 'Network'
select <*> 'tc' package under 'Network'
select <*> 'kmod-tun' under 'Kernel Modules -> network support'

IF TC PACKAGE NOT FOUND UNDER NETWORK in MENUCONFIG:
- select <*> 'kmod-sched-core' and 'kmod-sched' under 'Kernel Modules -> network support'
- 'kmod-sched-core' is prerequisite for TC.

save and exit

make kernel_menuconfig
select <*> 'Hierarchical Token Bucket (HTB)' under 'Networking support -> Networking options' in 'Queueing/Scheduling' section.

Note: Check my other post to select required packages if you need to enable pivot overlay

7. Make the final build
cd ~/openwrt/trunk
make V=s (Here, V=s is optional and will be useful to debug in case of any error)

8. Download and upload the image to router

Images can be found in cd ~/openwrt/trunk/bin/ar71xx/

Recommendations:
i. Before using your custom firmware flash router with openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-factory.bin from trunk website, as it will be useful if you have to restore your settings to original
                    http://downloads.openwrt.org/snapshots/trunk/ar71xx/
ii. Use openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin version to upgrade existing firmware with you build
Before 
iii. See below link on how to do sysupgrade
                    http://wiki.openwrt.org/doc/howto/generic.sysupgrade

9. I used factory image from trunk website mentioned above. If it was new install there won't be password set and u can use Telnet for the first time to login and set password. If you upgraded from previous version of OpenWRT, password will be same.
Below is login message at first login after uploading factory image.

BusyBox v1.19.4 (2014-03-13 02:11:02 MST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r39903)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------
root@OpenWrt:~#

10. Later upgrade the factory image with squashfs-sysupgrade.bin mentioned in 8.ii, which was generated with your custom compilation.

From your machine:
scp openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin root@192.168.1.1:/tmp

On OpenWRT router:
sysupgrade -v openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin


You can notice below, now latest version of Bleeding Edge is installed:

BusyBox v1.19.4 (2014-03-14 05:08:51 EDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r39917)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------

One other check you can do verify if you custom firmware is installed successfully is to verify difference between packages installed in steps 9 & 10. By using 'opkg list' command.

11. Install required packages manually

If TC was not installed before:
On desktop- scp ./tc_3.11.0-1_ar71xx.ipk root@192.168.1.1:/tmp/offline-packages
On router- opkg install ./tc_3.11.0-1_ar71xx.ipk

Create link for TC as follows, it's needed because openflow package won't start without TC.

cd /sbin
ln -s /usr/sbin/tc

Also create functions.sh link in /etc as below:

cd /etc
ln -s /lib/functions.sh

Reboot the router to verify if openflow running normally. It should be running ofprotocol and ofdatapath processes.

To check: ps | grep of

At least of protocol service should be running if network config and controller address is not correct.


For trunk version LUCI is not included in distribution by default. You can use "opkg install  luci" command to install it.

For some reason if you cannot use OPKG, it can be installed manually like TC package.


On router:

mkdir /tmp/offline-packages

On desktop:
mkdir ~/offline-packages

And download below packages:

libiwinfo-lua_35_ar71xx.ipk
liblua_5.1.5-1_ar71xx.ipk
libubus-lua_2014-02-23-334c38918063b5ece164624e20490021b2bff38a_ar71xx.ipk
libuci-lua_2014-02-18.1-1_ar71xx.ipk
lua_5.1.5-1_ar71xx.ipk
luci-app-bmx6_2_ar71xx.ipk
luci-i18n-english_trunk+svn9220-1_ar71xx.ipk
luci-lib-core_trunk+svn9220-1_ar71xx.ipk
luci-lib-ipkg_trunk+svn9220-1_ar71xx.ipk
luci-lib-lmo_trunk+svn9220-1_ar71xx.ipk
luci-lib-nixio_trunk+svn9220-1_ar71xx.ipk
luci-lib-sys_trunk+svn9220-1_ar71xx.ipk
luci-lib-web_trunk+svn9220-1_ar71xx.ipk
luci-mod-admin-core_trunk+svn9220-1_ar71xx.ipk
luci-mod-admin-full_trunk+svn9220-1_ar71xx.ipk
luci-proto-core_trunk+svn9220-1_ar71xx.ipk
luci-sgi-cgi_trunk+svn9220-1_ar71xx.ipk
luci-theme-base_trunk+svn9220-1_ar71xx.ipk
luci-theme-openwrt_trunk+svn9220-1_ar71xx.ipk
uhttpd_2013-11-21-cd66639800ee2882a0867ec54868502eb9b893d8_ar71xx.ipk

Also download tc package in case you were not able to select during compilation.

cd ~/offline-packages
scp ./*.ipk root@192.168.1.1:/tmp/offline-packages

On OpenWRT:
cd /tmp/offline-packages
opkg install ./*.ipk


If there is space issue in installing packages (/overlay is full) you will have clear configuration data first.

mtd -r erase rootfs_data

Device will reboot with factory settings, you will have to login using telnet and reset the password. But all the packages from last sys upgrade will be there.


Later packages can be installed one by one or few at a time. You are most likely to get space issues on WR740N. Enable commands are similar


References:

No comments:

Post a Comment