summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-08-12 15:29:18 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-14 17:11:39 +0000
commit2941f4874d8f8f8ff7d94bcf7aafadc49db0bc9a (patch)
treed2d92b634749fbdf75edc3103fe4f601e07033e8
parentb4348c2104746ab98d6081fb38216bb3b8fa1a82 (diff)
downloadchrome-ec-2941f4874d8f8f8ff7d94bcf7aafadc49db0bc9a.tar.gz
flash_ec: support "--read" and "--verify" flags for npcx_uut
This patch enables flash_ec to read EC image from npcx_uut type chip, and to verify the flash programmed image. BUG=b:133265593 BRANCH=none TEST=manually ran flash_ec on fleex and careena. flash_ec --board flex --image ${IMG} --verify flash_ec --board flex --read ${TMP_IMG} flash_ec --board careena --image ${IMG} --verify flash_ec --board careena --read ${TMP_IMG} Cq-Depend: chromium:1748803 Change-Id: Ifaefa64b0efed6c875c99ede59a3a1e0dfe0bf7f Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1749554 Reviewed-by: CH Lin <chlin56@nuvoton.com> Reviewed-by: Raul E Rangel <rrangel@chromium.org>
-rwxr-xr-xutil/flash_ec97
1 files changed, 74 insertions, 23 deletions
diff --git a/util/flash_ec b/util/flash_ec
index 226e4ee533..339ec98f11 100755
--- a/util/flash_ec
+++ b/util/flash_ec
@@ -155,16 +155,15 @@ DEFINE_integer port "${DEFAULT_PORT}" \
"Port to communicate to servo on."
DEFINE_boolean raiden "${FLAGS_FALSE}" \
"Use raiden_debug_spi programmer"
-DEFINE_string read "" "Stm32, it83xx and npcx_(|int_)spi only:"\
-" pathname of the file to store EC firmware image."
+DEFINE_string read "" "Pathname of the file to store EC firmware image."
DEFINE_boolean ro "${FLAGS_FALSE}" \
"Write only the read-only partition"
DEFINE_integer timeout 600 \
"Timeout for flashing the EC, measured in seconds."
DEFINE_boolean verbose "${FLAGS_FALSE}" \
"Verbose hw control logging"
-DEFINE_boolean verify "${FLAGS_FALSE}" "Stm32, it83xx and npcx_(int_)spi only:"\
-" verify EC firmware image after programming."
+DEFINE_boolean verify "${FLAGS_FALSE}" \
+ "Verify EC firmware image after programming."
# Parse command line
FLAGS_HELP="usage: $0 [flags]"
@@ -321,7 +320,7 @@ case "${BOARD}" in
esac
case "${CHIP}" in
- "stm32"|"npcx_spi"|"npcx_int_spi"|"it83xx") ;;
+ "stm32"|"npcx_spi"|"npcx_int_spi"|"it83xx"|"npcx_uut") ;;
*)
if [[ -n "${FLAGS_read}" ]]; then
die "The flag is not yet supported on ${CHIP}."
@@ -1206,13 +1205,13 @@ function flash_npcx_jtag() {
}
function flash_npcx_uut() {
- TOOL_PATH="${EC_DIR}/build/${BOARD}/util:$PATH"
- NPCX_UUT=$(PATH="${TOOL_PATH}" which uartupdatetool)
- EC_UART="$(servo_ec_uart)"
+ local TOOL_PATH="${EC_DIR}/build/${BOARD}/util:$PATH"
+ local NPCX_UUT=$(PATH="${TOOL_PATH}" which uartupdatetool)
+ local EC_UART="$(servo_ec_uart)"
# Look for npcx_monitor.bin in multiple directories, starting with
# the same path as the EC binary.
- MON=""
+ local MON=""
for dir in \
"$(dirname "$IMG")" \
"${EC_DIR}/build/${BOARD}/chip/npcx/spiflashfw" \
@@ -1231,7 +1230,10 @@ function flash_npcx_uut() {
info "Using NPCX image : ${MON}"
# The start address to restore monitor firmware binary
- MON_ADDR="0x200C3020"
+ local MON_ADDR="0x200C3020"
+ local BASE_ADDR="0x64000000" # The base flash memory address
+ local FLASH_SIZE=$(( $(dut_control_get ec_flash_size)*1024 ))
+ # EC Flash memory size
if [ ! -x "$NPCX_UUT" ]; then
die "no NPCX UART Update Tool found."
@@ -1258,23 +1260,72 @@ function flash_npcx_uut() {
sleep 0.1
# Remove the prefix "/dev/" because uartupdatetool will add it.
- EC_UART=${EC_UART#/dev/}
- UUT_ARGS="--port ${EC_UART} --baudrate 115200"
+ local UUT_ARGS=( "--port=${EC_UART#/dev/}" " --baudrate=115200" )
+ local IMG_READ="${FLAGS_read}"
+
+ # Program EC image.
+ if [[ -z "${IMG_READ}" ]]; then
+ info "Loading monitor binary."
+ local UUT_MON=( "${NPCX_UUT}" "${UUT_ARGS[@]}" \
+ "--opr=wr" "--addr=${MON_ADDR}" \
+ "--file=${MON}" )
+
+ # Load monitor binary to address 0x200C3020
+ if [[ "${FLAGS_verbose}" = ${FLAGS_TRUE} ]]; then
+ echo "${UUT_MON[*]}"
+ fi
+ timeout -k 10 -s 9 "${FLAGS_timeout}" \
+ "${UUT_MON[@]}" || die "Failed to load monitor binary."
+
+ info "Programming EC firmware image."
+ local UUT_WR=( "${NPCX_UUT}" "${UUT_ARGS[@]}" \
+ "--auto" "--offset=${FLAGS_offset}" \
+ "--file=${IMG}" )
+ if [[ "${FLAGS_verbose}" = ${FLAGS_TRUE} ]]; then
+ echo "${UUT_WR[*]}"
+ fi
+ timeout -k 10 -s 9 "${FLAGS_timeout}" \
+ "${UUT_WR[@]}" || die "${MSG_PROGRAM_FAIL}"
+
+ # If it is a program-verify request, then make a temporary
+ # directory to store the image.
+ if [[ "${FLAGS_verify}" == ${FLAGS_TRUE} ]]; then
+ local TEMP_SUFFIX=".$(basename ${SCRIPT}).${CHIP}.$$"
+ local TEMP_DIR="$(mktemp -d --suffix="${TEMP_SUFFIX}")"
+
+ IMG_READ="${TEMP_DIR}/ec.read.bin"
+ DELETE_LIST+=( "${TEMP_DIR}" )
+ FLASH_SIZE=$(stat -c %s "${IMG}")
+ fi
+ fi
+
+ # Read EC image.
+ if [[ -n "${IMG_READ}" ]]; then
+ info "Reading EC firmware image."
+
+ local UUT_RD=( "${NPCX_UUT}" "${UUT_ARGS[@]}" \
+ "--opr=rd" "--addr=${BASE_ADDR}" \
+ "--size=${FLASH_SIZE}"
+ "--file=${IMG_READ}" )
- # Load monitor binary to address 0x200C3020
- if [[ "${FLAGS_verbose}" = ${FLAGS_TRUE} ]]; then
- echo ${NPCX_UUT} ${UUT_ARGS} --opr wr --addr ${MON_ADDR} \
- --file ${MON}
+ if [[ "${FLAGS_verbose}" == ${FLAGS_TRUE} ]]; then
+ echo "${UUT_RD[*]}"
+ fi
+ timeout -k 10 -s 9 "${FLAGS_timeout}" \
+ "${UUT_RD[@]}" || die "${MSG_READ_FAIL}"
fi
- ${NPCX_UUT} ${UUT_ARGS} --opr wr --addr "${MON_ADDR}" \
- --file "${MON}" || die "Failed to load monitor binary."
- if [[ "${FLAGS_verbose}" = ${FLAGS_TRUE} ]]; then
- echo ${NPCX_UUT} ${UUT_ARGS} --auto --offset ${FLAGS_offset} \
- --file ${IMG}
+ # Verify the flash by comparing the source image to the read image,
+ # only if it was a flash write request.
+ if [[ -z "${FLAGS_read}" && "${FLAGS_verify}" == ${FLAGS_TRUE} ]]; then
+ info "Verifying EC firmware image."
+
+ if [[ "${FLAGS_verbose}" == ${FLAGS_TRUE} ]]; then
+ echo "diff ${IMG} ${IMG_READ}"
+ fi
+
+ diff -q "${IMG}" "${IMG_READ}" || die "${MSG_VERIFY_FAIL}"
fi
- ${NPCX_UUT} ${UUT_ARGS} --auto --offset "${FLAGS_offset}" \
- --file "${IMG}" || die "${MSG_PROGRAM_FAIL}"
}
function flash_npcx_5m5g_jtag() {