Hi everyone
I've got a D-Link DSL-502T AU, this is just a guide to de-bricking it and restoring the default DLink firmware, you should probably read this before you attempt to flash the router with Openwrt. If your router stops working use the recovery procedures outlined by D-Link first of all. Before flashing please get a JTAG cable and (optionally) a Serial cable. The JTAG will allow you to talk directly to the routers AR7 processor and restore the firmware. The serial cable will give you DMESG / debug information and is useful when trying to see why OpenWRT won't start
Another thing to check before flashing or attempting to flash to openwrt is that your flash memory chip is supported by HairyDairyMaids debrick utility, otherwise you are stuck
Get it here: http://downloads.openwrt.org/utils/ and run ./wrt54g and check if your flash chip is listed.
Inside the unit you will find: a 14 pin JTAG connector (soldered on mine), 14 pin GPIO (unsoldered), 5 pin Serial (soldered), 10 pin serial (unsoldered), my flash chip was Samsung K8D3216UBC (It's next to the JTAG connector).
If you have erased the bootloader or the config file you will have a dead router and need to recover using the JTAG method. This cannot happen when flashing with the default D-Link utilities! You can use the software recovery methods outlined on their site.
The only way to recover from this point is to use a JTAG cable to connect ot the router and talk directly to the AR7 MIPS based processor.
It's pretty simple, there are schematics here available for the poor mans JTAG, this is a cable with 4 or 5 resistors and no data buffer chip.
The WRT54G uses EJTAG 2.0 and a 12pin JTAG. You can buy one of these JTAG cables from ebay and then mod it to be used on your AR7 router, or you can build your own. The AR7 uses EJTAG 2.6 and has a 14pin JTAG. The difference? The WRT54G doesn't need pin 1 TRST set to high, the AR7 does. To do this you just get a 100ohm resistor and connect pin 1 to pin 8 via this resistor (note my pin numbering may be different to yours).
Pin schematics are here:
http://wiki.openwrt.org/AR7Port
http://wiki.openwrt.org/OpenWrtDocs/Cus … JTAG_Cable
My pins are numbered as so:
1 (TRST) - 14
2 - 13
3 - 12
4 - 11
5 - 10
6 - 9
7 - 8 (VIO/VCCC/VREF)
Now, my BIOS settings for my printer port were: ECP+EPP, 0x378.
Once you do this you can use HairyDairyMaids debrick utility 4.8
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
I will keep this simple, first of all flash the ADAM2 bootloader (64k):
root@ZPC:~/HairyDairyMaid_WRT54G_Debrick_Utility_v48# ./wrt54g -flash:custom /noerase /nobreak /nodma /window:0x90000000 /start:0x90000000 /length:0x10000 /nocwd
====================================
WRT54G/GS EJTAG Debrick Utility v4.8
====================================
Probing bus ... Done
Instruction Length set to 5
CPU Chip ID: 00000000000000000001000000001111 (0000100F)
*** Found a TI AR7WRD TNETD7300GDU Rev 1 CPU chip ***
- EJTAG IMPCODE ....... : 01000001010000000100000000000000 (41404000)
- EJTAG Version ....... : 2.6
- EJTAG DMA Support ... : No
*** DMA Mode Forced Off ***
Issuing Processor / Peripheral Reset ... Done
Enabling Memory Writes ... Skipped
Halting Processor ... Skipped
Clearing Watchdog ... Skipped
Probing Flash at (Flash Window: 0x90000000) ... Done
Flash Vendor ID: 00000000000000000000000011101100 (000000EC)
Flash Device ID: 00000000000000000010001010100010 (000022A2)
*** Found a K8D3216UBC 2Mx16 BotB (4MB) Flash Chip ***
- Flash Chip Window Start .... : 90000000
- Flash Chip Window Length ... : 00200000
- Selected Area Start ........ : 90000000
- Selected Area Length ....... : 00010000
*** You Selected to Flash the CUSTOM.BIN ***
=========================
Flashing Routine Started
=========================
Loading CUSTOM.BIN to Flash Memory...
[ 0% Flashed] 90000000: 40809000 40809800 401a6000 241bfffe
[ 0% Flashed] 90000010: 035bd024 3c1b0040 035bd025 409a6000
etc...
Done (CUSTOM.BIN loaded into Flash Memory OK)
=========================
Flashing Routine Complete
=========================
elapsed time: 1522 seconds
*** REQUESTED OPERATION IS COMPLETE ***
if you find the flash gets stuck at a certain percentage, use -erase:custom first to erase that area.
(Erase of config)
=========================
Erasing Routine Started
=========================
Total Blocks to Erase: 8
Erasing block: 1 (addr = 903f0000)...Done
Erasing block: 2 (addr = 903f2000)...Done
Erasing block: 3 (addr = 903f4000)...Done
Erasing block: 4 (addr = 903f6000)...Done
Erasing block: 5 (addr = 903f8000)...Done
Erasing block: 6 (addr = 903fa000)...Done
Erasing block: 7 (addr = 903fc000)...Done
Erasing block: 8 (addr = 903fe000)...Done
=========================
Erasing Routine Complete
=========================
elapsed time: 5 seconds
It takes about 20 mins to upload 64k and about 5 seconds to erase it
Once you have done this now you need to flash a configuration using window:0x903f0000 start:0x903f0000 length:0x10000
Get this MTD3 configuration file: http://mcmcc.bat.ru/dlinkt/restore_mtd3_50xT.rar
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!).
root@ZPC:~/HairyDairyMaid_WRT54G_Debrick_Utility_v48# ping 10.8.8.8
PING 10.8.8.8 (10.8.8.8) 56(84) bytes of data.
From 10.8.8.10 icmp_seq=1 Destination Host Unreachable
From 10.8.8.10 icmp_seq=2 Destination Host Unreachable
From 10.8.8.10 icmp_seq=3 Destination Host Unreachable
From 10.8.8.10 icmp_seq=4 Destination Host Unreachable
From 10.8.8.10 icmp_seq=5 Destination Host Unreachable
From 10.8.8.10 icmp_seq=6 Destination Host Unreachable
64 bytes from 10.8.8.8: icmp_seq=7 ttl=250 time=2006 ms
64 bytes from 10.8.8.8: icmp_seq=9 ttl=250 time=5.17 ms
64 bytes from 10.8.8.8: icmp_seq=10 ttl=250 time=5.16 ms
64 bytes from 10.8.8.8: icmp_seq=11 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=12 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=13 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=14 ttl=250 time=5.14 ms
64 bytes from 10.8.8.8: icmp_seq=15 ttl=250 time=5.16 ms
64 bytes from 10.8.8.8: icmp_seq=16 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=17 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=18 ttl=250 time=5.09 ms
64 bytes from 10.8.8.8: icmp_seq=19 ttl=250 time=5.14 ms
This is the glorious moment when my router started working again.
I found that all the adam2 bootloaders on the internet work fine, I ended up using olegs compiled version as this has a default IP hard coded into it. http://star.oai.pp.ru/jtag/adam2-oleg.zip
Now on to some instructions about how to restore the firmware from this stage,
First we need the firmware, just get the .bin from D-Link and rename it fw or fw.bin or something short
ftp://files.dlink.com.au/products/DSL-5 … 060808.bin
Now, you can upload the firmware (see below for an example)
root@ZPC:~# ifconfig eth0 10.8.8.7
root@ZPC:~# ftp 10.8.8.8 21
ftp: connect: No route to host
ftp>
ftp> o
(to) 10.8.8.8 21
Connected to 10.8.8.8.
220 ADAM2 FTP Server ready.
Name (10.8.8.8:z): adam2
331 Password required for adam2.
Password:
230 adam2 logged in.
ftp> quote MEDIA FLSH
200 media set to FLASH
ftp> binary
200 Type set to I.
ftp> hash
Hash mark printing on (1024 bytes/hash mark).
ftp> debug
Debugging on (debug=1).
ftp> put "fw" "fs mtd4"
local: fw remote: fs mtd4
---> PORT 10,8,8,7,170,251
200 Port command successful.
---> STOR fs mtd4
150 Opening BINARY mode.
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#############################################################################################################################################################
#################################################################
226 Transfer complete.
1996699 bytes sent in 27.36 secs (71.3 kB/s)
ftp> quote REBOOT
---> REBOOT
221 Goodbye.
ftp>
But let me guess... you didn't get the firmware to upload?
Did you get 550 can not erase or 550 flash erase failed
I think I know why!!
This is because the configuration file we just uploaded had the old firmware version 1 memory map and we are trying to upload a firmware version 2 which has a different memory mapping.
You can solve this by issuing SETENV commands with the correct memory mappings before uploading the firmware
quote "SETENV mtd0,0x90091000,0x903f0000" - filesystem
quote "SETENV mtd1,0x90010090,0x90090000" - kernel
quote "SETENV mtd2,0x90000000,0x90010000" - bootloader (adam2 mostly)
quote "SETENV mtd3,0x903f0000,0x90400000" - configuration
quote "SETENV mtd4,0x90010090,0x903f0000" - this just covers filesystem/kernel
(p.s. the extra , is no mistake, I think it's needed)
Another way to set these environment variables and upload the firwmare is to use CICLAMAB 3.7.9 (NOT 3.8.0 or 3.8.1 both crash), it does the same thing but has a nice GUI, you need to have your LAN IP as 10.8.8.1, router off and then run CICLAMAB, click no, click no, click on partitions, go to D-Link DSL-50xT v2, click setup, click cancel to return to previous screen, select your firmware, click on connection, power on modem, if your bootloader is detected you can click on 'execute' and you should see the following:
00:57:26 - Connection to "BootLoader" in progress...
00:57:27 x- < 220 ADAM2 FTP Server ready.
00:57:27 - 220 ADAM2 FTP Server ready.
00:57:27 - Connection to "BootLoader" done!
00:57:27 - USER adam2
00:57:27 x- < 331 Password required for adam2.
00:57:27 - 331 Password required for adam2.
00:57:27 - PASS adam2
00:57:27 x- < 230 adam2 logged in.
00:57:27 - 230 adam2 logged in.
00:57:27 -
00:57:27 - ---------------------------------------------------------
00:57:27 - modem/router info:
00:57:27 x- GETENV flashsize
00:57:27 x- < flashsize 0x00400000
200 GETENV successful
00:57:27 - bootloaderType ADAM2
00:57:27 x- GETENV bootloaderVersion
00:57:27 x- < bootloaderVersion 0.22.02
200 GETENV successful
00:57:27 - bootloaderVersion 0.22.02
00:57:27 - flashsize 0x00400000 (4 Mb)
00:57:27 x- GETENV usb_prod
00:57:27 x- < usb_prod N/A
200 GETENV successful
00:57:27 - usb_prod N/A
00:57:27 x- GETENV mtd0
00:57:27 x- < mtd0 0x90091000,0x903f0000
200 GETENV successful
00:57:27 - mtd0 0x90091000,0x903f0000
00:57:27 x- GETENV mtd1
00:57:27 x- < mtd1 0x90010090,0x90090000
200 GETENV successful
00:57:27 - mtd1 0x90010090,0x90090000
00:57:27 x- GETENV mtd2
00:57:27 x- < mtd2 0x90000000,0x90010000
200 GETENV successful
00:57:27 - mtd2 0x90000000,0x90010000
00:57:27 x- GETENV mtd3
00:57:27 x- < mtd3 0x903f0000,0x90400000
200 GETENV successful
00:57:27 - mtd3 0x903f0000,0x90400000
00:57:27 x- GETENV mtd4
00:57:27 x- < mtd4 0x90010000,0x903f0000
200 GETENV successful
00:57:27 - mtd4 0x90010000,0x903f0000
00:57:37 x- Transferring file:
00:57:37 x- Firmware: D:\FTP\software\ckz_XZ7X\DLinkAU_DSL-502T_singleimage_kernel_fs_V2.00B06.AU_20060808
Inputted parameters:
- Autoload on
- Partitioning mtd0, mtd1 and mtd3 for D-Link DSL-50xT/604T/G604T v2
To start the session:
00:57:45 - ---------------------------------------------------------
00:57:45 - The partitions are already of the required size.
00:57:45 - SETENV autoload,1
00:57:45 x- < 200 SETENV successful
00:57:45 - 200 SETENV successful
00:57:45 - TYPE I
00:57:45 x- < 200 Type set to I.
00:57:45 - 200 Type set to I.
00:57:45 - MEDIA FLSH
00:57:45 x- < 200 media set to FLASH
00:57:45 - 200 media set to FLASH
00:57:45 - Creating "mtd4" variable.
00:57:45 - SETENV mtd4,0x90010000,0x903f0000
00:57:45 x- < 200 SETENV successful
00:57:45 - 200 SETENV successful
00:57:45 - PASV
00:57:45 x- < 227 Entering Passive Mode (192,168,0,1,243,72).
00:57:45 - 227 Entering Passive Mode (192,168,0,1,243,72).
00:57:46 - Deleting partition "mtd4" in progress...
00:57:46 x- STOR single mtd4
00:58:18 x- < 150 Opening BINARY mode.
00:58:18 x- Erase time: 00' 32.27"
00:58:18 x- Nr. of blocks to send: 527
00:58:44 x- Transfer time: 00' 26.01"
00:58:44 x- < 226 Transfer complete.
00:58:44 - 226 Transfer complete.
00:58:44 - REBOOT
Ok so, power cycle the router and it should now work... lights should come on after 30 secs or so.
THE END!
Some extraneous information:
If you want to upload a custom OpenWRT firmware you will need to have a deeper understanding on the way the router works.
The single combined firmware is divided as so:
HEX
0-90 header
90-80FFF kernel with padded 0s at the end
81000-20EFFF filesystem with padded 0s
20F000-20F007 checksum for the entire file made with TICHKSUM (8 Bytes)
Please remember that a hex number is 4 bits, so each byte contains 2 hex numbers, this means 8 bytes = 16 hex numbers.
The TICHKSUM is not a standard 4 Byte CRC32 or 8 Byte CRC64, it is firstly a fixed set of 8 hex numbers 23DE53C4 (magic numbers) and then an 8 hex checksum such as:
23DE53C4 07D74626
Ok so.. what am I getting at here?
Well, if you compile the openwrt trunk and examine the ar7 firmware with a hex editor you will see that the squashfs.bin uses totally different mappings, openwrt does not waste space by padding to boundaries with extra 0s.
Openwrt is usually
0-x kernel
x-eof squashfs
so for this file system to boot, you will need to find the hex values of the start of the squashfs filesystem (use ghex under linux or XVI under windows) and search for 'hsq' this signifies the start of the squashfs. Now adjust mtd0 and mtd1 variables accordingly.
You also need to add a checksum to the end of the file by running ./tichksum under Linux or by compiling tichksum under windows.
TICHKSUM can be found in the DSL-502T source code.
--------
Note, if you compile your firmware and upload it and the DMZ lights stays on, this means your kernel has died You need a serial cable to work out how to fix it... as for me... I have no serial cable and no urge to work it out, so back to the default fw for me as SVN trunk 5109 wouldn't compile
(For anyone who tries to use ndbs march ar7 firmware, no lights go on at all for me with this)
(Last edited by Z3r0 on 15 Oct 2006, 16:54)