Skip to content

Commit eee1d53

Browse files
committed
flash.sh: take a backup of known good firmware state to rollback to, revert to rollback if flashing fails for whatever reason.
Warn sleeps and give output. Removed recovery shell access after warning again that we are in known good state (TPMTOTP/HOTP will succeed on next reboot. TODO: remove some output as part of subsequent QUIET cleanup Signed-off-by: Thierry Laurion <[email protected]>
1 parent 99157f2 commit eee1d53

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

initrd/bin/flash.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ case "$CONFIG_FLASH_OPTIONS" in
2121
esac
2222

2323
flash_rom() {
24-
ROM=$1
24+
#backup firmware to rollback into in all failed attempts
25+
warn "Taking a backup of firmware in case we need to rollback..."
26+
$CONFIG_FLASH_OPTIONS -r /tmp/${CONFIG_BOARD}_bak.rom
27+
28+
ROM=$1 # ROM file to flash
29+
2530
if [ "$READ" -eq 1 ]; then
2631
$CONFIG_FLASH_OPTIONS -r "${ROM}" \
2732
|| recovery "Backup to $ROM failed"
@@ -47,9 +52,13 @@ flash_rom() {
4752
dd if=/tmp/pchstrp9.bin bs=1 count=4 seek=292 of=/tmp/${CONFIG_BOARD}.rom conv=notrunc >/dev/null 2>&1
4853
fi
4954

50-
warn "Do not power off computer. Updating firmware, this will take a few minutes"
55+
warn "Do not power off computer. Updating firmware, this could take a few minutes"
5156
$CONFIG_FLASH_OPTIONS -w /tmp/${CONFIG_BOARD}.rom 2>&1 \
52-
|| recovery "$ROM: Flash failed"
57+
|| warn "$ROM: Flash failed, restoring rollback fimrware backup..." \
58+
&& $CONFIG_FLASH_OPTIONS -w /tmp/${CONFIG_BOARD}_bak.rom \
59+
&& warn "$ROM: Flash failed, restored previous known good firmware state."
60+
#TODO: there is a lot of output from flashprog here to suppress???
61+
# But at least we didn't cause a brick...
5362
fi
5463
}
5564

@@ -104,6 +113,6 @@ fi
104113
flash_rom $ROM
105114

106115
# don't leave temporary files lying around
107-
rm -f /tmp/flash.sh.bak
116+
rm -f /tmp/flash.sh.bak /tmp/${CONFIG_BOARD}_bak.rom
108117

109118
exit 0

0 commit comments

Comments
 (0)