Add update-verifier
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 27 Jul 2022 10:43:20 +0000 (12:43 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 27 Jul 2022 10:43:20 +0000 (12:43 +0200)
Change-Id: Id074d36297145e07f68d49be8f51feafcc726d5a

upgrade-verifier/README [new file with mode: 0644]
upgrade-verifier/checker.sh [new file with mode: 0755]
upgrade-verifier/fvt.sh [new file with mode: 0755]

diff --git a/upgrade-verifier/README b/upgrade-verifier/README
new file mode 100644 (file)
index 0000000..8dff305
--- /dev/null
@@ -0,0 +1,9 @@
+1. Connect the target
+2. Flash old image
+3. Perform the upgrade using the delta file
+4. Wait for the upgrade to complete
+2. Run ./fvt.sh <delta_file>
+
+The fvt.sh script will copy checker.sh and update.cfg from the delta file by sdb and run checker.sh.
+checker.sh will verify that the partitions checksum match.
+
diff --git a/upgrade-verifier/checker.sh b/upgrade-verifier/checker.sh
new file mode 100755 (executable)
index 0000000..4897313
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+CONFIG_PATH=update.cfg
+BACKGROUND_COPY_LIST=/hal/etc/upgrade/background_copy.list
+
+
+function is_cloned() {
+       [[ $(device_board_get_partition_ab_cloned) == "1" ]]
+}
+
+function get_part_labels() {
+       echo -e "${1}_a\n${1}_b"
+}
+
+function current_part_with_suffix() {
+       echo "${1}_$(current_suffix)"
+}
+
+function opposite_part_with_suffix() {
+       echo "${1}_$(opposite_suffix)"
+}
+
+function current_suffix() {
+       device_board_get_current_partition
+}
+
+function opposite_suffix() {
+       if [[ $(current_suffix) == "a" ]]; then
+               echo "b"
+       else
+               echo "a"
+       fi
+}
+
+function verify_part() {
+       PARTLABEL="$1"
+       SIZE="$2"
+       SHA="$3"
+       device=$(blkid -t PARTLABEL="$PARTLABEL" -o device)
+       CUR_SHA1=$(head -c "$SIZE" "$device" | sha1sum | awk '{print $1}')
+       [[ "$CUR_SHA1" == "$SHA" ]]
+}
+
+function verify_update() {
+       echo -e "\n\nVerify update"
+       echo "Current slot: $(device_board_get_current_partition)"
+       while read -r LABEL_NAME DELTA_NAME TYPE DEV OFFSET OLD_SIZE NEW_SIZE OLD_SHA NEW_SHA
+       do
+               PARTLABEL=$(current_part_with_suffix "$LABEL_NAME")
+               echo -n "Checking $LABEL_NAME ($PARTLABEL): "
+               if verify_part "$PARTLABEL" "$NEW_SIZE" "$NEW_SHA"; then
+                       echo "OK"
+               else
+                       echo "Incorrect checksum"
+               fi
+       done < <(sed -e '/^#/d' -e '/^$/d' "$CONFIG_PATH")
+}
+
+function verify_clone() {
+       echo -e "\n\nVerify clone"
+       echo "Opposite slot: $(opposite_suffix)"
+       while read -r LABEL_NAME
+       do
+               read -r SIZE SHA < <(awk "/$LABEL_NAME/ {print \$7 \" \" \$9}" $CONFIG_PATH)
+               PARTLABEL=$(opposite_part_with_suffix "$LABEL_NAME")
+               echo -n "Checking $LABEL_NAME ($PARTLABEL): "
+               if verify_part "$PARTLABEL" "$SIZE" "$SHA"; then
+                       echo "OK"
+               else
+                       echo "Incorrect checksum"
+               fi
+
+       done < <(sed -e '/^#/d' -e '/^$/d' "$BACKGROUND_COPY_LIST")
+}
+
+if ! is_cloned; then
+       clone_partitions.sh
+fi
+
+verify_update
+verify_clone
diff --git a/upgrade-verifier/fvt.sh b/upgrade-verifier/fvt.sh
new file mode 100755 (executable)
index 0000000..49ef53b
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+DEST_DIR=/opt/usr/verifier
+CHECKER_SH=checker.sh
+
+
+if [ "$#" != "1" ] || [ ! -f "$1" ]; then
+       echo "Use:"
+       echo "    $0 <delta_file>"
+       exit 1
+fi
+
+UPLOAD_FILES=( checker.sh update.cfg )
+
+echo "Extract update.cfg from $1"
+tar xvf "${1}" update.cfg
+
+echo "Upload files"
+{ sleep 0.2; echo tizen; } | sdb shell su -c "mkdir -p $DEST_DIR && chmod 777 $DEST_DIR"
+for FILE in "${UPLOAD_FILES[@]}"; do
+       sdb push "$FILE" "$DEST_DIR"
+done
+
+{ sleep 0.2; echo tizen; } | sdb shell su -c "chmod +x $DEST_DIR/$CHECKER_SH"
+
+echo "Run verifier"
+{ sleep 0.2; echo tizen; } | sdb shell su -c "cd $DEST_DIR && $DEST_DIR/$CHECKER_SH"
+