@@ -8,6 +8,8 @@ set -e -o pipefail
88. /etc/ash_functions
99. /tmp/config
1010
11+ echo
12+
1113TRACE " Under /bin/flash.sh"
1214
1315case " $CONFIG_FLASHROM_OPTIONS " in
@@ -20,54 +22,43 @@ case "$CONFIG_FLASHROM_OPTIONS" in
2022esac
2123
2224flashrom_progress () {
25+ # The ichspi programmer now spews register status lines constantly that are brutally slow
26+ # to feed through the parser in flashrom_progress_tokenize. Exclude them.
27+ # flashrom_progress_tokenize operates on individual tokens (not lines), so it splits by
28+ # spaces in 'read'. But we also need to separate the last word on a line from the next
29+ # line, so replace newlines.
30+ grep -v -e ' ^HSFS:' -e ' ^HSFC:' | tr ' \n' ' ' | flashrom_progress_tokenize " $1 "
31+ }
32+
33+ print_flashing_progress () {
34+ local spaces=' '
35+ local hashes=' ##################################################'
36+ local percent pct1 pct2 progressbar progressbar2
37+ percent=" $1 "
38+ pct1=$(( percent / 2 ))
39+ pct2=$(( 50 - percent / 2 ))
40+ progressbar=${hashes: 0: $pct1 }
41+ progressbar2=${spaces: 0: $pct2 }
42+ echo -ne " Flashing: [${progressbar}${spin: $spin_idx : 1}${progressbar2} ] (${percent} %)\\ r"
43+ }
44+
45+ flashrom_progress_tokenize () {
2346 local current=0
24- local total_bytes=0
47+ local total_bytes=" $1 "
2548 local percent=0
2649 local IN=' '
2750 local spin=' -\|/'
2851 local spin_idx=0
29- local progressbar=' '
30- local progressbar2=' '
3152 local status=' init'
3253 local prev_word=' '
3354 local prev_prev_word=' '
34- local spaces=' '
35- local hashes=' ##################################################'
3655
37- progressbar2=$( for i in ` seq 48` ; do echo -ne ' ' ; done)
38- echo -e " \nInitializing Flash Programmer"
56+ echo " Initializing Flash Programmer"
3957 while true ; do
4058 prev_prev_word=$prev_word
4159 prev_word=$IN
42- read -r -d' ' IN
43- if [ " $total_bytes " != " 0" ]; then
44- current=$( echo " $IN " | sed -nE ' s/.*(0x[0-9a-f]+).*/\1/p' )
45- if [ " ${current} " != " " ]; then
46- percent=$(( 100 * (current + 1 ) / total_bytes))
47- pct1=$(( percent / 2 ))
48- pct2=$(( 50 - percent / 2 ))
49- progressbar=${hashes: 0: $pct1 }
50- progressbar2=${spaces: 0: $pct2 }
51- fi
52- else
53- if [ " $prev_prev_word " == " Reading" ] && [ " $IN " == " bytes" ]; then
54- # flashrom may read the descriptor first, so ensure total_bytes is at least 4MB
55- if [[ $prev_word -gt 4194303 ]]; then
56- total_bytes=$prev_word
57- echo " Total flash size : $total_bytes bytes"
58- fi
59- fi
60- if [ " $prev_word " == " total_size:" ]; then
61- # Next is total size in bytes
62- total_bytes=$( echo " $IN " | grep -E -o ' [0-9]+' )
63- echo " Total flash size : $total_bytes bytes"
64- fi
65- fi
66- if [ " $percent " -gt 99 ]; then
67- spin_idx=4
68- else
69- spin_idx=$(( (spin_idx+ 1 ) % 4 ))
70- fi
60+ read -r -d" " -t 0.2 IN
61+ spin_idx=$(( (spin_idx+ 1 ) % 4 ))
7162 if [ " $status " == " init" ]; then
7263 if [ " $IN " == " contents..." ]; then
7364 status=" reading"
@@ -77,17 +68,32 @@ flashrom_progress() {
7768 if [ " $status " == " reading" ]; then
7869 if echo " ${IN} " | grep " done." > /dev/null ; then
7970 status=" writing"
71+ IN=
8072 fi
8173 fi
8274 if [ " $status " == " writing" ]; then
83- echo -ne " Flashing: [${progressbar}${spin: $spin_idx : 1}${progressbar2} ] (${percent} %)\\ r"
84- if echo " $IN " | grep " Verifying" > /dev/null ; then
75+ # walk_eraseblocks() prints info for each block, of the form
76+ # , 0xAAAAAA-0xBBBBBB:X
77+ # The 'X' is a char indicating the action, but the debug from actually erasing
78+ # and writing is mixed into the output so it may be separated. It can also be
79+ # interrupted occasionally, so only match a complete token.
80+ current=$( echo " $IN " | sed -nE ' s/^0x[0-9a-f]+-(0x[0-9a-f]+):.*$/\1/p' )
81+ if [ " $current " != " " ]; then
82+ percent=$(( 100 * (current + 1 ) / total_bytes))
83+ fi
84+ print_flashing_progress " $percent "
85+ if [ " $IN " == " done." ]; then
8586 status=" verifying"
87+ IN=
88+ print_flashing_progress 100
8689 echo " "
8790 echo " Verifying flash contents. Please wait..."
8891 fi
89- if echo " $IN " | grep " identical" > /dev/null ; then
92+ # This appears before "Erase/write done."; skip the verifying state
93+ if [ " $IN " == " identical" ]; then
9094 status=" done"
95+ IN=
96+ print_flashing_progress 100
9197 echo " "
9298 echo " The flash contents are identical to the image being flashed."
9399 break
@@ -142,7 +148,8 @@ flash_rom() {
142148 fi
143149
144150 flashrom $CONFIG_FLASHROM_OPTIONS -w /tmp/${CONFIG_BOARD} .rom \
145- -V -o " /tmp/flashrom-$( date ' +%Y%m%d-%H%M%S' ) .log" 2>&1 | flashrom_progress \
151+ -V -o " /tmp/flashrom-$( date ' +%Y%m%d-%H%M%S' ) .log" 2>&1 | \
152+ flashrom_progress " $( stat -c %s " /tmp/${CONFIG_BOARD} .rom" ) " \
146153 || die " $ROM : Flash failed"
147154 fi
148155}
0 commit comments