From 642338e3778b31698b334e56a11e5310cda24415 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Wed, 26 Oct 2022 15:14:29 -0400 Subject: [PATCH] flash.sh: single firmware read backup and logic fixes - 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) --- initrd/bin/flash.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/initrd/bin/flash.sh b/initrd/bin/flash.sh index d414fdc61..5f1862efc 100755 --- a/initrd/bin/flash.sh +++ b/initrd/bin/flash.sh @@ -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 @@ -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 @@ -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 @@ -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