initrd/bin/flash.sh: Improve speed and reliability

Improve speed by pre-filtering only for lines containing any tokens of
interest to flashrom_progress_tokenize().

Improve reliability by avoiding dropping tokens that cross a stream
buffer boundary.  Occasionally, a token could be missed if it crosses a
stream buffer boundary, due to read timing out too quickly before the
next buffer is flushed.  If this was a state-changing token,
flashrom_progress() would hang forever.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
Jonathon Hall 2023-08-31 17:11:45 -04:00
parent 8272d33e7c
commit 8342603993
No known key found for this signature in database
GPG Key ID: 1E9C3CA91AE25114

View File

@ -22,12 +22,13 @@ case "$CONFIG_FLASHROM_OPTIONS" in
esac esac
flashrom_progress() { flashrom_progress() {
# The ichspi programmer now spews register status lines constantly that are brutally slow # The ichspi programmer now spews register status lines constantly that are
# to feed through the parser in flashrom_progress_tokenize. Exclude them. # brutally slow to feed through the parser in flashrom_progress_tokenize.
# flashrom_progress_tokenize operates on individual tokens (not lines), so it splits by # Filter the input with grep for only lines containing at least one token
# spaces in 'read'. But we also need to separate the last word on a line from the next # that we care about.
# line, so replace newlines. grep -E -e 'contents\.\.\.' -e 'done\.' -e '0x[0-9a-f]+-(0x[0-9a-f]+):' \
grep -v -e '^HSFS:' -e '^HSFC:' | tr '\n' ' ' | flashrom_progress_tokenize "$1" -e 'identical' -e 'VERIFIED\.' -e 'FAILED' | \
tr ' ' '\n' | flashrom_progress_tokenize "$1"
} }
print_flashing_progress() { print_flashing_progress() {
@ -57,7 +58,7 @@ flashrom_progress_tokenize() {
while true ; do while true ; do
prev_prev_word=$prev_word prev_prev_word=$prev_word
prev_word=$IN prev_word=$IN
read -r -d" " -t 0.2 IN IFS= read -r -t 0.2 IN
spin_idx=$(( (spin_idx+1) %4 )) spin_idx=$(( (spin_idx+1) %4 ))
if [ "$status" == "init" ]; then if [ "$status" == "init" ]; then
if [ "$IN" == "contents..." ]; then if [ "$IN" == "contents..." ]; then