diff options
author | Craig Hesling <hesling@chromium.org> | 2019-11-12 17:00:23 -0800 |
---|---|---|
committer | Philip Chen <philipchen@chromium.org> | 2020-02-10 19:35:26 +0000 |
commit | 37a8704df83c088bc7839bec909cfab5e1dbd6da (patch) | |
tree | c75e017593f0bc02edd02bd05f1f9fb5e3d5c8b3 | |
parent | 5698cdb33eb3d9fb51a662c1233b65bc32c0f3a7 (diff) | |
download | chrome-ec-37a8704df83c088bc7839bec909cfab5e1dbd6da.tar.gz |
flash_fp_mcu: Add retry logic
This CL adds reset and retry logic.
This is important because stm32mon sometimes fails to get the stm32
bootloader's attention on startup, so we need to reset the chip and
try again.
BRANCH=nocturne,hatch
BUG=b:143374692,b:144729003
TEST=# Nocturne
flash_fp_mcu /opt/google/biod/fw/*.bin
TEST=# Ensure PS crrev.com/c/1921705 is applied.
# Run http://go/bit/hesling/5791510394044416
Signed-off-by: Craig Hesling <hesling@chromium.org>
Change-Id: I755d9b8cbb8813fe961f359c128c674e4c395ebb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1913626
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
(cherry picked from commit 80c42a77f0e8f2f553b969e1ef20436495228f08)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2047624
Reviewed-by: Philip Chen <philipchen@chromium.org>
Commit-Queue: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
-rw-r--r-- | util/flash_fp_mcu | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu index db9004c3f8..28e869b152 100644 --- a/util/flash_fp_mcu +++ b/util/flash_fp_mcu @@ -12,6 +12,7 @@ DEFINE_boolean 'remove_flash_read_protect' "${FLAGS_TRUE}" \ 'Remove flash read protection while performing command' 'U' DEFINE_boolean 'remove_flash_write_protect' "${FLAGS_TRUE}" \ 'Remove flash write protection while performing command' 'u' +DEFINE_integer 'retries' 4 'Specify number of retries' 'R' FLAGS_HELP="Usage: ${0} [flags] ec.bin" # Process commandline flags @@ -119,7 +120,7 @@ flash_fp_mcu_stm32() { local STM32MON_READ_FLAGS=" -p -s ${spidev} -r" local STM32MON_WRITE_FLAGS="-p -s ${spidev} -e -w" - local stm32mon_flags="" + local stm32mon_flags="--retries 6" if [[ "${FLAGS_remove_flash_write_protect}" -eq "${FLAGS_TRUE}" ]]; then STM32MON_READ_FLAGS=" -u ${STM32MON_READ_FLAGS}" @@ -136,13 +137,13 @@ flash_fp_mcu_stm32() { echo "Output file already exists: ${file}" exit 1 fi - stm32mon_flags="${STM32MON_READ_FLAGS}" + stm32mon_flags+=" ${STM32MON_READ_FLAGS}" else if [[ ! -f "${file}" ]]; then echo "Invalid image file: ${file}" exit 1 fi - stm32mon_flags="${STM32MON_WRITE_FLAGS}" + stm32mon_flags+=" ${STM32MON_WRITE_FLAGS}" fi check_hardware_write_protect_disabled @@ -180,16 +181,33 @@ flash_fp_mcu_stm32() { echo "${spiid}" > /sys/bus/spi/drivers/cros-ec-spi/bind 2>/dev/null echo "${spiid}" > /sys/bus/spi/drivers/spidev/bind - # Release reset as the SPI bus is now ready - echo 1 > "/sys/class/gpio/gpio${gpio_nrst}/value" - echo "in" > "/sys/class/gpio/gpio${gpio_nrst}/direction" - - # Print out the actual underlying command we're running and run it + local attempt=0 + local cmd_exit_status=1 local cmd="stm32mon ${stm32mon_flags} ${file}" - echo "${cmd}" - ${cmd} - local cmd_exit_status=$? + for attempt in $(seq ${FLAGS_retries}); do + # Reset sequence to enter bootloader mode + echo "out" > "/sys/class/gpio/gpio${gpio_nrst}/direction" + sleep 0.001 + echo 0 > "/sys/class/gpio/gpio${gpio_nrst}/value" + sleep 0.01 + + # Release reset as the SPI bus is now ready + echo 1 > "/sys/class/gpio/gpio${gpio_nrst}/value" + echo "in" > "/sys/class/gpio/gpio${gpio_nrst}/direction" + + # Print out the actual underlying command we're running and run it + echo "# ${cmd}" + ${cmd} + cmd_exit_status=$? + + if [[ "${cmd_exit_status}" -eq 0 ]]; then + break + fi + echo "# Attempt ${attempt} failed." + echo + sleep 1 + done # unload spidev echo "${spiid}" > /sys/bus/spi/drivers/spidev/unbind |