diff options
author | Dino Li <Dino.Li@ite.com.tw> | 2018-04-10 11:37:53 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-10 19:13:29 -0700 |
commit | 3a96c3cec4754abf953709b4f19c03a062c4d04a (patch) | |
tree | d8a66184da51c50449097a457b5822ba044c0389 | |
parent | 3a9b89116fd0b3e358706f9c5822d4ee944978b6 (diff) | |
download | chrome-ec-3a96c3cec4754abf953709b4f19c03a062c4d04a.tar.gz |
iteflash: Continue call ftdi_read_data() until all data is read
We found a symptom that iteflash always programming EC failed
on a specific host machine.
For this failed case, it is caused by the incomplete read from
ftdi_read_data(). For example, we want to read 32 bytes by just
call ftdi_read_data() one time, but ftdi_read_data() may return
(number of bytes read) 10 or 20 but just not 32.
This change will call ftdi_read_data() again and again until all
data is read.
Change draw_spinner() function to use fprintf().
We will show percentage increase from 0 percent to 100 percen
during verifying.
Change of flash_ec script:
Move operations of reinitialize ftdi_i2c interface to cleanup()
and we won't miss them if programming is failed.
BUG=none
BRANCH=none
TEST=To run iteflash on that host machine and flashing is done.
Change-Id: Ifa374652870737c8231fce5a699abe033a1f0237
Signed-off-by: Dino Li <Dino.Li@ite.com.tw>
Reviewed-on: https://chromium-review.googlesource.com/979903
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rwxr-xr-x | util/flash_ec | 12 | ||||
-rw-r--r-- | util/iteflash.c | 47 |
2 files changed, 38 insertions, 21 deletions
diff --git a/util/flash_ec b/util/flash_ec index 6577eaf10e..ffe4d5c54d 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -399,6 +399,13 @@ cleanup() { kill -CONT ${pid} done + if [ "${CHIP}" == "it83xx" ] ; then + info "Reinitialize ftdi_i2c interface" + dut_control --ftdii2c init + dut_control --ftdii2c open + dut_control --ftdii2c setclock + fi + if ! on_raiden || $(servo_has_cold_reset); then ec_reset fi @@ -847,11 +854,6 @@ function flash_it83xx() { info "Run iteflash..." sudo ${ITEFLASH} -w ${IMG} - - info "Reinitialize ftdi_i2c interface" - dut_control --ftdii2c init - dut_control --ftdii2c open - dut_control --ftdii2c setclock } function flash_lm4() { diff --git a/util/iteflash.c b/util/iteflash.c index 701c9dd2a5..2778583142 100644 --- a/util/iteflash.c +++ b/util/iteflash.c @@ -83,7 +83,7 @@ enum { static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, uint8_t *ptr, uint8_t *tbuf, int tcnt) { - int ret, i, j; + int ret, i, j, remaining_data, ack_idx; int tx_buffered = 0; static uint8_t ack[TX_BUFFER_LIMIT]; uint8_t *b = ptr; @@ -117,7 +117,18 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, } /* read ACK bits */ - ret = ftdi_read_data(ftdi, &ack[0], tx_buffered); + remaining_data = tx_buffered; + ack_idx = 0; + do { + ret = ftdi_read_data(ftdi, &ack[ack_idx], + remaining_data); + if (ret < 0) { + fprintf(stderr, "read ACK failed\n"); + return ret; + } + remaining_data -= ret; + ack_idx += ret; + } while (remaining_data); for (j = 0; j < tx_buffered; j++) { if ((ack[j] & 0x80) != 0) failed_ack = ack[j]; @@ -143,7 +154,7 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, static int i2c_add_recv_bytes(struct ftdi_context *ftdi, uint8_t *buf, uint8_t *ptr, uint8_t *rbuf, int rcnt) { - int ret, i; + int ret, i, rbuf_idx; uint8_t *b = ptr; for (i = 0; i < rcnt; i++) { @@ -170,9 +181,18 @@ static int i2c_add_recv_bytes(struct ftdi_context *ftdi, uint8_t *buf, fprintf(stderr, "failed to prepare read\n"); return ret; } - ret = ftdi_read_data(ftdi, rbuf, rcnt); - if (ret < 0) - fprintf(stderr, "read byte failed\n"); + + rbuf_idx = 0; + do { + ret = ftdi_read_data(ftdi, &rbuf[rbuf_idx], rcnt); + if (ret < 0) { + fprintf(stderr, "read byte failed\n"); + break; + } + rcnt -= ret; + rbuf_idx += ret; + } while (rcnt); + return ret; } @@ -587,7 +607,7 @@ static const char wheel[] = {'|', '/', '-', '\\' }; static void draw_spinner(uint32_t remaining, uint32_t size) { int percent = (size - remaining)*100/size; - printf("\r%c%3d%%", wheel[windex++], percent); + fprintf(stderr, "\r%c%3d%%", wheel[windex++], percent); windex %= sizeof(wheel); } @@ -723,6 +743,7 @@ int command_write_pages(struct ftdi_context *ftdi, uint32_t address, address += cnt; remaining -= cnt; } + draw_spinner(remaining, size); /* No error so far */ res = size; failed_write: @@ -801,6 +822,7 @@ wait_busy_cleared: } } /* No error so far */ + printf("\n\rErasing Done.\n"); res = 0; failed_erase: if (spi_flash_command_short(ftdi, SPI_CMD_WRITE_DISABLE, @@ -810,8 +832,6 @@ failed_erase: if (spi_flash_follow_mode_exit(ftdi, "erase") < 0) res = -EIO; - printf("\n"); - return res; } @@ -885,7 +905,7 @@ int write_flash(struct ftdi_context *ftdi, const char *filename, free(buffer); return -EIO; } - printf("\rDone.\n"); + printf("\n\rWriting Done.\n"); free(buffer); return 0; @@ -927,12 +947,7 @@ int verify_flash(struct ftdi_context *ftdi, const char *filename, res = command_read_pages(ftdi, offset, flash_size, buffer2); draw_spinner(flash_size-res, flash_size); res = memcmp(buffer, buffer2, file_size); - if (res != 0) { - fprintf(stderr, "Verify Error!! "); - goto exit; - } - - printf("\n\rVerify Done.\n"); + printf("\n\rVerify %s\n", res ? "Failed!" : "Done."); exit: free(buffer); |