mtd – The Flash Utility

For this method to work, you need to copy the file containing the firmware image to the router, preferably into /tmp/, the memory filesystem should be big enough to hold the full image. If not, use wget to get the image via http or ftp and pipe the result into mtd.

Then the image is written to flash using mtd, optionally giving additional options (see below).

The mtd utility was written with simplicity and code size in mind. It's features were derived from the mtd-utils, combining the needed parts into a single small tool providing all the functionality necessary for FreeWRT, and leaving everything out that's not.

mtd provides the following features:

unlock
some chips need unlocking before they can be written to
erase
this is a filesystem independent method to delete all contents on the flash. Basically this is like format in MS–DOS.
write
this is generally the same functionality as using dd or rawrite, but mtd takes care of the quirks that have to be paid attention to for correctly handling the type of flash in use

Further it can request your system to reboot. Some of the features mentioned here can also be combined, so it is e.g. possible to immediately reboot the system after the flash has been written.

Mostly, similar to the sample usage shown in the help output should be all that has to be done to write the firmware to flash:

[label=write a previously downloaded new firmware-file into flash]
# mtd -e firmware -r write freewrt.bin firmware &
Or via wget pipe:
[label=download and write a new firmware-file into flash]
# wget -O - http://www.yourserver.com/freewrt.bin | mtd -e firmware -r write - firmware &
The parameters explained in detail:
-e firmware
erase existing data in flash
-r
trigger rebooting right after finishing work
write
write the firmware image contained in the file given as next parameter to flash
freewrt.bin
the actual image to write – ignore the suffix, it is detected at runtime
firmware
this is an abstract identifier for a certain partition in flash, so don't change this
&
put the process into background, to prevent accidentally stopping