diff options
author | INAGAKI Hiroshi <musashino.open@gmail.com> | 2023-08-06 16:09:35 +0900 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2023-08-20 01:26:15 +0200 |
commit | 9088b5445f8e3586836820a63fd804941eda7b8a (patch) | |
tree | 4c49a53ea9ff9626035bc24db0198cca563f0f0c /target/linux/ramips | |
parent | 6cc14bf66aa924962b926ea9702b6153ae418a7d (diff) | |
download | openwrt-9088b5445f8e3586836820a63fd804941eda7b8a.tar.gz openwrt-9088b5445f8e3586836820a63fd804941eda7b8a.tar.bz2 openwrt-9088b5445f8e3586836820a63fd804941eda7b8a.zip |
ramips: improve sysupgrade helpers for I-O DATA devices
I-O DATA devices manufactured by MSTC (MitraStar Technology Corp.)
have some important flags for booting, "bootnum" and "debugflag".
The almost devices have both flags but some devices have only
"bootnum" flag.
So optimize helper functions in iodata.sh to set each flags.
- both:
- WN-AX1167GR2
- WN-AX2033GR
- WN-DX1167R
- WN-DX1200GR
- WN-DX2033GR
- "bootnum" only
- WN-DEAX1800GR
Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
Diffstat (limited to 'target/linux/ramips')
-rw-r--r-- | target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh | 90 | ||||
-rwxr-xr-x | target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh | 6 |
2 files changed, 61 insertions, 35 deletions
diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh index 8303ae9922..40b2b2c76b 100644 --- a/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh @@ -10,55 +10,79 @@ iodata_mstc_prepare_fail() { reboot -f } -# I-O DATA devices manufactured by MSTC (MitraStar Technology Corp.) -# have two important flags: -# - bootnum: switch between two os images -# use 1st image in OpenWrt -# - debugflag: enable/disable debug -# users can interrupt Z-Loader for recovering the device if enabled +# read/write 1byte in mtd device # # parameters: -# - $1: the offset of "debugflag" -iodata_mstc_upgrade_prepare() { - local persist_mtd="$(find_mtd_part persist)" - local factory_mtd="$(find_mtd_part factory)" - local dflag_offset="$1" +# $1: target mtd device ("/dev/mtdblockN") +# $2: offset of target value (decimal or hex) +# $3: value to set (decimal or hex, don't set when reading) +iodata_mstc_rw_byte() { + local mtd="$1" + local offset="$2" + local setval="$3" + local _val=$(hexdump -s $offset -n 1 -e '"%d"' $mtd) - if [ -z "$dflag_offset" ]; then - echo 'no debugflag offset provided' - iodata_mstc_prepare_fail + if [ -z "$setval" ]; then + echo $_val + return 0 fi - if [ -z "$persist_mtd" ] || [ -z "$factory_mtd" ]; then - echo 'cannot find mtd partition(s), "factory" or "persist"' - iodata_mstc_prepare_fail + # decimal or hex -> decimal + setval=$((setval)) + [ "$_val" = "$setval" ] && return 0 + setval="$(printf '%02x' $setval)" + + if ! (printf "\x$setval" | dd bs=1 seek=$((offset)) conv=notrunc of=$mtd 2>/dev/null); then + return 1 fi +} - local bootnum=$(hexdump -s 4 -n 1 -e '"%x"' ${persist_mtd}) - local debugflag=$(hexdump -s $((dflag_offset)) -n 1 -e '"%x"' ${factory_mtd}) +# set flag in mtd device on I-O DATA devices manufactured by MSTC +# (MitraStar Technology Corp.) +# +# parameters: +# $1: parameter name +# $2: mtd name contains target flag +# $3: offset of flag +# $4: valid flag values ("n,n,...", ex:"0,1" or "1,2") +# $5: value to set to the flag +iodata_mstc_set_flag() { + local name="$1" + local mtddev="$(find_mtd_part $2)" + local offset="$3" + local valid="$4" + local setval="$5" - if [ "$bootnum" != "1" ] && [ "$bootnum" != "2" ]; then - echo "failed to get bootnum, please check the value at 0x4 in ${persist_mtd}" + if [ -z "$offset" ]; then + echo "no $name flag offset provided" iodata_mstc_prepare_fail fi - if [ "$debugflag" != "0" ] && [ "$debugflag" != "1" ]; then - echo "failed to get debugflag, please check the value at ${dflag_offset} in ${factory_mtd}" + + if [ -z "$mtddev" ]; then + echo "cannot find \"$2\" mtd partition" iodata_mstc_prepare_fail fi - echo "current: bootnum => ${bootnum}, debugflag => ${debugflag}" - if [ "$bootnum" = "2" ]; then - if ! (echo -ne "\x01" | dd bs=1 count=1 seek=4 conv=notrunc of=${persist_mtd} 2>/dev/null); then - echo "failed to set bootnum" - iodata_mstc_prepare_fail + local flag=$(iodata_mstc_rw_byte "$mtddev" "$offset") + local _tmp + for i in ${valid//,/ }; do + if [ "$flag" = "$((i))" ]; then + _tmp=$flag + break fi - echo "### switch to 1st os-image on next boot ###" + done + + if [ -z "$_tmp" ]; then + echo "failed to get valid $name flag, please check the value at $offset in $mtddev" + iodata_mstc_prepare_fail fi - if [ "$debugflag" = "0" ]; then - if ! (echo -ne "\x01" | dd bs=1 count=1 seek=$((dflag_offset)) conv=notrunc of=${factory_mtd} 2>/dev/null); then - echo "failed to set debugflag" + echo "current: $name => $flag" + + if [ "$flag" != "$((setval))" ]; then + if ! iodata_mstc_rw_byte "$mtddev" "$offset" "$setval"; then + echo "failed to set \"$name\" flag" iodata_mstc_prepare_fail fi - echo "### enable debug ###" + echo " --> set \"$name\" flag to $setval (valid: $valid)" fi } diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh index 3c6d02f4fa..85e97b4f83 100755 --- a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh @@ -125,11 +125,13 @@ platform_do_upgrade() { iodata,wn-ax2033gr|\ iodata,wn-dx1167r|\ iodata,wn-dx2033gr) - iodata_mstc_upgrade_prepare "0xfe75" + iodata_mstc_set_flag "debugflag" "factory" "0xfe75" "0,1" "1" + iodata_mstc_set_flag "bootnum" "persist" "0x4" "1,2" "1" nand_do_upgrade "$1" ;; iodata,wn-dx1200gr) - iodata_mstc_upgrade_prepare "0x1fe75" + iodata_mstc_set_flag "debugflag" "factory" "0x1fe75" "0,1" "1" + iodata_mstc_set_flag "bootnum" "persist" "0x4" "1,2" "1" nand_do_upgrade "$1" ;; tplink,er605-v2) |