yuwei.net.nz | Bits of what I am doing

CAT | OpenWrt

Aria2-1.6.0 Makefile:


include $(TOPDIR)/rules.mk

PKG_NAME:=aria2
PKG_VERSION:=1.6.0
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=http://path.to/source

#PKG_MD5SUM:=c97eb0d4f36aa76448ecd660b143c467
#PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

TARGET_LDFLAGS+= \
	-Wl,-rpath-link=$(STAGING_DIR)/usr/lib \
	-static

TARGET_CXXFLAGS+= \
	-s

include $(INCLUDE_DIR)/package.mk

define Package/aria2
SECTION:=net
CATEGORY:=Network
DEFAULT:=y
TITLE:=download manager
URL:=http://aria2.sourceforge.net/
DEPENDS:=+libgnutls +zlib
endef

define Package/aria2/description
	download manager
endef

define Build/Configure
        (cd $(PKG_BUILD_DIR); \
		$(TARGET_CONFIGURE_OPTS) \
		 LDSHARED="$(TARGET_CC)" \
		 CXXFLAGS="$(TARGET_CXXFLAGS) $(TARGET_CFLAGS) $(FPIC)" \
		 LDFLAGS="$(TARGET_LDFLAGS)" \
		 UNAME_S="Linux" \
		 ./configure \
			 --with-gnutls --host=mipsel-linux --disable-nls \
			 --with-libz-prefix=$(STAGING_DIR)/usr/lib \
	 );
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
endef

define Package/aria2/install
	install -m0755 -d $(1)/usr/bin
	install -m0755 $(PKG_BUILD_DIR)/src/aria2c $(1)/usr/bin/
endef

$(eval $(call BuildPackage,aria2))

· ·

Jul/09

21

Audio on WL-500W

I bought a USB audio controller of trademe to continue add things to my WL-500W. The USB audio controller is one of those cheapest one(It cost me $6 plus $4 for postage.).  The reason I wanna add a USB audio controller to my WL-500 is that I want to use it as a mpd server for music.

The USB audio controller looks like this.

The package

The package


USB audio controller

USB audio controller

To get OpenWrt kernel to pick it up, there are some packages need to be installed

kmod-sound-core

kmod-usb-ohci

kmod-alsa

Of course, I would like to control the volume, so also

alsa-lib

alsa-utils

After install the modules and utilities, kernel recognized the audio controller. I tested it is working by using madplayer(is included in opkg repository) to play some mp3s. Of course, install mpd. That’s it. Music on.

There are some problems I found with this setup. Firstly, the USB audio controller only works when I plug in to the router directly. When I plug it to a USB hub which connect to the router, it doesn’t work. This means I only have one spear USB port left when I use this USB controller. Dmesg shows following error:

ALSA usbaudio.c:875: cannot submit datapipe for urb 0, error -89: enable CONFIG_USB_EHCI_SPLIT_ISO to play through a hub

I will look into that to find what is wrong or I just need to enable it by compiling my own kernel.

The second problem I found is that the volume control does not fully work. I uses alsamixer to control the volume. The problem is it can only turn on the volume(full/100) or turn it off(0). To cop with this, I use the volume control nob on my speaker. It is a big problem when using headset.

Another problem is that the USB controller itself just too big physically. It can only fit into the bottom USB port on the router. After plug it in, it doesn’t leave any space for the top port to be usable. Therefore, I am using a USB extension cord which solved this problem.

No tags

In last post, I use the mips compiler from buildroot to compile axel then copy it over to OpenWrt router for using. Today, I spent a little while to investigate the way to compile axel to an ipkg package.

First step is to create a directory for axel under $(TOPDIR)/package, where $(TOPDIR) is the buildroot root.

cd /path/to/trunk

mkdir package/axel

Then create a Makefile in that directory. The Makefile contains  following lines

include $(TOPDIR)/rules.mk

PKG_NAME:=axel
PKG_VERSION:=2.4
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/axel-$(PKG_VERSION)
PKG_SOURCE:=axel-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://path.to/axel-source
PKG_CAT:=zcat

include $(INCLUDE_DIR)/package.mk

define Package/axel
SECTION:=net
CATEGORY:=Network
DEFAULT:=y
TITLE:=axel
URL:=http://axel.alioth.debian.org/
endef

define Package/axel/install
install -m0755 -d $(1)/usr/bin
install -m0755 $(PKG_BUILD_DIR)/axel $(1)/usr/bin/
endef

$(eval $(call BuildPackage,axel))

This is for telling make what it is compiling, where the source code is and how it can be compiled. Remember to replace the PKG_SOURCE_URL to where your package is located.

Since axel does not use autoconf for Makefile configuration, it gets a bit hard to tell buildroot how to build it. The Makefile showed in above left out the compiling section to get buildroot to compile it by running ./configure and make. Therefore, I prepared a customized version of axel source code that uses autoconf.

Axel’s configure script not only generates the Makefile.settings which contains all the flags and arch settings, but also creates config.h file that contains the defined variables for code. Since I am only going to use axel on my openwrt router, I hardcoded the config.h file, as follow:

/* Axel settings, generated by configure */
#define _REENTRANT
#define _THREAD_SAFE
#define ETCDIR “/usr/bin”
#define LOCALE “/usr/share/locale”
#define ARCH “mipsel”

with this, we can now replace the configure script with autoconf. Configure.in file looks like this

AC_INIT(axel.c)

dnl find and test the C compiler
AC_PROG_CC
AC_LANG_C

AC_PROG_MAKE_SET

AC_HEADER_STDC
#AC_CHECK_FUNCS(gettext libpthread,,AC_MSG_ERROR(oop!))

VERSION=”2.4″
AC_SUBST(VERSION)

dnl read Makefile.in and write Makefile
AC_OUTPUT(Makefile)

I left out the dependemcy check for libintl and libpthread. If I enable it, buildroot would complain that libintl could not be found even it is installed.  Just remember to install them as well. and the Makefile.in looks like this

CC = @CC@
VERSION = @VERSION@
CFLAGS = @CFLAGS@ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Os -s
LFLAGS = -lpthread -lintl -static -L../../../staging_dir/target-mipsel_uClibc-0.9.30.1/usr/lib/libintl/lib

all: axel

axel: axel.o conf.o conn.o ftp.o http.o search.o tcp.o text.o
$(CC) *.o -o axel $(LFLAGS)

.c.o:
$(CC) -c $*.c -o $*.o -Wall $(CFLAGS)

clean:
rm -f axel *.o

distclean:
rm -f axel *.o Makefile

With these 2 file, run autoconf. Configure script will be generated. Now tar and zip your axel source folder to axel-2.4.tar.gz use the command:

cp -r /path/to/axel axel-2.4

tar zcvf axel-2.4.tar.gz axel-2.4

remember here, the folder must called axel-2.4. Otherwise, buildroot will complain that it can’t locate the source.

This is all. The next step is to build to world

cd /buildroot/directory

make package/symlink

make menuconfig          — select axel under network/net

make

Here is a version of axel I compiled. axel_2.4-1.ipkg

No tags

Jul/09

15

Crosscompile axel for OpenWrt

After the ASUS WL_500W has been setup, I had many fun playing with it. Since it has 2 USB 2.0 ports, it is a nice hardware to become my downloading machine, instead of my old 250W big box. Yep, save power bill. Usually, I downloading files from a remote server with Axel. By searching the package list from opkg, there is no sign of it. Google didn’t give much as well. So, last option, compile it myself.

Router itself is not suitable for compiling, considering the ram size and CPU speed. Therefore, cross compiling is the way to go. There are many ways to do that. I fell buildroot is the most straight forward method. Follow the link instruction, check out buildroot from svn, and compile it. We don’t really care about ‘make menuconfig’, since we only want the liberaries and compilers. However under the package directory where all the package is stored, there is no sign of gettext/libintl which is required for axel. So go back to the svn, check out gettext from branches/packages_8.09 and place it under package directory. They just type ‘make’ to compile the buildroot. This should give you all the things you need to compile axel.

Next, grab axel source from their website or svn. From openwrt’s buildroot doc, they would like you to compile the package under the packages directory with all the Makefile setup. In my case, I just want a working copy of axel, so I didn’t do that. I just compiled axel with the cross compiler from buildroot.

First of all, run ‘./confiure –i18n=0 –strip=0′ inside the axel source folder. This will disable the internationalization and binary stripping. Then edit the Makefile.setting. Replace

ARCH=Linux

to

ARCH=mipsel.

Edit LFLAGS to

LFLAGS=-static -L/path/to/buildroot/staging_dir/mipsel/usr/lib/libintl/lib -lintl -L/path/to/buildroot/staging_dir/toolchan-mipsel_gcc3.4.6/lib -lpthread

change CFLAGS to

CFLAGS=-Os -s -I/path/to/buildroot/staging_dir/toolchain-mipsel_gcc3.4.6/include -I/path/to/buildroot/staging_dir/mipsel/usr/lib/libintl/include -I/path/to/buildroot/staging_dir/mipsel/use/include

Remember the ‘-Os -s’. It helps to reduce the size of output binary. It is usually done during ‘make install’, but we are not doing that. So add it into your CFLAGS.

Next, change CC to your cross compiler

CC=/path/to/buildroot/staging_dir/toolchain-mipsel_gcc3.4.6/bin/mipsel-linux-gcc

Then, type ‘make’ to compile axel. An executable file called ‘axel’ should appear in the source directory. Copy it to your router and go nuts. For those of you don’t wanna compile it, here is a working copy I made.

No tags

Jul/09

13

Openwrt with Asus WL-500W

During the weekend, I got myself a Asus WL-500W and flashed openwrt onto it to make it more useful. This is a record of what I have done for future me.

Asus WL-500W is a 802.11n-draft wireless router. It includes 4 100mbps ehternet port, 3 wireless antennas(mimo), 1 wan port and 2x USB 2.0 ports. Under the hood, it contains a Broadcom 4704 processor running at 266MHz, 8MB flash, 32MB ram and a Broadcom 4321 mini-pci wireless card. Overall, it is a great piece of hardware to load openwrt on it.

Following are the steps to load openwrt onto it and some simple configurations.

Flash image to the router

Firstly, flashing the router with correct image over tftp. The openwrt image I were using is this. The reason to use a 2.4 kernel over 2.6 is simple, 802.11n wireless card doesn’t work stable under 2.6 kernel. Remember, don’t try to use snapshot image. The snapshot image contains a 2.4.37 kernel, whereas 8.09.1 contains a 2.4.35 kernel. Usually you may want a newer one, but the driver for broadcom card (kmod-brcm-wl-mimo) requires a 2.4.35 kernel. After download the image, tftp it onto WL-500W with these steps:

  • Set WL-500W to diag mode by pressing RESET button while plugin the power cable. The power LED should start flashing slowly.
  • Connect WL-500W to computer directly over ethernet cable from LAN1 port
  • type in following command

tftp 192.168.1.1

tftp> binary

tftp> trace

tftp> put openwrt-brcm-2.4-squashfs.trx

  • After flashing it, leave it for a while(I did for 5 minutes), then power cycle the router. DONE!

After flashed openwrt onto WL-500W, telnet to the router and set up root password with ‘passwd’.  SSH server is also up and runing, so ssh to the router and have fun.

Install wireless driver

At this point, wireless is not working. The default driver installed is kmod-brcm-wl which is for broadcom 802.11G cards. Remove me and install kmod-brcm-wl-mimo instead.

opkg update

opkg remove kmod-brcm-wl

opkg install kmod-brcm-wl-kmod

Setup Access Point with WPA2

If the wireless is used as an access point with WPA or WPA2 support, install hostapd or hostapd-mini if radius authorization is not required.

opkg install hostapd

or

opkg install hostapd-mini

The /etc/config/wireless will look like this:

config wifi-device wl0

option type broadcom

option channel 1

option disabled 0

config wifi-iface

option device wl0

option network lan

option mode ap

option ssid OpenWRT

option encryption psk

option key secretpasswor

Install USB driver and file system support

With this setup, the router should work fine. Remember? The router has 2 USB ports. To get that to work with external hard drive, install the drivers.

opkg install kmod-usb-uhci

opkg install kmod-usb2

Make it to support vfat file system, following packages need to be installed.

opkg install kmod-fs-vfat

opkg install kmod-nls-cp437

opkg install kmod-nls-iso8859-1

Reboot the router, the USB ports should be up and running. Plug in a usbkey, and mout it using the command:

mkdir /mnt/usbkey

mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/usbkey

NFS support

I also configured the router to support NFS. To do that, type in following commands.

opkg install kmod-fs-nfs

To mount the remote disk, use command:

mount host:/shared_directory /mnt/nfs_directory -o nolock

If the remote NFS server is using export, remember using nolock option. Otherwise, the mounting will taking very long time.

Problems

There are 3 problems I found with this router. First of all, 802.11n is not working. Due to the driver, the wireless card only operates as 802.11g. There is nothing I can do except waiting for the driver to arrive. The second problem is the USB ports are underpowered.  To use external hard drive, a powered USB hub will be required. The third problem is not about the router itself, it is that there is not axel package in openwrt repository. With the ability to support external hard drive, I will using the router as downloading machine, so axel is a must have application. I will see if I can compile it and use it on router.

What’s next?

I will start setting up dhcp/dns servers to replace the one is running on my linux box. I will also try to dig more on the USB port to get it to work with printer and USB audio device. Furthermore,  there are interesting projects like this and this. I would like to try out for myself.  Will keep updating to progress. Please leave comment if you have some cool ideas or you found anything I am doing wrong.



No tags

Theme Design by devolux.nh2.me