linksys.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 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. # re-enable recovery so we get back if the new firmware is broken
  21. fw_setenv auto_recovery yes
  22. echo "$target_firmware"
  23. }
  24. linksys_get_root_magic() {
  25. (get_image "$@" | dd skip=786432 bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
  26. }
  27. platform_do_upgrade_linksys() {
  28. local magic_long="$(get_magic_long "$1")"
  29. mkdir -p /var/lock
  30. local part_label="$(linksys_get_target_firmware)"
  31. touch /var/lock/fw_printenv.lock
  32. if [ ! -n "$part_label" ]
  33. then
  34. echo "cannot find target partition"
  35. exit 1
  36. fi
  37. local target_mtd=$(find_mtd_part $part_label)
  38. [ "$magic_long" = "73797375" ] && {
  39. CI_KERNPART="$part_label"
  40. if [ "$part_label" = "kernel1" ]
  41. then
  42. CI_UBIPART="rootfs1"
  43. else
  44. CI_UBIPART="rootfs2"
  45. fi
  46. nand_upgrade_tar "$1"
  47. }
  48. [ "$magic_long" = "27051956" ] && {
  49. # check firmwares' rootfs types
  50. local target_mtd=$(find_mtd_part $part_label)
  51. local oldroot="$(linksys_get_root_magic $target_mtd)"
  52. local newroot="$(linksys_get_root_magic "$1")"
  53. if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
  54. # we're upgrading from a firmware with UBI to one with UBI
  55. then
  56. # erase everything to be safe
  57. mtd erase $part_label
  58. get_image "$1" | mtd -n write - $part_label
  59. else
  60. get_image "$1" | mtd write - $part_label
  61. fi
  62. }
  63. }
  64. linksys_preupgrade() {
  65. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
  66. export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
  67. export RAMFS_COPY_DATA="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
  68. [ -f /tmp/sysupgrade.tgz ] && {
  69. cp /tmp/sysupgrade.tgz /tmp/syscfg/sysupgrade.tgz
  70. }
  71. }
  72. append sysupgrade_pre_upgrade linksys_preupgrade