diff options
author | Craig Hesling <hesling@chromium.org> | 2021-01-28 20:31:26 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-22 21:12:26 +0000 |
commit | a23f2c5c43a9dce5448271e55fd419a8665d51f4 (patch) | |
tree | 806aaf2270847743589f69b4ee15c6821b11e565 | |
parent | 47fa3cc55c973920cdbe7b9621436ff86e7161af (diff) | |
download | chrome-ec-a23f2c5c43a9dce5448271e55fd419a8665d51f4.tar.gz |
flash_fp_mcu: Refactor to use gpio function
This makes the script a bit more readable and allows for
implementing more generic gpio handling.
BRANCH=none
BUG=b:145245345
TEST=Test on hatch
Signed-off-by: Craig Hesling <hesling@chromium.org>
Change-Id: I80e3b9c7e322d53bb3eecfcb9da47cacc3de919c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2658367
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2713551
Tested-by: Sujit Kautkar <sujitka@chromium.org>
Reviewed-by: Sujit Kautkar <sujitka@chromium.org>
Commit-Queue: Sujit Kautkar <sujitka@chromium.org>
-rw-r--r-- | util/flash_fp_mcu | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu index b992a5d5b4..78841c5256 100644 --- a/util/flash_fp_mcu +++ b/util/flash_fp_mcu @@ -75,6 +75,32 @@ get_uartid() { exit 1 } +# Usage: gpio <unexport|export|in|out|0|1> <signal> [signal...] +gpio() { + local cmd="$1" + shift + + for signal in "$@"; do + case "${cmd}" in + unexport|export) + echo "${signal}" > "/sys/class/gpio/${cmd}" + ;; + in|out) + local direction="${cmd}" + echo "${direction}" > "/sys/class/gpio/gpio${signal}/direction" + ;; + 0|1) + local value="${cmd}" + echo "${value}" > "/sys/class/gpio/gpio${signal}/value" + ;; + *) + echo "Invalid gpio command: ${cmd}" >&2 + exit 1 + ;; + esac + done +} + # Taken verbatim from # https://chromium.googlesource.com/chromiumos/docs/+/master/lsb-release.md#shell # This should not be used by anything except get_platform_name. @@ -195,9 +221,9 @@ flash_fp_mcu_stm32() { # Ensure the ACPI is not cutting power when unloading cros-ec-spi if [[ "${gpio_pwren}" -gt 0 ]]; then - echo "${gpio_pwren}" > /sys/class/gpio/export - echo "out" > "/sys/class/gpio/gpio${gpio_pwren}/direction" - echo 1 > "/sys/class/gpio/gpio${gpio_pwren}/value" + gpio export "${gpio_pwren}" + gpio out "${gpio_pwren}" + gpio 1 "${gpio_pwren}" fi # Remove cros_fp if present @@ -208,14 +234,12 @@ flash_fp_mcu_stm32() { fi # Configure the MCU Boot0 and NRST GPIOs - echo "${gpio_boot0}" > /sys/class/gpio/export - echo "out" > "/sys/class/gpio/gpio${gpio_boot0}/direction" - echo "${gpio_nrst}" > /sys/class/gpio/export - echo "out" > "/sys/class/gpio/gpio${gpio_nrst}/direction" + gpio export "${gpio_boot0}" "${gpio_nrst}" + gpio out "${gpio_boot0}" "${gpio_nrst}" # Reset sequence to enter bootloader mode - echo 1 > "/sys/class/gpio/gpio${gpio_boot0}/value" - echo 0 > "/sys/class/gpio/gpio${gpio_nrst}/value" + gpio 1 "${gpio_boot0}" + gpio 0 "${gpio_nrst}" sleep 0.001 if [[ "${transport}" == "UART" ]]; then @@ -237,11 +261,11 @@ flash_fp_mcu_stm32() { for attempt in $(seq ${FLAGS_retries}); do # Reset sequence to enter bootloader mode - echo 0 > "/sys/class/gpio/gpio${gpio_nrst}/value" + gpio 0 "${gpio_nrst}" sleep 0.01 # Release reset as the SPI bus is now ready - echo 1 > "/sys/class/gpio/gpio${gpio_nrst}/value" + gpio 1 "${gpio_nrst}" # Print out the actual underlying command we're running and run it echo "# ${cmd}" @@ -262,16 +286,13 @@ flash_fp_mcu_stm32() { fi # Go back to normal mode - echo "out" > "/sys/class/gpio/gpio${gpio_nrst}/direction" - echo 0 > "/sys/class/gpio/gpio${gpio_boot0}/value" - echo 0 > "/sys/class/gpio/gpio${gpio_nrst}/value" - echo 1 > "/sys/class/gpio/gpio${gpio_nrst}/value" + gpio out "${gpio_nrst}" + gpio 0 "${gpio_boot0}" "${gpio_nrst}" + gpio 1 "${gpio_nrst}" # Give up GPIO control - echo "in" > "/sys/class/gpio/gpio${gpio_boot0}/direction" - echo "in" > "/sys/class/gpio/gpio${gpio_nrst}/direction" - echo "${gpio_boot0}" > /sys/class/gpio/unexport - echo "${gpio_nrst}" > /sys/class/gpio/unexport + gpio in "${gpio_boot0}" "${gpio_nrst}" + gpio unexport "${gpio_boot0}" "${gpio_nrst}" # wait for FP MCU to come back up (including RWSIG delay) sleep 2 @@ -282,7 +303,7 @@ flash_fp_mcu_stm32() { # Kernel driver is back, we are no longer controlling power if [[ "${gpio_pwren}" -gt 0 ]]; then - echo "${gpio_pwren}" > /sys/class/gpio/unexport + gpio unexport "${gpio_pwren}" fi fi |