summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/flash_fp_mcu40
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