Skip to content

Commit

Permalink
flash.sh: single firmware read backup and logic fixes
Browse files Browse the repository at this point in the history
- Have Talos II supported by detecting correctly size of mtd chip (not internal: different flashrom output needs to be parsed for chip size)
- Read SPI content only once: 66% speedup (TOCTOU? Don't think so, nothing should happen in parallel when flashing insingle user mode)
- Have the main lfash_progress loop not break, but break in flash_rom state subcases (otherwise, verifying step was breaking)
  • Loading branch information
tlaurion committed Oct 27, 2022
1 parent 0389eca commit 642338e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions initrd/bin/flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ flashrom_progress() {
while true ; do
prev_prev_word=$prev_word
prev_word=$IN
read -r -d' ' IN || break
read -r -d' ' IN
if [ "$total_bytes" != "0" ]; then
current=$(echo "$IN" | grep -E -o '0x[0-9a-f]+-0x[0-9a-f]+:.*' | grep -E -o "0x[0-9a-f]+" | tail -n 1)
if [ "${current}" != "" ]; then
Expand All @@ -51,6 +51,11 @@ flashrom_progress() {
echo "Total flash size : $total_bytes bytes"
fi
fi
if [ "$prev_word" == "total_size:" ]; then
# Next is total size in bytes
total_bytes=$(echo "$IN" | grep -E -o '[0-9]+')
echo "Total flash size : $total_bytes bytes"
fi
fi
if [ "$percent" -gt 99 ]; then
spin_idx=4
Expand All @@ -77,14 +82,19 @@ flashrom_progress() {
fi
if echo "$IN" | grep "identical" > /dev/null ; then
status="done"
echo ""
echo ""
echo "The flash contents are identical to the image being flashed."
break
fi
fi
if [ "$status" == "verifying" ]; then
if echo "${IN}" | grep "VERIFIED." > /dev/null ; then
status="done"
echo "The flash contents were verified and the image was flashed correctly."
break
elif echo "${IN}" | grep "FAILED" > /dev/null ; then
echo 'Error while verifying flash content'
break
fi
fi
done
Expand All @@ -101,18 +111,8 @@ flashrom_progress() {
flash_rom() {
ROM=$1
if [ "$READ" -eq 1 ]; then
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.1" \
|| die "$ROM: Read failed"
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.2" \
|| die "$ROM: Read failed"
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.3" \
|| die "$ROM: Read failed"
if [ `sha256sum ${ROM}.[123] | cut -f1 -d ' ' | uniq | wc -l` -eq 1 ]; then
mv ${ROM}.1 $ROM
rm ${ROM}.[23]
else
die "$ROM: Read inconsistent"
fi
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}" \
|| die "Backup to $ROM failed"
else
cp "$ROM" /tmp/${CONFIG_BOARD}.rom
sha256sum /tmp/${CONFIG_BOARD}.rom
Expand Down

0 comments on commit 642338e

Please sign in to comment.