Wednesday, July 16, 2025

Recovering TP-LINK router

 My WDR430 router has been bricked for a while.

Initially I tied to reflash it using a SOIC clip but alas, that proved impossible as I had no level shifters for 1.8 V flash. Therefore I soldered an UART interface and tried to flash it via serial. That wasn't as easy as I was never able to pres the U-Boot interupt sequence `tpl` fast enough. 
The solution was to write an expect script and use that - worked perfectly :)
 

<

#!/usr/bin/expect -f

#!/usr/bin/expect -f

# Show all output
log_user 1

# Start cu
spawn cu -l /dev/ttyUSB0 -s 115200

# Increase timeout
set timeout 180

# Wait for autoboot
expect {
    -re "Autobooting.*1 seconds" {
        send "tpl\r"
        sleep 1
    }
    timeout {
        puts "Timeout waiting for autoboot message."
        exit 1
    }
}

# Send tftpboot
send "tftpboot\r"

# Wait for done after tftpboot
expect {
    -re ".*done.*" {
        send "erase\r"
    }
    timeout {
        puts "Timeout waiting for 'done' after tftpboot."
        exit 1
    }
}

# Wait for done after erase
expect {
    -re ".*done.*" {
        send "cp.b\r"
    }
    timeout {
        puts "Timeout waiting for 'done' after erase."
        exit 1
    }
}

# Wait for done after cp.b
expect {
    -re ".*done.*" {
        puts "All steps completed."
        interact
    }
    timeout {
        puts "Timeout waiting for 'done' after cp.b."
        exit 1
    }
}