" class="title" title="home again woohoo">Home ?> pages bg right
 Currently Browsing: Featured Articles

Two fixes..For the price of one :)

Wow.. Didnt hope to release fixes so soon.
Yesterday, Jacky Yuen contacted me about a bug in the mod. It didn’t look like
the mod’s fault, but i took a deeper look.

The issue :

On his windows server (win2003, and XP) the mod was working, but was unable to
reach high speeds (1MB/s). (i heard something like this before, and all you need is
to change the packet size).
However, doing this, didn’t fix the issue. I tried this on my server, and i was
able to get about 500KB/s. Setting the packet size to 16384 gave me 1MB/s.
Jacky told me he still had problems, so i tried all windows systems i got around.

A windows 2003 server,
and a Windows 7 (32bits) showed the problem (max speed was 490KB/s)
A Windows 7 64bits and Win 2003 SP2 didnt.

The most awesome part, is that if you run Google Chrome, a Flash application, or
Windows Media Player, the mod is able to deliver up to 1MB/s.

Took me a while, but i found that Windows doesnt run a high resolution timer
all the time. In the servers with the issue, the timer run every 10 ms.
Whenever you run some of the mentioned apps, they set the timer to the highest
speed possible (in my equipment, 1 ms). This setting affects all other
applications, so the mod was able to sleep small times to deliver data as it
So, i wrote 2 fixes. The first one, i didnt wanted to, but i made the mod to
set the timer to the highest resolution possible (it is written to the logs if
you want to peek). And the second, is to avoid waiting small times to send
data. Minimum time to sleep is 200ms now, and data is adjusted for this. (only
for windows). Both fixes are under defines that will compile just for windows,
so linux users won’t notice any changes.
The good thing, for windows users, is that with this fixes, i’ve been able
to get speeds up to 2.45MB/s under windows!. Using apache by itself, i just
got 1.2MB/s. Just enabling the mod and setting a high limit, the speed got
pumped up.

That’s it. Now i’ll be back working on the next release.

– (previous readme.txt text follows dated 24/May/2010)

Again… It has been a while since i’ve upted the code. (work, personal
life, money issues, the same stuff we all fight daily)
However, that doesn’t mean i forgot about it. I’ve just been working my
*** off. I’ve got many emails with suggestions, some bugs, etc..
I’m doing one of the last updates of this line of mod_bw (0.x). It’s
mainly a couple of bugfix, and a little callback to get stats on the running
mod. I hope it wont break anything.. (of course i’ve tested it a lot).

Ah!, i said this is one of the last updates. Yes. This is because this line
of code is limiting the possibilities of the mod, so i’ve started a new mod_bw
using other set of techniques. (so, it is highly experimental, and uses
completely new instructions). This new branch of the mod was born thanks to
the email sent by Borislav Borislavov (icn.bg), who needed some special features
to be implemented, not possible with the current code.
So, if you wanted the mod to do per-ip limiting, traffic limiting, etc..
keep checking my site. I’ll be releasing a new branch of mod_bw to public soon.
(Unfortunately, it won’t be released under the Apache license yet).

Now, back to this mod :

First, i’ve fixed two annoying bugs.
– MinBandWidth -1 was screwing things up sometimes. All because i was using
an unsigned integer to store the -1. Yeah, my bad.
– The limiting handler was leaking memory. A few bytes at a time, but for
large files (really, really large) this could mean one of the apache childs
consuming almost all memory. Thanks to Christian Spielberger who insisted
and helped me to find this. (i was sure there was something.. but my servers
recycle apache childs pretty often). Fun Fact : I found the bug, was cleaning
my test code, and he sent me an email with the exact same solution i came up.
Great minds think alike, eh ? :)

Then, i made a status callback for the mod. This callback will show some
stats on the running mod, for each memory segment used to limit bandwidth.
Is it a simple stat. However, i received many emails asking for this.

This is easy to achieve :

In your admin vhost (if you have one.. If not, any vhost you want to check),
use a location to set a handler for the callback.

Suppose the vhost for :

    SetHandler modbw-handler

Now you can get information of the mod by visiting
You can get the same information in csv format at

Please, test this changes, let me know how it works.
If you have some ideas (i.e. information to add in the stats), email me. If
it can or can’t be done in this branch of the mod, i’ll let you know.

WRT54g2 – From DD-WRT to Original Firmware

So…A friend asked me to restore the original firmware on his Linksys WRT54g2 after having installed DD-WRT. Well, it isnt as straightforward as it is the other way around. In fact, it isnt doable just by software.

First, you need to open the router. Damn thing uses the only screwdriver i don’t have.

Safe Torx

It was easy to force a normal flat headed screwdriver. So , got it opened.
Next, Surprise. No serial or jtag port visible right away. *sigh*
Taking a good look, you’ll see adjacent black boxes where it was supposed to be some pins, only they are all green.
WRT Board

Looking around, you’ll find the 5 pins in the middle of the top face of the mainboard are a serial port. And the 6 boxes in the right (6 on top face, 6 on bottom face) are pins for jtag. You’ll have to scratch the green stuff out (carefully) using a screwdriver, nail, or something sharp. After leaving enough copper surface visible, you can proceed to solder cables or some kind of surface connector. (or, adapt a standard connector)

So far, so good.
You’ll need a jtag cable. You can get some online, from cheap ones, to really expensive ones. Plus, you need to know if it will support the chip the router uses.
Cheap solution : Use a home-made cable consisting in 4 resistors + 1 DB25 male connector (using the printer port. Note that it needs to be a REAL printer port. Not an USB “printer” port).
WRT Board
* Taken from OpenWRT Wiki

This easy to make cable (Unbuffered cable) has to be short. No more than 6 inches, or noise will be your enemy. I made one about 3 inches long.

WRT Board WRT Board

Get tjtag to tinkle with the board. Runs on windows and linux. As none of my laptops have a printer port, i used a colleague’s computer (WinXP). Now this becomes nasty xD

Running test commands, the software recognized the board and memory chip. All good!
Cable was good, board was alive (duh! it was working), and software was compatible.

tjtag3.exe -probeonly

Then, (just in case) i made a wholeflash backup. This will save all the flash content bit by bit, allowing a future restore to DD-WRT (in this case).

tjtag3.exe -backup:wholeflash

Flash Backup
(2MB backup, took 623 seconds to complete.)

Now, according to dd-wrt forums, once installed dd-wrt on this router, there is no way back. Well, this is partly true.
As i commented before, there is no “easy” way back. Better yet, if you do not make a wholeflash backup yourself, the “not easy” way back, becomes more “not easy”.
Well.. I received this router with dd-wrt preinstalled, and was asked to return it to firmware factory. All system hardware was “pristine”, so nobody mangled it, and… nobody made a flash backup. Fortunately , a guy in the forums was nice enough to post a wholeflash backup of his router. (different flash chip).

When decided to try it out, i renamed the file to wholeflash.bin and run

tjtag -flash:wholeflash

Started running…..
Continued running…..
A couple of numbers showed up on screen….
Flash Write
….. (i let it run, and i went back to work)
If you consider the time between the numbers on screen, it would have taken about 120 hours to flash the whole flash. I know jtag is slow, but this is ridiculous.

So, Control-C, and try again using some parameters.
Now the board started to act weird. Some times it didnt detected the flash chip, some times it complained about not being able to set debug mode on processor, hanged while enabling memory writes, etc.

After some time trying and reading, i decided to use the /dma, /noreset and /noemw parameters. (force enable dma (speed), disable reset and memory writes). Some times i had to force the flash id (/fc:09). Now it was running fast. (read, about 2 minute per each percent).
Off to work again.

Checked about 60 minutes later, and the damned thing hanged at 27%.

After that, came a series of erase of the flash, followed by differents tries to flash. Each attempt failed in different places. (6%, 12%, the most i got, was 37%).
Checked the cable, any interference around, etc. Same result.
I went home, and let the stupid board flashing. Didnt care anymore :D

Next day i tried a couple of things.
One of them lead me to success (hours later!)

The important steps were this :

- Connected the pin 1 of the unbuffered cable , to a Vcc source (used serial’s port) with a 100ohm resistor. (In the pictures the pin is connected…. i took the pictures after all this)
- Left each cable a couple of millimeters away from each other.
- Put the router in its own case, to isolate it from external noise. (however, i used the original casing.. Some suggest using some tinfoil around).

This led me to flash to 15% almost every time. (it was still hanging).
Then, i got fed up. Decided to split the bin file into smaller pieces (256KB seemed about right) and started flashing it by parts (8 parts). For this, you need to calculate the beginning area of the flash memory, and the length to program. With all the information you get with tflash, this is fairly easy.

Some more failures. Still dont know why, but after flashing part2 (256 to 512KB) i got some hangs in specific address. Tired, decided to go backwards (literally). Erased the flash, and started flashing from part 8 to 1.

It went smooth! No errors, about 560 seconds each part (something about 75 minutes total).
To confirm the procedure, made a wholeflash backup and compared it to the file… Damn. Differences. First difference occurred about 750KB from beggining.

If you check the addresses where the BSP or CFE is stored, you will realize that 750KB from the beggining is just past that. Im not going too write much about this, but it is important to know, CFE is the boot system used to boot linux (dd-wrt in this case), and BSP is the system used by linksys firmware based on VxWorks.

Taking that into account, i just rebooted the router. Lights went all on, then off…. Success !
Power light was blinking. That means firmware loading problem. Not that bad. Configured the computer to use , and connected via WEB to A simple page titled “Management Mode – Firmware Upgrade” asking me to select a file, appeared.
I went to Linksys.com, browsed for the latest firmware for this router (1.04.00) and selected it. Run!
A couple of minutes passed by, and the page asked me to reboot the router.

Power Off.
Power On.

Normal boot !

We are back to the original firmware.

Utilities and files :

- tjtag v0.3 [ from : here ]
- Whole flash backup [ from : here ]
- Original Linksys Firmware 1.0.04US [ from : here ]
- Splitted Flash : Each of the files to flash manually and by segments of 256KB.
* (including bat files with the command line)

All the files here, were taken from the sites specified.
If you think i am violating some copyright, please write me.

Page 1 of 212»