Netgear DG834G v2 with ADAM2 and RT 2.96

Support forum for routers of all shapes and sizes. As long as it's router based and doesn't fall into the other categories, this is the place to ask your questions.
Post Reply
albie
Newbie
Newbie
Posts: 1
Joined: Sat Dec 03, 2011 10:30 am

Netgear DG834G v2 with ADAM2 and RT 2.96

Post by albie » Sun Dec 04, 2011 8:21 am

These are some notes about how to get the RouterTech_3.6.0D_20110502_2.96_AR7WRD_Adam2_firmware.upgrade.img
loaded on an old DG834G v2 router without using PSP bootloader.

The approach is to split the img file into the kernel and squashfs components and then flash them into the
same partitions (mtd1,mtd0) as used by the normal netgear firmware.

ADAM2 boot loader loads the kernel from mtd1, and the kernel is configured to load the root suqashfs from mtd0.

0. use a linux-pc to get the current config
browser$ http://192.168.0.1/setup.cgi?todo=debug
pc$ telnet 192.168.0.1
router# cat /proc/ticfg/env
router# echo "my_ipaddress 192.168.0.1" > /proc/sys/dev/adam2/environment

PC# ifconfig eth0 192.168.0.2 up
PC# echo 0 512 512 > /proc/sys/net/ipv4/tcp_wmem # small tcp window size

1. backup the flash partitions mtd0,1,2,3,4.
use the procedure here: http://wiki.openwrt.org/toh/netgear/dg834.g/b
the trick with getting ftp to connect to the ADAM2 load is to immediately start the ftp client after powering on the router
you only have a second or two window to connect to ADAM2 via ftp

2. tweak the ADAM2 bootloader in mtd2 to load kernel without chksum it
see http://wiki.openwrt.org/toh/netgear/dg834.g/b
double check the cksum before flashing mtd2, if you mess this up its a brick
once you're happy do a test reboot to confirm old firmware still loads

Default Netgear DG834G v2 mtd config
--
mtd0 0x900d0000,0x903e0000 RootFS
mtd1 0x90020000,0x900d0000 Kernel
mtd2 0x90000000,0x90020000 ADAM2
mtd3 0x903e0000,0x903f0000 Netgear firmware config
mtd4 0x903f0000,0x90400000 ADAM2 config

3. split the RouterTech firmware up into kernel and rootfs

The first 0x90 bytes of the image seems to be the ADAM2 config which sets up things like the mtd partitions.
So skip it when extracting the mtd0 and mtd1 partitions from image.

Find where squashfs filesystem starts:
$ od -a RouterTech_3.6.0D_20110502_2.96_AR7WRD_Adam2_firmware.upgrade.img | grep 'h s q s'
2000000 h s q s { etx nul nul nul nul nul dle so stx @ 8

So offset to mtd0 filesystem needs to be 0x80000 (or 2000000 in octal) and so extract squashfs:
$ dd if=RouterTech_3.6.0D_20110502_2.96_AR7WRD_Adam2_firmware.upgrade.img of=rt-mtd0.bin skip=524288 bs=1
2818056+0 records in
2818056+0 records out
2818056 bytes (2.8 MB) copied, 4.09274 s, 689 kB/s

And kernel is the bit left over.
$ dd if=RouterTech_3.6.0D_20110502_2.96_AR7WRD_Adam2_firmware.upgrade.img of=rt-mtd1.bin skip=144 count=524144 bs=1
524144+0 records in
524144+0 records out
524144 bytes (524 kB) copied, 0.768861 s, 682 kB/s

4. Flash mtd0 and mtd1 (leave other partitions untouched)
power on router and immediately (within 1 sec)
$ ftp 192.168.0.1
Connected to 192.168.0.1.
220 ADAM2 FTP Server ready.
Name (192.168.0.1:xxx): adam2
331 Password required for adam2.
Password: adam2
230 User adam2 successfully logged in.
Remote system type is UNIX.

ftp> quote "MEDIA FLSH"
200 Media set to FLSH.
ftp> bin
200 Type set to I.

ftp> put rt-mtd0.bin "fs mtd0"
local: rt-mtd0.bin remote: fs mtd0
200 Port command successful.
150 Opening BINARY mode data connection for file transfer.
226 Transfer complete.
2621304 bytes sent in 28.58 secs (89.6 kB/s)

ftp> put rt-mtd1.bin "fs mtd1"
local: rt-mtd1.bin remote: fs mtd1
200 Port command successful.
150 Opening BINARY mode data connection for file transfer.
226 Transfer complete.
720896 bytes sent in 10.03 secs (70.2 kB/s)

ftp> quote REBOOT
221-Thank you for using the FTP service on ADAM2.
221 Goodbye.

Note: ADAM2 requires small TCP window.
linux-PC# echo 0 512 512 > /proc/sys/net/ipv4/tcp_wmem # small tcp window size

5. wait a few minutes for router to boot (note LEDs don't work)
browser$ http://192.168.1.1
Login Admin / Admin

Backout:
--
Restore mtd0,1 and the router config mtd3 using FTP to ADAM2
mstombs
RouterTech Team
RouterTech Team
Posts: 3753
Joined: Wed Jan 10, 2007 11:54 pm

Re: Netgear DG834G v2 with ADAM2 and RT 2.96

Post by mstombs » Tue Dec 06, 2011 10:19 am

Interesting, thanks - the tcp window tweak is new to me - may help explain why adam2 transfers can be unreliable. We used to provide separate images - maybe there is one that still works?

For info this is some code I used to use to split single image firmwares, yes last time used was 2009, with whatever Ubuntu version I had then:-

Code: Select all

FW=RouterTech_3.6.0D_20090922_2.91.1_AR7RD-1Port_psbl-4mb-flash_firmware.upgrade.img

#find position of filesystem
x=$(hexdump -C $FW | grep hsqs)
# take first hex number  
x="${x%% *}"
#add hex prefix
x="0x$x"
dd bs=$((x)) skip=1 if=$FW of=theFS.img
dd bs=$((x)) count=1 if=$FW of=theKernel.img
I think I got this from a "Bored_Individual" on Aus Whirlpool forums... looks like it leaves the combined firmware header in the kernel bit - first 144 bytes?
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Netgear DG834G v2 with ADAM2 and RT 2.96

Post by thechief » Tue Dec 06, 2011 4:54 pm

The Firmware Tool will (among other things) do the splitting into filesystem and kernel images for you.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
Post Reply