linksys.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #
  2. # Copyright (C) 2014 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. fw_setenv bootcmd "run altnandboot"
  13. elif [ "$cur_boot_part" = "2" ]
  14. then
  15. # current alt boot - update primary boot
  16. target_firmware="kernel1"
  17. fw_setenv boot_part 1
  18. fw_setenv bootcmd "run nandboot"
  19. fi
  20. echo "$target_firmware"
  21. }
  22. linksys_get_root_magic() {
  23. (get_image "$@" | dd skip=786432 bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
  24. }
  25. platform_do_upgrade_linksys() {
  26. local magic_long="$(get_magic_long "$1")"
  27. mkdir -p /var/lock
  28. local part_label="$(linksys_get_target_firmware)"
  29. touch /var/lock/fw_printenv.lock
  30. if [ ! -n "$part_label" ]
  31. then
  32. echo "cannot find target partition"
  33. exit 1
  34. fi
  35. local target_mtd=$(find_mtd_part $part_label)
  36. [ "$magic_long" = "73797375" ] && {
  37. CI_KERNPART="$part_label"
  38. if [ "$part_label" = "kernel1" ]
  39. then
  40. CI_UBIPART="rootfs1"
  41. else
  42. CI_UBIPART="rootfs2"
  43. fi
  44. nand_upgrade_tar "$1"
  45. }
  46. [ "$magic_long" = "27051956" ] && {
  47. # check firmwares' rootfs types
  48. local target_mtd=$(find_mtd_part $part_label)
  49. local oldroot="$(linksys_get_root_magic $target_mtd)"
  50. local newroot="$(linksys_get_root_magic "$1")"
  51. if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
  52. # we're upgrading from a firmware with UBI to one with UBI
  53. then
  54. # erase everything to be safe
  55. mtd erase $part_label
  56. get_image "$1" | mtd -n write - $part_label
  57. else
  58. get_image "$1" | mtd write - $part_label
  59. fi
  60. }
  61. }
  62. linksys_preupgrade() {
  63. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
  64. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
  65. export RAMFS_COPY_DATA="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
  66. }
  67. append sysupgrade_pre_upgrade linksys_preupgrade