For my reference in the future I will record here the steps that I had to follow in order to install Openwrt on the tp-link router EX220. This was done using a Windows 11 machine.
Disclaimer: Use this tutorial at your own risk. We are not responsible for any damage/harms done to your device using the information from this tutorial.
These are the steps provided at the official https://openwrt.org/toh/tp-link/ex220_v1 page:
1. Establish a serial connection.
2. Set up a TFTP server and copy both initramfs and sysupgrade images there.
3. Power on the device and press any key to interrupt normal boot.
4. Load the initramfs image using tftpboot.
5. Boot with bootm.
6. If you haven't done so already, back up all stock mtd partitions.
7. Copy the sysupgrade image to the router.
8. Flash OpenWrt through either LuCI or the sysupgrade command. Remember not to attempt saving settings.
Next we will detail each one of them.
For this we will need the following pieces of hardware:
- USB to TTL adaptor (CP2102)
- Ethernet cable
- Female Female jump connectors (3x)
- Header pins
- Start by opening the router and soldering the header pins to the UART port
- Connect the 3 jumper connectors (
3V3- GND - RX - TX) - In my case I had to bend the pins, otherwise it would not be possible to close the case. This is the result:
- Start by installing Putty
- Connect the CP2102 adapter to your PC and go to Device Manager. Check the COM ports and take note of it
- Open Putty and configure it using the correct serial line to connect to. In my case it is the COM4 (as show above). Also set the Speed (baud) to 115200, Data bits to 8, Stop bits to 1, Parity to None and Flow Control to None.
- (optional) Save the Session
- (optional) Make sure that your CP2102 adapter is working. You can do a loopback test by connecting the RXD to the TXD port, and writing anything in the Putty console (if it is working you will see the text that you are writing at the console, otherwise nothing will appear).
- Connect the CP2102 adapter to your router (GND, RX and TX only). Do not connect the 3.3V pin from the router to your adapter.
- Open the Putty console using the configurations from step 3
- Turn on the router. You will start to see (in the Putty console) a lot of (readable) textual information received from the router.
- Turn off the router.
With this we now confirm that the serial communication between the PC and the Router is working. We can proceed to the TFTP step.
- Download the tftpd64 program (the portable version)
- Download the initramfs image (check the link from the official page)
- (optional) Rename the image name to initramfs.bin
- Copy the image file to the root directory of tftp64
- Click on the program tftp64.exe and configure it by going into Settings. Go to GLOBAL tab and check only the TFTP Server checkbox. Go to the TFTP tab and configure like the image below:
- You can close the program after configuring it
- (optional) Deactivate the Wifi and turn off the firewall (not sure if this is necessary)
- Configure your Ethernet to use Manual IPv4 (instead of DHCP):
- IP Address: the same from tftp64, in our case, 192.168.0.2
- Mask: 255.255.255.0
- Gateway: 192.168.0.1
- DNS: any, I am using the 8.8.8.8
- Connect your router to your PC via the ethernet cable.
- Connect your router to your PC via USB (CP2102) adapter
We are now ready to copy the initramfs file to the router.
- Open a new Putty console (using the settings from step 3 of section Accessing the Console)
- Turn on the router and click any key on the Putty console. You need to be fast, otherwise the normal boot will not be interupted.
- If everything works, now you should be seeing a screen with the U-Boot Boot Menu.
- Press DOWN to move and ENTER the option
0. U-Boot console
The initramfs image is like a OpenWRT "test driven" image that lives only in the RAM. That means that it will be erased as soon as you turn off the router. We will need to load this image on the RAM of our router (for backup reasons and to copy the sysupgrade.bin to the /tmp/ directory). For our case we are using the address 0x80010000
. The reason to use this address is that this was the one used when we tried to load the image using the 5. Load Image
option. Not sure if this is correct (it worked for us).
At the U-Boot console, enter the following commands:
setenv ipaddr 192.168.0.1
setenv serverip 192.168.0.2
tftpboot 0x80010000 initramfs.bin
bootm 0x80010000
Wait for a while. At some point no new text will appear at the console. At this point you can hit Enter.
BusyBox v1.36.1 (2024-02-04 00:12:51 UTC) built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt SNAPSHOT, r25002-6e8df06fc1
-----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
We can now proceed to the Backup.
There are different ways to do this. The one that worked for us was by setting a SSH server on the windows PC and accessing it via Dropbear client on the router. We will not detail how to setup an SSH Server on Windows. But notice that it was important that the (a) server was configured password-less, (b) default WSL2 shell and (c) Server IP 192.168.1.2, Port 2222. An excelent guide by Adam Fields can be found here. Other resource used was the Microsoft Get started with OpenSSH for Windows page.
For me this was the trickiest part...
- You can close the tftpd64.exe program (we will no longer need TFTP).
- At your Windows PC, configure the Ethernet to Manual IPv4 with IP 192.168.1.2, Mask 255.255.255.0, Gateway 192.168.1.0, DNS 8.8.8.8. The motivation for this is that the router is with 192.168.1.1 IP address (you can confirm with the ifconfig command), and we need to be in the same net (also, IIRC, it is using SSH to listen for incoming connections at port 22, that is why we used port 2222 for the Windows SSH server).
- At the Openwrt "console" enter the follwing commands:
mkdir ~/.ssh
dropbearkey -t rsa -f ~/.ssh/id_dropbear
- Copy the generated public key to the file .ssh\authorized_keys on the Windows PC (you can do this by clicking with the mouse right buttom at the Putty taskbar and "Copy all to Clipboard").
- Restart the SSH service using a PowerShell console and the command:
Restart-Service sshd
- Using Putty/OpenWRT, create a backup script at the tmp directory:
cat << "EOF" > /tmp/backup.sh
, and the enter:
#!/bin/sh
BACKUP_HOST="192.168.1.2"
BACKUP_USER="CHANGETOYOURWINDOWSUSERNAME"
echo "Backup host ${BACKUP_HOST}"
cat /proc/mtd | tail -n+2 | while read; do
MTD_DEV=$(echo ${REPLY} | cut -f1 -d:)
MTD_NAME=$(echo ${REPLY} | cut -f2 -d\")
echo "Backing up ${MTD_DEV} (${MTD_NAME})"
dd if=/dev/${MTD_DEV}ro | dbclient ${BACKUP_USER}@${BACKUP_HOST} -p 2222 "dd of=~/${MTD_DEV}_${MTD_NAME}.backup"
done
EOF
- Run the script:
sh /tmp/backup.sh
- If everything works, now you will have your backup files at the WSL FS (hint, use
explorer.exe .
to copy the files outside the VM). - (optional) Turn off the router. Disconnect the adaptor. Turn off your PC.
We now need to copy the sysupgrade image to the router (tmp directory). This time the router will be the server and the PC will be the client. For more info see "Troubleshooting, If you cant use 'wget'".
- Repeat Steps 1 - 5 (in case you turned off the router/PC)
- Use scp:
scp openwrt-ramips-mt7621-tplink_ex220-v1-squashfs-sysupgrade.bin [email protected]:/tmp
(Ensure you have set a non-null password for your device root account to properly use scp).
We will use the sysupgrade command.
- Execute command
sysupgrade -v /tmp/firmware_image.bin
. More info here, "Flash the new OpenWrt firmware" .