Building a Wifi Radio – Part 4, Installing OpenWrt

This is the fourth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out parts one, two, and three for some background about the project.

At this point you should have an Asus WL-520GU wireless router with a serial port header installed and some way of communicating with the serial port from your PC.  If not, go back to part three.

What is OpenWrt?

According to openwrt.org:

OpenWrt is described as a Linux distribution for embedded devices.

OpenWrt replaces the stock firmware on the WL-520GU with an open source Linux distribution that aims to be extremely powerful and flexible.  This is important for us because in turning a wireless router into a Wifi radio, we using the device in a way that the manufacturer never intended for it to be used.  In addition to including a stripped down version of the Linux operating system, drivers for wireless networking and all the basic functionality of a residential network gateway, a package manager called opkg allows you to install a wide variety of add-on modules to extend the functionality even further.

Setup:

To install OpenWrt on the WL-520GU you will need a few things:

  • Your Asus WL-520GU wireless router, modified to allow access to the internal serial port
  • A 3.3V USB-serial cable like the FTDI-232-3V3
  • A short ethernet cable (a crossover cable is not required)
  • A desktop or laptop computer with an open USB and ethernet port
  • A terminal program such as ZTerm or Hyperterminal
  • A TFTP client, (surprisingly) included with most operating systems.  I’ll be using the one included with OS X.
  • A WiFi network with a reasonably simple encryption scheme (ie. none, WEP, WPA)

If you want to compile your own OpenWrt image and optional packages, you’ll also need

  • A machine running Debian or similar Linux operating system, or if you are really ambitious, a Mac running OS X.  I won’t cover compiling OpenWrt using OS X here, but there are several issues that prevent it from being straightfoward, the first of which is that OS X does not use a case-sensitive filesystem by default.

Note: If for any reason you need to go back to the stock firmware, you can download it from Asus here (enter WL-520GU into the search field on the left).

Getting OpenWrt:

There are two ways to do this:

The hard way:

Visit the OpenWrt Wiki and read the instructions on Installation.  Follow these instructions to build Kamikaze (Kamikaze is the current OpenWrt distribution).  Download the source with subversion (svn), and compile it yourself.  This method requires a moderate level of skill with Linux, but if you can compile your own kernel you should be able to compile OpenWrt.  You will need to link to the feeds for madplay, mpc, and mpd (as well as any other 3rd party packages you want) before executing make menuconfig, by using the scripts/feeds command.  Here is the sequence of commands I used, yours may differ slightly:

svn co https://svn.openwrt.org/openwrt/trunk/ ~/kamikaze
cd ~/kamikaze
./scripts/feeds update -a
./scripts/feeds install madplay mpc mpd
make prereq

If make fails, you may need to install some optional Linux tools, such as gawk, bison, or gcc.  On Debian I used the apt-get command to do this

apt-get install gawk bison gcc

Once you have all necessary prerequisites installed, you can configure the build with

make menuconfig

You’ll need to set the following options:

  • Target System (Broadcom BCM947xx/953xx [2.4])
  • Target Profile (Generic, Broadcom WiFi (default))
  • Select all packages by default
  • Image configuration —>
    • Base system (Added 12/18/08 to support part six)
      • busybox (press enter to open hidden menu)
        • Configuration
          • Coreutils
            • stty
    • Kernel modules
      • Sound support
        • kmod-sound-core
      • USB support
        • kmod-usb-core
        • kmod-usb-ohci
        • kmod-usb-audio
    • Sound
      • mpd
      • mpc
      • madplay

Once you’re done, exit, saving the configuration.  Then execute

make world

This will take quite a while.  If the build fails, you will be prompted to run make again

make world V=99

and fix any problems that occur, based on the error messages.  The OpenWrt forums are a good place to get help, but do a quick search before you post to avoid asking a question that has already been answered.

If the build completes successfully, you should be left with a bunch of files in the kamikaze/bin directory, including openwrt-brcm-2.4-squashfs.trx, the main image file, and a bunch of packages in the bin/packages/mipsel directory.

The easy way:

I’ve already done the hard work for you.

Download my precompiled openwrt-brcm-2.4-squashfs.trx image.

Addon packages (you’ll need a few of these when we configure the router later) are located here.

Installing OpenWrt:

Connect your FTDI cable to the serial port on the router that you added in part three.  Launch your favorite terminal program and connect to the router at 115200 baud, 8N1.

Connect the LAN1 port of the router to your computer using a short ethernet cable.  The router is hardcoded to be 192.168.1.1 on boot, and we need to configure our computer to talk to that address.  I set my Macbook to use a static IP of 192.168.1.185.  You may need to set a gateway to 192.168.1.1.  If your home network is also on the 192.168.1.x subnet, you will need to disconnect/disable it.  On my Macbook, this meant disabling the internal wireless and losing internet access while the router was connected.  (Eventually I got tired of this and moved my home network to 192.168.24.x, but that is outside the scope of this tutorial.)

Press and hold the Restore button on the back of the router and plug in the power cable.  The Restore button is shown just to the right of the red EZSetup button here:

WL-520GU Restore Button Closeup

Continue holding the Restore button until the power LED starts flashing once a second.  Release the restore button.  In your terminal window, you should see some boot messages and then

Reading :: TFTP Server.
Failed.: Timeout occured
Reading :: TFTP Server.
Failed.: Timeout occured

and so on (the messages will repeat forever).

Now it’s time to transfer our .trx file to the router.  These instructions are for OS X.  Instructions for other operating systems are here.

cd ~/kamikaze/bin
tftp
trace
timeout 1
mode binary
connect 192.168.1.1
put openwrt-brcm-2.4-squashfs.trx

On the serial console you should see (exact numbers may vary):

Reading :: TFTP Server.
TFTP_BLKLEN!!
break!! last block!!
Done. 1918724 bytes read
Download of 0x1d4704 bytes completed
Write kernel and filesystem binary to FLASH (0xbfc20000)
Programming...
copysize=1918724, amtcopy=1918724

If you don’t see this, chances are your computer is not talking to the router.  Most likely this is a configuration problem with your ethernet port or you don’t have the cable connected to a LAN port of the router.

If it worked, wait a couple minutes (don’t touch anything, unplugging the router at this point could brick the router!)  Eventually you should see the message

done. 1918724 bytes written

After this message appears (it typically takes 3-5 minutes for the whole process) unplug the router, wait a few seconds, and then plug it back in again.  In your serial terminal window, you should see the Linux boot messages again, but the process will pause briefly while the jffs file system is created.  Once the router has finished booting, you’ll see a couple messages like this

mini_fo: using base directory: /
mini_fo: using storage directory: /jffs

Press enter and you should now see the OpenWrt banner and a shell prompt

BusyBox v1.11.2 (2008-10-02 20:59:06 PDT) 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, r12831) -------------------
  * 10 oz Vodka       Shake well with ice and strain
  * 10 oz Triple sec  mixture into 10 shot glasses.
  * 10 oz lime juice  Salute!
 ---------------------------------------------------
root@OpenWrt:/#

Congratulations!  You have successfully installed OpenWrt!

A complete log of the first boot is available here.

Configuring OpenWRT:

There is a lot of information on the OpenWRT Wiki with regard to Configuring Kamikaze, but I will walk through the fairly basic configuration I am using here.  To follow along, you will need to be comfortable using vi (if not, check out this quick reference card.)

You should be able to use your serial terminal to execute the following commands.  I had issues using the arrow keys to navigate in vi and had to use the basic movement keys instead (h=left, l=right, k=up, j=down).

Before we can get the router on a WiFi network we need to modify a couple files.

root@OpenWrt:~# vi /etc/config/wireless

You should edit this file to look like this (changes are in bold)

config wifi-device  wl0
	option type     broadcom
	option channel  2  # the channel your wireless network is on

	# REMOVE THIS LINE TO ENABLE WIFI:
	# option disabled 1 (comment out or remove this line entirely)

config wifi-iface
	option device   wl0
	option network	lan
	option mode     sta  # configures the router to connect to your network
	option ssid     MyNetwork # the SSID of your network
	option encryption wep  # the encryption mode of your network
	option key	XXXXXXXXXX  # add this line with your WEP key in place of X...X

Now we need to modify the networking configuration to use DHCP (this should apply for most people):

root@OpenWrt:~# vi /etc/config/network

Scroll down and look for the LAN configuration section, and edit it to look like this (note the dhcp option in bold, also comment out the last two lines as shown):

#### LAN configuration
config interface lan
      option type     bridge
      option ifname   "eth0.0"
      option proto    dhcp
      #option ipaddr   192.168.1.1
      #option netmask  255.255.255.0

Lastly, verify that resolv.conf is set correctly.

root@OpenWrt:~# vi /etc/resolv.conf

You should see the following line (this assumes the router will get a valid DNS server address via DHCP, if not, you can set it manually here):

nameserver 127.0.0.1

Then execute the following command:

root@OpenWrt:/# /etc/init.d/network restart

After a moment, if everything is working, the AIR light on the router should turn on and you should be able to ping some servers by name.

root@OpenWrt:/# ping www.google.com
PING www.google.com (74.125.19.104): 56 data bytes
64 bytes from 74.125.19.104: seq=0 ttl=240 time=20.113 ms

If you made it this far, congratulations!  You now have a working embedded Linux device on your WiFi network!

That concludes part four of this series.  In part five, I’ll cover installing addon packages using opkg.  If we’re lucky, we’ll get the router to play some tunes!

Update: Part five is now available.

Update 2: There is a new Wifi Radio Discussion Forum, hop over there to ask questions about the project or see what other people are working on!  (4/12/09)

49 thoughts on “Building a Wifi Radio – Part 4, Installing OpenWrt”

  1. HELP!
    Where are you getting the file referenced in this part of the Windows instructions?

    In the other window, prepare the tftp command “tftp -i 192.168.1.1 PUT OpenWrt-gs-code.bin”. Do not press enter yet!

    All I have is a trx file my system doesn’t know what to do with

  2. Carlos –

    There shouldn’t be any password on the serial console.

    I would try reinstalling and see if you still have the issue.

  3. Hi:
    I followed your instructions and installed your firmware image, and all that worked fine. But now I can’t log into my router because apparently the root password is changed and I don’t know what it is… Can you tell me or give me any advice?

  4. I managed to get open-wrt talking to my dd-wrt router over WPA2 without installing additional packages. If I have a chance tonight I’ll post my setttings. I could be wrong, because I did mess with nas a bit, but it doesn’t appear to be running after rebooting.

  5. Just for anyone who is wondering, if your network name has spaces in it i believe you can write the name like this:

    option ssid ‘My Network’ # the SSID of your network

    Also, only WEP and unencrypted connections seem to work (WPA is not supported but you can apparently download something that can fix that)

  6. The WL-330* hasn’t been added to the OpenWrt supported devices list yet so you’re in uncharted waters!

    http://wiki.openwrt.org/Hardware/Asus

    I would search the OpenWrt forums to see if anyone has started playing with that router yet. Without access to the serial port you are working blind which will make reflashing much more difficult. Before trying to reflash with the images here, I would try to get access to the serial port so you can see the stock firmware’s boot log and compare it with one for the WL-520 (posted in part 3).

    In general, I don’t recommend trying to flash routers that are not on the OpenWrt supported hardware list (unless you are looking for a challenge.) I would not have chosen the WL-520gU for this project if it wasn’t on the list, and in fact I started with the WL-500gpV2 because it had more success reports, then moved to the 520 when I felt more comfortable with OpenWrt.

  7. Hi to All,
    I try to reprogram my new ASUS WL-330gE with OpenWrt, as I read and I can see all CPU and RAM configuration of router is the same. I really need to reprogram this router because I whant to use it for my RS232 embeded robotic project.

    Do you think that the same kernel can be used for WL-330gE?

    Thank you again!

  8. I have tried 2 usb hubs and 2 different usb sound adapters, with no luck. Although they work well when attached directly to the router or via a usb 1.1 hub.

    According to this:

    http://wiki.openwrt.org/UsbAudioHowto
    (section 3:devices)

    A kernel option CONFIG_USB_EHCI_SPLIT_ISO is needed to be enabled for usb audio attached to usb 2.0 hub. But where do I set this? I put it in .config but appears no effect.

    Thanks.

    DM

  9. Jeff,

    I was wrong. USB audio works in 2.4 kernel. I have added usb storage support and let mpd play from an attached hard drive. It is my nice low-power low-cost jukebox!

    However, it seems that if you attach the usb sound adapter to a usb 2.0 hub then to the router, it won’t work. I am now using a usb 1.2 hub.

    DM

  10. I tried both 7.09 and the snapsort image. However, the performance of the wireless connection is not that good. iperf shows that the network throughput is bounded by 10 Mbps for UDP traffic. Any solution ? Thx

  11. I noticed that too – ssh fixes the terminal settings. I didn’t have the patience to figure out why – it just works. Now that you have ssh running you can actually scp files onto/off the router from another system – handy for backing up your config files if nothing else.

  12. Basically, GTKTerm is a really bare bones terminal. VI and it don’t get along. Shades once again of Xenix and incompatible termcap, or the grand question, “What really is VT-100 emulation and why do I have to rewrite the termcap for the Wyse-60?”

    Once I got SSH access (set root password), VI became usable for editing with the Putty SSH Terminal.

  13. OpenWRT installed.

    I’m remembering why I don’t like VI(LE).

    Got the lan networking functional and doing DHCP, will wait on the wireless as when I open the wireless config file, it doesn’t display anything; despite the fact that cat’ting on the command prompt shows a complete file. Xenixoid memories there, heh.

  14. Stephen –

    Good point about the TTL levels. There are a few different ways to convert RS-232 to TTL (Maxim has a couple chips that will do it) but the FTDI USB cable is one of the easiest ways and it can be reused for other projects.

    I’ll add a note cautioning others that they need an adapter, sorry you ran into so much frustration!

    Jeff

  15. One piece of knowledge that I missed (since I’m a little new to this) was that serial TTL is not the same as RS-232. In case anyone is thinking about cutting up an old DB-9 cable, soldering the wires directly to the router’s TTL interface, and trying to talk to it from your PC, I can save you a few hours of frustration by telling you in advance that it won’t work. In fact, you can actually damage your board with the higher voltage (hoping I haven’t damaged mine yet).

    On another note, I’m planning to get sshfs running on mine so I can mount a remote filesystem to use as mpd’s music directory. I think that should work, and would solve the problem of not having any space for music. It would be sweet to connect it to a NAS device.

  16. For those that run into errors when running “make world”, I was able to get through the entire process by unselecting these modules:

    “kmod-p54-*”, “kmod-net-prism54” under kernelmodules-wirelessdrivers
    “kmod-libertas” under kernelmodules-othermodules

    hope that helps…

  17. I’m using 2.4, and USB audio works great! There is some experimental support for Broadcom wireless in the 2.6 kernel, but I haven’t had a chance to test it out.

  18. Jeff,

    Which Linux kernel are you using? I thought USB audio does not work on 2.4 kernel and Broadcom wireless does not work on 2.6 kernel.

    DM

  19. @Brian: thanks for the ‘psk’ tip, it save me a great deal of time digging through the openwrt wiki/forums.

  20. I am still gathering parts, and intestinal fortitude, but I am getting impatient for part 5. With a project this high on the Awesome scale, you make it hard to wait.

  21. Great news- I got mine through part 4 tonight. Started working on it last night as time permitted and as far as soldering in that connector goes, I really dislike what must be lead free solder they used. It took way too much effort even with a nice Metcal soldering iron.

    The wireless configuration took a little more effort and good old fashioned RTFM work to find the right magic spells to cast. The main sticking point was in the encryption used on my wireless network. The precise words used by my router (WPA Personal, TKIP) didn’t match the precise words used by the openwrt documentation I could track down. Setting encryption mode to ‘psk’ in /etc/config/wireless did the trick. Everything else is just as Jeff described.

    Also looking forward to part 5.

    Brian

  22. Thanks for the positive feedback guys. I am really happy to see other people using this information. I feel like this router is totally underrated – for the price, nothing else comes even close. And the WL-500gP v2 is great too if you need USB 2.0, and you can use the exact same OpenWrt images on both routers (I have tested it on both).

  23. hey Jeff!

    I too am building a music player with this config as you go along. I had started using my old Xbox as the machine, but this is MUCH quieter and simpler, and you’ve inspired me to go this route instead.

    Thanks! Look forward to part 5!
    Durin

  24. @Jeff: thanks for the great series of posts.

    My SYBA SD-CM-UAUD arrived last week and the wl-520gu arrived today. I managed to get it on rebate and the low cost of the whole project still makes me grin. That, and I love the feeling of unboxing something and disassembling it right away.

    Keep up the great work! I’m looking forward to the rest of the series.

Leave a Reply