Skip to content

Commit

Permalink
WiP: backup rom first, revert to backup if flashing fails
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Laurion <[email protected]>
  • Loading branch information
tlaurion committed Nov 30, 2024
1 parent 99157f2 commit 1cda403
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions initrd/bin/flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ case "$CONFIG_FLASH_OPTIONS" in
esac

flash_rom() {
ROM=$1
#backup firmware to rollback into in all failed attempts
$CONFIG_FLASH_OPTIONS -r /tmp/${CONFIG_BOARD}_bak.rom

ROM=$1 # ROM file to flash

if [ "$READ" -eq 1 ]; then
$CONFIG_FLASH_OPTIONS -r "${ROM}" \
|| recovery "Backup to $ROM failed"
Expand All @@ -47,9 +51,10 @@ flash_rom() {
dd if=/tmp/pchstrp9.bin bs=1 count=4 seek=292 of=/tmp/${CONFIG_BOARD}.rom conv=notrunc >/dev/null 2>&1
fi

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

Expand Down Expand Up @@ -104,6 +109,6 @@ fi
flash_rom $ROM

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

exit 0

0 comments on commit 1cda403

Please sign in to comment.