Skip to content

Commit 9e675e5

Browse files
JonathonHall-Purismtlaurion
authored andcommitted
modules/flashrom: Update to 1776bb46
Update flashrom - in particular, this includes support for new chipsets like Jasper Lake. CONFIG_INTERAL_X86 was created so CONFIG_INTERNAL could apply to other platforms, enable it for x86. The default build target now requires sphinx, just build flashrom itself. Update flashrom_progress - filter out noise in newer flashrom that chokes the progress bar implementation, make size detection more robust, improve progress bar implementation slightly. Signed-off-by: Jonathon Hall <[email protected]> Co-signed by: Thierry Laurion <[email protected].
1 parent db20f78 commit 9e675e5

File tree

2 files changed

+63
-43
lines changed

2 files changed

+63
-43
lines changed

initrd/bin/flash.sh

+58-40
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ set -e -o pipefail
88
. /etc/ash_functions
99
. /tmp/config
1010

11+
echo
12+
1113
TRACE "Under /bin/flash.sh"
1214

1315
case "$CONFIG_FLASHROM_OPTIONS" in
@@ -20,54 +22,43 @@ case "$CONFIG_FLASHROM_OPTIONS" in
2022
esac
2123

2224
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() {
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
}

modules/flashrom

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ modules-$(CONFIG_FLASHROM) += flashrom
22

33
flashrom_depends := pciutils $(musl_dep)
44

5-
flashrom_version := b1f858f65b2abd276542650d8cb9e382da258967
5+
flashrom_version := 1776bb46ba6ea3d1ab2ec3f0cd88158aabed7400
66
flashrom_dir := flashrom-$(flashrom_version)
77
flashrom_tar := $(flashrom_dir).tar.gz
88
flashrom_url := https://github.com/flashrom/flashrom/archive/$(flashrom_version).tar.gz
9-
flashrom_hash := 4873ad50f500629c244fc3fbee64b56403a82307d7f555dfa235336a200c336c
9+
flashrom_hash := 65e262ca4428a0ceddd73f481ed0d8444393b73a78469f266a4457dfc834ecb7
1010

1111
# Default options for flashrom
1212
flashrom_cfg := \
1313
WARNERROR=no \
1414
CONFIG_NOTHING=yes \
1515
CONFIG_INTERNAL=yes \
16+
CONFIG_INTERNAL_X86=yes
1617
CONFIG_DUMMY=yes \
1718
CONFIG_AST1100=yes \
1819

@@ -28,7 +29,8 @@ endif
2829
flashrom_target := \
2930
$(MAKE_JOBS) \
3031
$(CROSS_TOOLS) \
31-
$(flashrom_cfg)
32+
$(flashrom_cfg) \
33+
flashrom
3234

3335
flashrom_output := \
3436
flashrom

0 commit comments

Comments
 (0)