diff --git a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/bios_util.sh b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/bios_util.sh index fa5f8a146e6..384e3f54736 100644 --- a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/bios_util.sh +++ b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/bios_util.sh @@ -10,7 +10,7 @@ usage() { program=$(basename "$0") echo "Usage:" echo "$program " - echo " : read, write, erase, recover" + echo " : read, write, erase, verify" exit 1 } @@ -44,13 +44,21 @@ fi if [ "$1" = "erase" ]; then echo "Erasing flash content ..." - flashrom -p linux_spi:dev=/dev/spidev1.0 -E -c $CHIPTYPE + flashrom -f -p linux_spi:dev=/dev/spidev1.0 -E -c $CHIPTYPE || exit 1 elif [ "$1" = "read" ]; then echo "Reading flash content..." - flashrom -p linux_spi:dev=/dev/spidev1.0 -r "$2" -c $CHIPTYPE + flashrom -p linux_spi:dev=/dev/spidev1.0 -r "$2" -c $CHIPTYPE || exit 1 +elif [ "$1" = "verify" ]; then + echo "Verifying flash content..." + flashrom -f -p linux_spi:dev=/dev/spidev1.0 -v "$2" -c $CHIPTYPE || exit 1 elif [ "$1" = "write" ]; then echo "Writing flash content..." - flashrom -p linux_spi:dev=/dev/spidev1.0 -w "$2" -c $CHIPTYPE || exit 1 + flashrom -n -f -p linux_spi:dev=/dev/spidev1.0 -w "$2" -c $CHIPTYPE || exit 1 + echo "Verifying flash content..." + # ELBERTTODO understand why read is flaky, giving false verification fails + # Retry verification up to 5 times + retry_command 5 flashrom -f -p linux_spi:dev=/dev/spidev1.0 \ + -v "$2" -c $CHIPTYPE || exit 1 else usage fi diff --git a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/board-utils.sh b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/board-utils.sh index 5c3d042b977..c0fa3504864 100644 --- a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/board-utils.sh +++ b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/board-utils.sh @@ -212,3 +212,22 @@ power_off_pim() { fi logger pim_enable: powered off PIM"${pim}" } + +retry_command() { + # Retry command up to $1 attempts + local retries=$1 + shift + + local count=0 + until "$@"; do + exit=$? + count=$((count+1)) + if [ "$count" -lt "$retries" ]; then + echo "Attempt $count/$retries failed with $exit, retrying..." + else + echo "Retry $count/$retries failed with $exit, no more retries left" + return $exit + fi + done + return 0 +}