recovery: init script mount fixes

- Added a 5 seconds delay before mounting external disks so they have
  time to be recognized in the system.
- Check if UBI volume is mounted before formatting it.
- Check if eMMC block device exists before formatting it.

Signed-off-by: David Escalona <david.escalona@digi.com>
This commit is contained in:
David Escalona 2016-12-28 16:55:18 +01:00
parent 047849b848
commit f4ece3821e
1 changed files with 20 additions and 9 deletions

View File

@ -248,6 +248,12 @@ format_ubi_volume() {
if [ -z "${mtd_num}" ]; then if [ -z "${mtd_num}" ]; then
quit_with_error "Could not find MTD partition for volume '${1}'" quit_with_error "Could not find MTD partition for volume '${1}'"
else else
# Umount in case partition is mounted, ignore errors.
if grep -qs "${1}" /proc/mounts; then
local path="$(sed -ne "s/.*:${1} \(.*\) ubifs.*/\1/g;T;p" /proc/mounts 2>/dev/null)"
umount "${path}" >/dev/null 2>&1
ubidetach -p "/dev/mtd${mtd_num}" >/dev/null 2>&1
fi
# Format MTD partition. # Format MTD partition.
ubiformat "/dev/mtd${mtd_num}" >/dev/null 2>&1 ubiformat "/dev/mtd${mtd_num}" >/dev/null 2>&1
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
@ -277,6 +283,7 @@ format_ubi_volume() {
format_emmc_block() { format_emmc_block() {
# Find partition block number. # Find partition block number.
local partition_block="/dev/mmcblk0p$(parted -s /dev/mmcblk0 print | sed -ne "s,^[^0-9]*\([0-9]\+\).*\<${1}\>.*,\1,g;T;p")" local partition_block="/dev/mmcblk0p$(parted -s /dev/mmcblk0 print | sed -ne "s,^[^0-9]*\([0-9]\+\).*\<${1}\>.*,\1,g;T;p")"
if [ -b "${partition_block}" ]; then
# Umount in case partition is mounted, ignore errors. # Umount in case partition is mounted, ignore errors.
if grep -qs "${partition_block}" /proc/mounts; then if grep -qs "${partition_block}" /proc/mounts; then
umount "${partition_block}" >/dev/null 2>&1 umount "${partition_block}" >/dev/null 2>&1
@ -288,6 +295,9 @@ format_emmc_block() {
else else
quit_with_error "Error erasing '${1}' partition" quit_with_error "Error erasing '${1}' partition"
fi fi
else
quit_with_error "Could not find partition block for '${1}'"
fi
} }
# Main # Main
@ -376,6 +386,7 @@ if [ -n "${update_package_bool}" ]; then
else else
log "Update package location: ${update_package}" log "Update package location: ${update_package}"
# Mount external disks. # Mount external disks.
sleep 5
mount_external_disks mount_external_disks
# Mount update partition. # Mount update partition.
mount_partition update "${UPDATE_MOUNT_DIR}" mount_partition update "${UPDATE_MOUNT_DIR}"