untested hack but may help
#!/bin/sh
cat <<EOF >devices.tmp
"Linksys EA3500", "linksys-audi", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys E4200v2/EA4500", "linksys-viper", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys EA6350v3", "linksys-ea6350v3", "mtd10", "mtd12", 192, "boot_part", 1, 2
"Linksys EA8300", "linksys-ea8300", "mtd10", "mtd12", 192, "boot_part", 1, 2
"Linksys EA8500", "ea8500", "mtd13", "mtd15", 32, "boot_part", 1, 2
"Linksys EA9500", "linksys-panamera", "mtd3", "mtd6", 28, "boot_part", 1, 2
"Linksys WRT1200AC", "linksys-caiman", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys WRT1900AC", "linksys-mamba", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys WRT1900ACv2", "linksys-cobra", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys WRT1900ACS", "linksys-shelby", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Linksys WRT3200ACM", "linksys-rango", "mtd5", "mtd7", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"NETGEAR WNDR3700", "netgear-wndr3700v2", "mtd3", "mtd1", nil, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"
"Synology RT2600AC", "rt2600ac", "mmcblk0p1", "mmcblk0p3", 256, "emmc", 1, 2
"ZyXEL NBG6817","nbg6817","mmcblk0p4","mmcblk0p7", 32, nil, 255, 1
EOF
MODEL=$(cat /etc/board.json 2>/dev/null | jsonfilter -e '@["model"]["id"]' 2>/dev/null)
RTRNAME=$(cat /etc/board.json 2>/dev/null | jsonfilter -e '@["model"]["name"]' 2>/dev/null)
if ! cat /proc/cmdline | grep -q 'root='; then
echo "no root= on cmdline"; sleep 2
rootdev="`cat /proc/mtd | grep kernel | cut -d':' -f1`"
else
if read cmdline < /proc/cmdline; then
case "$cmdline" in
*root=*)
rootpart="${cmdline##*root=}" #echo "rootpart1: $rootpart"
rootpart="${rootpart%% *}"
rootdev="`echo ${rootpart} | cut -b6-`"
;;
esac
else
echo "cannot read cmdline" && exit 1
fi
fi
while IFS=, read dev nm p1 p2 oset un1 un1v1 un1v2 un2 un2v1 un2v2; do
#echo "dbg1: un1: $un1"
if [ "$un1" = "nil" -o "$un1v1" -eq 255 ]; then
rtrclass=3;
elif [ -z "$un2" ]; then
rtrclass=1;
else
rtrclass=2;
fi
echo "############################################## CLASS:$rtrclass"
echo " device: $dev $nm"
echo " un1: $un1:$un1v1 $p1"
echo " un1: $un1:$un1v2 $p2"
echo " offset: $oset"
if [ ! -z "$un2" ]; then echo " un2: $un2"; fi
if [ ! -z "$un2v1" ]; then echo " un2v1: $un2v1"; fi
if [ ! -z "$un2v2" ]; then echo " un2v2: $un2v2"; fi
dev=$(echo $dev | cut -d'"' -f2)
un1=$(echo $un1 | cut -d'"' -f2)
un1v1=$(echo $un1v1 | cut -d'"' -f2)
un1v2=$(echo $un1v2 | cut -d'"' -f2)
p1=$(echo $p1 | cut -d'"' -f2)
p2=$(echo $p2 | cut -d'"' -f2)
un2=$(echo $un2 | cut -d'"' -f2)
un2v1=$(echo $un2v1 | cut -d'"' -f2)
un2v2=$(echo $un2v2 | cut -d'"' -f2)
oset=$(echo $oset | sed "s! !!")
if [ "$RTRNAME" == "$dev" ]; then
thisclass="$rtrclass"
echo "$dev [match]"
break
else
echo "$dev [no match]"
fi
done < devices.tmp
if [ -z "$thisclass" ]; then echo "model: $RTRNAME unsupported" && exit 1; fi
echo "############################################## CLASS:$rtrclass"
echo " device: $dev $nm"
echo " un1: $un1:$un1v1 $p1"
echo " un1: $un1:$un1v2 $p2"
echo " offset: $oset"
if [ ! -z "$un2" ]; then echo " un2: $un2"; fi
if [ ! -z "$un2v1" ]; then echo " un2v1: $un2v1"; fi
if [ ! -z "$un2v2" ]; then echo " un2v2: $un2v2"; fi
echo ""
sleep 2
if [ "$rootdev" != "$p1" ]; then
echo "################ current rootdev: $rootdev is not p1:$p1"
else
echo "################ current rootdev: $rootdev is p1:$p1"
fi
if [ "$rootdev" != "$p2" ]; then
echo "################ current rootdev: $rootdev is not p2:$p2"
else
echo "################ current rootdev: $rootdev is p2:$p2"
fi
case "$osp1" in
*"LEDE"*)
echo "os-p1: is LEDE"
;;
*"OpenWrt"*)
echo "os-p1: is OpenWrt"
;;
*"Linksys"*)
echo "os-p1: is Linksys"
;;
*"ZyXEL"*)
echo "os-p1: is ZyXEL"
;;
*"Synology"*)
echo "os-p1: is Synology"
;;
*)
echo "os-p1: is unknown"
;;
esac
case "$osp2" in
*"LEDE"*)
echo "os-p1: is LEDE"
;;
*"OpenWrt"*)
echo "os-p1: is OpenWrt"
;;
*"Linksys"*)
echo "os-p1: is Linksys"
;;
*"ZyXEL"*)
echo "os-p1: is ZyXEL"
;;
*"Synology"*)
echo "os-p1: is Synology"
;;
*"DD-WRT"*)
echo "os-p1: is DD-WRT"
;;
*)
echo "os-p1: is unknown"
;;
esac
case $thisclass in
1)
curu1="`fw_printenv | grep "$un1=" | cut -d'=' -f2`"
if [ "$curu1" = "$un1v1" ]; then
newun1="$un1v2"
pcheck="$p1"
echo "current env1: $un1 is $curu1 > $newun1"
elif [ "$curu1" = "$un1v2" ]; then
newu1="$un1v1"
pcheck="${p2}"
echo "current env1: $un1 is $curu1 > $newun1"
else
echo "un1: $un1 is $curu1 no match for 1:$un1v1 2:$un1v2"
fi
if ! echo $rootpart | grep -q "$pcheck"; then
echo "warning: rootpart $rootpart checkfail != $pcheck"
fi
echo ""
echo "> fw_setenv $un1 $newun1"
echo "> reboot"
;;
2)
curu1="`fw_printenv | grep "$un1=" | cut -d'=' -f2`"
if [ "$curu1" = "$un1v1" ]; then
newun1="$un1v2"
pcheck="$p1"
echo "un1: $un1 is $curu1 > $newun1"
elif [ "$curu1" = "$un1v2" ]; then
newu1="$un1v1"
pcheck="${p2}"
echo "un1: $un1 is $curu1 > $newun1"
else
echo "un1: $un1 is $curu1 no match for 1:$un1v1 2:$un1v2"
fi
curu2="`fw_printenv | grep "$un2=" | cut -d'=' -f2`"
if [ "$curu2" = "$un2v1" ]; then
newun2="$un2v2"
echo "current env2: $un2 is $curu2 > $newun2"
elif [ "$curu2" = "$un2v2" ]; then
newun2="$un2v1"
echo "current env2: $un2 is $curu2 > $newun2"
else
echo "un2: $un2 is $curu2 no match for 1:$un2v1 or 2:$un2v2"
fi
echo "> fw_setenv $un1 $newun1"
echo "> fw_setenv $un2 $newun2"
echo "> reboot"
if ! echo $rootpart | grep -q "$pcheck"; then
echo "###### warning: rootpart $rootpart checkfail != $pcheck ######"
fi
;;
3)
echo "fw_printenv CLASS3 | grep $un2 | grep $un2v1"
;;
5)
echo "fw_printenv CLASS5 | grep $un2 | grep $un2v1"
;;
*)
echo "fw_printenv disabled unknown class: $thisclass"
:
;;
esac
exit 0
missing the payload end... but might be enough for you to squeeze your specific disk read logix in... from memory the linksys stuff is mostly grouped under the same logic so you might be catching an edge case on it. badblocks maybe...