diff options
author | Rodrigo Balerdi <lanchon@gmail.com> | 2022-05-03 03:47:43 -0300 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2022-10-30 14:29:56 +0000 |
commit | af347335939531eeb5701f52549cc4d366eb60d5 (patch) | |
tree | 08ee40e4816ba536a3307075f158632f65c93dd7 /package/base-files/files/lib/upgrade/nand.sh | |
parent | e25e6d8e5407119746cba624244a5ac1a5cdbc83 (diff) |
base-files: fix ubinized nand sysupgrade
It has been reported that ubinized nand sysupgrade fails under certain
circumstances, being unable to detach the existing ubi partition due to
volumes within the partition being mounted.
This is an attempt to solve such issues by unmounting and removing
ubiblock devices and unmounting ubi volumes within the target partition
prior to detaching and formatting it.
Signed-off-by: Rodrigo Balerdi <lanchon@gmail.com>
Diffstat (limited to 'package/base-files/files/lib/upgrade/nand.sh')
-rw-r--r-- | package/base-files/files/lib/upgrade/nand.sh | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh index 76a984483e..19e51c55c0 100644 --- a/package/base-files/files/lib/upgrade/nand.sh +++ b/package/base-files/files/lib/upgrade/nand.sh @@ -127,17 +127,41 @@ nand_restore_config() { } nand_remove_ubiblock() { - local ubivol=$1 - local ubiblk=ubiblock${ubivol:3} - if [ -e /dev/$ubiblk ]; then - echo "removing $ubiblk" - if ! ubiblock -r /dev/$ubivol; then + local ubivol="$1" + + local ubiblk="ubiblock${ubivol:3}" + if [ -e "/dev/$ubiblk" ]; then + umount "/dev/$ubiblk" && echo "unmounted /dev/$ubiblk" || : + if ! ubiblock -r "/dev/$ubivol"; then echo "cannot remove $ubiblk" return 1 fi fi } +nand_detach_ubi() { + local ubipart="$1" + + local mtdnum="$( find_mtd_index "$ubipart" )" + if [ ! "$mtdnum" ]; then + echo "cannot find ubi mtd partition $ubipart" + return 1 + fi + + local ubidev="$( nand_find_ubi "$ubipart" )" + if [ "$ubidev" ]; then + for ubivol in $(find /dev -name "${ubidev}_*" -maxdepth 1 | sort); do + ubivol="${ubivol:5}" + nand_remove_ubiblock "$ubivol" || : + umount "/dev/$ubivol" && echo "unmounted /dev/$ubivol" || : + done + if ! ubidetach -m "$mtdnum"; then + echo "cannot detach ubi mtd partition $ubipart" + return 1 + fi + fi +} + nand_upgrade_prepare_ubi() { local rootfs_length="$1" local rootfs_type="$2" @@ -235,15 +259,10 @@ nand_upgrade_prepare_ubi() { nand_upgrade_ubinized() { local ubi_file="$1" - local mtdnum="$( find_mtd_index "$CI_UBIPART" )" - if [ ! "$mtdnum" ]; then - echo "cannot find ubi mtd partition $CI_UBIPART" - return 1 - fi + nand_detach_ubi "$CI_UBIPART" || return 1 - local mtddev="/dev/mtd${mtdnum}" - ubidetach -p "${mtddev}" || : - ubiformat "${mtddev}" -y -f "${ubi_file}" && ubiattach -p "${mtddev}" + local mtdnum="$( find_mtd_index "$CI_UBIPART" )" + ubiformat "/dev/mtd$mtdnum" -y -f "$ubi_file" && ubiattach -m "$mtdnum" } # Write the UBIFS image to UBI rootfs volume |