From 212448fe2d0c26d0b63a3276fa3ec589d9d87989 Mon Sep 17 00:00:00 2001 From: Gabriel Valcazar Date: Thu, 16 Jul 2020 15:54:24 +0200 Subject: [PATCH] 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 --- .../recovery-initramfs-init | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/meta-digi-dey/recipes-core/recovery/recovery-initramfs/recovery-initramfs-init b/meta-digi-dey/recipes-core/recovery/recovery-initramfs/recovery-initramfs-init index 02c590551..a38146cd7 100644 --- a/meta-digi-dey/recipes-core/recovery/recovery-initramfs/recovery-initramfs-init +++ b/meta-digi-dey/recipes-core/recovery/recovery-initramfs/recovery-initramfs-init @@ -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}"