OpenWrt  [OpenWrtDocs] [TitleIndex] [WordIndex]

OpenWrtDocs/Hardware/D-Link/DSL-502T

Work in Progress

Porting OpenWrt to the DSL-502T is a work in progress.

This page is mostly current as at r14165 (24 Jan 2009)

Related models

I have a 504T, it's the same as the 502T but doesn't have the USB port and it has 4 ethernet 10/100 ports -- war3333

I have a 562T, it's the same as the 502T but for Annex B (ISDN) instead of Annex A (POTS). I am running Kamikaze r10180 without any problems. -- DominikKubla

The 524T is reportedly similar to the 504T: no USB, 4 ethernet ports, Annex A.

Specifications

How to get OpenWRT onto the router:

Preamble/Disclaimer

It's possible (but unlikely) that you will 'brick' the router (e.g. if you manage to delete the bootloader or config space) such that it can't be booted at all. This needs a JTAG cable to recover from. They are around US$20 from eBay.

In most other situations, the worst that will happen is that you will have to power-cycle the router and flash known good firmware onto the router to recover it.

Get the source code

Warning! over 2GB space needed to complete install

The sourcecode is held in a subversion repository and is updated continuously. Install the subversion package (e.g. using the synaptic package manager on ubuntu). To get the latest trunk code:

$ svn co https://svn.openwrt.org/openwrt/trunk

To get a specific revision:

$ svn -r6250 co https://svn.openwrt.org/openwrt/trunk

To update an existing checkout to the latest version (only the changes are downloaded):

$ svn update

Apply useful patches that aren't in subversion yet

These are patches that have tickets open but haven't made it into the subversion tree yet:

In general they can be applied by downloading and saving the "original version" of the patchfile attached to the ticket, then "cd openwrt/trunk; patch -p0 <name-of-patch-file"

Retrieve optional extra packages

$ cd openwrt/trunk
$ scripts/feeds update packages luci   # update the "packages" and "luci" feeds, see feeds.conf.default
$ scripts/feeds install -a             # 'install' all available packages. (This just makes them available for configuration later)

Install prerequisites for compiling

For Ubuntu grab 'build-essential' 'gawk' 'flex' 'bison' 'autoconf' 'zlib1g-dev' 'libncurses5-dev', 'automake', 'g++' i.e

$ sudo apt-get install build-essential gawk flex bison autoconf zlib1g-dev libncurses5-dev automake g++

For Debian:

At the time of writing (30/12/2007), Debian 'stable' has gcc-4.1 which breaks during the make process. There are no backports for gcc-4.2, but 'testing' has gcc-4.2, which may require you to cross-grade. [BD]

Select firmware components

Run:

$ make menuconfig

Select at least:

Plus any extra packages you desire (don't go overboard, there's not much space on these devices)

Quit and save the config.

Run 'make' to download essential packages (approximately 100MByte, this is an extreme under estimate, I run out of space after having more than 600MB of free space) and compile the firmware. Go and get a coffee. Maybe a second coffee too.

The final firmware produced by the build is located in bin/openwrt-ar7-squashfs.bin.

Flash the new firmware

$ scripts/flashing/adam2flash-502T.pl 192.168.1.1 -setmtd1 bin/openwrt-ar7-squashfs.bin
Looking for device: ..... found!
ADAM2 version 0.22.2 at 192.168.1.1 (192.168.1.1)
Firmware type: OpenWRT (little-endian)
logging into ADAM2 bootloader.. ok.
checking hardware.. AR7RD / DSL-502T.
checking MTD settings.. ok.
Firmware size: 0x00280004
Available flash space: 0x003e0000
Preparing to flash.. ok.
Erasing flash and establishing data connection (this may take a while): ok.
Writing firmware: ... (lots more dots) ... done.
Rebooting device.

You can also use adam2flash-502T.pl to restore the original D-Link firmware if needed - it recognizes D-Link firmware and adjusts MTD settings accordingly.

The flashing process can be a bit flaky. It will often hang halfway through the firmware transfer; if that happens, power the router off and try again. It seems to help if you do not have other network traffic present while doing the firmware transfer (DNS lookups, etc)

Manually flashing the firmware

This is basically just a case of doing what adam2flash does yourself, manually. See ADAM2 for more information. adam2flash-502T.pl has a large comment at the top explaining the expected MTD layout. The process is essentially:

Checking that it worked

The router will go through three states while rebooting:

  1. "status" off - bootloader running
  2. "status" flashing rapidly - image loaded OK, kernel booted, OpenWrt initializing

    • "ADSL" should start flashing as the DSL line is brought up
  3. "status" pulsing in a heartbeat (pulse pulse - pause - pulse pulse - pause) - OpenWrt completed booting, normal operation

Some time after rebooting, you should be able to ping and telnet to 192.168.1.1. Note that the first reboot is often slower than normal as there is some one-off initialization that is done on the first boot.

You can reconfigure your PC for DHCP if you like, you should be given an IP in the 192.168.1.x range.

Password protect the router

Get a ssh client such as openssh (probably installed by default on your build system). Under Windows, try PuTTY.

Telnet to the router and type 'passwd' to set a password. Now telnet will be disabled, and you should log back in over ssh.

Configure the front-panel LEDs

You can configure the spare LEDs ("ethernet" / "usb") to display network activity. Edit /etc/config/system and add something like this:

config led
        option name ethernet
        option sysfs ethernet
        option trigger netdev
        option mode 'link tx rx'
        option dev eth0
        
config led
        option name usb
        option sysfs usb
        option trigger netdev
        option mode 'link tx rx'
        option dev ppp0

This maps the "Ethernet" LED to ethernet traffic, and the "USB" LED to ADSL/PPP traffic.

Then run /etc/init.d/led start (or reboot the device) to reload the configuration.

Enabling ADSL

Set up modulation

This usually works without needing anything changed. That said ..

Current firmware supports both ADSL1 (G.DMT, G.lite, T.1413, Multi-Mode) and ADSL2+.

The modulation can be changed via the adam2 prompt: "SETENV modulation,GDMT" or T1413/GLITE/MMODE. Or specify a hex bitmask of allowable modes. The NZ firmware has modulation=0xffff (allow all modes) and this appears to auto-negotiate ADSL1 and ADSL2 modes as appropriate.

Check your line is in sync

If DSL is working, the ADSL LED should be solidly on. Check 'dmesg' or 'logread' for DSL log messages:

registered device TI Avalanche SAR
Sangam detected
requesting firmware image "ar0700xx.bin"
avsar firmware released
tn7dsl_set_modulation : Setting mode to 0xffff
Creating new root folder avalanche in the proc for the driver stats
Texas Instruments ATM driver: version:[7.02.01.00]
DSL in Sync

Check the link state in /proc/avalanche/avsar_modem_training if you have problems:

There are a number of stats available in /proc/avalanche/avsar_modem_stats including upstream/downstream speeds.

PPPoA configuration

Edit /etc/config/network. Add a section like this at the end:

config interface wan
        option ifname   ppp0
        option unit     0
        option proto    pppoa
        option encaps   vc
        option vpi      0
        option vci      100
        option username (your username here)
        option password (your password here)
        option keepalive 5,5

encaps should be "vc" or "llc". vpi and vci are specific to your ISP.

PPPoE configuration

Edit /etc/config/network. One more section is needed for the ATM-bridge.

config atm-bridge
        option unit     0
        option encaps   llc
        option vpi      8
        option vci      35

config interface wan
        option ifname   nas0
        option proto    pppoe
        option username (your username here)
        option password (your password here)

encaps should be "vc" or "llc". vpi and vci are specific to your ISP.

Connect to your ISP directly using DHCP

Most people will be using PPPoE or PPPoA. However, if you are using DHCP, please read this thread: http://forum.openwrt.org/viewtopic.php?id=8019

Bring up the ADSL connection

/etc/init.d/br2684ctl restart  # for PPPoE
ifup wan
/etc/init.d/firewall restart

The firewall/bridge only needs to be restarted after making configuration changes, not every time.

Currently the ADSL connection will not start automatically on boot. See #2781 for a patch to fix this, or manually run 'ifup wan' after a reboot.

The "USB" LED should turn on (it's been hijacked to display PPP state, not USB state), and 'ifconfig' should show something like this:

ppp0      Link encap:Point-to-Point Protocol
          inet addr:222.154.180.230  P-t-P:125.237.255.1  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:1742 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1818 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:1313740 (1.2 MiB)  TX bytes:306881 (299.6 KiB)

'logread' should show some PPP connection messages:

Dec  1 06:17:42 OpenWrt daemon.info pppd[638]: Plugin pppoatm.so loaded.
Dec  1 06:17:42 OpenWrt daemon.notice pppd[639]: pppd 2.4.3 started by root, uid 0
Dec  1 06:17:42 OpenWrt daemon.info pppd[639]: Using interface ppp0
Dec  1 06:17:42 OpenWrt daemon.notice pppd[639]: Connect: ppp0 <--> 0.100
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: PAP authentication succeeded
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: PAP authentication succeeded
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: local  IP address 222.154.81.8
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: remote IP address 125.237.255.1
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: primary   DNS address 202.27.158.40
Dec  1 06:17:43 OpenWrt daemon.notice pppd[639]: secondary DNS address 202.27.156.72

And you should now have internet access!

ADSL2+ performance

You will start running out of CPU when forwarding packets at about 10-12Mbps of downstream traffic. ADSL2+ connections can do more than this (e.g. I get 15-17Mbps in theory) so that's a bit annoying. It's somewhat hard to narrow down the culprit as OProfile does not support the MIPS 4K CPUs.

The cpmac ethernet driver on its own can manage around 21Mbps of traffic being generated by the local TCP stack (so presumably more than that if the traffic is just being forwarded). There is some room for optimization of the transmit path - currently it generates a completion interrupt for every packet sent, as there is only ever one packet queued for transmission at a time. Adding a transmit ring and moving to a NAPI model on the tx path may help. In comparison, the rx path (which uses a receive ring and NAPI) can handle 40Mbps being received by local TCP with far fewer interrupts.

The ADSL driver is a horrible tangle of HAL layers and OEM code. I wouldn't be too surprised if it was sucking more CPU than it needed to, but it's hard to single out any one bit of that code for cleanup.

Troubleshooting

WPNT834 Performance problem

Poor performance of the ADSL connection exists between the Netgear WPNT834 Rangemax 240 and D-Link DSL-502T, characterised by poor transfer speeds which may be asynchronous in nature, many retransmits and general packet loss in TCPdump and poor telnet access/webpage access to the DSL-502T, this is caused by poor ethernet performance between the two devices. This is possibly caused by a duplex mismatch or buggy 100FD/HD code on one of the devices.

The only way to solve this at present is to force the DSL-502T ethernet connection to Autonegotiate 10Mbit/s by changing one line of source code: see the last two posts here: http://forum.openwrt.org/viewtopic.php?id=8117

How to Debrick

You can generally use the methods on D-Link's site, or just change your mtd0/1/4 variables back to defaults and upload the dlink firmware.

But if you've accidentally destroyed your mtd2 adam2 bootloader or mtd3 config file you will need a JTAG cable.

Also see this (old) thread for more details - it may be out of date: http://forum.openwrt.org/viewtopic.php?id=7742

How to make a JTAG cable

I grabbed one from ebay but you can make your own with 4/5 resistors, pin schematics are here:

http://wiki.openwrt.org/AR7Port http://wiki.openwrt.org/OpenWrtDocs/Customizing/Hardware/JTAG_Cable

The cable I purchased from Ebay was for the WRT54G, it had a 12 pin header, whereas my router had an already soldered 14 pin header, the WRT54G uses EJTAG 2.0 and the AR7 uses EJTAG 2.6, to make the JTAG cable work I simple connected pin 1 TRST with pin 8 VCC/VIO/VRED via a 100 ohm resistor (I didn't bother soldering it on) and then placed the 12 pin JTAG on top squashing it into place, bending back the extra 2 pins.

My pins are numbered as so:

1 (TRST) - 14
2 - 13
3 - 12
4 - 11
5 - 10
6 - 9
7 - 8 (VIO/VCCC/VREF)

Bios settings

My BIOS settings for my printer port were: ECP+EPP, 0x378.

Using the Debrick utility to restore the bootloader and config

Once you do this you can use HairyDairyMaids debrick utility 4.8. Get it here: http://downloads.openwrt.org/utils/

Under Windows: load giveio.sys by running loaddrv.exe and adding 'giveio.sys' to the end of the line and clicking install+start.

Under Linux (Ubuntu): Get the build essentials package, compile the binary using 'make' from the folder you extracted the files to, then you need to do this to read the parallel port: rmmod lp, modprobe parport, mknod /dev/parport0 c 99 0

You can now do ./wrt54g -probeonly to test if the unit can be detected

Grab Olegs Adam2 bootloader: http://star.oai.pp.ru/jtag/adam2-oleg.zip

rename the adam2 file to CUSTOM.BIN then do:

./wrt54g -flash:custom /noerase /nobreak /nodma /window:0x90000000 /start:0x90000000 /length:0x10000 /nocwd

Grab mtd3 config http://mcmcc.bat.ru/dlinkt/restore_mtd3_50xT.rar

rename this to CUSTOM.BIN then do:

./wrt54g -flash:custom /noerase /nobreak /nodma /window:0x903f0000 /start:0x903f0000 /length:0x10000 /nocwd

You may not have to do /noerase /nobreak or /nocwd but /nodma is required

Once this is done, set you lan IP as 10.8.8.1 subnet 255.0.0.0 (on Linux u need to do ifconfig eth0 10.8.8.1 to set your IP) and then reboot the router, ftp into 10.8.8.8 21 using the command prompt FTP (not anything else) and you will see an adam2 prompt (gratz!).

ping 10.8.8.8 to see if adam2 is working

Uploading the original firmware

Now that ADAM2 is working, you can use adam2flash-502T.pl to install firmware of your choice, including the original D-Link firmware. See above.

Acknowlegements

(Moved from the top)

Thanks Strider for starting the page off for me.

Thank you nbd and all the OpenWRT developers for making this work-Z3r0 (not the z3r0 on IRC)

Thank you Mr Chandler for fixing some of the formatting.

Note, as of 17th May '07 I am no longer maintaining this page as I no longer have a DSL-502T, if you would like to update this page please feel free to. (Z3r0)


CategoryModel . CategoryAR7Device


2009-03-29 22:43