netgear.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. . /lib/functions.sh
  3. platform_do_upgrade_netgear_orbi_upgrade() {
  4. command -v losetup >/dev/null || {
  5. logger -s "Upgrade failed: 'losetup' not installed."
  6. return 1
  7. }
  8. local tar_file=$1
  9. local kernel=$2
  10. local rootfs=$3
  11. [ -z "$kernel" ] && kernel=$(find_mmc_part "kernel")
  12. [ -z "$rootfs" ] && rootfs=$(find_mmc_part "rootfs")
  13. [ -z "$kernel" ] && echo "Upgrade failed: kernel partition not found! Rebooting..." && reboot -f
  14. [ -z "$rootfs" ] && echo "Upgrade failed: rootfs partition not found! Rebooting..." && reboot -f
  15. netgear_orbi_do_flash $tar_file $kernel $rootfs
  16. echo "sysupgrade successful"
  17. umount -a
  18. reboot -f
  19. }
  20. netgear_orbi_do_flash() {
  21. local tar_file=$1
  22. local kernel=$2
  23. local rootfs=$3
  24. # keep sure its unbound
  25. losetup --detach-all || {
  26. echo "Failed to detach all loop devices. Skip this try."
  27. reboot -f
  28. }
  29. # use the first found directory in the tar archive
  30. local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
  31. board_dir=${board_dir%/}
  32. echo "flashing kernel to $kernel"
  33. tar xf $tar_file ${board_dir}/kernel -O >$kernel
  34. echo "flashing rootfs to ${rootfs}"
  35. tar xf $tar_file ${board_dir}/root -O >"${rootfs}"
  36. # a padded rootfs is needed for overlay fs creation
  37. local offset=$(tar xf $tar_file ${board_dir}/root -O | wc -c)
  38. [ $offset -lt 65536 ] && {
  39. echo "Wrong size for rootfs: $offset"
  40. sleep 10
  41. reboot -f
  42. }
  43. # Mount loop for rootfs_data
  44. local loopdev="$(losetup -f)"
  45. losetup -o $offset $loopdev $rootfs || {
  46. echo "Failed to mount looped rootfs_data."
  47. sleep 10
  48. reboot -f
  49. }
  50. echo "Format new rootfs_data at position ${offset}."
  51. mkfs.ext4 -F -L rootfs_data $loopdev
  52. mkdir /tmp/new_root
  53. mount -t ext4 $loopdev /tmp/new_root && {
  54. echo "Saving config to rootfs_data at position ${offset}."
  55. cp -v "$UPGRADE_BACKUP" "/tmp/new_root/$BACKUP_FILE"
  56. umount /tmp/new_root
  57. }
  58. # Cleanup
  59. losetup -d $loopdev >/dev/null 2>&1
  60. sync
  61. }