recovery-initramfs: adapt format_ubi_volume() to new partition layout of ccmp1

The ccmp1 has two MTD partitions (UBI, UBI_2) with different system
volumes.
Previously, the fact of having two ubi devices was taken as proof of
being on a multi-MTD system (one that has one UBI volume per partition).
Instead, this commit reformulates the condition to having a partition of
the same name than the UBI volume.

For the case of the ccmp1, add a new for loop to iterate across any number
of UBI devices.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
This commit is contained in:
Hector Palacios 2023-08-25 16:24:18 +02:00
parent 8c0dc9af13
commit 7e81e706a1
1 changed files with 22 additions and 15 deletions

View File

@ -231,21 +231,10 @@ format_ubi_volume() {
psplash_message "Formatting '${1}' partition..." psplash_message "Formatting '${1}' partition..."
psplash_progress "0" psplash_progress "0"
# If /dev/ubi1 exists is a system with multiple MTD partitions # If the system is a multi-MTD, there must be an MTD partition by the
if [ ! -c "/dev/ubi1" ]; then # same name as the UBI volume
# Find the volume number associated to the volume name result="$(grep '\"${1}\"$' /proc/mtd)"
for d in /dev/ubi0_*; do if [ -n "${result}" ]; then
volname="$(ubinfo ${d} | grep ^Name | awk '{print $(2)}')"
if [ "${volname}" = "${1}" ]; then
# Find mountpoint
mountpoint="$(mount | grep ubi0:${1} | awk '{print $(3) }')"
umount ${mountpoint} 2> /dev/null
# Wipe out volume
ubiupdatevol ${d} -t
fi
done
psplash_progress "100"
else
# Find the MTD partition. # Find the MTD partition.
local mtd_num="$(sed -ne "s/mtd\([0-9]\+\):.*\<${1}\>.*/\1/g;T;p" /proc/mtd 2>/dev/null)" local mtd_num="$(sed -ne "s/mtd\([0-9]\+\):.*\<${1}\>.*/\1/g;T;p" /proc/mtd 2>/dev/null)"
if [ -z "${mtd_num}" ]; then if [ -z "${mtd_num}" ]; then
@ -280,6 +269,24 @@ format_ubi_volume() {
quit_with_error "Error creating '${1}' UBI volume" quit_with_error "Error creating '${1}' UBI volume"
fi fi
fi fi
else
# Find the volume number associated to the volume name
ubidevs="$(ls /dev/ubi* | grep 'ubi[0-9]\+$')"
for d in $ubidevs;do
for v in "${d}"_*; do
volname="$(ubinfo ${v} | grep ^Name | awk '{print $(2)}')"
if [ "${volname}" = "${1}" ]; then
# Find mountpoint
u="$(basename ${d})"
mountpoint="$(mount | grep ${u}:${1} | awk '{print $(3) }')"
umount ${mountpoint} 2> /dev/null
# Wipe out volume
ubiupdatevol ${v} -t
break 2
fi
done
done
psplash_progress "100"
fi fi
} }