Set/clear partition status when processing fota or partition cloning 65/275465/6
authorSangYoun Kwak <sy.kwak@samsung.com>
Wed, 25 May 2022 08:09:34 +0000 (17:09 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 26 May 2022 01:35:44 +0000 (01:35 +0000)
Clear partition cloned status (as 0) before FOTA.
Set partition status as "ok" after partitions are cloned.

Change-Id: Icacc0630c716f0b4c7bc1cccf10508c63b388d05
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
clone_partitions/clone_partitions.sh
clone_partitions/clone_partitions_recovery.service
scripts/upgrade-trigger.sh

index ee21340b5a56f628c74d67da99656d55df3caf28..9fb74ea7b97f64119757d5777567dfe27b5fc9a2 100644 (file)
@@ -28,6 +28,32 @@ log() {
        echo "$LOG"
 }
 
+do_clone() {
+       if /usr/libexec/upgrade-support/upgrade-prepare-partitions.sh; then
+               log "[Info] Partitions have been cloned"
+               device_board_set_partition_ab_cloned
+       else
+               critical_log "[Error] Partitions have not been cloned"
+               exit 1
+       fi
+
+       return 0
+}
+
+set_partition_status_ok(){
+               CURRENT_AB=$(device_board_get_current_partition)
+
+               if [ "$CURRENT_AB" == "a" ]; then
+                       OPPOSITE_AB="b"
+               elif [ "$CURRENT_AB" == "b" ]; then
+                       OPPOSITE_AB="a"
+               else
+                       exit 1
+               fi
+
+               device_board_set_partition_status $OPPOSITE_AB "ok"
+}
+
 set -o errexit
 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
@@ -36,14 +62,13 @@ if [ ! -z "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
-if [ "$(device_board_get_partition_ab_cloned)" -eq "1" ]; then
-       log "[Info] Partitions already cloned"
-       exit 0
-fi
-
-if /usr/libexec/upgrade-support/upgrade-prepare-partitions.sh; then
-       log "[Info] Partitions have been cloned"
-       device_board_set_partition_ab_cloned
-else
-       critical_log "[Error] Partitions have not been cloned"
-fi
+case $1 in
+       "recovery")
+               /bin/device_board_clear_partition_ab_cloned
+               do_clone
+               set_partition_status_ok
+               ;;
+       *)
+               do_clone
+               ;;
+esac
index 6665692e07ce2df13dc0a0f26e78cec25024b3f6..bc49f23b083cc2e15baa3060959714bcf8fb4748 100644 (file)
@@ -8,8 +8,7 @@ ConditionKernelCommandLine=bootmode=recovery
 [Service]
 Type=oneshot
 SmackProcessLabel=System
-ExecStartPre=/bin/device_board_clear_partition_ab_cloned
-ExecStart=/usr/bin/clone_partitions.sh
+ExecStart=/usr/bin/clone_partitions.sh recovery
 RemainAfterExit=true
 
 [Install]
index 2caa66ca66e45bbc8150a01d38f2aef0b6388565..2d5cdc307053f9e486f2676d815df64f51333081 100755 (executable)
@@ -51,7 +51,9 @@ is_ab_upgrade() {
        [ ! -z "${AB_SLOT}" ]
 }
 
-check_update_type() {
+do_update() {
+       device_board_clear_partition_ab_cloned
+
        if is_ab_upgrade; then
                if is_full_upgrade; then
                        # If the update.cfg file contains only PRE_UA type updates, we consider
@@ -105,4 +107,4 @@ tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc
 
 set_upgrade_status 1
 verify_img "${DOWNLOAD_DELTA}"
-check_update_type
+do_update