Merge pull request #1230 from tlaurion/flash_sh-fixes

flash.sh: UX and logic fixes
This commit is contained in:
tlaurion 2022-11-01 11:15:18 -04:00 committed by GitHub
commit f848070d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,21 +27,23 @@ flashrom_progress() {
local status='init' local status='init'
local prev_word='' local prev_word=''
local prev_prev_word='' local prev_prev_word=''
local spaces=' '
local hashes='##################################################'
progressbar2=$(for i in `seq 48` ; do echo -ne ' ' ; done) progressbar2=$(for i in `seq 48` ; do echo -ne ' ' ; done)
echo -e "\nInitializing internal Flash Programmer" echo -e "\nInitializing Flash Programmer"
while true ; do while true ; do
prev_prev_word=$prev_word prev_prev_word=$prev_word
prev_word=$IN prev_word=$IN
read -r -d' ' IN || break read -r -d' ' IN
if [ "$total_bytes" != "0" ]; then 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) current=$(echo "$IN" | sed -nE 's/.*(0x[0-9a-f]+).*/\1/p')
if [ "${current}" != "" ]; then if [ "${current}" != "" ]; then
percent=$((100 * (current + 1) / total_bytes)) percent=$((100 * (current + 1) / total_bytes))
pct1=$((percent / 2)) pct1=$((percent / 2))
pct2=$((49 - percent / 2)) pct2=$((50 - percent / 2))
progressbar=$(for i in `seq $pct1 2>/dev/null` ; do echo -ne '#' ; done) progressbar=${hashes:0:$pct1}
progressbar2=$(for i in `seq $pct2 2>/dev/null` ; do echo -ne ' ' ; done) progressbar2=${spaces:0:$pct2}
fi fi
else else
if [ "$prev_prev_word" == "Reading" ] && [ "$IN" == "bytes" ]; then if [ "$prev_prev_word" == "Reading" ] && [ "$IN" == "bytes" ]; then
@ -51,6 +53,11 @@ flashrom_progress() {
echo "Total flash size : $total_bytes bytes" echo "Total flash size : $total_bytes bytes"
fi fi
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 fi
if [ "$percent" -gt 99 ]; then if [ "$percent" -gt 99 ]; then
spin_idx=4 spin_idx=4
@ -77,14 +84,19 @@ flashrom_progress() {
fi fi
if echo "$IN" | grep "identical" > /dev/null ; then if echo "$IN" | grep "identical" > /dev/null ; then
status="done" status="done"
echo "" echo ""
echo "The flash contents are identical to the image being flashed." echo "The flash contents are identical to the image being flashed."
break
fi fi
fi fi
if [ "$status" == "verifying" ]; then if [ "$status" == "verifying" ]; then
if echo "${IN}" | grep "VERIFIED." > /dev/null ; then if echo "${IN}" | grep "VERIFIED." > /dev/null ; then
status="done" status="done"
echo "The flash contents were verified and the image was flashed correctly." 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
fi fi
done done
@ -101,18 +113,8 @@ flashrom_progress() {
flash_rom() { flash_rom() {
ROM=$1 ROM=$1
if [ "$READ" -eq 1 ]; then if [ "$READ" -eq 1 ]; then
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.1" \ flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}" \
|| die "$ROM: Read failed" || die "Backup to $ROM 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
else else
cp "$ROM" /tmp/${CONFIG_BOARD}.rom cp "$ROM" /tmp/${CONFIG_BOARD}.rom
sha256sum /tmp/${CONFIG_BOARD}.rom sha256sum /tmp/${CONFIG_BOARD}.rom