From 5de54625129ace255632429104e2f80709da4187 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Mon, 27 Sep 2021 18:56:21 +0200 Subject: [PATCH 01/16] Fix the updating of the RPM database Until now the RPM database has only been updated if the system version has changed. However such an update is needed even if the version number does not change. Change-Id: Ide8a6d7c5b79c18559c916895274145ae71c9b7b --- upgrade/update-init.sh.in | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/upgrade/update-init.sh.in b/upgrade/update-init.sh.in index 8f1d15b..c23c525 100755 --- a/upgrade/update-init.sh.in +++ b/upgrade/update-init.sh.in @@ -9,14 +9,11 @@ DEBUG_MODE_FILE=/opt/usr/.upgdebug if [ -f $RW_MACRO ]; then source $RW_MACRO - get_version_info fi -if [ ! "$OLD_VER" = "$NEW_VER" ]; then - # Restore rpm db - rm -rf /var/lib/rpm/* - restore_backup_file -f /opt/var/lib/rpm -fi +# Restore rpm db +rm -rf /var/lib/rpm/* +restore_backup_file -f /opt/var/lib/rpm # Permission Update for shared directories /etc/gumd/useradd.d/91_user-dbspace-permissions.post owner -- 2.7.4 From fff6248f7527c062ae3e7922643f38098272ef16 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 28 Oct 2021 17:08:40 +0200 Subject: [PATCH 02/16] No reboot after RW Update if there is A/B Update Change-Id: Ic2fa8cd56972b5c3676ebd6294bedf2eab5a8720 --- packaging/system-rw-update.spec | 6 ++++++ units/update-post.service | 12 ++++++++++++ upgrade/update-post.sh | 9 +++++++++ upgrade/update.sh.in | 5 +++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 units/update-post.service create mode 100755 upgrade/update-post.sh diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index aa184e2..4ede81a 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -44,6 +44,7 @@ cp upgrade/rw-update-macro.inc %{buildroot}%{upgrade_dir} cp upgrade/update-init.sh %{buildroot}%{upgrade_dir} cp upgrade/update.sh %{buildroot}%{upgrade_dir} cp upgrade/update-checkpoint-create.sh %{buildroot}%{upgrade_dir} +cp upgrade/update-post.sh %{buildroot}%{upgrade_dir} mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants install -m 644 units/offline-update.service %{buildroot}%{_unitdir} ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wants/ @@ -66,6 +67,10 @@ ln -s ../data-checkpoint.target %{buildroot}%{_unitdir}/system-update.target.wan mkdir -p %{buildroot}%{_unitdir}/data-checkpoint.target.wants ln -s ../data-checkpoint.service %{buildroot}%{_unitdir}/data-checkpoint.target.wants/data-checkpoint.service +# RW-Update finalize +install -m 644 units/update-post.service %{buildroot}%{_unitdir} +ln -s ../update-post.service %{buildroot}%{_unitdir}/system-update.target.wants + %clean rm -rf %{buildroot} @@ -82,6 +87,7 @@ fi %license LICENSE.Apache-2.0 %TZ_SYS_UPGRADE/* %{_unitdir}/offline-update.service +%{_unitdir}/update-post.service %{_unitdir}/system-update.target.wants %{_unitdir}/udev-sdb-init.service %{_unitdir}/udev-trigger-dmbow@.service diff --git a/units/update-post.service b/units/update-post.service new file mode 100644 index 0000000..1c9ee29 --- /dev/null +++ b/units/update-post.service @@ -0,0 +1,12 @@ +[Unit] +Description=RW Update finalization +DefaultDependencies=no +Wants=offline-update.service +After=offline-update.service +IgnoreOnIsolate=true + +[Service] +Type=oneshot +SmackProcessLabel=System::Privileged +ExecStart=/usr/share/upgrade/update-post.sh + diff --git a/upgrade/update-post.sh b/upgrade/update-post.sh new file mode 100755 index 0000000..8f454c7 --- /dev/null +++ b/upgrade/update-post.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [[ $( Date: Tue, 9 Nov 2021 18:07:55 +0100 Subject: [PATCH 03/16] Fix data commit on GPT partitions Without this patch it could happen that a partition has only PARTLABEL and LABEL is not set. In this case, the script would not recognize the partition type and would end with an error. Change-Id: I8e0ebedd39b566f9f591661c46f9dac61492ca72 --- upgrade/update.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade/update.sh.in b/upgrade/update.sh.in index 1277e48..df178c1 100755 --- a/upgrade/update.sh.in +++ b/upgrade/update.sh.in @@ -122,7 +122,7 @@ COMMIT_PARTITION() return fi - TYPE=$(blkid --match-token LABEL="${LABEL}" -o value -s TYPE | tail -n 1) + TYPE=$(blkid ${PART_DEVICE} -o value -s TYPE | tail -n 1) if [ "${TYPE}" = "ext4" ]; then COMMIT_BOW_PARTITION "${LABEL}" elif [ "${TYPE}" = "f2fs" ]; then -- 2.7.4 From 9c24ba61ee9f74eb272a6523c72716cfa70ab830 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 4 Nov 2021 17:23:24 +0100 Subject: [PATCH 04/16] Add update-finalize.service The service is started when RW Update is executed and default.target is reached. It is used to verify that the system has booted correctly. Change-Id: I5c046255d62fd943b63e111e3c999ce8bd45122a --- CMakeLists.txt | 1 + packaging/system-rw-update.spec | 8 ++++ units/update-finalize.service | 15 +++++++ upgrade/rw-update-macro.inc | 95 +++++++++++++++++++++++++++++++++++++++++ upgrade/update-finalize.sh.in | 22 ++++++++++ upgrade/update.sh.in | 82 +++-------------------------------- 6 files changed, 147 insertions(+), 76 deletions(-) create mode 100644 units/update-finalize.service create mode 100755 upgrade/update-finalize.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5481ce4..93e1591 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(rw-updater C) CONFIGURE_FILE(upgrade/install-sdb-rule.sh.in upgrade/install-sdb-rule.sh @ONLY) CONFIGURE_FILE(upgrade/update-init.sh.in upgrade/update-init.sh @ONLY) CONFIGURE_FILE(upgrade/update.sh.in upgrade/update.sh @ONLY) +CONFIGURE_FILE(upgrade/update-finalize.sh.in upgrade/update-finalize.sh @ONLY) CONFIGURE_FILE(upgrade/record-version.sh.in upgrade/record-version.sh @ONLY) CONFIGURE_FILE(units/udev-sdb-init.service.in units/udev-sdb-init.service @ONLY) CONFIGURE_FILE(units/offline-update.service.in units/offline-update.service @ONLY) diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index 4ede81a..06d78fc 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -45,6 +45,7 @@ cp upgrade/update-init.sh %{buildroot}%{upgrade_dir} cp upgrade/update.sh %{buildroot}%{upgrade_dir} cp upgrade/update-checkpoint-create.sh %{buildroot}%{upgrade_dir} cp upgrade/update-post.sh %{buildroot}%{upgrade_dir} +cp upgrade/update-finalize.sh %{buildroot}%{upgrade_dir} mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants install -m 644 units/offline-update.service %{buildroot}%{_unitdir} ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wants/ @@ -71,6 +72,11 @@ ln -s ../data-checkpoint.service %{buildroot}%{_unitdir}/data-checkpoint.target. install -m 644 units/update-post.service %{buildroot}%{_unitdir} ln -s ../update-post.service %{buildroot}%{_unitdir}/system-update.target.wants +# Update finalize +mkdir -p %{buildroot}%{_unitdir}/delayed.target.wants +install -m 644 units/update-finalize.service %{buildroot}%{_unitdir} +ln -s ../update-finalize.service %{buildroot}%{_unitdir}/delayed.target.wants + %clean rm -rf %{buildroot} @@ -88,9 +94,11 @@ fi %TZ_SYS_UPGRADE/* %{_unitdir}/offline-update.service %{_unitdir}/update-post.service +%{_unitdir}/update-finalize.service %{_unitdir}/system-update.target.wants %{_unitdir}/udev-sdb-init.service %{_unitdir}/udev-trigger-dmbow@.service %{_unitdir}/data-checkpoint.target %{_unitdir}/data-checkpoint.service %{_unitdir}/data-checkpoint.target.wants/data-checkpoint.service +%{_unitdir}/delayed.target.wants/update-finalize.service diff --git a/units/update-finalize.service b/units/update-finalize.service new file mode 100644 index 0000000..a98ce54 --- /dev/null +++ b/units/update-finalize.service @@ -0,0 +1,15 @@ +[Unit] +Description=Finalize OS update +DefaultDependencies=no +#Requisite=update-post.service default.target +#After=update-post.service default.target system-delayed-target-done.service +#IgnoreOnIsolate=true +After=system-delayed-target-done.service +ConditionKernelCommandLine=bootmode=fota + +[Service] +Type=oneshot +SmackProcessLabel=System::Privileged +ExecStart=/usr/share/upgrade/update-finalize.sh +RemainAfterExit=true + diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index 2bd932f..27ab6e8 100644 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -1,8 +1,31 @@ #!/bin/sh +STAT="/usr/bin/stat" OLD_VER= NEW_VER= OLD_VER_INFO="/opt/etc/version" +COLOR_ERROR='\033[01;31m' +COLOR_DEBUG='\033[01;34m' +COLOR_NOTIFY='\033[01;33m' +COLOR_RESET='\033[00;00m' + +DEBUG() +{ + LOG_TEXT=$1 + echo -e "${COLOR_DEBUG}${LOG_TEXT}${COLOR_RESET}" +} + +ERROR() +{ + LOG_TEXT=$1 + echo -e "${COLOR_ERROR}${LOG_TEXT}${COLOR_RESET}" +} + +NOTIFY() +{ + LOG_TEXT=$1 + echo -e "${COLOR_NOTIFY}${LOG_TEXT}${COLOR_RESET}" +} # Convert version to 4 digits convert_version() { @@ -128,3 +151,75 @@ restore_backup_file() { done fi } + +COMMIT_BOW_PARTITION() +{ + LABEL=${1} + + BOWDEV_PATH=/dev/mapper/bowdev_${LABEL} + DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH})))) + echo 2 > /sys/block/dm-${DM_NUMBER}/bow/state + NOTIFY "Changes on partition ${LABEL} commited (dm-bow)" +} + +COMMIT_F2FS_PARTITION() +{ + LABEL=${1} + PART_DEVICE=${2} + + mount -o remount,checkpoint=enable "${PART_DEVICE}" + NOTIFY "Changes on partition ${LABEL} commited (f2fs)" +} + +DELETE_BTRFS_PARTITION() { + PART="$1" + MNT_POINT="$("$FINDMNT" "$PART" -o TARGET)" + if [ "$MNT_POINT" = "" ]; then + ERROR "Unable to find btrfs mountpoint for: $PART" + return + fi + NOTIFY "Deleting btrfs snapshot" + umount "${MNT_POINT}" + mount -o subvolid=5,rw "${PART}" "${MNT_POINT}" + btrfs subvolume delete "$MNT_POINT"/fota/RO_update + rm -rf "$MNT_POINT/fota/RO_update" + umount "${MOUNT_POINT}" + mount -o rw "${PART}" "${MNT_POINT}" +} + + +COMMIT_BTRFS_PARTITION() +{ + LABEL=${1} + PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) + DELETE_BTRFS_PARTITION "${PART_SYSTEM_DATA}" + NOTIFY "Changes on partition ${LABEL} commited (btrfs)" +} + +COMMIT_PARTITION() +{ + LABEL=${1} + + PART_DEVICE=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) + if [ -z "${PART_DEVICE}" ]; then + NOTIFY "WARNING: Partition ${LABEL} not found" + return + fi + + TYPE=$(blkid ${PART_DEVICE} -o value -s TYPE | tail -n 1) + if [ "${TYPE}" = "ext4" ]; then + COMMIT_BOW_PARTITION "${LABEL}" + elif [ "${TYPE}" = "f2fs" ]; then + COMMIT_F2FS_PARTITION "${LABEL}" ${PART_DEVICE} + elif [ "${TYPE}" = "btrfs" ]; then + COMMIT_BTRFS_PARTITION "${LABEL}" + else + ERROR "ERROR: Cannot commit ${LABEL}: Unsupported filesystem ${TYPE}" + fi +} + +COMMIT_CHANGES() +{ + COMMIT_PARTITION system-data + COMMIT_PARTITION user +} diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in new file mode 100755 index 0000000..f80af43 --- /dev/null +++ b/upgrade/update-finalize.sh.in @@ -0,0 +1,22 @@ +#!/bin/bash + +UPDATE_SCRIPT_DIR=@TZ_SYS_UPGRADE_SCRIPTS@ +UPDATE_DATA_DIR=/opt/data/update +SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules + +RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc + +if [ -f $RW_MACRO ]; +then + source $RW_MACRO +else + ERROR "FAIL: Upgrade macro does not exist" + UPDATE_PREPARE_ERR=1 +fi + +if true; then + COMMIT_CHANGES +fi + +touch /tmp/set_BOOTING_OK +touch /tmp/booting_change_bootmode diff --git a/upgrade/update.sh.in b/upgrade/update.sh.in index df178c1..0d23538 100755 --- a/upgrade/update.sh.in +++ b/upgrade/update.sh.in @@ -1,9 +1,8 @@ -#!/bin/sh +#!/bin/bash # # System RW Update Script # STATUS_FILE="/opt/data/update/RW.STATUS" -STAT="/usr/bin/stat" COLOR_ERROR='\033[01;31m' COLOR_DEBUG='\033[01;34m' COLOR_NOTIFY='\033[01;33m' @@ -68,79 +67,6 @@ SET_UPDATE_RESULT() echo "$1" > ${UPDATE_RESULT_FILE} } -COMMIT_BOW_PARTITION() -{ - LABEL=${1} - - BOWDEV_PATH=/dev/mapper/bowdev_${LABEL} - DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH})))) - echo 2 > /sys/block/dm-${DM_NUMBER}/bow/state - NOTIFY "Changes on partition ${LABEL} commited (dm-bow)" -} - -COMMIT_F2FS_PARTITION() -{ - LABEL=${1} - PART_DEVICE=${2} - - mount -o remount,checkpoint=enable "${PART_DEVICE}" - NOTIFY "Changes on partition ${LABEL} commited (f2fs)" -} - -DELETE_BTRFS_PARTITION() { - PART="$1" - MNT_POINT="$("$FINDMNT" "$PART" -o TARGET)" - if [ "$MNT_POINT" = "" ]; then - ERROR "Unable to find btrfs mountpoint for: $PART" - return - fi - NOTIFY "Deleting btrfs snapshot" - umount "${MNT_POINT}" - mount -o subvolid=5,rw "${PART}" "${MNT_POINT}" - btrfs subvolume delete "$MNT_POINT"/fota/RO_update - rm -rf "$MNT_POINT/fota/RO_update" - umount "${MOUNT_POINT}" - mount -o rw "${PART}" "${MNT_POINT}" -} - - -COMMIT_BTRFS_PARTITION() -{ - LABEL=${1} - PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) - DELETE_BTRFS_PARTITION "${PART_SYSTEM_DATA}" - NOTIFY "Changes on partition ${LABEL} commited (btrfs)" -} - -COMMIT_PARTITION() -{ - LABEL=${1} - - PART_DEVICE=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) - if [ -z "${PART_DEVICE}" ]; then - NOTIFY "WARNING: Partition ${LABEL} not found" - return - fi - - TYPE=$(blkid ${PART_DEVICE} -o value -s TYPE | tail -n 1) - if [ "${TYPE}" = "ext4" ]; then - COMMIT_BOW_PARTITION "${LABEL}" - elif [ "${TYPE}" = "f2fs" ]; then - COMMIT_F2FS_PARTITION "${LABEL}" ${PART_DEVICE} - elif [ "${TYPE}" = "btrfs" ]; then - COMMIT_BTRFS_PARTITION "${LABEL}" - else - ERROR "ERROR: Cannot commit ${LABEL}: Unsupported filesystem ${TYPE}" - fi -} - -COMMIT_CHANGES() -{ - rm ${STATUS_FILE} - COMMIT_PARTITION system-data - COMMIT_PARTITION user -} - NOTIFY "----------------------------------------------------------------------" NOTIFY "System RW update: rw update started" @@ -209,5 +135,9 @@ rm /opt/.do_rw_update /bin/sync NOTIFY "----------------------------------------------------------------------" -COMMIT_CHANGES +if [[ ! $( Date: Tue, 23 Nov 2021 16:41:38 +0100 Subject: [PATCH 05/16] Commit changes on HAL partition for non-A/B upgrade Change-Id: I26c3569ff7aec2b28e112fe575b2c99109d60bcf --- units/data-checkpoint.service.in | 2 +- upgrade/rw-update-macro.inc | 4 ++++ upgrade/update-checkpoint-create.sh | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/units/data-checkpoint.service.in b/units/data-checkpoint.service.in index 866611f..b71fb49 100644 --- a/units/data-checkpoint.service.in +++ b/units/data-checkpoint.service.in @@ -1,7 +1,7 @@ [Unit] Description=Data checkpoint DefaultDependencies=no -Before=systemd-journald.service opt.mount opt-usr.mount +Before=systemd-journald.service opt.mount opt-usr.mount mnt-inform.mount [Service] diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index 27ab6e8..67369b1 100644 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -222,4 +222,8 @@ COMMIT_CHANGES() { COMMIT_PARTITION system-data COMMIT_PARTITION user + if [[ ! $( Date: Wed, 24 Nov 2021 14:52:54 +0100 Subject: [PATCH 06/16] Set the PATH variable Change-Id: I62e525d326c010fe045b3da71447a9b8542725ff --- upgrade/update-finalize.sh.in | 1 + upgrade/update-post.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index f80af43..105a32c 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -1,5 +1,6 @@ #!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin UPDATE_SCRIPT_DIR=@TZ_SYS_UPGRADE_SCRIPTS@ UPDATE_DATA_DIR=/opt/data/update SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules diff --git a/upgrade/update-post.sh b/upgrade/update-post.sh index 8f454c7..8aa3bb9 100755 --- a/upgrade/update-post.sh +++ b/upgrade/update-post.sh @@ -1,5 +1,7 @@ #!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin + if [[ $( Date: Wed, 24 Nov 2021 17:17:58 +0100 Subject: [PATCH 07/16] Change the smack label for update-* services Change-Id: I97cab0128aeed3aeff2219f9208739a89df4f643 --- units/update-finalize.service | 5 +---- units/update-post.service | 2 +- upgrade/update-finalize.sh.in | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/units/update-finalize.service b/units/update-finalize.service index a98ce54..2a059c6 100644 --- a/units/update-finalize.service +++ b/units/update-finalize.service @@ -1,15 +1,12 @@ [Unit] Description=Finalize OS update DefaultDependencies=no -#Requisite=update-post.service default.target -#After=update-post.service default.target system-delayed-target-done.service -#IgnoreOnIsolate=true After=system-delayed-target-done.service ConditionKernelCommandLine=bootmode=fota [Service] Type=oneshot -SmackProcessLabel=System::Privileged +SmackProcessLabel=System ExecStart=/usr/share/upgrade/update-finalize.sh RemainAfterExit=true diff --git a/units/update-post.service b/units/update-post.service index 1c9ee29..67f958e 100644 --- a/units/update-post.service +++ b/units/update-post.service @@ -7,6 +7,6 @@ IgnoreOnIsolate=true [Service] Type=oneshot -SmackProcessLabel=System::Privileged +SmackProcessLabel=System ExecStart=/usr/share/upgrade/update-post.sh diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index 105a32c..7c47741 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -1,9 +1,6 @@ #!/bin/bash PATH=/bin:/usr/bin:/sbin:/usr/sbin -UPDATE_SCRIPT_DIR=@TZ_SYS_UPGRADE_SCRIPTS@ -UPDATE_DATA_DIR=/opt/data/update -SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc @@ -15,9 +12,11 @@ else UPDATE_PREPARE_ERR=1 fi +# TOOD: check if system is stable if true; then COMMIT_CHANGES fi +# TODO: Replace this by calling the appropriate commands touch /tmp/set_BOOTING_OK touch /tmp/booting_change_bootmode -- 2.7.4 From cb16bbdda71bb06351af7c02c1c260fbf3f23c15 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 21 Dec 2021 15:59:24 +0100 Subject: [PATCH 08/16] Reboot after RW update Change-Id: Ia4ada1d338c295d9a18a14eb7debdb6c4b7dbac9 --- upgrade/update-finalize.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index 7c47741..b6de3d3 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -20,3 +20,4 @@ fi # TODO: Replace this by calling the appropriate commands touch /tmp/set_BOOTING_OK touch /tmp/booting_change_bootmode +reboot -f -- 2.7.4 From 7a8f65b59f01c5c11d7c41e8af4e0c2a5ac1098d Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 11 Jan 2022 10:31:17 +0100 Subject: [PATCH 09/16] Clear boot mode and set boot success after upgrade Change-Id: I8d16c29d18b8a9d03c73d0556a2a9d2954664198 --- upgrade/update-finalize.sh.in | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index 7c47741..e1f119b 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -13,10 +13,12 @@ else fi # TOOD: check if system is stable -if true; then +UPDATE_SUCCESS=1 + +if [ -z ${UPDATE_PREPARE_ERR+x} ] && [ "${UPDATE_SUCCESS}" == "1" ]; then + /usr/bin/device_board_clear_boot_mode COMMIT_CHANGES + /usr/bin/device_board_set_boot_success +else + reboot -f fota fi - -# TODO: Replace this by calling the appropriate commands -touch /tmp/set_BOOTING_OK -touch /tmp/booting_change_bootmode -- 2.7.4 From a14a1cf0ed85ddeabcff0016d6b2b4ba908cbc89 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 15 Feb 2022 15:09:30 +0100 Subject: [PATCH 10/16] Commit data and reboot right after RW-Upgrade Change-Id: I5ea54eb86edfb8c701c9680da399d861ade313e0 --- upgrade/update-post.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/upgrade/update-post.sh b/upgrade/update-post.sh index 8aa3bb9..dd52044 100755 --- a/upgrade/update-post.sh +++ b/upgrade/update-post.sh @@ -4,7 +4,16 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin if [[ $( Date: Fri, 4 Mar 2022 16:37:08 +0100 Subject: [PATCH 11/16] Cancel the RW Update if there is no .do_rw_update files This change is to prevent re-executing an upgrade if the system was booted in FOTA mode for reasons other than the actual upgrade. Change-Id: Ib5dc49c42b8878d8389f17d678526ff51f1ba39d --- upgrade/update.sh.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/upgrade/update.sh.in b/upgrade/update.sh.in index 0d23538..7471a2b 100755 --- a/upgrade/update.sh.in +++ b/upgrade/update.sh.in @@ -15,6 +15,7 @@ UPDATE_DATA_DIR=/opt/data/update SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc +RW_UPDATE_FLAG=/opt/.do_rw_update DEBUG() { @@ -67,6 +68,12 @@ SET_UPDATE_RESULT() echo "$1" > ${UPDATE_RESULT_FILE} } +if [[ $( Date: Thu, 12 May 2022 18:45:27 +0200 Subject: [PATCH 12/16] Set upgrade status Change-Id: Ie9494ad78cd95d71d6d1ba1a9398b2131efcf45c --- upgrade/update-finalize.sh.in | 1 + upgrade/update.sh.in | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index 7823516..ea7cdc8 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -19,6 +19,7 @@ if [ -z ${UPDATE_PREPARE_ERR+x} ] && [ "${UPDATE_SUCCESS}" == "1" ]; then /usr/bin/device_board_clear_boot_mode COMMIT_CHANGES /usr/bin/device_board_set_boot_success + /usr/bin/device_board_set_upgrade_status 100 reboot -f else reboot -f fota diff --git a/upgrade/update.sh.in b/upgrade/update.sh.in index 7471a2b..47a96d8 100755 --- a/upgrade/update.sh.in +++ b/upgrade/update.sh.in @@ -13,6 +13,9 @@ SHELL=/bin/bash UPDATE_SCRIPT_DIR=@TZ_SYS_UPGRADE_SCRIPTS@ UPDATE_DATA_DIR=/opt/data/update SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules +HAL_SET_UPGRADE_STATUS=/usr/bin/device_board_set_upgrade_status +HAL_PROGRESS_MIN=80 +HAL_PROGRESS_MAX=99 RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc RW_UPDATE_FLAG=/opt/.do_rw_update @@ -68,9 +71,15 @@ SET_UPDATE_RESULT() echo "$1" > ${UPDATE_RESULT_FILE} } +SET_UPGRADE_STATUS() +{ + ${HAL_SET_UPGRADE_STATUS} "$1" +} + if [[ $( Date: Tue, 17 May 2022 10:50:45 +0200 Subject: [PATCH 13/16] Error handling of checkpoint creation Change-Id: Iabae1e33e69fc347335f9804b1fba8abacf80915 --- upgrade/update-checkpoint-create.sh | 40 ++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/upgrade/update-checkpoint-create.sh b/upgrade/update-checkpoint-create.sh index cc276d1..4d4c1ed 100755 --- a/upgrade/update-checkpoint-create.sh +++ b/upgrade/update-checkpoint-create.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash PATH="/usr/bin:/bin:/usr/sbin:/sbin" SYNC="/bin/sync" @@ -15,6 +15,15 @@ USER_MNT="opt/usr" HAL_MNT="hal" BTRFS="/usr/sbin/btrfs" +exit_handler() { + if [ $? -ne 0 ]; then + echo "[Error] Failure to create checkpoint. Reboot." + reboot -f + exit 1 + fi + echo "[Debug] Checkpoint created" +} + get_partition_id() { PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=rootfs -o device || "$BLKID" --match-token LABEL=rootfs -o device) PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=system-data -o device || "$BLKID" --match-token LABEL=system-data -o device) @@ -41,15 +50,26 @@ mount_bow_partition() { DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH})))) echo 1 > /sys/block/dm-${DM_NUMBER}/bow/state - echo "[Debug] Mounted ${PARTITION} as DM-BOW" + if [ "$( Date: Wed, 18 May 2022 17:18:55 +0200 Subject: [PATCH 14/16] Clear partition AB cloned status after upgrade Change-Id: Ie115dd48a4ced91536d32686e127c85a29504abc --- upgrade/update-finalize.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index ea7cdc8..b7d08fc 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -18,6 +18,7 @@ UPDATE_SUCCESS=1 if [ -z ${UPDATE_PREPARE_ERR+x} ] && [ "${UPDATE_SUCCESS}" == "1" ]; then /usr/bin/device_board_clear_boot_mode COMMIT_CHANGES + /usr/bin/device_board_clear_partition_ab_cloned /usr/bin/device_board_set_boot_success /usr/bin/device_board_set_upgrade_status 100 reboot -f -- 2.7.4 From b182de84f2cbe379f0a76627719cfac28f916289 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Fri, 10 Jun 2022 16:08:21 +0900 Subject: [PATCH 15/16] Add '-l' option to blkid for optimization Change-Id: I9aa205a318c0786b547b28a65bd8d0e2eb3b3f00 Signed-off-by: SangYoun Kwak --- upgrade/rw-update-macro.inc | 4 ++-- upgrade/update-checkpoint-create.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index 67369b1..3ad1365 100644 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -191,7 +191,7 @@ DELETE_BTRFS_PARTITION() { COMMIT_BTRFS_PARTITION() { LABEL=${1} - PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) + PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device -l || blkid --match-token LABEL="${LABEL}" -o device -l) DELETE_BTRFS_PARTITION "${PART_SYSTEM_DATA}" NOTIFY "Changes on partition ${LABEL} commited (btrfs)" } @@ -200,7 +200,7 @@ COMMIT_PARTITION() { LABEL=${1} - PART_DEVICE=$(blkid --match-token PARTLABEL="${LABEL}" -o device || blkid --match-token LABEL="${LABEL}" -o device) + PART_DEVICE=$(blkid --match-token PARTLABEL="${LABEL}" -o device -l || blkid --match-token LABEL="${LABEL}" -o device -l) if [ -z "${PART_DEVICE}" ]; then NOTIFY "WARNING: Partition ${LABEL} not found" return diff --git a/upgrade/update-checkpoint-create.sh b/upgrade/update-checkpoint-create.sh index 4d4c1ed..525f1a4 100755 --- a/upgrade/update-checkpoint-create.sh +++ b/upgrade/update-checkpoint-create.sh @@ -25,11 +25,11 @@ exit_handler() { } get_partition_id() { - PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=rootfs -o device || "$BLKID" --match-token LABEL=rootfs -o device) - PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=system-data -o device || "$BLKID" --match-token LABEL=system-data -o device) - PART_USER=$("$BLKID" --match-token PARTLABEL=user -o device || "$BLKID" --match-token LABEL=user -o device) + PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=rootfs -o device -l || "$BLKID" --match-token LABEL=rootfs -o device -l) + PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=system-data -o device -l || "$BLKID" --match-token LABEL=system-data -o device -l) + PART_USER=$("$BLKID" --match-token PARTLABEL=user -o device -l || "$BLKID" --match-token LABEL=user -o device -l) if [[ ! $( Date: Mon, 27 Jun 2022 18:59:42 +0900 Subject: [PATCH 16/16] Add critical log where upgrade status is changing Change-Id: Ib6030b3236750d538149fe69c7f032c300da5668 Signed-off-by: SangYoun Kwak --- upgrade/rw-update-macro.inc | 10 ++++++++++ upgrade/update-finalize.sh.in | 25 ++++++++++++++++++++++++- upgrade/update.sh.in | 17 +++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index 3ad1365..5ed8aea 100644 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -27,6 +27,16 @@ NOTIFY() echo -e "${COLOR_NOTIFY}${LOG_TEXT}${COLOR_RESET}" } +CRITICAL_LOG() +{ + LOG="[$SCRIPT_NAME]$1" + dlogsend -k "$LOG" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + # Convert version to 4 digits convert_version() { i=0 diff --git a/upgrade/update-finalize.sh.in b/upgrade/update-finalize.sh.in index b7d08fc..acb2a14 100755 --- a/upgrade/update-finalize.sh.in +++ b/upgrade/update-finalize.sh.in @@ -4,6 +4,29 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc +HAL_SET_UPGRADE_STATUS=/usr/bin/device_board_set_upgrade_status + +SCRIPT_NAME=$(basename $0) +CRITICAL_LOG() +{ + LOG="[$SCRIPT_NAME]$1" + dlogsend -k "$LOG" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + +SET_UPGRADE_STATUS() +{ + ${HAL_SET_UPGRADE_STATUS} "$1" + if [ $? -eq 0 ]; then + CRITICAL_LOG "set_upgrade_status success: ${1}" + else + CRITICAL_LOG "set_upgrade_status failed: ${1}" + fi +} + if [ -f $RW_MACRO ]; then source $RW_MACRO @@ -20,7 +43,7 @@ if [ -z ${UPDATE_PREPARE_ERR+x} ] && [ "${UPDATE_SUCCESS}" == "1" ]; then COMMIT_CHANGES /usr/bin/device_board_clear_partition_ab_cloned /usr/bin/device_board_set_boot_success - /usr/bin/device_board_set_upgrade_status 100 + SET_UPGRADE_STATUS 100 reboot -f else reboot -f fota diff --git a/upgrade/update.sh.in b/upgrade/update.sh.in index 47a96d8..662fe64 100755 --- a/upgrade/update.sh.in +++ b/upgrade/update.sh.in @@ -20,6 +20,8 @@ HAL_PROGRESS_MAX=99 RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc RW_UPDATE_FLAG=/opt/.do_rw_update +SCRIPT_NAME=$(basename $0) + DEBUG() { LOG_TEXT=$1 @@ -38,6 +40,16 @@ NOTIFY() echo -e "${COLOR_NOTIFY}${LOG_TEXT}${COLOR_RESET}" } +CRITICAL_LOG() +{ + LOG="[$SCRIPT_NAME]$1" + dlogsend -k "$LOG" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + PROGRESS_DIR=/tmp/upgrade PROGRESS_INIT() { @@ -74,6 +86,11 @@ SET_UPDATE_RESULT() SET_UPGRADE_STATUS() { ${HAL_SET_UPGRADE_STATUS} "$1" + if [ $? -eq 0 ]; then + CRITICAL_LOG "set_upgrade_status success: ${1}" + else + CRITICAL_LOG "set_upgrade_status failed: ${1}" + fi } if [[ $(