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 <jonathon.hall@puri.sm>
Co-signed by: Thierry Laurion <insurgo@riseup.net.
This commit is contained in:
Jonathon Hall 2023-06-23 12:21:49 -04:00 committed by Thierry Laurion
parent 91f65bed79
commit a1be4e4467
No known key found for this signature in database
GPG Key ID: E7B4A71658E36A93
2 changed files with 52 additions and 43 deletions

View File

@ -8,6 +8,8 @@ set -e -o pipefail
. /etc/ash_functions
. /tmp/config
echo
TRACE "Under /bin/flash.sh"
case "$CONFIG_FLASHROM_OPTIONS" in
@ -20,54 +22,43 @@ case "$CONFIG_FLASHROM_OPTIONS" in
esac
flashrom_progress() {
# The ichspi programmer now spews register status lines constantly that are brutally slow
# to feed through the parser in flashrom_progress_tokenize. Exclude them.
# flashrom_progress_tokenize operates on individual tokens (not lines), so it splits by
# spaces in 'read'. But we also need to separate the last word on a line from the next
# line, so replace newlines.
grep -v -e '^HSFS:' -e '^HSFC:' | tr '\n' ' ' | flashrom_progress_tokenize "$1"
}
print_flashing_progress() {
local spaces=' '
local hashes='##################################################'
local percent pct1 pct2 progressbar progressbar2
percent="$1"
pct1=$((percent / 2))
pct2=$((50 - percent / 2))
progressbar=${hashes:0:$pct1}
progressbar2=${spaces:0:$pct2}
echo -ne "Flashing: [${progressbar}${spin:$spin_idx:1}${progressbar2}] (${percent}%)\\r"
}
flashrom_progress_tokenize() {
local current=0
local total_bytes=0
local total_bytes="$1"
local percent=0
local IN=''
local spin='-\|/'
local spin_idx=0
local progressbar=''
local progressbar2=''
local status='init'
local prev_word=''
local prev_prev_word=''
local spaces=' '
local hashes='##################################################'
progressbar2=$(for i in `seq 48` ; do echo -ne ' ' ; done)
echo -e "\nInitializing Flash Programmer"
echo "Initializing Flash Programmer"
while true ; do
prev_prev_word=$prev_word
prev_word=$IN
read -r -d' ' IN
if [ "$total_bytes" != "0" ]; then
current=$(echo "$IN" | sed -nE 's/.*(0x[0-9a-f]+).*/\1/p')
if [ "${current}" != "" ]; then
percent=$((100 * (current + 1) / total_bytes))
pct1=$((percent / 2))
pct2=$((50 - percent / 2))
progressbar=${hashes:0:$pct1}
progressbar2=${spaces:0:$pct2}
fi
else
if [ "$prev_prev_word" == "Reading" ] && [ "$IN" == "bytes" ]; then
# flashrom may read the descriptor first, so ensure total_bytes is at least 4MB
if [[ $prev_word -gt 4194303 ]]; then
total_bytes=$prev_word
echo "Total flash size : $total_bytes bytes"
fi
fi
if [ "$prev_word" == "total_size:" ]; then
# Next is total size in bytes
total_bytes=$(echo "$IN" | grep -E -o '[0-9]+')
echo "Total flash size : $total_bytes bytes"
fi
fi
if [ "$percent" -gt 99 ]; then
spin_idx=4
else
spin_idx=$(( (spin_idx+1) %4 ))
fi
read -r -d" " -t 0.2 IN
spin_idx=$(( (spin_idx+1) %4 ))
if [ "$status" == "init" ]; then
if [ "$IN" == "contents..." ]; then
status="reading"
@ -77,17 +68,32 @@ flashrom_progress() {
if [ "$status" == "reading" ]; then
if echo "${IN}" | grep "done." > /dev/null ; then
status="writing"
IN=
fi
fi
if [ "$status" == "writing" ]; then
echo -ne "Flashing: [${progressbar}${spin:$spin_idx:1}${progressbar2}] (${percent}%)\\r"
if echo "$IN" | grep "Verifying" > /dev/null ; then
# walk_eraseblocks() prints info for each block, of the form
# , 0xAAAAAA-0xBBBBBB:X
# The 'X' is a char indicating the action, but the debug from actually erasing
# and writing is mixed into the output so it may be separated. It can also be
# interrupted occasionally, so only match a complete token.
current=$(echo "$IN" | sed -nE 's/^0x[0-9a-f]+-(0x[0-9a-f]+):.*$/\1/p')
if [ "$current" != "" ]; then
percent=$((100 * (current + 1) / total_bytes))
fi
print_flashing_progress "$percent"
if [ "$IN" == "done." ]; then
status="verifying"
IN=
print_flashing_progress 100
echo ""
echo "Verifying flash contents. Please wait..."
fi
if echo "$IN" | grep "identical" > /dev/null ; then
# This appears before "Erase/write done."; skip the verifying state
if [ "$IN" == "identical" ]; then
status="done"
IN=
print_flashing_progress 100
echo ""
echo "The flash contents are identical to the image being flashed."
break
@ -142,7 +148,8 @@ flash_rom() {
fi
flashrom $CONFIG_FLASHROM_OPTIONS -w /tmp/${CONFIG_BOARD}.rom \
-V -o "/tmp/flashrom-$(date '+%Y%m%d-%H%M%S').log" 2>&1 | flashrom_progress \
-V -o "/tmp/flashrom-$(date '+%Y%m%d-%H%M%S').log" 2>&1 | \
flashrom_progress "$(stat -c %s "/tmp/${CONFIG_BOARD}.rom")" \
|| die "$ROM: Flash failed"
fi
}

View File

@ -2,17 +2,18 @@ modules-$(CONFIG_FLASHROM) += flashrom
flashrom_depends := pciutils $(musl_dep)
flashrom_version := b1f858f65b2abd276542650d8cb9e382da258967
flashrom_version := 1776bb46ba6ea3d1ab2ec3f0cd88158aabed7400
flashrom_dir := flashrom-$(flashrom_version)
flashrom_tar := $(flashrom_dir).tar.gz
flashrom_url := https://github.com/flashrom/flashrom/archive/$(flashrom_version).tar.gz
flashrom_hash := 4873ad50f500629c244fc3fbee64b56403a82307d7f555dfa235336a200c336c
flashrom_hash := 65e262ca4428a0ceddd73f481ed0d8444393b73a78469f266a4457dfc834ecb7
# Default options for flashrom
flashrom_cfg := \
WARNERROR=no \
CONFIG_NOTHING=yes \
CONFIG_INTERNAL=yes \
CONFIG_INTERNAL_X86=yes
CONFIG_DUMMY=yes \
CONFIG_AST1100=yes \
@ -28,7 +29,8 @@ endif
flashrom_target := \
$(MAKE_JOBS) \
$(CROSS_TOOLS) \
$(flashrom_cfg)
$(flashrom_cfg) \
flashrom
flashrom_output := \
flashrom