buffalo.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2018 OpenWrt.org
  2. #
  3. . /lib/functions.sh
  4. # The mtd partition 'ubi' and 'rootfs_1' on NAND flash are os-image
  5. # partitions. These partitions are called as "Bank1/Bank2" in U-Boot
  6. # on WXR-2533DHP, and they are checked conditions when booting.
  7. # Then, U-Boot checks kernel and rootfs volumes in ubi, but U-Boot
  8. # needs "ubi_rootfs" as rootfs volume name. And, U-Boot checks the
  9. # checksum at the end of rootfs (ubi_rootfs).
  10. # When U-Boot writes os-image into the Bank, only kernel, rootfs
  11. # (ubi_rootfs) and rootfs_data (ubi_rootfs_data) volumes are wrote
  12. # into the Bank. (not full ubi image)
  13. #
  14. # == U-Boot Behaviors ==
  15. # - Bank1/Bank2 images are good, images are different
  16. # -> writes os-image to Bank1 from Bank2
  17. # (this behavior is used to firmware upgrade in stock firmware)
  18. # - Bank1 image is broken (or checksum error)
  19. # -> writes os-image to Bank1 from Bank2
  20. # - Bank2 image is broken (or checksum error)
  21. # -> writes os-image to Bank2 from Bank1
  22. # - Bank1/Bank2 images are broken (or checksum error)
  23. # -> start tftp
  24. buffalo_upgrade_prepare_ubi() {
  25. local ubidev="$( nand_find_ubi ubi )"
  26. local mtdnum2="$( find_mtd_index rootfs_1 )"
  27. if [ ! "$mtdnum2" ]; then
  28. echo "cannot find second ubi mtd partition rootfs_1"
  29. return 1
  30. fi
  31. local ubidev2="$( nand_find_ubi rootfs_1 )"
  32. if [ ! "$ubidev2" ] && [ -n "$mtdnum2" ]; then
  33. ubiattach -m "$mtdnum2"
  34. ubidev2="$( nand_find_ubi rootfs_1 )"
  35. fi
  36. ubirmvol /dev/$ubidev -N ubi_rootfs_data &> /dev/null || true
  37. ubirmvol /dev/$ubidev2 -N kernel &> /dev/null || true
  38. }