Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automated: linux: enable custom path for OTA rollback u-boot #512

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions automated/linux/ota-rollback/download-update.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2021 Foundries.io Ltd.
# Copyright (C) 2021-2024 Foundries.io Ltd.

# shellcheck disable=SC1091
. ../../lib/sh-test-lib
Expand All @@ -13,13 +13,13 @@ export UBOOT_VAR_TOOL
UBOOT_VAR_SET_TOOL=fw_setenv
export UBOOT_VAR_SET_TOOL
PACMAN_TYPE="ostree+compose_apps"
UBOOT_IMAGE_NAME="u-boot.itb"
UBOOT_IMAGE_PATH="/sysroot/ostree/deploy/lmp/deploy/\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb"
DEBUG="false"
SOTA_CONFDIR="/etc/sota/conf.d"

usage() {
echo "\
Usage: $0 [-t <kernel|uboot>] [-u <u-boot var read>] [-s <u-boot var set>] [-o <ostree|ostree+compose_apps>] [-d <true|false>]
echo "\
Usage: $0 [-t <kernel|uboot>] [-u <u-boot var read>] [-s <u-boot var set>] [-o <ostree|ostree+compose_apps>] [-d <true|false>]

-t <kernel|uboot|app>
This determines type of corruption test performed:
Expand All @@ -40,22 +40,31 @@ usage() {
These change the 'type' variable in 'pacman' section
of the final .toml file used by aklite. Default is
ostree+compose_apps
-f u-boot image file name to corrupt. On some machines
u-boot image has different name. Default is u-boot.itb
-f path to u-boot image file name to corrupt. On some machines
u-boot image has different name. Default is:
/sysroot/ostree/deploy/lmp/deploy/\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb
DEPLOYMENT_HASH is substituted after the OTA update
is downloaded.
Additional variable FS_HASH is available to construct
the final path. FS_HASH is a string that corresponds to
DEPLOYMENT_HASH ostree commit ID and is used in the
filesystem paths.
-d <true|false> Enables more debug messages. Default: false
"
"
}

while getopts "t:u:s:o:f:d:h" opts; do
case "$opts" in
case "$opts" in
t) TYPE="${OPTARG}";;
u) UBOOT_VAR_TOOL="${OPTARG}";;
s) UBOOT_VAR_SET_TOOL="${OPTARG}";;
o) PACMAN_TYPE="${OPTARG}";;
f) UBOOT_IMAGE_NAME="${OPTARG}";;
f) IMAGE_PATH="${OPTARG}"
eval UBOOT_IMAGE_PATH="${IMAGE_PATH}"
;;
d) DEBUG="${OPTARG}";;
h|*) usage ; exit 1 ;;
esac
esac
done

# the script works only on builds with aktualizr-lite
Expand Down Expand Up @@ -147,9 +156,9 @@ fi
# wait for 'install-post' signal
while ! grep "install-post" /var/sota/ota.signal
do
echo "Sleeping 1s"
sleep 1
cat /var/sota/ota.signal
echo "Sleeping 1s"
sleep 1
cat /var/sota/ota.signal
done
report_pass "${TYPE}-install-post-received"

Expand Down Expand Up @@ -191,19 +200,28 @@ fi

if [ "${UPGRADE_AVAILABLE}" -eq 1 ]; then
if [ "${TYPE}" = "uboot" ]; then
# obtain new deployment hash
DEPLOYMENT_HASH=$(ostree admin status | grep pending | awk -F' ' '{print $2}')
FS_HASH=""
# add debug print to understand which file is corrupted
ostree admin status
for DIRECTORY in /ostree/boot.0/lmp/*
do
echo "$DIRECTORY/0 ->"
readlink "$DIRECTORY/0"
D=$(realpath "$DIRECTORY/0")
echo "${D}"
if echo "${D}" | grep "${DEPLOYMENT_HASH}"; then
FS_HASH=${DIRECTORY##*/}
fi
done
echo "UBOOT_IMAGE_PATH: ${UBOOT_IMAGE_PATH}"
echo "FS_HASH: ${FS_HASH}"
echo "DEPLOYMENT_HASH: ${DEPLOYMENT_HASH}"

# obtain new deployment hash
DEPLOYMENT_HASH=$(ostree admin status | grep pending | awk -F' ' '{print $2}')
echo "Corrupting u-boot.itb in /sysroot/ostree/deploy/lmp/deploy/${DEPLOYMENT_HASH}/usr/lib/firmware/${UBOOT_IMAGE_NAME}"
eval UBOOT_PATH="${UBOOT_IMAGE_PATH}"
echo "Corrupting u-boot.itb in ${UBOOT_PATH}"
# corrupt u-boot.itb
echo bad > "/sysroot/ostree/deploy/lmp/deploy/${DEPLOYMENT_HASH}/usr/lib/firmware/${UBOOT_IMAGE_NAME}"
echo bad > "${UBOOT_PATH}"
fi
if [ "${TYPE}" = "kernel" ]; then
cat /etc/os-release
Expand Down
5 changes: 3 additions & 2 deletions automated/linux/ota-rollback/download-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ metadata:
params:
UBOOT_VAR_TOOL: "fw_printenv"
UBOOT_VAR_SET_TOOL: "fw_setenv"
UBOOT_IMAGE_NAME: "u-boot.itb"
# use double escape before $
UBOOT_IMAGE_PATH: "/sysroot/ostree/deploy/lmp/deploy/\\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb"
TYPE: "kernel"
PACMAN_TYPE: "ostree+compose_apps"
DEBUG: "false"
run:
steps:
- cd ./automated/linux/ota-rollback
- ./download-update.sh -t "${TYPE}" -u "${UBOOT_VAR_TOOL}" -s "${UBOOT_VAR_SET_TOOL}" -o "${PACMAN_TYPE}" -f "${UBOOT_IMAGE_NAME}" -d "${DEBUG}"
- ./download-update.sh -t "${TYPE}" -u "${UBOOT_VAR_TOOL}" -s "${UBOOT_VAR_SET_TOOL}" -o "${PACMAN_TYPE}" -f "${UBOOT_IMAGE_PATH}" -d "${DEBUG}"
- ../../utils/send-to-lava.sh ./output/result.txt
Loading