diff options
author | Craig Hesling <hesling@chromium.org> | 2019-11-12 17:00:23 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-08 01:01:37 +0000 |
commit | 80c42a77f0e8f2f553b969e1ef20436495228f08 (patch) | |
tree | cb9c267a7b88a2b23d30264281d9449c0f1ce3be | |
parent | 1f5cc901ecc4026ebce41d4eeca602875ad7f4b6 (diff) | |
download | chrome-ec-80c42a77f0e8f2f553b969e1ef20436495228f08.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>
-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 8baebbd6a3..086b742e8e 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 @@ -183,16 +184,33 @@ flash_fp_mcu_stm32() { # poorly behaved chip select line. See b/145023809. sleep 0.5 - # 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 |