linksys.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Copyright (C) 2014-2015 OpenWrt.org
  3. #
  4. linksys_get_target_firmware() {
  5. cur_boot_part=`/usr/sbin/fw_printenv -n boot_part`
  6. target_firmware=""
  7. if [ "$cur_boot_part" = "1" ]
  8. then
  9. # current primary boot - update alt boot
  10. target_firmware="kernel2"
  11. fw_setenv boot_part 2
  12. #In EA8500 bootcmd is always "bootipq", so don't change
  13. #fw_setenv bootcmd "run altnandboot"
  14. elif [ "$cur_boot_part" = "2" ]
  15. then
  16. # current alt boot - update primary boot
  17. target_firmware="kernel1"
  18. fw_setenv boot_part 1
  19. #In EA8500 bootcmd is always "bootipq", so don't change
  20. #fw_setenv bootcmd "run nandboot"
  21. fi
  22. # re-enable recovery so we get back if the new firmware is broken
  23. fw_setenv auto_recovery yes
  24. echo "$target_firmware"
  25. }
  26. linksys_get_root_magic() {
  27. (get_image "$@" | dd skip=786432 bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
  28. }
  29. platform_do_upgrade_linksys() {
  30. local magic_long="$(get_magic_long "$1")"
  31. mkdir -p /var/lock
  32. local part_label="$(linksys_get_target_firmware)"
  33. touch /var/lock/fw_printenv.lock
  34. if [ ! -n "$part_label" ]
  35. then
  36. echo "cannot find target partition"
  37. exit 1
  38. fi
  39. local target_mtd=$(find_mtd_part $part_label)
  40. [ "$magic_long" = "73797375" ] && {
  41. CI_KERNPART="$part_label"
  42. if [ "$part_label" = "kernel1" ]
  43. then
  44. CI_UBIPART="rootfs1"
  45. else
  46. CI_UBIPART="rootfs2"
  47. fi
  48. nand_upgrade_tar "$1"
  49. }
  50. [ "$magic_long" = "27051956" ] && {
  51. # check firmwares' rootfs types
  52. local target_mtd=$(find_mtd_part $part_label)
  53. local oldroot="$(linksys_get_root_magic $target_mtd)"
  54. local newroot="$(linksys_get_root_magic "$1")"
  55. if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
  56. # we're upgrading from a firmware with UBI to one with UBI
  57. then
  58. # erase everything to be safe
  59. mtd erase $part_label
  60. get_image "$1" | mtd -n write - $part_label
  61. else
  62. get_image "$1" | mtd write - $part_label
  63. fi
  64. }
  65. }
  66. linksys_preupgrade() {
  67. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
  68. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
  69. export RAMFS_COPY_DATA="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
  70. [ -f /tmp/sysupgrade.tgz ] && {
  71. cp /tmp/sysupgrade.tgz /tmp/syscfg/sysupgrade.tgz
  72. }
  73. }
  74. append sysupgrade_pre_upgrade linksys_preupgrade