Skip to content

Commit

Permalink
modules/flashrom: Update to 1776bb46
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
JonathonHall-Purism authored and tlaurion committed Jun 26, 2023
1 parent b4eb215 commit 02da1a9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 39 deletions.
94 changes: 58 additions & 36 deletions initrd/bin/flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set -e -o pipefail
. /etc/ash_functions
. /tmp/config

echo

TRACE "Under /bin/flash.sh"

case "$CONFIG_FLASHROM_OPTIONS" in
Expand All @@ -20,50 +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
read -r -d" " -t 0.2 IN
if [ "$percent" -eq 99 ]; then
spin_idx=4
else
spin_idx=$(( (spin_idx+1) %4 ))
Expand All @@ -77,17 +72,43 @@ 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
#if [ "$prev_prev_word" = "writing" ] && [ "$prev_word" = "range" ]; then
# # "... is writable, writing range (0x000000..0x000fff)"
# 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))
# echo "current: $current, total: $total_bytes, percent: $percent"
# print_flashing_progress "$percent"
# else
# echo "failed to match: $IN"
# fi
#fi
# 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
Expand Down Expand Up @@ -142,7 +163,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
}
Expand Down
8 changes: 5 additions & 3 deletions modules/flashrom
Original file line number Diff line number Diff line change
Expand Up @@ -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 \

Expand All @@ -28,7 +29,8 @@ endif
flashrom_target := \
$(MAKE_JOBS) \
$(CROSS_TOOLS) \
$(flashrom_cfg)
$(flashrom_cfg) \
flashrom

flashrom_output := \
flashrom
Expand Down

0 comments on commit 02da1a9

Please sign in to comment.