From 5f058dbaa248fc15150475389c9e2027315fb8c4 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Wed, 11 May 2022 20:02:12 +0200 Subject: [PATCH] Set upgrade progress Change-Id: If4c51014c5f2638eae3f15bc97ab988d1de7a500 --- CMakeLists.txt | 1 + packaging/tota-ua.spec | 1 + scripts/upgrade-common.inc | 21 ++++++++++++++++----- scripts/upgrade-full.sh | 2 ++ scripts/upgrade-partial.sh | 6 +++--- scripts/upgrade-trigger.sh | 18 ++++++++++++------ src/ua.c | 13 +++++++++++++ 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18a1142..93fa8a1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ pkg_check_modules(pkgs REQUIRED openssl1.1 blkid liblzma-tool + hal-api-device ) pkg_check_modules(blkid_pkgs REQUIRED diff --git a/packaging/tota-ua.spec b/packaging/tota-ua.spec index 4bea150..a2dbaa3 100755 --- a/packaging/tota-ua.spec +++ b/packaging/tota-ua.spec @@ -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 diff --git a/scripts/upgrade-common.inc b/scripts/upgrade-common.inc index de7bfb1..bf1ff93 100644 --- a/scripts/upgrade-common.inc +++ b/scripts/upgrade-common.inc @@ -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 +} diff --git a/scripts/upgrade-full.sh b/scripts/upgrade-full.sh index 0cd55b2..12126c7 100755 --- a/scripts/upgrade-full.sh +++ b/scripts/upgrade-full.sh @@ -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 diff --git a/scripts/upgrade-partial.sh b/scripts/upgrade-partial.sh index 2290844..9f8ff76 100755 --- a/scripts/upgrade-partial.sh +++ b/scripts/upgrade-partial.sh @@ -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 diff --git a/scripts/upgrade-trigger.sh b/scripts/upgrade-trigger.sh index 21c8649..2caa66c 100755 --- a/scripts/upgrade-trigger.sh +++ b/scripts/upgrade-trigger.sh @@ -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 diff --git a/src/ua.c b/src/ua.c index d5fc51c..5d33bed 100755 --- a/src/ua.c +++ b/src/ua.c @@ -32,6 +32,8 @@ #include #include +#include + #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 */ -- 2.7.4