@@ -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,43 @@ 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+ # if [ "$prev_prev_word" = "writing" ] && [ "$prev_word" = "range" ]; then
76+ # # "... is writable, writing range (0x000000..0x000fff)"
77+ # current=$(echo "$IN" | sed -nE 's/^\(0x[0-9a-f]+..(0x[0-9a-f]+)\)\.$/\1/p')
78+ # if [ "$current" != "" ]; then
79+ # percent=$((100 * (current + 1) / total_bytes))
80+ # echo "current: $current, total: $total_bytes, percent: $percent"
81+ # print_flashing_progress "$percent"
82+ # else
83+ # echo "failed to match: $IN"
84+ # fi
85+ # fi
86+ # walk_eraseblocks() prints info for each block, of the form
87+ # , 0xAAAAAA-0xBBBBBB:X
88+ # The 'X' is a char indicating the action, but the debug from actually erasing
89+ # and writing is mixed into the output so it may be separated. It can also be
90+ # interrupted occasionally, so only match a complete token.
91+ current=$( echo " $IN " | sed -nE ' s/^0x[0-9a-f]+-(0x[0-9a-f]+):.*$/\1/p' )
92+ if [ " $current " != " " ]; then
93+ percent=$(( 100 * (current + 1 ) / total_bytes))
94+ fi
95+ print_flashing_progress " $percent "
96+ if [ " $IN " == " done." ]; then
8597 status=" verifying"
98+ IN=
99+ print_flashing_progress 100
86100 echo " "
87101 echo " Verifying flash contents. Please wait..."
88102 fi
89- if echo " $IN " | grep " identical" > /dev/null ; then
103+ # This appears before "Erase/write done."; skip the verifying state
104+ if [ " $IN " == " identical" ]; then
90105 status=" done"
106+ IN=
107+ print_flashing_progress 100
91108 echo " "
92109 echo " The flash contents are identical to the image being flashed."
93110 break
@@ -142,7 +159,8 @@ flash_rom() {
142159 fi
143160
144161 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 \
162+ -V -o " /tmp/flashrom-$( date ' +%Y%m%d-%H%M%S' ) .log" 2>&1 | \
163+ flashrom_progress " $( stat -c %s " /tmp/${CONFIG_BOARD} .rom" ) " \
146164 || die " $ROM : Flash failed"
147165 fi
148166}
0 commit comments