Installing OpenWrt via TFTP

Go back to generic.flashing

TFTP is a very simple protocol, simple enough to be implemented in small boot loaders. The basic idea is that when the router gets powered on, then for a few seconds it initializes the wired lan ports, and listens to TFTP requests for transferring a flash image. Then either flashes the received image, or continues booting the device normally if the TFTP communication timed out.

Warning!
This section describes actions that might damage your device or firmware. Proceed with care!

Bootloader contains TFTP client

Example1

For example the bootloader implementation of the DIR-300 redboot contains a TFTP client. Two steps:

  1. first you install and start a TFTP server (or daemon) on your host and place the image(s) to be flashed in the <root directory> of this software (you may be required to do this as root). Example:
    sudo apt­-get install tftpd­-hpa
    sudo cp ~/uboot/arch/arm/boot/uboot.img /var/lib/tftpboot
    
  2. Test the server:
    sudo apt­-get install tftp-­hpa
    tftp localhost
    > get uboot.img
    
  3. connect to the bootloader, and tell it to get the images on your harddisk via its TFTP client (in case of the DIR-300 you obtain a connection via telnet on the non-default port 9000). Example:
    telnet 192.168.20.81 9000
    Redboot> load uboot.img
    go
  4. after successful installation of OpenWrt, do not forget to deactivate the TFTP server again!

Example2

In case of the xxx Step 3 from Example 1 above is not applicable. There is no console to login to, the bootloader will automatically try to get a firmware over TFTP from a pre-configured IP address at every boot.

FIXME TODO

Bootloader contains TFTP server

TODO


Cleanup Required!
This page or section needs cleanup. You can edit this page to fix wiki markup, redundant content or outdated information.

Please check Bootloader functionality to understand what you will be doing here. ;-)

Although you can install the firmware through more traditional means (via webpage), there are reasons to install via TFTP. This is NOT a requirement, simply a damned good idea if you use self compiled firmware images; if anything goes wrong you can just TFTP the old firmware back.

When the device boots it runs a bootloader. It's the responsibility of this bootloader to perform basic system initialization along with validating and loading the actual firmware; think of it as the BIOS of the device before control is passed over to the operating system. Should the firmware fail to pass a CRC check, the bootloader will presume the firmware is corrupt and wait for a new firmware to be uploaded over the network. The type of the preinstalled bootloader depends on your router model: Atheros based routers use RedBoot or Das U-Boot, Broadcom based routers use CFE or RedBoot or PMON, Texas Instruments based routers use. See bootloader

The basic procedure of using a tftp client to upload a new firmware to your router:

  • unplug the power to your router
  • start your tftp client
  • give it the router's address (usually 192.168.1.1)
  • set mode to octet/binary
  • tell the client to resend the file, until it succeeds.
  • put the file
  • plug your router, while having the tftp client running and constantly probing for a connection
  • the tftp client will receive an ack from the bootloader and starts sending the firmware

:!: Please be patient, the reflashing occurs after the firmware has been transferred. In most cases the router will automatically reboot itself. Some models like the WL500GP do not reboot, wait at least 15 minutes before power cycling then.

:!: Note that the bootloader usually does not use the IP address stored in nvram, it will revert to the factory default instead, which is 192.168.1.1 in most cases.

:!: Put a hub or switch between the router and the computer, this will make sure that the local computer link is up before the boot_wait period is passed. This is a requirement to make TFTP work on computers where the local link is brought up too late.

On routers with a DMZ LED, OpenWrt will light the DMZ LED while booting, after the bootup scripts are finished it will turn off the DMZ LED.

The TFTP commands vary across different implementations. Here are some examples:

Linux/BSD

:!: If you get an ACK from your router but don't send any data, try a different tftp client - atftp works well. This occurs with some netkit tftp packages.

:!: If you can flash your router and after that it says "Boot program checksum is invalid" or "Invalid boot block on disk" on serial console try a different tftp client - atftp works well. This occurs with some netkit tftp packages and big firmwares.

:!: The link must be up in the few seconds long TFTP time window. Make sure that no programs mess with the interface config when the cable gets plugged in/out (router power cycle). A typical problem is when Network Manager has a wired DHCP connection set to auto connect.

First you need to make sure that you can reach the router on your network, and that it can reach you. If you are using an existing machine which is not on 192.168.1.x, you can temporarily add an interface alias (on most modern Linux distros). Presuming that the correct network interface is eth0 (if you don't know, assume that it's eth0), run this as root:

ifconfig eth0:1 192.168.1.5 netmask 255.255.255.0

When you're done configuring the router, run this (as root again) to take the alias down

ifconfig eth0:1 down

Using atftp

(atftp source code: http://downloads.openwrt.org/sources/atftp-0.7.tar.gz)

As a single command-line:

atftp --trace --option "timeout 1" --option "mode octet" --put --local-file openwrt-xxx-x.x-xxx.bin 192.168.1.1

Step by step:

atftp
connect 192.168.1.1
mode octet
trace
timeout 1
put openwrt-xxx-x.x-xxx.bin

Using netkit's tftp

As a single command-line:

echo -e "binary\nrexmt 1\ntimeout 60\ntrace\nput openwrt-xxx-x.x-xxx.bin\n" | tftp 192.168.1.1

Step by step:

tftp 192.168.1.1
binary
rexmt 1
timeout 60
trace
Packet tracing on.
tftp> put openwrt-xxx-x.x-xxx.bin

Setting "rexmt 1" will cause the tftp client to constantly retry to send the file to the given address. As advised above, plug in your box after typing the commands, and as soon as the bootloader starts to listen, your client will successfully connect and send the firmware. You can try to run "ping -f 192.168.1.1" (as root) in a separate window and enter the line "put openwrt-xxx-x.x-xxx.bin" as the colons stop running over your terminal when you power-recycle your router.

Note: for some versions of the CFE bootloader, the last line may need to be "put openwrt-xxx-x.x-xxx.bin code.bin". If this does not work try other variations instead of code.bin - e.g. openwrt-g-code.bin or openwrt-gs-code.bin. One CFE version only worked after renaming the '….bin' file to 'code.bin'. From Linux Ubuntu I then used the command 'tftp -m binary 192.168.1.1 -c put code.bin' and the transfer process came to life.

MacOS X

On Mac OS X, you should be able to flash the router with the command line tftp client, which behaves identically to netkit's tftp above.

Some people have had problems with the command line tftp client, however, and recommend using MacTFTP Client instead:

  • Download, install, and open MacTFTP
  • Choose Send
  • Address: 192.168.1.1
  • Choose the openwrt-xxx-x.x-xxx.bin file
  • Click on start while applying power to the WRT54G

Many Macs will disable the Ethernet card when the router is powered off and will take too long to re-enable the card, causing the TFTP transfer to fail with an "Invalid Password" error. Many people have had success if they manually configure their network card (in the "Ethernet" tab of "Built-in Ethernet" in System Preferences' Network panel) to:

  • Configure: Manual (Advanced)
  • Speed: 10 BaseT/UTP
  • Duplex: full-duplex

Alternatively, you can connect the router to the Mac via a hub or switch; see below for more information.

tftpd server on Mac OS X Lion

OS X Lion comes with a tftpd but its disabled by default. Like most services in OS X, tftpd is controlled by launchctl. The configuration with which the daemon is lauched is in /System/Library/LaunchDaemons/tftp.plist and the the identifier is com.apple.tftpd

before you make changes to the config run:

sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist

after:

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist

to stop tftpd run:

sudo launchctl stop com.apple.tftpd

to start tftpd run:

sudo launchctl start com.apple.tftpd

Here is an example config file that will works:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.apple.tftpd</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/libexec/tftpd</string>
		<string>-l</string>
		<string>-s</string>
		<string>/private/tftpboot</string>
	</array>
	<key>inetdCompatibility</key>
	<dict>
		<key>Wait</key>
		<true/>
	</dict>
	<key>InitGroups</key>
	<true/>
	<key>Sockets</key>
	<dict>
		<key>Listeners</key>
		<dict>
			<key>SockServiceName</key>
			<string>tftp</string>
			<key>SockType</key>
			<string>dgram</string>
		</dict>
	</dict>
</dict>
</plist>

Differences from the default include removing this, to enable the service:

<key>Disabled</key>
<true/>

Adding this to make it log to /var/log/syslog.log

<string>-l</string>

and place the openwrt image file we want to serve in:

<string>/private/tftpboot</string>

Notice that even after running launchctl start com.apple.tftpd you will not see tftpd running when executing ps aux | grep tftpd because of the way launchctl works. tftpd is in fact not running but launchctl will launch it as soon as it is required.

In some cases, when the output on the serial console is grabbled you can still act on faith and executer the following commands, which will work in most cases:

setenv ipaddr 192.168.1.1
setenv serverip 192.168.1.100
tftpboot 0x80000000 openwrt-xxx-generic-xxx-squashfs-factory.bin
erase 0x9f020000 +0x332004
cp.b 0x80000000 0x9f020000 0x332004
boot.m 0x9f020000

Windows 2000/XP

Windows 2000 and Windows XP have a built-in TFTP client and it can be used to flash with OpenWrt firmware.

Important: If you have a personal firewall, make sure it is disabled for this part. Some personal firewalls will not give any indication that they have blocked the tftp client. Please bear in mind that you should only be connected to the router when your personal firewall is disabled to avoid any nastiness, and remember to re-enable it when you are done.

Windows 2000/XP TFTP Client short Instructions

  • Open two command windows (Start-Run-Enter "cmd")
  • In one window, type "ping -t -w 10 192.168.1.1" and press enter. 192.168.1.1 is the router IP.
  • Ping will continuously try to contact the wrt with 10 ms timeout instead of default 4000 ms. Keep this running
  • In the other window, prepare the tftp command "tftp -i 192.168.1.1 PUT OpenWrt-gs-code.bin". Do not press enter yet!
  • Now you may plug in the router (unplug it first if it was plugged).
  • In the ping window it will start saying "Hardware Error"
  • Return to the tftp window. As soon as the ping window starts to answer again, press enter in the tftp window.
  • The image should now be flashed without multiple tries.
  • If ping starts with "Hardware Error", then starts to answer, and then returns to "Hardware Error" again for a short moment, you waited too long.

if you have a openwrt54gl (v1.1 testet) the timespan might be very short and is located about 2 seconds after pluging in and about 1 second before the ping starts to answer.

Note: if your computer set DHCP, you may not get "Hardware Error" but "Destination host unreachable" or "Request timeout". Set your computer static IP before.

Troubleshooting

Don't forget about your firewall settings, if you use one. It is best to run the "put" command and then immediately apply power to the router, since the upload window is extremely short and very early in boot.

TFTP Error Reason
Code pattern is incorrect The firmware image you're uploading was intended for a different model.
Invalid Password The firmware has booted and you're connected to a password protected tftp server contained in the firmware, not the bootloader's tftp server.
Timeout Ping to verify the router is online
Try a different tftp client (some are known not to work properly)

Some machines will disable the ethernet when the router is powered off and not enable it until after the router has been powered on for a few seconds. If you're consistantly getting "Invalid Password" failures try connecting your computer and the router to a hub or switch. Doing so will keep the link up and prevent the computer from disabling its interface while the router is off.

Before you go searching for a hub to keep your link live, try setting your TCP/IP setting to a static IP (192.168.1.10; 255.255.255.0; 192.168.1.1 [gateway]) method instead of DHCP.

Example

On many routers, including the Asus WL-500g Premium v1 that I use, you flash an image by disconnecting power, press and hold down the reset button, and connect the power again. Wait a few seconds and the PWR LED will start to blink. Release the reset button. The device will now have a TFTP server running on 192.168.1.1.

You’ll have to use a Ethernet cable at this point. Connect it to LAN1-LAN4, not WAN. Configure your local machine on the 192.168.1.x/24 network, for example as 192.168.1.42. The router will use 192.168.1.1.

$ tftp 192.168.1.1
tftp> trace
Packet tracing on.
tftp> binary
tftp> put openwrt-brcm-2.4-squashfs.trx
sent WRQ <file=openwrt-brcm-2.4-squashfs.trx, mode=octet>
received ACK <block=0>
sent DATA <block=1, 512 bytes>
received ACK <block=1>
sent DATA <block=2, 512 bytes>
received ACK <block=2>
sent DATA <block=3, 512 bytes>
received ACK <block=3>
sent DATA <block=4, 512 bytes>
...
received ACK <block=4742>
sent DATA <block=4743, 512 bytes>
received ACK <block=4743>
sent DATA <block=4744, 512 bytes>
received ACK <block=4744>
sent DATA <block=4745, 0 bytes>
received ACK <block=4745>
Sent 2428928 bytes in 6.2 seconds
tftp> quit
$

Wait one minute and restart the box by disconnecting and reconnecting power. Some documentations claim that the device should restart by itself but I have never seen this happen, no matter how long I wait.

What TFTP client should I use to flash my device?

Which ever you want!

Some people suggest atftp with GNU/Linux and other *ixes, and on Windows one of the following:

MAC OS X

Getting tftp to work in MacOSX "Lion"

If you get "tftp: timeout", use below

below from http://forums.creativecow.net/thread/180/857349

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist

sudo launchctl start com.apple.tftpd

You will get errors like this

below from http://www.linuxsmiths.com/blog/?p=427

tftp: server says: File not found

to fix it use

cd /var/tftpboot touch (the file in your tmp dir that you are going to send)

chmod 777 (the file in your tmp dir that you are going to send)

then do the tftp command again (ie: # tftp -p -l /tmp/mtd1 192.168.2.2)

TODO

Back to top

doc/howto/generic.flashing.tftp.txt · Last modified: 2012/05/08 17:00 by attila.lendvai