summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/lm4/openocd/lm4x_cmds.tcl12
-rwxr-xr-xutil/flash_ec43
2 files changed, 32 insertions, 23 deletions
diff --git a/chip/lm4/openocd/lm4x_cmds.tcl b/chip/lm4/openocd/lm4x_cmds.tcl
index 00bec7f7b5..056a143512 100644
--- a/chip/lm4/openocd/lm4x_cmds.tcl
+++ b/chip/lm4/openocd/lm4x_cmds.tcl
@@ -6,7 +6,7 @@
# Program internal flash
-proc flash_lm4 {path offset size} {
+proc flash_lm4 {path offset} {
#set firstsect [expr {$offset / 1024}];
#set lastsect [expr {($offset + $size) / 1024 - 1}];
reset halt;
@@ -16,19 +16,19 @@ proc flash_lm4 {path offset size} {
# Link proto0 has 128KB flash; proto1+ have 256KB
proc flash_link { } {
- flash_lm4 ../../../build/link/ec.bin 0 262144
+ flash_lm4 ../../../build/link/ec.bin 0
}
proc flash_link_ro { } {
- flash_lm4 ../../../build/link/ec.RO.flat 0 81920
+ flash_lm4 ../../../build/link/ec.RO.flat 0
}
proc flash_link_rw { } {
- flash_lm4 ../../../build/link/ec.RW.bin 81920 81920
+ flash_lm4 ../../../build/link/ec.RW.bin 81920
}
proc flash_bds { } {
- flash_lm4 ../../../build/bds/ec.bin 0 262144
+ flash_lm4 ../../../build/bds/ec.bin 0
}
# Boot a software using internal RAM only
@@ -51,5 +51,5 @@ proc ramboot_bds { } {
proc flash_emerged_link { } {
set firmware_image ../../../../../../chroot/build/link/firmware/ec.bin
- flash_lm4 $firmware_image 0 262144
+ flash_lm4 $firmware_image 0
}
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