From 6a144d98d3d09c2beea3ae5002a371a4f71a23f0 Mon Sep 17 00:00:00 2001 From: Namyoon Woo Date: Fri, 15 Mar 2019 13:03:11 -0700 Subject: flash_ec: remove sed or cut call in getting a value from dut-control BUG=none BRANCH=none TEST=manually ran flash_ec on coral, scarlet, and ampton. The test log is at gpaste/6202232963858432. $ ./util/flash_ec --board=coral --read ${IMG} $ ./util/flash_ec --board=scarlet --read ${IMG} --bitbang_rate=57600 $ ./util/flash_ec --board=ampton --read ${IMG} Tested with a EXPECT_TO_FAIL case with a line, dut_control_get xxxx $ ./util/flash_ec --board=scarlet --read ${IMG} --verbose Problem with ['xxxx'] :: No control named "xxxx" ERROR: dut_control_get failed: dut-control --port=9999 xxxx Tested with a board name in stm32_dfu, and checked dut_command_get is not called. $ ./util/flash_ec --board dingdong --image ${IMG} --verbose INFO: Using a dedicated debug cable INFO: Using toad. INFO: Using ec image : /tmp/ec.read.bin INFO: Flashing chip stm32_dfu. INFO: Using dfu flasher : dfu-util ... Change-Id: Ib936cf450c3d12f0784ff1aaf3c33e9d18069606 Signed-off-by: Namyoon Woo Reviewed-on: https://chromium-review.googlesource.com/1524670 Reviewed-by: Matthew Blecker --- util/flash_ec | 84 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/util/flash_ec b/util/flash_ec index 07ee541a96..66dbb3b618 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -174,14 +174,17 @@ fi set -e -DUT_CONTROL_CMD="dut-control --port=${FLAGS_port}" +DUT_CONTROL_CMD=( "dut-control" "--port=${FLAGS_port}" ) function dut_control() { + local DUT_CTRL_CML=( "${DUT_CONTROL_CMD[@]}" ) + DUT_CTRL_CML+=( "$@" ) + if [ "${FLAGS_verbose}" = ${FLAGS_TRUE} ]; then - echo "$DUT_CONTROL_CMD $@" 1>&2 + echo "${DUT_CTRL_CML[*]}" 1>&2 fi - $DUT_CONTROL_CMD "$@" >/dev/null + "${DUT_CTRL_CML[@]}" >/dev/null } function dut_control_or_die { @@ -189,32 +192,24 @@ function dut_control_or_die { } function dut_control_get() { - local DUT_GETVAL= - if dut_control "$1" ; then - DUT_GETVAL=$(${DUT_CONTROL_CMD} $1) + if [ $# -gt 1 ]; then + error "${FUNCNAME[0]} failed: more than one argument: $@" + return 1 fi - # Remove the shortest prefix ending ':' - echo "${DUT_GETVAL#*:}" - } -function get_servo_type() { - if dut_control "servo_type" ; then - $DUT_CONTROL_CMD servo_type | sed -e s/servo_type:// + local ARGS DUT_GETVAL RETVAL + ARGS=( "${DUT_CONTROL_CMD[@]}" "$1" ) + RETVAL=0 + # || statement is attached to avoid an exit if error exit is enabled. + DUT_GETVAL=$( "${ARGS[@]}" ) || RETVAL="$?" + if (( "${RETVAL}" )) ; then + error "${FUNCNAME[0]} failed: ${ARGS[*]} returned ${RETVAL}." + return "${RETVAL}" fi + # Remove the shortest prefix ending ':' + echo "${DUT_GETVAL#*:}" } -SERVO_EC_CHIP="$(($DUT_CONTROL_CMD ec_chip) | sed -e s/ec_chip://)" -SERVO_EC_CHIP="${SERVO_EC_CHIP,,}" -if [[ "${SERVO_EC_CHIP}" =~ "unknown" ]]; then - SERVO_EC_CHIP="" -fi - -if [[ -z "${FLAGS_board}" && -z "${FLAGS_chip}" && \ - -z "${SERVO_EC_CHIP}" ]]; then - die "Please check that servod is running or," \ - "manually specify either --board or --chip." -fi - BOARD=${FLAGS_board} in_array() { @@ -267,12 +262,16 @@ if [[ ${#SUPPORTED_CHIPS[@]} -eq 0 && -n "${FLAGS_chip}" ]]; then SUPPORTED_CHIPS+="${FLAGS_chip}" fi -if [[ ${#SUPPORTED_CHIPS[@]} -eq 0 && -n "${SERVO_EC_CHIP}" ]]; then +if [[ ${#SUPPORTED_CHIPS[@]} -eq 0 ]]; then + SERVO_EC_CHIP="$(dut_control_get ec_chip)" + SERVO_EC_CHIP="${SERVO_EC_CHIP,,}" + if [[ "${SERVO_EC_CHIP}" =~ "unknown" || -z "${SERVO_EC_CHIP}" ]]; then + die "Please check that servod is running or," \ + "manually specify either --board or --chip." + fi SUPPORTED_CHIPS+=("${SERVO_EC_CHIP}") fi -SERVO_TYPE="$(get_servo_type)" - if [[ ${#SUPPORTED_CHIPS[@]} -eq 0 ]]; then # This happens if ${FLAGS_board} is not known in this flash_ec yet, # ${FLAGS_chip} is not given, and servod doesn't know ec_chip. @@ -304,6 +303,16 @@ if [[ "${CHIP}" = "stm32_dfu" ]]; then NEED_SERVO="no" fi +# Servo variables management +case "${BOARD}" in + chocodile_bec ) MCU="usbpd" ;; + oak_pd|samus_pd|strago_pd ) MCU="usbpd" ;; + chell_pd|glados_pd ) MCU="usbpd" ;; + nami_fp|nocturne_fp ) MCU="usbpd" ;; + dingdong|hoho|twinkie ) DUT_CONTROL_CMD=( "true" ); MCU="ec" ;; + *) MCU="ec" ;; +esac + case "${CHIP}" in "stm32"|"npcx_spi"|"npcx_int_spi"|"it83xx") ;; *) @@ -320,6 +329,8 @@ case "${CHIP}" in ;; esac +SERVO_TYPE="$(dut_control_get servo_type)" + servo_has_warm_reset() { dut_control -i warm_reset >/dev/null 2>&1 } @@ -595,24 +606,14 @@ function ec_image() { # Find the EC UART provided by servo. function servo_ec_uart() { SERVOD_FAIL="Cannot communicate with servod. Is servod running?" - PTY=$(($DUT_CONTROL_CMD raw_${MCU}_uart_pty || - $DUT_CONTROL_CMD ${MCU}_uart_pty) | cut -d: -f2) + PTY=$(dut_control_get raw_${MCU}_uart_pty || + dut_control_get ${MCU}_uart_pty) if [[ -z "${PTY}" ]]; then die "${SERVOD_FAIL}" fi echo $PTY } -# Servo variables management -case "${BOARD}" in - chocodile_bec ) MCU="usbpd" ;; - oak_pd|samus_pd|strago_pd ) MCU="usbpd" ;; - chell_pd|glados_pd ) MCU="usbpd" ;; - nami_fp|nocturne_fp ) MCU="usbpd" ;; - dingdong|hoho|twinkie ) DUT_CONTROL_CMD="true" ; MCU="ec" ;; - *) MCU="ec" ;; -esac - # Not every control is supported on every servo type. Therefore, define which # controls are supported by each servo type. servo_v2_VARS="jtag_buf_on_flex_en jtag_buf_en cold_reset spi1_vref" @@ -653,7 +654,7 @@ function servo_save() { SERVO_VARS_NAME=${SERVO_TYPE}_VARS if [[ -n "${!SERVO_VARS_NAME}" ]]; then - $DUT_CONTROL_CMD ${!SERVO_VARS_NAME} + "${DUT_CONTROL_CMD[@]}" "${!SERVO_VARS_NAME}" fi } @@ -715,8 +716,7 @@ function get_serial() { sn_ctl="" fi - SERIALNAME=$(${DUT_CONTROL_CMD} "${sn_ctl}serialname" | cut -d: -f2) - echo $SERIALNAME + dut_control_get "${sn_ctl}serialname" } # Board specific flashing scripts -- cgit v1.2.1