@@ -8,6 +8,8 @@ set -e -o pipefail
8
8
. /etc/ash_functions
9
9
. /tmp/config
10
10
11
+ echo
12
+
11
13
TRACE " Under /bin/flash.sh"
12
14
13
15
case " $CONFIG_FLASHROM_OPTIONS " in
@@ -20,54 +22,43 @@ case "$CONFIG_FLASHROM_OPTIONS" in
20
22
esac
21
23
22
24
flashrom_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 () {
23
46
local current=0
24
- local total_bytes=0
47
+ local total_bytes=" $1 "
25
48
local percent=0
26
49
local IN=' '
27
50
local spin=' -\|/'
28
51
local spin_idx=0
29
- local progressbar=' '
30
- local progressbar2=' '
31
52
local status=' init'
32
53
local prev_word=' '
33
54
local prev_prev_word=' '
34
- local spaces=' '
35
- local hashes=' ##################################################'
36
55
37
- progressbar2=$( for i in ` seq 48` ; do echo -ne ' ' ; done)
38
- echo -e " \nInitializing Flash Programmer"
56
+ echo " Initializing Flash Programmer"
39
57
while true ; do
40
58
prev_prev_word=$prev_word
41
59
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 ))
71
62
if [ " $status " == " init" ]; then
72
63
if [ " $IN " == " contents..." ]; then
73
64
status=" reading"
@@ -77,17 +68,43 @@ flashrom_progress() {
77
68
if [ " $status " == " reading" ]; then
78
69
if echo " ${IN} " | grep " done." > /dev/null ; then
79
70
status=" writing"
71
+ IN=
80
72
fi
81
73
fi
82
74
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
85
97
status=" verifying"
98
+ IN=
99
+ print_flashing_progress 100
86
100
echo " "
87
101
echo " Verifying flash contents. Please wait..."
88
102
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
90
105
status=" done"
106
+ IN=
107
+ print_flashing_progress 100
91
108
echo " "
92
109
echo " The flash contents are identical to the image being flashed."
93
110
break
@@ -142,7 +159,8 @@ flash_rom() {
142
159
fi
143
160
144
161
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" ) " \
146
164
|| die " $ROM : Flash failed"
147
165
fi
148
166
}
0 commit comments