Skip to content
Snippets Groups Projects
Commit e899bd8a authored by Denis Pynkin's avatar Denis Pynkin
Browse files

lib: add function set_bootcounter()


Function to reset the boot counter
Supporting old and new formats
Accept 2 arguments:
 bootcounter: number, 0 if skipped
 upgrade flag (could be omitted):
   1: set upgrade state (default)
   0: disable upgrade state

Signed-off-by: default avatarDenis Pynkin <denis.pynkin@collabora.com>
parent 93739185
No related branches found
No related tags found
3 merge requests!24Apply all changes from v2021pre,!23Backport refactoring ostree upgrade tests 2022dev1 -> v2021pre,!22Refactoring ostree upgrade tests
......@@ -19,11 +19,8 @@ phase_boot()
OLDREV=$(ostree rev-parse $BRANCHNAME)
ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$OLDREV
# Emulate the ugrade state -- set the upgrade flag and bootcounter to 0
# Use old format to be compatible with the first implementation of the counter
# echo "bc 00" | xxd -r -p /boot/uboot.cnt
# New format (depending on U-Boot installed):
echo "bd 01 00 01" | xxd -r -p > /boot/uboot.cnt
# Emulate the ugrade state -- set bootcounter to 0 and the upgrade flag
set_bootcounter 0 1
# Store the commit with prepared revision for use in tests later
echo $OLDREV > $(get_phase_data_path)
......@@ -55,9 +52,7 @@ phase_check_update()
# Emulate the ugrade state -- set the upgrade flag and bootcounter to any value above the limit
# This should to trigger the U-Boot to boot previous version after reboot
# New format (depending on U-Boot installed):
echo "bd 01 05 01" | xxd -r -p > /boot/uboot.cnt
sync
set_bootcounter 5
}
phase_check_rollback()
......
......@@ -47,9 +47,7 @@ phase_check_update()
# Emulate the ugrade state -- set the upgrade flag and bootcounter to any value above the limit
# This should to trigger the U-Boot to boot previous version after reboot
# New format (depending on U-Boot installed):
echo "bd 01 05 01" | xxd -r -p > /boot/uboot.cnt
sync
set_bootcounter 5
}
phase_check_rollback()
......
......@@ -344,3 +344,38 @@ check_bootcounter()
return $ret
)
}
# Function to reset the boot counter
# Supporting old and new formats
# Accept 2 arguments:
# bootcounter: number, 0 if skip
# upgrade flag (could be omitted):
# 1: set upgrade state (default)
# 0: disable upgrade state
set_bootcounter()
{
local bootcount="${1:-0}"
local upgrade_flag="${2:-1}"
local magic="bc"
test -f /boot/uboot.cnt && magic="$(od -An -t x1 -N1 /boot/uboot.cnt | tr -d ' ')"
case "$magic" in
"bc") # Old style "BC 00"
if [ "$upgrade_flag" -eq 1 ]; then
echo "bc $(printf "%.2x" $bootcount)" | xxd -r -p > /boot/uboot.cnt
else
# Remove the file to mark we are not in upgrade state
rm -f /boot/uboot.cnt
fi
;;
"bd") # New style "BD 01 00 01"
echo "bd 01 $(printf "%.2x" $bootcount) $(printf "%.2x" $upgrade_flag)" | xxd -r -p > /boot/uboot.cnt
;;
*)
echo "Unknown magic ($magic) in /boot/uboot.cnt"
return 1
;;
esac
sync
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment