Modify upgrade-verifier to verify partitions with image files
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 18 Aug 2022 01:58:05 +0000 (10:58 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 18 Aug 2022 10:19:22 +0000 (19:19 +0900)
Change-Id: I7d83092a65ff153e18dd498e40122d6787318094
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
upgrade-verifier/README
upgrade-verifier/checker.sh [deleted file]
upgrade-verifier/fvt.sh [deleted file]
upgrade-verifier/upgrade-verifier-on-device.sh [new file with mode: 0755]
upgrade-verifier/upgrade-verifier.sh [new file with mode: 0755]

index 8dff305..01b8632 100644 (file)
@@ -2,8 +2,7 @@
 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.
+2. Run ./upgrade-verifier.sh <bl_image> <ap_image> <target delta.cfg>
 
+The upgrade-verifier.sh script will copy upgrade-verifier-on-device.sh and checksum.txt(created by upgrade-verifier.sh) by sdb and run upgrade-verifier-on-device.sh.
+upgrade-verifier-on-device.sh will verify that the partitions checksum match.
diff --git a/upgrade-verifier/checker.sh b/upgrade-verifier/checker.sh
deleted file mode 100755 (executable)
index 4897313..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/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
deleted file mode 100755 (executable)
index 49ef53b..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/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"
-
diff --git a/upgrade-verifier/upgrade-verifier-on-device.sh b/upgrade-verifier/upgrade-verifier-on-device.sh
new file mode 100755 (executable)
index 0000000..9bc2e5b
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+function current_suffix() {
+       device_board_get_current_partition
+}
+
+function opposite_suffix() {
+       if [[ $(current_suffix) == "a" ]]; then
+               echo "b"
+       else
+               echo "a"
+       fi
+}
+
+function verify_partitions() {
+       local slot=$1
+       local checksum_file=$2
+
+       echo -e "\n\nVerify partition ${slot}"
+
+       while read -r label_name bin_name bin_size bin_sha1; do
+               local partlabel="${label_name}_${slot}"
+               local dev_path=$(blkid -t PARTLABEL="${partlabel}" -o device)
+
+               echo -n "Checking ${label_name} (bin_name=${bin_name}, partlabel=${partlabel}, dev_path=${dev_path}): "
+
+               if [[ -z ${dev_path} ]]; then
+                       echo "Invalid partlabel"
+                       continue
+               fi
+
+               if [[ -z "${bin_name}" ]]; then
+                       echo "No binary found, skip"
+                       continue
+               fi
+
+               local part_sha1=$(head -c ${bin_size} ${dev_path} | sha1sum | awk '{print $1}')
+               if [[ "${bin_sha1}" == "${part_sha1}" ]]; then
+                       echo "OK"
+               else
+                       echo "Incorrect checksum(${bin_sha1} != ${part_sha1})"
+               fi
+       done < <(sed -e '/^#/d' -e '/^$/d' "${checksum_file}")
+}
+
+if [ "$(device_board_get_partition_ab_cloned)" != "1" ]; then
+       clone_partitions.sh
+fi
+
+verify_partitions "$(current_suffix)" "checksums.txt"
+verify_partitions "$(opposite_suffix)" "checksums.txt"
diff --git a/upgrade-verifier/upgrade-verifier.sh b/upgrade-verifier/upgrade-verifier.sh
new file mode 100755 (executable)
index 0000000..04e7975
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+usage() {
+       echo "usage: $0 <bl_image> <ap_image> <target delta.cfg>"
+}
+
+create_checksum() {
+       local bl_img=$1
+       local ap_img=$2
+       local delta_cfg=$3
+       local checksum_file=$4
+       local temp_dir=".imgs_tmp"
+
+       if [ -d ${temp_dir} ]; then
+               echo "${temp_dir} already exist"
+               return 1
+       fi
+
+       echo "Creating ${checksum_file}"
+
+       mkdir ${temp_dir}
+       tar xfv ${bl_img} -C ${temp_dir} > /dev/null
+       tar xfv ${ap_img} -C ${temp_dir} > /dev/null
+
+       : > ${checksum_file}
+       while read -r partition_label bin_name delta_name update_type blk_dev blk_offset; do
+               local bin_path="${temp_dir}/${bin_name}"
+               if [ ! -f ${bin_path} ]; then
+                       echo "${bin_name} not exist"
+                       echo "${partition_label}" >> ${checksum_file}
+                       continue
+               fi
+               local checksum=$(sha1sum ${bin_path} | awk '{print $1}')
+               local bin_size=$(stat -c %s "${bin_path}")
+               echo "${partition_label} ${bin_name} ${bin_size} ${checksum}" >> ${checksum_file}
+       done < <(sed -e '/^#/d' -e '/^$/d' "${delta_cfg}")
+
+       echo "${checksum_file} created"
+       rm ${temp_dir} -r
+
+       return 0
+}
+
+# check parameters
+if [ $# -ne 3 ]; then
+       usage $0
+       exit 1
+fi
+
+BL_IMG=$1
+AP_IMG=$2
+DELTA_CFG=$3
+CHECKSUM_FILE="checksums.txt"
+DEST_DIR="/opt/usr/verifier"
+CHECKER_SCRIPT="upgrade-verifier-on-device.sh"
+
+if [ ! -f "${BL_IMG}" ] || [ ! -f "${AP_IMG}" ] || [ ! -f "${DELTA_CFG}" ]; then
+       usage $0
+       exit 1
+fi
+
+create_checksum ${BL_IMG} ${AP_IMG} ${DELTA_CFG} ${CHECKSUM_FILE}
+if [ $? -ne 0 ]; then
+       echo "failed to create checksum file"
+       exit 1
+fi
+
+echo "Upload files"
+{ sleep 1; echo tizen; } | sdb shell su -c "mkdir -p $DEST_DIR && chmod 777 $DEST_DIR"
+sdb push "${CHECKER_SCRIPT}" "${DEST_DIR}"
+sdb push "${CHECKSUM_FILE}" "${DEST_DIR}"
+{ sleep 1; echo tizen; } | sdb shell su -c "chmod +x $DEST_DIR/$CHECKER_SCRIPT"
+
+echo "Run verifier"
+{ sleep 1; echo tizen; } | sdb shell su -c "cd $DEST_DIR && $DEST_DIR/$CHECKER_SCRIPT"