From: Mateusz Moscicki Date: Fri, 5 Apr 2024 16:30:52 +0000 (+0200) Subject: Separation of OS Upgrade into two stages X-Git-Tag: accepted/tizen/unified/20240502.044634~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5323af83788ae07f6ce9ab2015cb17b9045a818a;p=platform%2Fcore%2Fsystem%2Fupgrade.git Separation of OS Upgrade into two stages If ugprade-trigger.sh is called without any additional parameters, the behavior will be as before - an OS Upgrade will be performed and then a reboot. You can also use additional options: upgrade-trigger.sh --ro-update - only the upgrade will be done. upgrade-trigger.sh --finish - the active slot will be changed and a reboot will occur Change-Id: I4e343a4791e8f94bb39ec3bc592127562c9aa8b8 --- diff --git a/scripts/upgrade-support/upgrade-trigger.sh b/scripts/upgrade-support/upgrade-trigger.sh index d36f89d..60cf13a 100644 --- a/scripts/upgrade-support/upgrade-trigger.sh +++ b/scripts/upgrade-support/upgrade-trigger.sh @@ -8,10 +8,11 @@ if [ -n "${UPGRADE_DEBUG}" ]; then set -x fi +PROGRESS_AFTER_RO=80 + PATH=/bin:/usr/bin:/sbin:/usr/sbin FOTA_DIR="/opt/usr/data/fota" STATUS_DIR="/opt/data/update" -DOWNLOAD_DELTA="$1" SCRIPT_UPGRADE_PREPARE_PARTITIONS="upgrade-prepare-partitions.sh" SCRIPT_UPGRADE_PARTIAL="upgrade-partial.sh" SCRIPT_UPGRADE_FOTA="upgrade-fota.sh" @@ -88,8 +89,6 @@ do_update() { # be modified, so they will not be a clone of the current partitions device_board_clear_partition_ab_cloned - unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}" - unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}" run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL} ${DOWNLOAD_DELTA}" @@ -98,27 +97,12 @@ do_update() { exit_error fi - set_upgrade_status 40 + set_upgrade_status $PROGRESS_AFTER_RO # During the execution of ${SCRIPT_UPGRADE_FOTA} system will reboot, so the # script will be aborted. We don't want this to be treated as an error. untrap set -u errexit - run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}" - if ! [ $RET -ne 0 ]; then - # We want to check if we are here becasue the reboot interrupted the - # execution of ${SCRIPT_UPGRADE_FOTA} or for some other reason. - # If a reboot is currently in progress then /proc/1/exe will point to - # something other than "systemd" (e.g. deviced-shudown). - if [ "$(basename "$(readlink /proc/1/exe)")" = "systemd" ]; then - # No, it's not a reboot. Rather it is a regular error. - exit_error - else - set_upgrade_status 80 - log "[Info] RO update: $SCRIPT_NAME success" - fi - fi - else log "[Error] Non-A/B upgrade is unsupported" device_board_set_upgrade_status -1 @@ -126,6 +110,29 @@ do_update() { fi } +do_finish() { + current_upgrade_status=$(device_board_get_upgrade_status) + if [ "$current_upgrade_status" != "$PROGRESS_AFTER_RO" ]; then + critical_log "[Error] Cannot finish upgrade - RO Upgrade has not been completed" + exit_error + fi + + run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}" + if ! [ $RET -ne 0 ]; then + # We want to check if we are here becasue the reboot interrupted the + # execution of ${SCRIPT_UPGRADE_FOTA} or for some other reason. + # If a reboot is currently in progress then /proc/1/exe will point to + # something other than "systemd" (e.g. deviced-shudown). + if [ "$(basename "$(readlink /proc/1/exe)")" = "systemd" ]; then + # No, it's not a reboot. Rather it is a regular error. + exit_error + else + set_upgrade_status $PROGRESS_AFTER_RO + log "[Info] RO update: $SCRIPT_NAME success" + fi + fi +} + verify_file() { FILE_PATH="$1" FILE_NAME=$(basename "$FILE_PATH") @@ -146,45 +153,102 @@ verify_file() { log "[Info] Checksum of $FILE_NAME is OK" } -( -flock 9 +MODE_RO_UPDATE=false +MODE_FINISH_UPDATE=false + +while [[ $# -gt 0 ]]; do + case "$1" in + --ro-update) + MODE_RO_UPDATE=true + ;; + --finish) + MODE_FINISH_UPDATE=true + ;; + *) + DOWNLOAD_DELTA="$1" + ;; + esac + shift +done + +if [ $MODE_RO_UPDATE = false ] && [ $MODE_FINISH_UPDATE = false ]; then + MODE_RO_UPDATE=true + MODE_FINISH_UPDATE=true +fi -if [ "$#" != "1" ] || [ ! -f "$1" ]; then - echo "[Error] Usage: $0 path_to_delta.tar[.gz]" +if [ $MODE_RO_UPDATE = true ] && [ ! -f "$DOWNLOAD_DELTA" ]; then + echo "[Error] Usage: $0 [--ro_update ] [--finish]" exit 1 fi -prepare_fota_dir - -tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" checksum.SHA1 -tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc - -. "$FOTA_DIR"/upgrade-common.inc -upgrade_log_init -set_script_name_and_log_file "${BASH_SOURCE[0]}" +( +if [ $MODE_RO_UPDATE = false ] && [ $MODE_FINISH_UPDATE = true ]; then + if ! flock -n 9; then + echo "[Error] Upgrade in progress" + exit 2 + fi +else + flock 9 +fi -verify_file "$FOTA_DIR/upgrade-common.inc" +# if [ "$#" != "1" ] || [ ! -f "$1" ]; then +# echo "[Error] Usage: $0 path_to_delta.tar[.gz]" +# exit 1 +# fi +if [ $MODE_RO_UPDATE = true ]; then + prepare_fota_dir -verify_file "$0" -tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" update-info.ini -verify_file "$FOTA_DIR/update-info.ini" -tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" delta-verifier -verify_file "$FOTA_DIR/delta-verifier" + tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" checksum.SHA1 -log "[Info] Begin delta verification" -RET=0 -# '||'' used to stop script form exiting (errexit is set) -"${FOTA_DIR}/delta-verifier" --update_info_path "$FOTA_DIR/update-info.ini" || RET=$? + tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc +fi -if [ ${RET} -ne 0 ]; then - log "[Error] Delta verification unsuccessful" +if [ ! -f "$FOTA_DIR/upgrade-common.inc" ]; then + echo "[Error] upgrade-common.inc not exist" device_board_set_upgrade_status -1 exit 1 fi -log "[Info] Delta verification success" -set_upgrade_status 1 -verify_img "${DOWNLOAD_DELTA}" -do_update + . "$FOTA_DIR"/upgrade-common.inc + +if [ $MODE_RO_UPDATE = true ]; then + upgrade_log_init + set_script_name_and_log_file "${BASH_SOURCE[0]} $*" + + verify_file "$FOTA_DIR/upgrade-common.inc" + + verify_file "$0" + unpack_file "${DOWNLOAD_DELTA}" update-info.ini + unpack_file "${DOWNLOAD_DELTA}" delta-verifier + unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}" + unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}" + + log "[Info] Begin delta verification" + RET=0 + # '||'' used to stop script form exiting (errexit is set) + "${FOTA_DIR}/delta-verifier" --update_info_path "$FOTA_DIR/update-info.ini" || RET=$? + rm -f "${FOTA_DIR}/delta-verifier" + rm -f "${FOTA_DIR}/update-info.ini" + + if [ ${RET} -ne 0 ]; then + log "[Error] Delta verification unsuccessful" + device_board_set_upgrade_status -1 + exit 1 + fi + log "[Info] Delta verification success" + + set_upgrade_status 1 + verify_img "${DOWNLOAD_DELTA}" + do_update +fi + +if [ $MODE_FINISH_UPDATE = true ]; then + set_script_name_and_log_file "${BASH_SOURCE[0]}" + + verify_file "$0" + verify_file "$FOTA_DIR/upgrade-common.inc" + do_finish + +fi ) 9> "$FLOCK_PATH"