Script to backup Flash binary contents on Routertech

An area of the forum to discuss router binaries (utilities and applications that run on routers) etc.
Post Reply
mstombs
RouterTech Team
RouterTech Team
Posts: 3753
Joined: Wed Jan 10, 2007 11:54 pm

Script to backup Flash binary contents on Routertech

Post by mstombs » Tue Feb 26, 2008 11:22 pm

I found how to use the busybox tftp command in Routertech firmware, and a free tftp server for my XP box :-
"TFTPD32 v3.23 Build Jun 2 2007 copyrighted 1998-2007 by Philippe Jounin" tftp server (philippe@jounin.net) on windows XP. http://tftpd32.jounin.net/tftpd32_download.html

so wrote this little script

Code: Select all

#!/bin/sh -x
if [ "$1" ];then
	PC=$1
else
	PC=192.168.1.2
fi
cd /var/tmp
block=2
while [ "$block" -lt 6 ]; do
mtd=mtd"$block".bin
cat /dev/mtdblock/$block >$mtd
tftp -p -l $mtd $PC
rm $mtd
let block=$block+1
done
with result on my PC

Code: Select all

 Directory of C:\tftp

26/02/2008  22:07            65,536 mtd2.bin
26/02/2008  22:07            65,536 mtd3.bin
26/02/2008  22:07         3,538,944 mtd4.bin
26/02/2008  22:07           524,288 mtd5.bin
               4 File(s)      4,194,304 bytes
which is the total contents of the 4MB flash on my pspboot router, and a lot faster than doing it all manually!

Only real use of binary files in this form is via JTAG (mtd2 bootloader, mtd3 env+config, no need for kernel+filesystem mtd4), but thought I'd share it...
Last edited by mstombs on Wed Feb 27, 2008 11:52 am, edited 2 times in total.
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Wed Feb 27, 2008 8:37 am

Well, it's good to know this anyway!
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.
User avatar
Neo
RouterTech Team
RouterTech Team
Posts: 3586
Joined: Thu Jan 26, 2006 1:09 pm
Contact:

Post by Neo » Wed Feb 27, 2008 3:12 pm

It's good to have a quick way of backing up the firmware but I suspect you need to have a router with a reasonable amount of free RAM in order to accommodate the 'blocks'...
RouterTech Team and Founding Member
Image
RouterTech Merchandise (UK)
No support via PM, please ask your questions on the forum!
mstombs
RouterTech Team
RouterTech Team
Posts: 3753
Joined: Wed Jan 10, 2007 11:54 pm

Post by mstombs » Thu Feb 28, 2008 12:31 am

Sure I never know how to interpret the declared free memory though

Just after booting my router currently has

Code: Select all

Mem: 10428K used, 3728K free, 0K shrd, 1200K buff, 4072K cached
If I create a 3456KB file for mtd4.bin this changes to

Code: Select all

Mem: 11272K used, 2884K free, 0K shrd, 40K buff, 6192K cached
I can do this again

Code: Select all

Mem: 13616K used, 540K free, 0K shrd, 60K buff, 8612K cached
so I now have 6912KB of temp files

Code: Select all

/var # ls -laF foo.*
-rw-r--r--    1 0        0         3538944 Feb 27 23:19 foo.tmp
-rw-r--r--    1 0        0         3538944 Feb 27 23:21 foo.tmp2
and all is well, but crash the router if try again... so just delete the files and now

Code: Select all

Mem: 6756K used, 7400K free, 0K shrd, 112K buff, 1692K cached
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Thu Feb 28, 2008 9:03 am

Its the linux memory manager - things are swapped in and out of RAM as required, so the free memory stats don't always tell you how much memory can be freed for use.
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