2
0

zyxel.sh 1.0 KB

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