Go to The University of Queensland Homepage
Takes you back to the ITEE Homepage You are at the ITEE site

 Getting OpenWRT going on the D-Link DSL-502T
by Chris Pascoe

The D-Link DSL-502T is a single-port ADSL2/2+ modem/router that is rather ubuiquitous in Australia. They can be found rather cheaply at online auction sites, mostly due to a large number of ISPs supplying them as their entry level modem.

The DSL-502T has a TI AR7 CPU, runs Linux and has 4MB of flash and 16MB of RAM. Because the core components have source released under the GPL, it is possible to run other firmware on the device.

Unfortunately there are a number of bugs in the default firmware for the DSL-502T that make it less than reliable in my environment - in particular, static routes were not reconfigured after reboot, the inbuilt DNS relay occasionally answers with the wrong cached address, and the modem drops out for no apparent reason in the middle of the night. I tried to have these issues resolved by the vendor, however they cannot be replicated despite me experiencing them at half a dozen sites.

OpenWRT, Come on down!

As I started a hunt for other simple modems that I could substitute, I delved into Whirlpool's DSL Hardware Forum. In there I read a lot of discussion that, frankly, turned me off practically all of the modems currently on the market. Amongst the noise, I wandered across a discussion about alternate firmware for the Linksys AG241 where this alternate router software distribution called OpenWRT was mentioned.

Delving further, I found that the AG241 has the same TI AR7 chip as the DSL-502T and furthermore that "Z3r0" has written an excellent guide entry in the OpenWRT Wiki on how to go about getting a stock OpenWRT image to boot on a DSL-502T.

Unfortunately though, due to the nature of the OpenWRT project and the fact that AR7 support is currently experimental, things were a bit finicky and you have to tinker with the boot loader configuration to get code onto the device. Furthermore, the current OpenWRT code only supports ADSL1 on the AR7.

My Goal

I wanted to avoid these caveats with OpenWRT and produce a working image that could be easily flashed onto the device (without having to tinker with the bootloader configuration), and to have the system protected enough that the user will always be able to return back to the original D-Link firmware. I also wanted to use ADSL2 on my device!

I have achieved this goal by:

  1. Updating the bootloader to record the size of the compressed kernel;
  2. Updating the flash maps to:
    • write protect the ADAM2 bootloader and its configuration space,
    • accomodate the vendor's signature at the start of the file,
    • dynamically locate the SquashFS filesystem after the end of the compressed kernel, and
    • provide a MTD map that a vendor image can be flashed directly to return to the original firmware;
  3. Importing the ADSL2/2+ support from the ACorp GPL release and porting it to the OpenWRT 2.4.37 kernel:
    • This provides the "DSP 7.01" API (if you've heard about all the different versions).
    • My almost-daily ADSL2+ connection dropouts are now a thing of the past!
  4. Implementing code to permit in-memory (only) environment changes (for setting ADSL parameters, etc), so that if you change a parameter and it has an unintended side-effect, a reboot will undo the change;
    • To change an ADAM2 environment setting until the next boot:
          echo "var value" > /proc/ticfg/env_local
    • Note that you will need to manually rmmod/insmod the 'tiatm' module for any ADSL related changes you make to take effect.
    • If you want to make environment changes "persistent", you can create a script /etc/rc.d/S01_adam2_env" to set the desired values for you at each boot, or use the FTP interface to ADAM2 to set them in the prom.
    • Introducing rules to generate images in a format that the genuine D-Link firmware will perform upgrades from.

Known caveats

There are no flashing lights on the device to show that it is running OK, nor to indicate the flow of packets (there is a light to indicate DSL sync, however).

There is no web interface (in the default install) that you can configure the modem, so you'll need to have some knowledge of Linux networking should you want to do anything fancy.

Before continuing, note:

  • This code has only been tested on Australian DSL-502T devices with hardware revision A5 (Generation I).
  • As with all firmware upgrades, there is a chance that your modem will die during the process. You should make sure that you have at hand the latest .EXE firmware upgrade file available from D-Link's DSL-502T firmware page. You should also download the READ ME - How to Recover Router file and familiarise yourself with the process it describes. It might even be worth doing a recovery-mode flash to ensure that the process works on your router.
  • Your modem needs to be running v2 firmware before. If it is not, you should upgrade with the firmware from the link in the previous item before proceeding. There is also a document READ ME - ADSL2(+) Firmware.txt that details the risks involved with and procedure to upgrade to an ADSL2+ image.

Getting it going - for the extremely savvy

If you're already savvy with OpenWRT, you can fetch a patch that implements the changes described above. Apply it in the root directory of a clean checkout of OpenWRT with the -p0 option to patch. Select the appropriate OpenWRT options, kick off the build, and you should be rewarded with an OpenWRT image for the device in your bin/ directory.

Note that if you intend to use PPPoE, you may also want to apply this patch for PPPoE, that tries to avoid some crashes that occur (sometimes) when PPPoE interfaces are started/shut down.

Getting it going - for the moderately lazy ;)

I have put together a script that runs through the steps in Z3r0's "How to get OpenWRT onto the router" guide. Fetch this bootstrap script, run it in an empty directory on your machine with 1.5GB of free space. The script will download the patches and a clean OpenWRT tree, and you will be put into the configuration tool where you can select other packages that you want to add - though I've already selected sufficient packages to do PPPoE/PPPoA connections, Dynamic DNS updates, UPNP, DNS, DHCP. Once that's done, a make -C trunk will cause a flashable image to be created as trunk/bin/DLinkAU_DSL-502T_openwrt-2.4-squashfs.img.

Getting it going - for the super super lazy :D

Here's a precompiled, ready to install image. It's what you'd get from running the bootstrap script, above.

Flashing your device - the first time

Once you have successfully generated the image, you can say good-bye to the D-Link firmware and hello to OpenWRT simply by uploading it to the device via its web interface (in Tools/Firmware). The modem will proceed through its normal flash process and then restart.

About two minutes after the flash process completes, you should be able to renew the IP address on your PC and you will get an address from the modem in the range 192.168.1.100-192.168.1.150. Note that the modem will not come up on its default IP address (192.168.1.1) if it detects another DHCP server on the network. If you have another DHCP server running, you will need to either temporarily disable it or try connecting the modem to your PC directly via Ethernet (bypassing any other network devices) and then power cycle it.

Configuration steps

  1. Set the root password:
    • Telnet to the router.
          telnet 192.168.1.1
    • Set a password.
          passwd
    • Log out.
          exit
    • The modem will disable telnet connections and will start accepting connections via ssh within a few minutes.

  2. Configure PPPoA/PPPoE via a template:
    • Fetch this PPP configuration template
    • Open it with a text editor, and edit the "ISP specific settings" up the top. You probably only need to set the username and password if you are an Australian user.
    • Reconnect to the router, now using SSH and the password you set in step 1.
          ssh root@192.168.1.1
    • Paste the contents of your modified template file into your terminal window. You should see the router execute the commands without any errors. Keep the terminal session open.

  3. Configure Dynamic DNS via a template:
    • If you don't to perform Dynamic DNS updates, rename the default configuration file out of the way, and then skip the rest of the Dynamic DNS steps.
          mv /etc/ez-ipupdate.conf /etc/ez-ipupdate.conf.disabled
    • Fetch this ez-ipupdate configuration template
    • Open it with a text editor, and edit the "Dynamic DNS provider specific settings" up the top, filling them out with the values your provider needs.
    • Paste the contents of your modified template file into your terminal window. Once again, you should see the commands activate without any errors. Again, keep the terminal session open.

  4. Reboot the router to activate your changes:
    • In your open window,
          reboot

Backing up and restoring your configuration changes

OpenWRT saves your filesystem (effectively, configuration) changes in a JFFS filesystem mounted at /jffs. As this filesystem is dynamically sized based upon the size of your kernel and SquashFS, uploading a new firmware image may cause your configuration to be lost.

You can back your changes up to a file on your local machine via ssh:
    ssh root@192.168.1.1 tar cf - /jffs/ > dsl502t-backup.tar

To restore a saved configuration, we reverse the direction of the transfer. The following command checks the configuration copied properly before deleting the old configuration:
    ssh root@192.168.1.1 'cat > /tmp/.r.$$ && tar tf /tmp/.r.$$ && cd / && rm -rf jffs/* && tar xf /tmp/.r.$$' < dsl502t-backup.tar

I recommend rebooting immediately after performing a configuration restore.

Subsequent device flash updates

Once you have OpenWRT running on your modem, you can update your system image or return to a vendor image by reflashing the "DSL-502T Single Image" mtd device.

  1. First copy the new image to the modem. The image you install should be either a DSL-502T OpenWRT/squashfs image (from your trunk/bin directory) or a D-Link singleimage_kernel_fs WEB file.
        scp trunk/bin/DLinkAU_DSL-502T_openwrt-2.4-squashfs.img root@192.168.1.1:/tmp/newimg
  2. Check that there were no errors reported during the image copy.
  3. Write the image into the Flash ROM. The modem will reboot automatically when the write is complete to activate the new image.
        mtd -r write /tmp/newimg "DSL-502T Single Image"
  4. Dependent on whether the changes that you made resized the image over a flash sector boundary, you may find that the device has returned to defaults and you will need to restore a configuration backup after the reboots.

Links