Skip to content

Commit 443b0f2

Browse files
mwasilewroxell
authored andcommitted
automated: linux: enable custom path for OTA rollback u-boot
This patch allows to corrupt u-boot image in arbitrary path. It's required for systems that use LUKS encryption. When LUKS is used, after downloading an update, bootloader files are copied to unencrypted partition, from where they can be read by u-boot runtime. Signed-off-by: Milosz Wasilewski <milosz.wasilewski@foundries.io>
1 parent 931f926 commit 443b0f2

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

automated/linux/ota-rollback/download-update.sh

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0-only
3-
# Copyright (C) 2021 Foundries.io Ltd.
3+
# Copyright (C) 2021-2024 Foundries.io Ltd.
44

55
# shellcheck disable=SC1091
66
. ../../lib/sh-test-lib
@@ -13,7 +13,7 @@ export UBOOT_VAR_TOOL
1313
UBOOT_VAR_SET_TOOL=fw_setenv
1414
export UBOOT_VAR_SET_TOOL
1515
PACMAN_TYPE="ostree+compose_apps"
16-
UBOOT_IMAGE_NAME="u-boot.itb"
16+
UBOOT_IMAGE_PATH="/sysroot/ostree/deploy/lmp/deploy/\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb"
1717
DEBUG="false"
1818
SOTA_CONFDIR="/etc/sota/conf.d"
1919

@@ -40,8 +40,15 @@ usage() {
4040
These change the 'type' variable in 'pacman' section
4141
of the final .toml file used by aklite. Default is
4242
ostree+compose_apps
43-
-f u-boot image file name to corrupt. On some machines
44-
u-boot image has different name. Default is u-boot.itb
43+
-f path to u-boot image file name to corrupt. On some machines
44+
u-boot image has different name. Default is:
45+
/sysroot/ostree/deploy/lmp/deploy/\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb
46+
DEPLOYMENT_HASH is substituted after the OTA update
47+
is downloaded.
48+
Additional variable FS_HASH is available to construct
49+
the final path. FS_HASH is a string that corresponds to
50+
DEPLOYMENT_HASH ostree commit ID and is used in the
51+
filesystem paths.
4552
-d <true|false> Enables more debug messages. Default: false
4653
"
4754
}
@@ -52,7 +59,9 @@ while getopts "t:u:s:o:f:d:h" opts; do
5259
u) UBOOT_VAR_TOOL="${OPTARG}";;
5360
s) UBOOT_VAR_SET_TOOL="${OPTARG}";;
5461
o) PACMAN_TYPE="${OPTARG}";;
55-
f) UBOOT_IMAGE_NAME="${OPTARG}";;
62+
f) IMAGE_PATH="${OPTARG}"
63+
eval UBOOT_IMAGE_PATH="${IMAGE_PATH}"
64+
;;
5665
d) DEBUG="${OPTARG}";;
5766
h|*) usage ; exit 1 ;;
5867
esac
@@ -191,19 +200,28 @@ fi
191200

192201
if [ "${UPGRADE_AVAILABLE}" -eq 1 ]; then
193202
if [ "${TYPE}" = "uboot" ]; then
203+
# obtain new deployment hash
204+
DEPLOYMENT_HASH=$(ostree admin status | grep pending | awk -F' ' '{print $2}')
205+
FS_HASH=""
194206
# add debug print to understand which file is corrupted
195207
ostree admin status
196208
for DIRECTORY in /ostree/boot.0/lmp/*
197209
do
198210
echo "$DIRECTORY/0 ->"
199-
readlink "$DIRECTORY/0"
211+
D=$(realpath "$DIRECTORY/0")
212+
echo "${D}"
213+
if echo "${D}" | grep "${DEPLOYMENT_HASH}"; then
214+
FS_HASH=${DIRECTORY##*/}
215+
fi
200216
done
217+
echo "UBOOT_IMAGE_PATH: ${UBOOT_IMAGE_PATH}"
218+
echo "FS_HASH: ${FS_HASH}"
219+
echo "DEPLOYMENT_HASH: ${DEPLOYMENT_HASH}"
201220

202-
# obtain new deployment hash
203-
DEPLOYMENT_HASH=$(ostree admin status | grep pending | awk -F' ' '{print $2}')
204-
echo "Corrupting u-boot.itb in /sysroot/ostree/deploy/lmp/deploy/${DEPLOYMENT_HASH}/usr/lib/firmware/${UBOOT_IMAGE_NAME}"
221+
eval UBOOT_PATH="${UBOOT_IMAGE_PATH}"
222+
echo "Corrupting u-boot.itb in ${UBOOT_PATH}"
205223
# corrupt u-boot.itb
206-
echo bad > "/sysroot/ostree/deploy/lmp/deploy/${DEPLOYMENT_HASH}/usr/lib/firmware/${UBOOT_IMAGE_NAME}"
224+
echo bad > "${UBOOT_PATH}"
207225
fi
208226
if [ "${TYPE}" = "kernel" ]; then
209227
cat /etc/os-release

automated/linux/ota-rollback/download-update.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ metadata:
2020
params:
2121
UBOOT_VAR_TOOL: "fw_printenv"
2222
UBOOT_VAR_SET_TOOL: "fw_setenv"
23-
UBOOT_IMAGE_NAME: "u-boot.itb"
23+
# use double escape before $
24+
UBOOT_IMAGE_PATH: "/sysroot/ostree/deploy/lmp/deploy/\\${DEPLOYMENT_HASH}/usr/lib/firmware/u-boot.itb"
2425
TYPE: "kernel"
2526
PACMAN_TYPE: "ostree+compose_apps"
2627
DEBUG: "false"
2728
run:
2829
steps:
2930
- cd ./automated/linux/ota-rollback
30-
- ./download-update.sh -t "${TYPE}" -u "${UBOOT_VAR_TOOL}" -s "${UBOOT_VAR_SET_TOOL}" -o "${PACMAN_TYPE}" -f "${UBOOT_IMAGE_NAME}" -d "${DEBUG}"
31+
- ./download-update.sh -t "${TYPE}" -u "${UBOOT_VAR_TOOL}" -s "${UBOOT_VAR_SET_TOOL}" -o "${PACMAN_TYPE}" -f "${UBOOT_IMAGE_PATH}" -d "${DEBUG}"
3132
- ../../utils/send-to-lava.sh ./output/result.txt

0 commit comments

Comments
 (0)