diff options
author | Craig Hesling <hesling@chromium.org> | 2021-02-10 11:33:48 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-29 00:17:33 +0000 |
commit | 6a0f8c27a341ac7a2dce2cd21c885f76900c327b (patch) | |
tree | 88a4ccea187cb0882229d2cd8bf7783afa9f59d0 /util/flash_fp_mcu | |
parent | 502845b84b190a965d1968c894326a71bf9a27a9 (diff) | |
download | chrome-ec-6a0f8c27a341ac7a2dce2cd21c885f76900c327b.tar.gz |
flash_fp_mcu: Simplify and make shellcheck happy
BRANCH=none
BUG=none
TEST=scp util/flash_fp_mcu dut1:/usr/local/bin/flash_fp_mcu
ssh dut1 flash_fp_mcu --hello
TEST=shellcheck util/flash_fp_mcu
Signed-off-by: Craig Hesling <hesling@chromium.org>
Change-Id: I719c70efebca9817ba702b1661a1e3b49aabf4e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2687826
Reviewed-by: Josie Nordrum <josienordrum@google.com>
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'util/flash_fp_mcu')
-rw-r--r-- | util/flash_fp_mcu | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu index 468b832d5b..569365734d 100644 --- a/util/flash_fp_mcu +++ b/util/flash_fp_mcu @@ -33,14 +33,18 @@ fi # print out canonical path to differentiate between /usr/local/bin and # /usr/bin installs -echo "$(readlink -f "$0")" +readlink -f "$0" readonly CROS_EC_SPI_MODALIAS_STR="of:NcrfpTCgoogle,cros-ec-spi" readonly CROS_EC_UART_MODALIAS_STR="of:NcrfpTCgoogle,cros-ec-uart" check_hardware_write_protect_disabled() { - local hardware_write_protect_state="$(crossystem wpsw_cur)" + local hardware_write_protect_state + if ! hardware_write_protect_state="$(crossystem wpsw_cur)"; then + echo "Failed to get hardware write protect status" >&2 + exit 1 + fi if [[ "${hardware_write_protect_state}" != "0" ]]; then echo "Please make sure hardware write protect is disabled." echo "See https://www.chromium.org/chromium-os/firmware-porting-guide/firmware-ec-write-protection" @@ -59,7 +63,7 @@ get_spiid() { for dev in /sys/bus/spi/devices/*; do if [[ "$(cat "${dev}/modalias")" == "${CROS_EC_SPI_MODALIAS_STR}" ]]; then - echo "$(basename "${dev}")" + basename "${dev}" return 0 fi done @@ -72,7 +76,7 @@ get_uartid() { for dev in /sys/bus/serial/devices/*; do if [ -f "${dev}/modalias" ]; then if [[ "$(cat "${dev}/modalias")" == "${CROS_EC_UART_MODALIAS_STR}" ]]; then - echo "$(basename "${dev}")" + basename "${dev}" return 0 fi fi @@ -232,14 +236,13 @@ flash_fp_mcu_stm32() { check_hardware_write_protect_disabled if [[ "${transport}" == "UART" ]]; then - deviceid="$(get_uartid)" - if [[ $? -ne 0 ]]; then + if ! deviceid="$(get_uartid)"; then echo "Unable to find FP sensor UART device: ${CROS_EC_UART_MODALIAS_STR}" exit 1 fi else - deviceid="$(get_spiid)" - if [[ $? -ne 0 ]]; then + + if ! deviceid="$(get_spiid)"; then echo "Unable to find FP sensor SPI device: ${CROS_EC_SPI_MODALIAS_STR}" exit 1 fi @@ -303,7 +306,7 @@ flash_fp_mcu_stm32() { local cmd_exit_status=1 local cmd="stm32mon ${stm32mon_flags}" - for attempt in $(seq ${FLAGS_retries}); do + for attempt in $(seq "${FLAGS_retries}"); do # Reset sequence to enter bootloader mode gpio 0 "${gpio_nrst}" sleep 0.01 @@ -515,9 +518,7 @@ if [[ "$(type -t "config_${PLATFORM_NAME}")" != "function" ]]; then exit 1 fi -config_${PLATFORM_NAME} - -if [[ $? -ne 0 ]]; then +if ! "config_${PLATFORM_NAME}"; then echo "Configuration failed for platform ${PLATFORM_NAME}" exit 1 fi |