summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorCraig Hesling <hesling@chromium.org>2021-04-28 16:58:25 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-29 18:14:35 +0000
commit8d00c8ddf875d549aec338ce1f0f814f0b241d55 (patch)
tree488c289a6742325a0c91463b76d883a2b18ed3eb /util
parent3193d78aad3b984df7bc127780174cea1c27533b (diff)
downloadchrome-ec-8d00c8ddf875d549aec338ce1f0f814f0b241d55.tar.gz
flash_fp_mcu: Refactor to use main function
https://google.github.io/styleguide/shellguide.html#s7.8-main BRANCH=none BUG=b:176500425 TEST=# dut1 is a dratini device scp util/flash_fp_mcu dut1:/usr/local/bin/flash_fp_mcu ssh dut1 flash_fp_mcu --hello; echo "Status $?" # Should succeed ssh dut1 flash_fp_mcu '/opt/google/biod/fw/bloonchipper*'; echo "Status $?" # Should succeed ssh dut1 flash_fp_mcu; echo "Status $?" # Should error out about no filename Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: I2f5f0c05e6c0a83a67948c5f914470b08a5d2c56 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2858276 Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/flash_fp_mcu101
1 files changed, 53 insertions, 48 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu
index 0f6b8e33bc..27312bc093 100644
--- a/util/flash_fp_mcu
+++ b/util/flash_fp_mcu
@@ -25,16 +25,6 @@ FLAGS_HELP="Usage: ${0} [flags] ec.bin"
FLAGS "${@}" || exit 1
eval set -- "${FLAGS_ARGV}"
-if [[ "$#" -eq 0 ]] && [[ "${FLAGS_hello}" -eq "${FLAGS_FALSE}" ]]; then
- echo "Missing filename"
- flags_help
- exit 1
-fi
-
-# print out canonical path to differentiate between /usr/local/bin and
-# /usr/bin installs
-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"
@@ -219,14 +209,14 @@ flash_fp_mcu_stm32() {
# Read from FPMCU to file
if [[ -e "${file}" ]]; then
echo "Output file already exists: ${file}"
- exit 1
+ return 1
fi
stm32mon_flags+=" -r ${file}"
else
# Write to FPMCU from file
if [[ ! -f "${file}" ]]; then
echo "Invalid image file: ${file}"
- exit 1
+ return 1
fi
stm32mon_flags+=" -e -w ${file}"
fi
@@ -238,13 +228,13 @@ flash_fp_mcu_stm32() {
if [[ "${transport}" == "UART" ]]; then
if ! deviceid="$(get_uartid)"; then
echo "Unable to find FP sensor UART device: ${CROS_EC_UART_MODALIAS_STR}"
- exit 1
+ return 1
fi
else
if ! deviceid="$(get_spiid)"; then
echo "Unable to find FP sensor SPI device: ${CROS_EC_SPI_MODALIAS_STR}"
- exit 1
+ return 1
fi
fi
@@ -367,7 +357,7 @@ flash_fp_mcu_stm32() {
fi
if [[ "${cmd_exit_status}" -ne 0 ]]; then
- exit 1
+ return 1
fi
# Inform user to reboot if transport is UART.
@@ -497,36 +487,51 @@ config_guybrush() {
readonly GPIO_PWREN=-1
}
-# The "platform name" corresponds to the underlying board (reference design)
-# that we're running on (not the FPMCU or sensor). At the moment all of the
-# reference designs use the same GPIOs. If for some reason a design differs in
-# the future, we will want to add a nested check in the config_<platform_name>
-# function. Doing it in this manner allows us to reduce the number of
-# configurations that we have to maintain (and reduces the amount of testing
-# if we're only updating a specific config_<platform_name>).
-if ! PLATFORM_NAME="$(get_platform_name)"; then
- echo "Failed to get platform name"
- exit 1
-fi
-readonly PLATFORM_NAME
-
-echo "Using config for ${PLATFORM_NAME}"
-
-# Check that the config function exists
-if [[ "$(type -t "config_${PLATFORM_NAME}")" != "function" ]]; then
- echo "No config for platform ${PLATFORM_NAME}"
- exit 1
-fi
-
-if ! "config_${PLATFORM_NAME}"; then
- echo "Configuration failed for platform ${PLATFORM_NAME}"
- exit 1
-fi
-
-flash_fp_mcu_stm32 \
- "${TRANSPORT}" \
- "${DEVICE}" \
- "${GPIO_NRST}" \
- "${GPIO_BOOT0}" \
- "${GPIO_PWREN}" \
- "${1}"
+main() {
+ if [[ "$#" -eq 0 ]] && [[ "${FLAGS_hello}" -eq "${FLAGS_FALSE}" ]]; then
+ echo "Missing filename"
+ flags_help
+ exit 1
+ fi
+
+ # print out canonical path to differentiate between /usr/local/bin and
+ # /usr/bin installs
+ readlink -f "$0"
+
+ # The "platform name" corresponds to the underlying board (reference design)
+ # that we're running on (not the FPMCU or sensor). At the moment all of the
+ # reference designs use the same GPIOs. If for some reason a design differs in
+ # the future, we will want to add a nested check in the config_<platform_name>
+ # function. Doing it in this manner allows us to reduce the number of
+ # configurations that we have to maintain (and reduces the amount of testing
+ # if we're only updating a specific config_<platform_name>).
+ if ! PLATFORM_NAME="$(get_platform_name)"; then
+ echo "Failed to get platform name"
+ exit 1
+ fi
+ readonly PLATFORM_NAME
+
+ echo "Using config for ${PLATFORM_NAME}"
+
+ # Check that the config function exists
+ if [[ "$(type -t "config_${PLATFORM_NAME}")" != "function" ]]; then
+ echo "No config for platform ${PLATFORM_NAME}"
+ exit 1
+ fi
+
+ if ! "config_${PLATFORM_NAME}"; then
+ echo "Configuration failed for platform ${PLATFORM_NAME}"
+ exit 1
+ fi
+
+ flash_fp_mcu_stm32 \
+ "${TRANSPORT}" \
+ "${DEVICE}" \
+ "${GPIO_NRST}" \
+ "${GPIO_BOOT0}" \
+ "${GPIO_PWREN}" \
+ "${1}"
+ exit $?
+}
+
+main "$@"