ubnt.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #
  2. # Copyright (C) 2015 OpenWrt.org
  3. #
  4. . /lib/functions.sh
  5. #Note: this code also uses some functions from nand.sh, but it is expected to be run by nand.sh, so we are not
  6. #sourcing it explicitly here
  7. UBNT_ERX_KERNEL_INDEX_OFFSET=160
  8. ubnt_update_kernel_flag() {
  9. local factory_mtd=$1
  10. local kernel_index=$(hexdump -s $UBNT_ERX_KERNEL_INDEX_OFFSET -n 1 -e '/1 "%X "' ${factory_mtd})
  11. if [ $kernel_index = "0" ]; then
  12. echo "Kernel flag already set to kernel slot 1"
  13. return 0
  14. fi
  15. if ! (echo -e "\x00" | dd of=${factory_mtd} bs=1 count=1 seek=$UBNT_ERX_KERNEL_INDEX_OFFSET); then
  16. echo 'Failed to update kernel bootup index' >&2
  17. return 1
  18. fi
  19. }
  20. platform_upgrade_ubnt_erx() {
  21. local factory_mtd=$(find_mtd_part factory)
  22. if [ -z "$factory_mtd" ]; then
  23. echo "cannot find factory partition" >&2
  24. exit 1
  25. fi
  26. #Remove volume possibly left over from stock firmware
  27. local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  28. if [ -z "$ubidev" ]; then
  29. local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
  30. if [ -z "$mtdnum" ]; then
  31. echo "cannot find ubi mtd partition $CI_UBIPART" >&2
  32. exit 1
  33. fi
  34. ubiattach -m "$mtdnum"
  35. sync
  36. ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  37. fi
  38. if [ -n "$ubidev" ]; then
  39. local troot_ubivol="$( nand_find_volume $ubidev troot )"
  40. [ -n "$troot_ubivol" ] && ubirmvol /dev/$ubidev -N troot || true
  41. fi
  42. ubnt_update_kernel_flag ${factory_mtd} || exit 1
  43. nand_do_upgrade "$1"
  44. }