1
0
mirror of https://git.openwrt.org/openwrt/openwrt.git synced 2024-10-18 21:48:23 +02:00

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>
This commit is contained in:
Rodrigo Balerdi 2022-05-03 03:47:43 -03:00 committed by Daniel Golle
parent e25e6d8e54
commit af34733593
2 changed files with 33 additions and 14 deletions

@ -127,17 +127,41 @@ nand_restore_config() {
} }
nand_remove_ubiblock() { nand_remove_ubiblock() {
local ubivol=$1 local ubivol="$1"
local ubiblk=ubiblock${ubivol:3}
if [ -e /dev/$ubiblk ]; then local ubiblk="ubiblock${ubivol:3}"
echo "removing $ubiblk" if [ -e "/dev/$ubiblk" ]; then
if ! ubiblock -r /dev/$ubivol; then umount "/dev/$ubiblk" && echo "unmounted /dev/$ubiblk" || :
if ! ubiblock -r "/dev/$ubivol"; then
echo "cannot remove $ubiblk" echo "cannot remove $ubiblk"
return 1 return 1
fi fi
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() { nand_upgrade_prepare_ubi() {
local rootfs_length="$1" local rootfs_length="$1"
local rootfs_type="$2" local rootfs_type="$2"
@ -235,15 +259,10 @@ nand_upgrade_prepare_ubi() {
nand_upgrade_ubinized() { nand_upgrade_ubinized() {
local ubi_file="$1" local ubi_file="$1"
local mtdnum="$( find_mtd_index "$CI_UBIPART" )" nand_detach_ubi "$CI_UBIPART" || return 1
if [ ! "$mtdnum" ]; then
echo "cannot find ubi mtd partition $CI_UBIPART"
return 1
fi
local mtddev="/dev/mtd${mtdnum}" local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
ubidetach -p "${mtddev}" || : ubiformat "/dev/mtd$mtdnum" -y -f "$ubi_file" && ubiattach -m "$mtdnum"
ubiformat "${mtddev}" -y -f "${ubi_file}" && ubiattach -p "${mtddev}"
} }
# Write the UBIFS image to UBI rootfs volume # Write the UBIFS image to UBI rootfs volume

@ -41,7 +41,7 @@ switch_to_ramfs() {
pivot_root mount_root reboot sync kill sleep \ pivot_root mount_root reboot sync kill sleep \
md5sum hexdump cat zcat dd tar \ md5sum hexdump cat zcat dd tar \
ls basename find cp mv rm mkdir rmdir mknod touch chmod \ ls basename find cp mv rm mkdir rmdir mknod touch chmod \
'[' printf wc grep awk sed cut \ '[' printf wc grep awk sed cut sort \
mtd partx losetup mkfs.ext4 nandwrite flash_erase \ mtd partx losetup mkfs.ext4 nandwrite flash_erase \
ubiupdatevol ubiattach ubiblock ubiformat \ ubiupdatevol ubiattach ubiblock ubiformat \
ubidetach ubirsvol ubirmvol ubimkvol \ ubidetach ubirsvol ubirmvol ubimkvol \