ramips: mt7621: add support for ZyXEL WSM20
[openwrt/staging/wigyori.git] / target / linux / ramips / mt7621 / base-files / lib / upgrade / zyxel.sh
1 #
2 # Copyright (C) 2023 OpenWrt.org
3 #
4
5 . /lib/functions.sh
6
7 zyxel_mstc_prepare_fail() {
8 echo "failed to check and prepare the environment, rebooting..."
9 umount -a
10 reboot -f
11 }
12
13 zyxel_mstc_upgrade_prepare() {
14 local persist_mtd="$(find_mtd_part persist)"
15 local firmware_mtd="$(find_mtd_part firmware)"
16
17 if [ -z "$persist_mtd" ] || [ -z "$firmware_mtd" ]; then
18 echo 'cannot find mtd partition(s) "persist" or "firmware"'
19 zyxel_mstc_prepare_fail
20 fi
21
22 local bootnum=$(hexdump -s 4 -n 1 -e '"%x"' ${persist_mtd})
23
24 if [ "$bootnum" != "1" ] && [ "$bootnum" != "2" ]; then
25 echo "failed to get bootnum, please check the value at 0x4 in ${persist_mtd}"
26 zyxel_mstc_prepare_fail
27 fi
28 echo "current: bootnum => ${bootnum}"
29
30 [ "$(fw_printenv -n bootmenu_delay)" = "3" ] || fw_setenv bootmenu_delay 3
31
32 if [ "$bootnum" = "2" ]; then
33 if ! ( echo -ne "\x01" | dd of=${persist_mtd} count=1 bs=1 seek=4 conv=notrunc 2>/dev/null ); then
34 echo "failed to set new boot partition"
35 zyxel_mstc_prepare_fail
36 fi
37 echo "### switch to 1st os-image on next boot ###"
38 fi
39 }