summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2012-11-05 10:41:02 -0800
committerGerrit <chrome-bot@google.com>2012-11-07 09:48:29 -0800
commit4efe1ed157b732cc3408e8b1e8af6bd823b4247c (patch)
treea2f727b04e75e87d70bef7a9604e6cf8ea2fdeaa /util
parent25bbb6b5dec3e0eb9672e6d3e0acf032f9e8d8d1 (diff)
downloadchrome-ec-4efe1ed157b732cc3408e8b1e8af6bd823b4247c.tar.gz
Fix the ec flash programming script to properly handle errors
When a nonexisting file is specified as the EC image, the ec flash programming script reports the error, but continues running and returns zero status (success) after completion. With this change the exit status on some errors gets communicated to the caller. The openocd script is edited to drop the unused parameter of the flash_lm4() function and the flash_ec script is edited not to require EC images to be executable. BRANCH=none BUG=chrome-os-partner:15610 TEST=manual . run flash_ec with nonexisting or nonreadable file as a parameter, observe it to report proper return status. Run it with a proper image file name and observe it succeed. . run the command again, while the device is being programmed enter 'ctl-c', observe programming stepped but the 'Restoring servo settings..." message still showing up. Change-Id: Iac0b233fe579b0d5a84cf5a9acf85ed8bf10422e Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/37363 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-xutil/flash_ec43
1 files changed, 26 insertions, 17 deletions
diff --git a/util/flash_ec b/util/flash_ec
index 417a823fd5..194270d1fc 100755
--- a/util/flash_ec
+++ b/util/flash_ec
@@ -14,6 +14,8 @@ DEFINE_string image "" \
"Full pathname of the EC firmware image to flash."
DEFINE_boolean ro "${FLAGS_FALSE}" \
"Write only the read-only partition"
+DEFINE_string offset "0" \
+ "Offset where to program the image from."
# Parse command line
FLAGS_HELP="usage: $0 [flags]"
@@ -21,6 +23,20 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
check_flags_only_and_allow_null_arg "$@" && set --
+set -e
+
+cleanup() {
+ if [ -n "${save}" ]; then
+ info "Restoring servo settings..."
+ servo_restore "$save"
+ fi
+
+ # reset the EC
+ dut_control cold_reset:on
+ dut_control cold_reset:off
+}
+trap cleanup EXIT
+
BOARD=${FLAGS_board}
BOARD_ROOT=/build/${BOARD}
@@ -36,18 +52,18 @@ LOCAL_BUILD=${SRC_ROOT}/platform/ec/build/${BOARD}/${EC_FILE}
# Find the EC image to use
function ec_image() {
# No image specified on the command line, try default ones
- if [[ ! -z "${FLAGS_image}" ]] ; then
- if [ ! -r "${FLAGS_image}" ]; then
- die "Invalid image path : ${FLAGS_image}"
+ if [[ -n "${FLAGS_image}" ]] ; then
+ if [ -f "${FLAGS_image}" ]; then
+ echo "${FLAGS_image}"
+ return
fi
- echo "${FLAGS_image}"
- return
+ die "Invalid image path : ${FLAGS_image}"
else
- if [ -x "${LOCAL_BUILD}" ]; then
+ if [ -f "${LOCAL_BUILD}" ]; then
echo "${LOCAL_BUILD}"
return
fi
- if [ -x "${EMERGE_BUILD}" ]; then
+ if [ -f "${EMERGE_BUILD}" ]; then
echo "${EMERGE_BUILD}"
return
fi
@@ -104,15 +120,15 @@ function flash_daisy() {
}
function flash_link() {
- IMG_SIZE=262144
OCD_CFG="servo_v2_slower.cfg"
OCD_PATH="${SRC_ROOT}/platform/ec/chip/lm4/openocd"
- OCD_CMDS="init ; flash_lm4 ${IMG} 0 262144 ; exit"
+ OCD_CMDS="init ; flash_lm4 ${IMG} ${FLAGS_offset}; shutdown;"
dut_control jtag_buf_on_flex_en:on
dut_control jtag_buf_en:on
- sudo openocd -s "${OCD_PATH}" -f "${OCD_CFG}" -c "${OCD_CMDS}"
+ sudo openocd -s "${OCD_PATH}" -f "${OCD_CFG}" -c "${OCD_CMDS}" || \
+ die "Failed to program ${IMG}"
}
IMG="$(ec_image)"
@@ -130,10 +146,3 @@ case "${BOARD}" in
esac
info "Flashing done."
-
-# Restore servo settings
-servo_restore "$save"
-
-# reset the EC
-dut_control cold_reset:on
-dut_control cold_reset:off