recovery-initramfs: don't format the rootfs partition unless it's necessary

By default, we generate SWU files which update both the linux and rootfs
partitions. This, along with the fact that platforms using NAND as the storage
media require a reboot for the rootfs partition's "enc" flag to take effect,
makes it safe to format the NAND's rootfs partition before performing an
update, regardless of having to encrypt the rootfs or not.

However, customers that wish to use the swupdate feature to update just the
linux partition will find that the rootfs is completely erased after the update
is finished, because a new rootfs hasn't been written in its place.

To avoid this scenario, parse the SWU package's description to verify that it
contains a rootfs image before formatting the partition.

https://jira.digi.com/browse/DEL-7067

Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
This commit is contained in:
Gabriel Valcazar 2020-07-16 15:54:24 +02:00
parent e8d4360ebf
commit 212448fe2d
1 changed files with 16 additions and 6 deletions

View File

@ -26,6 +26,9 @@ PUBLIC_KEY="/etc/ssl/certs/key.pub"
USB_MOUNT_DIR="/run/media"
UPDATE_MOUNT_DIR="/mnt/update"
ROOTFS_NEEDS_FORMAT="no"
SWUPDATE_OUTPUT="swupdate_output.txt"
REBOOT_TIME=10
# Functions.
@ -297,14 +300,19 @@ check_swu_package() {
# Check software update package.
if [ -f "${PUBLIC_KEY}" ]; then
swupdate -c -i "${update_package}" -k "${PUBLIC_KEY}"
swupdate -c -v -i "${update_package}" -k "${PUBLIC_KEY}" > "${SWUPDATE_OUTPUT}"
else
swupdate -c -i "${update_package}"
swupdate -c -v -i "${update_package}" > "${SWUPDATE_OUTPUT}"
fi
if [ "$?" != "0" ]; then
quit_with_error "Invalid update package '$(basename ${1})'"
fi
# Format the rootfs partition if and only if the package contains a rootfs image.
if [ "$(is_nand)" = "yes" ]; then
grep "Found Image" "${SWUPDATE_OUTPUT}" | grep -qs "rootfs" && ROOTFS_NEEDS_FORMAT="yes"
fi
}
#------------------------------------------------------------------------------
@ -475,11 +483,13 @@ if [ -n "${update_package_bool}" ]; then
psplash_message "Updating firmware..."
psplash_progress "0"
# Format the UBI volume before updating.
# Format the UBI volume before updating if needed.
if [ "$(is_nand)" = "yes" ]; then
psplash_message "Formatting rootfs partition..."
format_ubi_volume rootfs
psplash_progress "0"
if [ "$ROOTFS_NEEDS_FORMAT" = "yes" ]; then
psplash_message "Formatting rootfs partition..."
format_ubi_volume rootfs
psplash_progress "0"
fi
fi
log "Update package location: ${update_package}"