2 # Copyright (C) 2023 OpenWrt.org
7 zyxel_mstc_prepare_fail
() {
8 echo "failed to check and prepare the environment, rebooting..."
13 zyxel_mstc_upgrade_prepare
() {
14 local persist_mtd
="$(find_mtd_part persist)"
15 local firmware_mtd
="$(find_mtd_part firmware)"
17 if [ -z "$persist_mtd" ] ||
[ -z "$firmware_mtd" ]; then
18 echo 'cannot find mtd partition(s) "persist" or "firmware"'
19 zyxel_mstc_prepare_fail
22 local bootnum
=$
(hexdump -s 4 -n 1 -e '"%x"' ${persist_mtd})
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
28 echo "current: bootnum => ${bootnum}"
30 [ "$(fw_printenv -n bootmenu_delay)" = "3" ] || fw_setenv bootmenu_delay
3
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
37 echo "### switch to 1st os-image on next boot ###"