OpenWRT

OpenWRT is a wonderful piece of open source software that the community has made. It is basically the customization and molding of Linux to form a custom firmware which can run on embedded systems such as the Linksys WRT54G (from which the name came). Once loaded, the firmware allows for the execution of basically all Linux software that you can get to compile under it. This turns your cheap router into a power horse router capable of many crazy and awesome things. One thing it also does is open this router up to use as things other than a router.

WL520GU

Initially for this project we decided to use OpenWRT on a router to be the base for our platform from which we would build around. Since the WL-520GU was listed as being supported (or at least the BCM5354 chipset was), we decided to go with it. Little did we know the complications that would ensue.

Kernel 2.6 vs 2.4

A debate quickly arose as to which version of the kernel would be run on the system. The pros and cons of each were weighed. Basically what it came down to was what features each provided.

USB

One thing that we decided we needed was USB support. It did not click with me that only the 2.6 kernel would bring along USB2 support. Remembering this as to being one of the reasons I originally made the jump to 2.6 in the first place I resigned to using kernel version 2.6 on the router. An added bonus was the addition of the linux-uvc module. The module ended up being 2.6 specific but allowed for the attachment of one special usb device to the router. In our case we wanted to attach a USB webcam to be added on and used. The linux-uvc module did this in a manner which took advantage of the hardware capabilities of the cameras and placed minimal load on the server. It was not all fun and games however.
After reading the openwrt-devel mailing list and openwrt forums, it suddenly came to my attention that ehci support on the WL-520GU was not working. It ends up that ASUS lied that their device used USB2.0 and even commented the actual support out in their own firmware. After many troubling hours it was discovered that a good Samaritan by the name of sbrown committed some patches to the forums and mailing list which allowed for partial USB2.0 support. After some struggles with OpenWRT I was able to build a custom kernel which had support for both the USB and the linux-uvc driver. The battle of USB had been won…for now.

Wireless

The WL-520GU employs a Broadcom 5354 chipset on board. I had known that there was an issue, with Broadcom not open-sourcing their wl driver, which prevented most broadcom devices from using the Linux 2.6 kernel. I had read however that limited success had been made in using the B43 kernel module being developed by the broadcom guys. The reports indicated that the router had been unable to enter AP mode to act as an access point but were able to connect in STA mode and be a client to another network. Since this was exactly what we wanted to do, connect our router to UDel's wireless network, we decided to give it a try. Only after loading it and encountering numerous segmentation faults did we realize that we had over looked something. Evidently reports were floating around about the B43 driver not supporting the WL-520GU's chipset. It has something to do with the LP PHY portion of the wireless, which I assume to be a Low Power output to a PHYsical amplifier. Reports on the broadcom site showed work was in progress but was not near completion. The people on the OpenWRT IRC channel told me that “it was only a matter of time”. Time was just not something we had on our time so therefor I abandoned wireless and moved on in the hopes that one day, some dev out there would hear my cry for help and answer it. Until then, I was bound to this earth by a wire.

Conclusion

As you might have guessed by now, I decided to go with the 2.6 kernel. The webcam was just too important to give up and we wanted that webcam bad. Wireless would just have to come at another point…

Build Your Own Firmware...

…Or brick your router trying! To try and get the project rolling I decided to be a brave soul and explore the bleeding edge trunk of OpenWRT. To do this I decided to return to my favorite school server: Lazuri - a 3.2GHz Pentium 4 with 1GB of RAM running a custom build of Gentoo Linux (a personal favorite of mine). It is part of the ECE Undergraduate Lab and tends to not be used during off semesters. For this reason I decided to use it to start my experiments. To start off with I executed the following:

mkdir /lazuri/trunk
cd /lazuri/trunk
svn co https://svn.openwrt.org/openwrt/packages/

This provided me with an up to date version of OpenWRT. Excited, I quickly set out to compile a custom build. Doing what any good Linux user does best, I decided to RTFM. Although it seemed like a seemingly painless process, as with all things computers - 10 minutes turned into 10 hours and so on. The system would hang at boot, resulting it me discovering a patch to be applied in order to allow it to post. My .config may not have been optimal but it ended up getting the system to post.

So I don't forget…enable stty!

To change serial speed via stty:

stty -F /dev/ttyS0 baudRate

baudRates tested: 9600, 19200, 38400, 115200

PERL

So on a lot of my OpenWRT projects I tend to use Perl for communications with the serial port. This was just a sadistic habit I got into. The problem always seems to revolve around the process of getting perl to compile correctly. I have done it several times however each time it becomes slightly increasingly more painful due to errors. This time I promised myself I would document the process.

Packages from Source

Sometime ago I discovered that someone had already built the OpenWRT packages for Perl and a number of associated modules. These were listed on a forum post on the OpenWRT forum. After several painful hours I realized that these packages were for White Russian and not Kamikaze. Reading down further provided a new http://www.cip.ifi.lmu.de/~colberg/openwrt/packages/ to Kamikaze compatible packages. After downloading the tar-ball containing the packages and extracting them, I copied perl and libdb-compat to the package directory and began the make:

cp -r perl libdb-compat ../../package/
cd ../..
make V=99

This ran for some time but proved to result in a linking error of some sort.

mipsel-linux-uclibc-gcc  -o miniperl \
    `echo   gv.o toke.o perly.o op.o pad.o regcomp.o dump.o util.o mg.o reentr.o 
mro.o hv.o av.o perl.o run.o pp_hot.o sv.o pp.o scope.o pp_ctl.o pp_sys.o doop.o doio.o 
regexec.o utf8.o taint.o deb.o universal.o xsutils.o globals.o perlio.o perlapi.o 
numeric.o mathoms.o locale.o pp_pack.o pp_sort.o  | sed 's/ op.o / /'` 
    miniperlmain.o opmini.o -lnsl -ldl -lm -lcrypt -lutil -lc 
sv.o: In function `Perl_sv_vcatpvfn':
sv.c:(.text+0x47d4): undefined reference to `gcvt'
sv.c:(.text+0x48a0): undefined reference to `gcvt'
sv.o: In function `Perl_sv_2pv_flags':
sv.c:(.text+0x5c24): undefined reference to `gcvt'
sv.c:(.text+0x618c): undefined reference to `gcvt'
collect2: ld returned 1 exit status
make[4]: *** [miniperl] Error 1

Searching around online showed a ticket stating similar problems and simply being closed without an answer. Looking around in the actual perl directory resulted in finding the following:

grep -R gcvt *
files/config.sh-avr32-linux-uclibc.in:# Fixes perl: can't resolve symbol 'gcvt'
..
files/config.sh-mipsel-linux-uclibc.in:d_Gconvert='gcvt((x),(n),(b))'

Upon further investigation into the avr32 file the following lines were found:

# Matteo Croce, Mon, 21 Apr 2008 03:19:30 +0200
# Fixes perl: can't resolve symbol 'gcvt'
d_Gconvert='sprintf((b),"%.*g",(n),(x))'

Using this as a reference I decided to modify the mipsel file in the following manner:

#d_Gconvert='gcvt((x),(n),(b))'
d_Gconvert='sprintf((b),"%.*g",(n),(x))'

Compiling them succeed and I was greeted with a plethora of packages in the bin directory.

Device-SerialPort

In order to access the serial port the PERL device-serialport module was needed. This was available via the old White Russian builds but not in the Kamikaze builds. To compile it, a new Makefile was needed. This Makefile used the other ones for Kamikaze as a model while using the White Russian Makefile as a reference. In the end a binary was successfully compiled.

Makefile
include $(TOPDIR)/rules.mk

PKG_NAME:=perl-device-serialport
PKG_VERSION:=1.002
PKG_RELEASE:=1
PKG_MD5SUM:=aeef199bfdd2aece043649a0673146d5

PKG_SOURCE_URL:=        http://search.cpan.org/CPAN/authors/id/C/CO/COOK/
PKG_SOURCE:=    Device-SerialPort-$(PKG_VERSION).tar.gz
PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/perl/Device-SerialPort-$(PKG_VERSION)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install

include $(INCLUDE_DIR)/package.mk
include ../perl/perlmod.mk

define Package/perl-device-serialport
        SECTION:=lang
        CATEGORY:=Languages
        TITLE:=A module that enables access to the serial port
        DEPENDS:=perl
endef

define Build/Configure
        $(call perlmod/Configure,,)
endef

define Build/Compile
        $(call perlmod/Compile,,)
endef

define Package/perl-device-serialport/install
        $(call perlmod/Install,$(1),Device,SerialPort)
endef

$(eval $(call BuildPackage,perl-device-serialport))
Further Trouble

Upon executing the test script I wrote I received the following output:

Compilation failed in require at /tmp/test.pl line 1.
 at /tmp/test.pl line 1
    main::BEGIN() called at /usr/lib/perl5/5.10/Device/SerialPort.pm line 1
    eval {...} called at /usr/lib/perl5/5.10/Device/SerialPort.pm line 1
 BEGIN failed--compilation aborted at /tmp/test.pl line 1

After comparing the installation to that of one which I conducted on a Fonera, I noticed there was a directory missing in /usr/lib/perl5/5.10/auto which contained the binaries. I found them in the build directory and tar'd them up/moved them to the router. After this the program executed successfully.

Dependencies

Through much trial, error, and lots of pages wasted I finally have what I believe to be the dependencies needed for perl's serial port module to run:

  • perl
  • perlbase-autoloader
  • perlbase-base
  • perlbase-config
  • perlbase-cpan - Option to have added packages
  • perlbase-db - Optional for CPAN
  • perlbase-devel
  • perlbase-essential
  • perlbase-fcntl
  • perlbase-io
  • perlbase-perl5db - Optional for Debugging
  • perlbase-posix
  • perlbase-selectsaver
  • perlbase-symbol
  • perlbase-term
  • perlbase-tie
  • perlbase-xsloader

RouterStation

After the hardship that was the WL520GU hal0 found a more attractive base platform. While a bit more expensive (both in price and power consumption) the router's peripheral accessories were the most attractive factor. Combined with the allure of OpenWRT support, the router stations were a must get for our purposes. The install process was quite simple also…

Initial Boot Issues

The RouterStation shipped with Kamikaze Bleeding Edge (r13658). After powering up the router, an IP was received and a ssh server appeared. Initially only the LAN port closest to the WAN port provided a link, the other provided no link. Credentials were provided by UBNT on the small paper insert included with the router. The credentials were username: root, password: ubnt. 1) After connecting the following familiar prompt appeared:

BusyBox v1.11.3 (2008-12-17 13:03:27 EET) 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
KAMIKAZE (bleeding edge, r13658) -------------------
 * 10 oz Vodka       Shake well with ice and strain
 * 10 oz Triple sec  mixture into 10 shot glasses.
 * 10 oz lime juice  Salute!
---------------------------------------------------

After this the TL-WN560G was installed. Following a reboot and the editing of /etc/conf/wireless to remove the disable option, wireless came up. The WAN port continued to resist coming up until hal0 made a new custom crossover cable which for some reason worked. The WAN successfully came up and received a DHCP address.

Upgrade

The initial install came with kernel 2.6.26 onboard it. After performing an opkg update/upgrade all the packages upgraded for kernel 2.6.27. This meant a kernel upgrade was required.

RedBoot

RedBoot is a firmware bootloader included on many atheros based SoCs. It allows for firmware upgrading to be performed in the field on the product. Access to it is usually performed via telnet or serial. To access via telnet a break character should be sent to the devices IP 2) on port 9000. After this, a telnet session can be launched on the same port and redboot access is given. Serial is much easier to use however since it does not require the precise timing like telnet does. After access is obtained, a tftp server is used to upload the images to the system so that they might be written to flash.

Once in, the upgrade proceeded quite messily. First the flash was completely whipped accidently by pressing enter too soon. It was discovered that by default the router looks for the TFTP server to be at 192.168.1.42. Following discussions on the Ubiquiti forums along with the snapshots found on OpenWRTs site several attempts were made to upgrade the system. Initial trouble was run into due to a lack of documentation as to which memory locations should be used. Luckily a working boot of the 2.6 kernel was captured before the upgrade was performed and values were obtained from that. Boot failure occurred using the openwrt-ar71xx-ubnt-rs-squashfs.bin image provided. A successful boot was achieved using the openwrt-ar71xx-root.squashfs image. This however did required specific boot parameters to be passed to the kernel. How to make this permanent is still being looked into.

Command Sequence

Install:

fis init
load -r -b %{FREEMEMLO} openwrt-ar71xx-vmlinux.lzma 
fis create -r 0x80041000 -e 0x80041000 kernel
load -r -b %{FREEMEMLO} openwrt-ar71xx-root.squashfs
fis create -l 0x00F00000 rootfs 

Boot:

fis load -d -e kernel
exec -c "board=UBNT-RS"

Make Boot Permanent:

RedBoot> fconfig
Network hardware address [MAC]: 0x00:0x15:0x6D:0xC1:0x2A:0xAF
Run script at boot: true
Boot script:
.. fis load -d -e kernel
.. exec
Enter script, terminate with empty line
>> fis load -d -e kernel
>> exec -c "board=UBNT-RS"
>>
Boot script timeout (1000ms resolution): 5000
Use BOOTP for network configuration: false
Gateway IP address:
Local IP address: 192.168.1.20
Local IP address mask: 255.255.255.0
Default server IP address: 192.168.1.42
Console baud rate: 115200
GDB connection port: 9000
Force console for special debug messages: false
Network debug at boot time: false
Update RedBoot non-volatile configuration - continue (y/n)? y
... Erase from 0xbfff0000-0xc0000000: .
... Program from 0x83ff0000-0x84000000 at 0xbfff0000: .
RedBoot>

Configuration

Network

root@OpenWrt:/etc/config# cat network 
# Copyright (C) 2006 OpenWrt.org

config interface loopback
	option ifname	lo
	option proto	static
	option ipaddr	127.0.0.1
	option netmask	255.0.0.0

config interface lan
	option ifname	"eth0 eth1"
	option type 	bridge
	option proto	static
	option ipaddr	192.168.1.20
	option netmask	255.255.255.0
root@OpenWrt:/etc/config# cat firewall 
config defaults
	option syn_flood	1
	option input		ACCEPT
	option output		ACCEPT 
	option forward		REJECT

config zone
	option name		lan
	option input	ACCEPT 
	option output	ACCEPT 
	option forward	REJECT

config zone
	option name		wan
	option input	REJECT
	option output	ACCEPT 
	option forward	REJECT
	option masq		1 

config forwarding 
	option src      lan
	option dest     wan

Wireless

root@OpenWrt:/etc/config# cat wireless 
config wifi-device  wifi0
	option type     atheros
	option channel  auto

	# REMOVE THIS LINE TO ENABLE WIFI:
	option disabled 1

config wifi-iface
	option device	wifi0
	option network	lan
	option mode	ap
	option ssid	OpenWrt
	option encryption none
config wifi-device  wifi1
	option type     atheros
	option channel  auto

	# REMOVE THIS LINE TO ENABLE WIFI:
	option disabled 1

Package Installs

The RouterStation comes pre-installed with a variety of packages. These however did not suite all the needs of the project and thus extra software was needed. This is a list of packages installed and their associated dependencies required for them to run.

  • openvpn
    • liblzo
    • libopenssl
    • zlib
  • kmod-video-uvc
    • kmod-usb-core
    • kmod-video-core
  • mjpg-streaer
    • libjpeg
    • libpthread
    • librt
  • python (you have the option for python-mini)
    • libffi
  • pyserial
1) Another set of defaults to add to the password list…
2) 192.168.1.20 in the RouterStation's case
 
Back to top
projects/securouter/openwrt.txt · Last modified: 2009/01/27 22:50 by afterburn
 
 
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0