Skip to content

Commit

Permalink
Merge branch 'upstream_flashrom_13' into staging_all
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaurion committed Jun 28, 2023
2 parents 30cc112 + 979c9dd commit 92e29c4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
87 changes: 47 additions & 40 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,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"
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 13 additions & 8 deletions modules/flashrom
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@ 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_DUMMY=yes \
CONFIG_AST1100=yes \
CONFIG_INTERNAL_X86=yes \

ifeq "$(CONFIG_TARGET_ARCH)" "ppc64"
flashrom_cfg := \
WARNERROR=no \
CONFIG_NOTHING=yes \
CONFIG_LINUX_MTD=yes \
CONFIG_DUMMY=yes \
CONFIG_AST1100=yes
CONFIG_LINUX_MTD=yes
endif

#Only enable AST1100 if requested per board configs
ifeq "$(CONFIG_FLASHROM_AST1100)" "y"
flashrom_cfg += CONFIG_AST1100=yes
endif



flashrom_target := \
$(MAKE_JOBS) \
$(CROSS_TOOLS) \
$(flashrom_cfg)
$(flashrom_cfg) \
flashrom

flashrom_output := \
flashrom
Expand Down

0 comments on commit 92e29c4

Please sign in to comment.