Building a Wifi Radio – Part 4, Installing OpenWrt

November 3rd, 2008 by Jeff

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)

Tags: , , , , , ,

49 Responses to “Building a Wifi Radio – Part 4, Installing OpenWrt”

  1. Jeff says:

    You need tftp. I believe Windows XP comes with tftp according to this:
    http://wiki.openwrt.org/OpenWrtDocs/Installing/TFTP

  2. Cameron says:

    Just in case anyone else runs into this problem:
    If you are using an ASCII WEP key instead of hex, you need to put s: before it in the config file.

  3. Marcin says:

    To Carlos:
    After reflashing you need to telnet to router for the first session (telnet 192.168.1.1)

  4. David Nichols says:

    Jeff

    Thanks so much for your docs here – with a little help from the OpenWRT wiki, in particular the note that the firewall needs to be turned off in order to bridge ethernet traffic, I am jamming with an OpenWRT wireless bridge and about to get the serial port rocking. Tthis is awesome!

    David

  5. Derrick says:

    I have everything working wired. I cannot get the wireless light to come on. HELP!!! My wireless router is WGR614 using wep with 128 bit enc. I am also using SSH to configure ASUS WL-520gu. The xxxxxxx’s are replaced with my real key. This is a great project. Thanks

    config wifi-device wl0
    option type broadcom
    option channel 11

    # REMOVE THIS LINE TO ENABLE WIFI:

    config wifi-iface
    option device wl0
    option network lan
    option mode sta
    option ssid Thnig_Pad
    option encryption wep
    option key xxxxxxxxxxxxxxxx

  6. Derrick says:

    I fixed the problem. The option ssid was wrong. This is great.

  7. Jeff says:

    David – Thanks!

    Derrick – Glad you got it figured out!

    I created a forum for this project over at http://mightyohm.com/forum/viewforum.php?f=2

    If you have any other questions, try asking over there – I’m hoping the forums help me answer questions more efficiently (and help other people answer your questions too!).

  8. IrrKlang_704 says:

    Hi all,
    I will show you how to load the openWrt firmware using windows XP. First of all turn off your windows firewall from control panel and then turnoff the antivirus and its firewall. Now set your router in recovery mode by pressing RESTORE button and turn on the router, the power LED will blink once a second to show this. now select the firmware restoration application provided in cd or download from the asus website.
    Put the firmware path in it and then click Upload, wait for sometime and then its done!!
    Enjoy XP users

  9. IrrKlang_704 says:

    The second issue im facing is before configuring router i was able to telnet via PUTTY into my router. After configuring the router im not able to telnet.
    Also the AIR light on my router turned on but it is fade not fully lit.

    I have ultimately configured my router on no encryption and i am able to ping some servers but when ping the responce

    root@OpenWrt:/# ping http://www.google.com
    PING http://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
    64 bytes from 74.125.19.104: seq=1 ttl=240 time=20.313 ms
    64 bytes from 74.125.19.104: seq=2 ttl=240 time=20.122 ms
    64 bytes from 74.125.19.104: seq=3 ttl=240 time=20.123 ms
    64 bytes from 74.125.19.104: seq=4 ttl=240 time=20.112 ms
    64 bytes from 74.125.19.104: seq=5 ttl=240 time=20.133 ms
    .
    .
    .
    never ends is there any idea??? is it normal???

    i am eagerly waiting for reply

    • Jeff says:

      Once you set a password on the router (using the passwd command) you will no longer be able to telnet into the router, you will have to use ssh with PuTTY or another program.

      The dim AIR light is normal.

      It is normal for ping to repeat forever. If you press Ctrl-C it should end the command.

      For more help try posting on the forums at:
      http://mightyohm.com/forum/viewforum.php?f=2

      It is much easier for me to answer questions there, and other members of the forums can help as well.

      Good luck.

  10. Jason says:

    I’m using WPA2-personal as my encryption how do I use it with my password?

  11. […] to replace my previous Netgear router that (ahem) happened to blow up one day. Thanks to Jeff at mightyOhm, I was able to get OpenWrt up and running on it right quick. I’m using his kernel image for […]

  12. bbf says:

    Is there an option to configure it to use LAN instead of WiFi? I have a WL500W with buggy wifi card. two lan ports and wan is OK, system boots and works ok, only without wifi inserted.

    • Jeff says:

      Yes.

      Just disable the wireless interface in /etc/config/wireless and set up /etc/config/network according to your needs.

      I’m pretty sure the WAN port comes set up to do what you want, try just plugging it in to your network and see what happens. The changes should be pretty minor if you need to make any.

      You might need to check the firewall configuration, the assignment of ports to wan/lan, bridging, etc, but it should not be much work.

      All of the documentation you need should be available at openwrt.org.

      • bbf says:

        aahhh! all went well, i used your distro on WL500W, works like a dream, now i just have to wait for the CM119 (or 108, whatever it will be) to show up in my mailbox :)
        so far i get to: “No audio_output specified and unable to detect a default audio output device”..
        Wireless part is not set up, since the card is missing and also etc/config/wireless file is empty, so i guess it is dissabled that way.
        the router works great, it’s a little tricky to set it up since no web server, but for a basic network it is just fine! actualy i didn’t do any editing in etc/config/network, and it works as i type :)
        Flashing was done in a minute (for 1,9 meg file).

        Thanks for all the info and keep a good work!

  13. Jamie Reid says:

    Hi Jeff,

    Owe you many thanks, this excellent tutorial inspired me to create a wifi-controlled relay using a 520gu and a phidgets relayboard (http://www.phidgets.com/products.php?category=9&product_id=1014).

    The phidgets board is extremely pricey for what it is but after examining the cost of printing my own PCB, it didn’t seem that outrageous for a one-off. I had also intended to leverage the API, which has packages on openwrt…

    Unfortunately, their API never built right and I ended up writing my own code with libusb…. but that’s another story.

    • Jeff says:

      Jamie,

      Cool!

      If you share your libusb code, please post a link here or on the forums. There are almost certainly others who would like to use the phidgets relay boards with OpenWrt.

  14. […] to replace my previous Netgear router that (ahem) happened to blow up one day. Thanks to Jeff at mightyOhm, I was able to get OpenWrt up and running on it right quick. I’m using his kernel image for […]


www.flickr.com
mightyohm More of mightyohm

%d bloggers like this: