buffalo.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. . /lib/functions.sh
  2. # Prepare UBI devices for OpenWrt installation
  3. # - rootfs (mtd22)
  4. # - remove "ubi_rootfs" volume (rootfs on stock)
  5. # - remove "fw_hash" volume (firmware hash)
  6. # - user_property (mtd24)
  7. # - remove "user_property_ubi" volume (user configuration)
  8. # - remove "extra_property" volume (gzipped syslog)
  9. buffalo_upgrade_prepare() {
  10. local ubi_rootdev ubi_propdev
  11. if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
  12. ! ubi_propdev="$(nand_attach_ubi user_property)"; then
  13. echo "failed to attach UBI volume \"rootfs\" or \"user_property\", rebooting..."
  14. reboot -f
  15. fi
  16. ubirmvol /dev/$ubi_rootdev -N ubi_rootfs &> /dev/null || true
  17. ubirmvol /dev/$ubi_rootdev -N fw_hash &> /dev/null || true
  18. ubirmvol /dev/$ubi_propdev -N user_property_ubi &> /dev/null || true
  19. ubirmvol /dev/$ubi_propdev -N extra_property &> /dev/null || true
  20. }
  21. # Re-create small dummy ubi_rootfs volume and update
  22. # fw_hash volume to pass the checking by U-Boot
  23. # - rootfs (mtd22)
  24. # - re-create "ubi_rootfs" volume
  25. # - re-create and update "fw_hash" volume
  26. # - rootfs_recover (mtd23)
  27. # - update "fw_hash" volume
  28. buffalo_upgrade_optvol() {
  29. local ubi_rootdev ubi_rcvrdev
  30. local hashvol_root hashvol_rcvr
  31. if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
  32. ! ubi_rcvrdev="$(nand_attach_ubi rootfs_recover)"; then
  33. echo "failed to attach UBI volume \"rootfs\" or \"rootfs_recover\", rebooting..."
  34. reboot -f
  35. fi
  36. ubimkvol /dev/$ubi_rootdev -N ubi_rootfs -S 1
  37. ubimkvol /dev/$ubi_rootdev -N fw_hash -S 1 -t static
  38. if ! hashvol_root="$(nand_find_volume $ubi_rootdev fw_hash)" || \
  39. ! hashvol_rcvr="$(nand_find_volume $ubi_rcvrdev fw_hash)"; then
  40. echo "\"fw_hash\" volume in \"rootfs\" or \"rootfs_recover\" not found, rebooting..."
  41. reboot -f
  42. fi
  43. echo -n "00000000000000000000000000000000" > /tmp/dummyhash.txt
  44. ubiupdatevol /dev/$hashvol_root /tmp/dummyhash.txt
  45. ubiupdatevol /dev/$hashvol_rcvr /tmp/dummyhash.txt
  46. }