Set upgrade progress 14/275014/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 11 May 2022 18:02:12 +0000 (20:02 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 16 May 2022 12:19:58 +0000 (14:19 +0200)
Change-Id: If4c51014c5f2638eae3f15bc97ab988d1de7a500

CMakeLists.txt
packaging/tota-ua.spec
scripts/upgrade-common.inc
scripts/upgrade-full.sh
scripts/upgrade-partial.sh
scripts/upgrade-trigger.sh
src/ua.c

index 18a1142..93fa8a1 100755 (executable)
@@ -56,6 +56,7 @@ pkg_check_modules(pkgs REQUIRED
        openssl1.1
        blkid
        liblzma-tool
+       hal-api-device
 )
 
 pkg_check_modules(blkid_pkgs REQUIRED
index 4bea150..a2dbaa3 100755 (executable)
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(openssl1.1)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(dlog)
 Buildrequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(hal-api-device)
 
 Requires:       tar
 Requires:       gzip
index de7bfb1..bf1ff93 100644 (file)
@@ -4,6 +4,7 @@ HAL_UPGRADE_CFG_DIR="/hal/etc/upgrade/"
 HAL_PART_MAP_FILE="label_map.list"
 HAL_PART_LIST_FILE="background_copy.list"
 CONFIG_FILE="update.cfg"
+SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status"
 
 #------------------------------------------------
 #       log msg [file]
@@ -37,7 +38,7 @@ verify_img() {
                if ! "$IMG_VERIFIER" -i "$DELTA_FILE" -l "/opt/var/log/last_iv.log"; then
                        log "[Error] Update package verification FAILED..." "$LOG_FILE"
                        echo 5 > "$STATUS_DIR"/result
-                       exit 1
+                       exit_error
                else
                        log "[Info] Update package verification PASSED!" "$LOG_FILE"
                fi
@@ -48,7 +49,7 @@ check_ab_partition_scheme() {
        CURRENT_AB="$(/bin/sed -E 's|.*(partition_ab=)([a-b]).*|\2|' /proc/cmdline)"
        if [ "$CURRENT_AB" != "a" ] && [ "$CURRENT_AB" != "b" ]; then
                flog "[Info] There is no A/B partition scheme"
-               exit 1
+               exit_error
        fi
        NEXT_AB="b"
        if [ "$CURRENT_AB" == "b" ]; then
@@ -67,7 +68,7 @@ check_used_block_device() {
        if ! EMMC_DEVICE="/dev/$(/bin/lsblk -ndo pkname "${ROOTFS_DEVICE}")" ||\
                [ "$EMMC_DEVICE" == "/dev/" ]; then
                flog "[Error] Unable to find used block device: $EMMC_DEVICE, for /"
-               exit 1
+               exit_error
        fi
 }
 
@@ -90,7 +91,7 @@ background_copy() {
                fi
                if [ "$CURRENT_PARTITION" == "" ] || [ "$NEXT_PARTITION" = "" ]; then
                        flog "[Error] current: $CURRENT_PARTITION or next: $NEXT_PARTITION partition is empty on $EMMC_DEVICE device"
-                       exit 1
+                       exit_error
                fi
                if [ "$CURRENT_PARTITION" == "$NEXT_PARTITION" ]; then
                        flog "[Info] $partition_name partition current and next are the same: $CURRENT_PARTITION on $EMMC_DEVICE device"
@@ -146,7 +147,7 @@ upgrade_images() {
                                flog "[Info] Checksums match"
                        else
                                flog "[Info] Checksums don't match ($CURRENT_SHA != $NEW_SHA). Abort."
-                               exit 1
+                               exit_error
                        fi
                else
                        PARTS_NAME_TO_UPDATE+=( "$PART_NAME:$TYPE" )
@@ -185,3 +186,13 @@ write_version_info() {
 
        echo "OLD_VER=$CVT_VER" > "$VERSION_FILE"
 }
+
+set_upgrade_status() {
+       VALUE="$1"
+       ${SET_UPGRADE_STATUS} ${VALUE}
+}
+
+exit_error() {
+       set_upgrade_status -1
+       exit 1
+}
index 0cd55b2..12126c7 100755 (executable)
@@ -56,5 +56,7 @@ check_used_block_device
 unpack_file "$DELTA_TAR" "$CONFIG_FILE"
 load_background_copy_list
 background_copy
+set_upgrade_status 20
 upgrade_images "$DOWNLOAD_DELTA"
+set_upgrade_status 80
 reboot_to_fota
index 2290844..9f8ff76 100755 (executable)
@@ -170,18 +170,18 @@ upgrade_images "$DELTA_TAR"
 if ! prepare_for_ua; then
        flog "[Error] Unable to prepare_for_ua"
        cleanup
-       exit 1
+       exit_error
 fi
 
 if ! run_setup_script "$DELTA_TAR"; then
        flog "[Error] Unable to run_setup_script"
        cleanup
-       exit 1
+       exit_error
 fi
 
 if ! run_ro_update; then
        flog "[Error] Unable to run_ro_update"
        cleanup
-       exit 1
+       exit_error
 fi
 cleanup
index 21c8649..2caa66c 100755 (executable)
@@ -59,22 +59,28 @@ check_update_type() {
                        # the appropriate partitions directly from the archive so as not to
                        # consume additional space on the device.
                        unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FULL}"
-                       "${FOTA_DIR}/${SCRIPT_UPGRADE_FULL}" "${DOWNLOAD_DELTA}"
+                       set_upgrade_status 5
+                       if ! "${FOTA_DIR}/${SCRIPT_UPGRADE_FULL}" "${DOWNLOAD_DELTA}"; then
+                               exit_error
+                       fi
                else
                        # Regular A/B Upgrade
                        unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PREPARE_PARTITIONS}"
                        unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}"
                        unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}"
-
+                       set_upgrade_status 5
                        if ! "${FOTA_DIR}/${SCRIPT_UPGRADE_PREPARE_PARTITIONS}"; then
-                               exit 1
+                               exit_error
                        fi
+                       set_upgrade_status 20
                        if ! "${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL}" "${DOWNLOAD_DELTA}"; then
-                               exit 1
+                               exit_error
                        fi
+                       set_upgrade_status 40
                        if ! "${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}"; then
-                               exit 1
+                               exit_error
                        fi
+                       set_upgrade_status 80
                fi
        else
                # Legacy upgrade (non-A/B)
@@ -93,10 +99,10 @@ fi
 log "[Info] Using <$DOWNLOAD_DELTA> delta file." "$LOG_FILE"
 
 prepare_fota_dir
-
 tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc
 
 . "$FOTA_DIR"/upgrade-common.inc
 
+set_upgrade_status 1
 verify_img "${DOWNLOAD_DELTA}"
 check_update_type
index d5fc51c..5d33bed 100755 (executable)
--- a/src/ua.c
+++ b/src/ua.c
@@ -32,6 +32,8 @@
 #include <string.h>
 #include <blkid/blkid.h>
 
+#include <hal/device/hal-board.h>
+
 #include "SS_Common.h"
 #include "fota_common.h"
 #include "ua.h"
@@ -85,6 +87,9 @@ static void save_cause(int cause);
 #define TMP_DIR "/tmp/upgrade"
 #define PROGRESS_FILE TMP_DIR "/ro_progress"
 
+#define HAL_PROGRESS_MIN 40
+#define HAL_PROGRESS_MAX 80
+
 void print_usage(const char *msg)
 {
        if (msg) {
@@ -195,6 +200,12 @@ update_progress:
        LOG("Succeed to write\n");
 }
 
+static void set_upgrade_progress(int percent)
+{
+       int relative_precent = HAL_PROGRESS_MIN + ((HAL_PROGRESS_MAX - HAL_PROGRESS_MIN) * percent)/100;
+       hal_device_board_set_upgrade_status(relative_precent);
+}
+
 /*-----------------------------------------------------------------------------
   fota_gui_progress
  ----------------------------------------------------------------------------*/
@@ -213,6 +224,7 @@ void fota_gui_progress(void * pbUserData, unsigned long uPercent)
        else
                percent = ua_update_data->weight_offset + (ua_update_data->weight * uPercent / 100);
 
+       set_upgrade_progress(percent);
        /**
         * re-arrange progress percentage between scout & update
         *
@@ -233,6 +245,7 @@ void fota_gui_progress(void * pbUserData, unsigned long uPercent)
                to = 100;
                break;
        }
+
        percent = from + ((to - from) * percent / 100);
 
        fota_gui_update_progress(percent);      /* update progress bar and text */