Skip to content

Commit 1cda403

Browse files
committed
WiP: backup rom first, revert to backup if flashing fails
Signed-off-by: Thierry Laurion <[email protected]>
1 parent 99157f2 commit 1cda403

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

initrd/bin/flash.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ 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+
$CONFIG_FLASH_OPTIONS -r /tmp/${CONFIG_BOARD}_bak.rom
26+
27+
ROM=$1 # ROM file to flash
28+
2529
if [ "$READ" -eq 1 ]; then
2630
$CONFIG_FLASH_OPTIONS -r "${ROM}" \
2731
|| recovery "Backup to $ROM failed"
@@ -47,9 +51,10 @@ flash_rom() {
4751
dd if=/tmp/pchstrp9.bin bs=1 count=4 seek=292 of=/tmp/${CONFIG_BOARD}.rom conv=notrunc >/dev/null 2>&1
4852
fi
4953

50-
warn "Do not power off computer. Updating firmware, this will take a few minutes"
54+
warn "Do not power off computer. Updating firmware, this could take a few minutes"
5155
$CONFIG_FLASH_OPTIONS -w /tmp/${CONFIG_BOARD}.rom 2>&1 \
52-
|| recovery "$ROM: Flash failed"
56+
|| $CONFIG_FLASH_OPTIONS -w /tmp/${CONFIG_BOARD}_bak.rom \
57+
&& recovery "$ROM: Flash failed, restored previous known good firmware state" \
5358
fi
5459
}
5560

@@ -104,6 +109,6 @@ fi
104109
flash_rom $ROM
105110

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

109114
exit 0

0 commit comments

Comments
 (0)