linksys.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. # remove "squashfs" vol (in case we are flashing over a stock image, which is also UBI)
  49. local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
  50. if [ ! "$mtdnum" ]; then
  51. echo "cannot find ubi mtd partition $CI_UBIPART"
  52. return 1
  53. fi
  54. local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  55. if [ ! "$ubidev" ]; then
  56. ubiattach -m "$mtdnum"
  57. sync
  58. ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  59. fi
  60. if [ "$ubidev" ]; then
  61. local squash_ubivol="$( nand_find_volume $ubidev squashfs )"
  62. # kill volume
  63. [ "$squash_ubivol" ] && ubirmvol /dev/$ubidev -N squashfs || true
  64. fi
  65. # complete std upgrade
  66. nand_upgrade_tar "$1"
  67. }
  68. [ "$magic_long" = "27051956" ] && {
  69. # check firmwares' rootfs types
  70. local oldroot="$(linksys_get_root_magic $target_mtd)"
  71. local newroot="$(linksys_get_root_magic "$1")"
  72. if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
  73. # we're upgrading from a firmware with UBI to one with UBI
  74. then
  75. # erase everything to be safe
  76. mtd erase $part_label
  77. get_image "$1" | mtd -n write - $part_label
  78. else
  79. get_image "$1" | mtd write - $part_label
  80. fi
  81. }
  82. }
  83. linksys_preupgrade() {
  84. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
  85. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
  86. export RAMFS_COPY_DATA="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
  87. }
  88. append sysupgrade_pre_upgrade linksys_preupgrade