Skip to content

Commit

Permalink
Merge pull request #1230 from tlaurion/flash_sh-fixes
Browse files Browse the repository at this point in the history
flash.sh: UX and logic fixes
  • Loading branch information
tlaurion authored Nov 1, 2022
2 parents 0389eca + 5a7902c commit f848070
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions initrd/bin/flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ flashrom_progress() {
local status='init'
local prev_word=''
local prev_prev_word=''
local spaces=' '
local hashes='##################################################'

progressbar2=$(for i in `seq 48` ; do echo -ne ' ' ; done)
echo -e "\nInitializing internal Flash Programmer"
echo -e "\nInitializing Flash Programmer"
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)
current=$(echo "$IN" | sed -nE 's/.*(0x[0-9a-f]+).*/\1/p')
if [ "${current}" != "" ]; then
percent=$((100 * (current + 1) / total_bytes))
pct1=$((percent / 2))
pct2=$((49 - percent / 2))
progressbar=$(for i in `seq $pct1 2>/dev/null` ; do echo -ne '#' ; done)
progressbar2=$(for i in `seq $pct2 2>/dev/null` ; do echo -ne ' ' ; done)
pct2=$((50 - percent / 2))
progressbar=${hashes:0:$pct1}
progressbar2=${spaces:0:$pct2}
fi
else
if [ "$prev_prev_word" == "Reading" ] && [ "$IN" == "bytes" ]; then
Expand All @@ -51,6 +53,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 +84,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 +113,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 f848070

Please sign in to comment.