A script to install pepe2k's uboot mod

Recently I decided to try out pepe2k's custom uboot for my fleet of TP-Link TL-WR710N v1 devices, and in the process of doing that, I wrote a short script to install it on my live running devices out in the field.

Unfortunately the available installation options didn't meet my needs. I have devices out in the field and can't bring them back in or flash and image that will take them offline. So I wrote my own.

There are two important issues in play: The first is that we have to make the /dev/mtd0 device writable, which it normally isn't. We accomplish this by installing the kmod-mtd-rw package.

The second issue is combining the old uboot image unique data with the new uboot image. That's pretty easy to do locally.

Below is a draft of the script I wrote. Maybe someone else will find it useful some day. Be sure to customize the FILE_URL and SHA256SUM hash with your own.

There is minimal validation here, so make sure each command block was successful before moving on to the next one -- don't run this all at once.

# Define where we are going to get our custom uboot image from, and it's sha256 hash for verification.
FILE_URL=http://projects.dymacz.pl/u-boot_mod/u-boot_mod__tp-link_tl-wr710n_v1__20180223__git_master-7a540a78.bin
SHA256SUM=c0acbb4a08a6206c65fb5c9b300c7bd014946a29a8f7be009d0237efd61769ef

# Define common variables
MTD_DEV=/dev/mtd0
MTD_FILE=$(basename $MTD_DEV)
WORK_DIR=/tmp/ubootmod
NEW_FILE=$(basename $FILE_URL)

# Install the kmod-mtd-rw package and load the module.
opkg update
opkg install kmod-mtd-rw
insmod mtd-rw.ko i_want_a_brick=1

# Set up a work directory
mkdir $WORK_DIR
cd $WORK_DIR

# Download the new image file
wget $FILE_URL

# Verify the new file
NEW_HASH=$(sha256sum $NEW_FILE | cut -f 1 -d ' ')
if [[ "$NEW_HASH" == "$SHA256SUM" ]] ; then
  echo "File hash is good."
else
  echo "File hash is BAD! ABORT!"
fi

# Combine the old uboot image with the new one
dd if=$MTD_DEV of=${MTD_FILE}.orig
cp -ap ${MTD_FILE}.orig ${MTD_FILE}.new
dd if=$NEW_FILE of=${MTD_FILE}.new conv=notrunc

# Finally, install the new uboot
mtd -e $MTD_DEV write ${MTD_FILE}.new $MTD_DEV

# Clean up
rmmod mtd-rw.ko
opkg remove kmod-mtd-rw

Then reboot to find out if it worked or if you just broke your device. If it boots up normally, it probably worked.

To test, try holding down the power button for 3-4 seconds (four full LED blinks) and then if the LED flickers and starts fading in/out, then your device just entered http recovery mode.

I feel like this could be fully scripted into a package installed via opkg. That would make it super easy for people to install.

As documented, you can download pre-compiled image files here:

http://projects.dymacz.pl/?dir=u-boot_mod

Hm... mhm... and what about this one?

HEYO pepe2k!

I saw that script when I was looking at your project but for some reason I got the impression that it required previously-unlocked MTD partitions. Your installation instructions gave me the impression that this was a part of the pre-built OpenWRT images, and I didn't notice it does make use of the mtd-wr kmod.

I was clearly mistaken.

Anywyay, I had to apply this mod to a small fleet of 20 devices, so I needed to get rid of all of the user-prompting and locally set variables to make it so the script would work within a bash heredoc "<-- EOF" block which I run over ssh, so I was going to have to write my own anyway.

Something like this:

for D in $DEVICES ; do
  echo "Installing new uboot for $D"
  ssh ${D} <<- EOF
    # ... run all my commands here
    EOF
done
1 Like

if anybody found this looking for beginner info on the uboot mod i made a video on how to install and use it because i had trouble finding documentation. i had to bother the mod author by email a bit. so no one else has to do that i made the video here https://www.youtube.com/watch?v=i4A321qDbTU&t=174s

2 Likes