Skip to content

Commit 2472a3b

Browse files
committed
dasharo-deploy: Add sanity check before flash
This commit adds last resort check before performing any flashrom commands. For heads update, we shall not proceed if FD or ME is locked. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@3mdeb.com>
1 parent 15e6c41 commit 2472a3b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

include/dts-functions.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,41 @@ set_flashrom_update_params() {
688688
fi
689689
}
690690

691+
# A final check for locked regions before flashing via flashrom.
692+
# Decide whether we can proceed if any regions are locked.
693+
flashrom_sanity_check() {
694+
local locked_regions=()
695+
local region_list verb
696+
697+
if [ "$BOARD_FD_REGION_RW" -eq 0 ]; then
698+
locked_regions+=("FD")
699+
fi
700+
701+
if [ "$BOARD_ME_REGION_RW" -eq 0 ]; then
702+
locked_regions+=("ME")
703+
fi
704+
705+
if [ "${#locked_regions[@]}" -eq 0 ]; then
706+
return 0
707+
fi
708+
709+
if [ "${#locked_regions[@]}" -eq 1 ]; then
710+
region_list="${locked_regions[0]}"
711+
verb="is"
712+
else
713+
region_list="${locked_regions[0]} and ${locked_regions[1]}"
714+
verb="are"
715+
fi
716+
717+
if [[ "$SWITCHING_TO" == "heads" ]]; then
718+
print_error "Cannot proceed with heads update when $region_list $verb locked!"
719+
return 1
720+
fi
721+
722+
print_warning "Proceeding without $region_list $verb flashing, as they $verb not critical."
723+
return 0
724+
}
725+
691726
set_intel_regions_update_params() {
692727
local fd_me_locked="no"
693728
if [ $BOARD_HAS_FD_REGION -eq 0 ]; then

scripts/dasharo-deploy.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,11 @@ deploy_firmware() {
10501050
fi
10511051
done
10521052

1053+
# Last restort check before flashing
1054+
if ! flashrom_sanity_check; then
1055+
return 1
1056+
fi
1057+
10531058
_jobs_total=${#_jobs[@]}
10541059

10551060
# Execute scheduled tasks
@@ -1245,7 +1250,10 @@ update_workflow() {
12451250
display_warning
12461251
fi
12471252

1248-
deploy_firmware update
1253+
# Check if update succeeded
1254+
if ! deploy_firmware update; then
1255+
return 1
1256+
fi
12491257

12501258
# TODO: Could it be placed somewhere else?
12511259
if [ ! -z "$SWITCHING_TO" ]; then

0 commit comments

Comments
 (0)