diff options
author | Donald Huang <donald.huang@ite.com.tw> | 2016-01-28 14:21:15 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-01-29 01:06:33 -0800 |
commit | bca1ba350f58c16c1749631ba4cfc6d0de84243d (patch) | |
tree | e50282c0f57dc622d3242f4323c771fcb8c8c9ef | |
parent | 88e64e11e19be5284ce77fb1afab1dae48970a50 (diff) | |
download | chrome-ec-bca1ba350f58c16c1749631ba4cfc6d0de84243d.tar.gz |
it8380dev: util: Enhance iteflash
Add verify function.
BRANCH=none
BUG=none
TEST=Test OK on ITE8390CX.
You can run "make -j BOARD=it8380dev" to build ec.bin
and flash the ec.bin via
"sudo ./build/it8380dev/util/iteflash -w ./build/it8380dev/ec.bin"
/* ==SNAPSHOT START== */
(cr) (b-verify) donald@donald-nb ~/trunk/src/platform/ec $ sudo ./build/it8380dev/util/iteflash -w ./build/it8380dev/ec.bin
Waiting for the EC power-on sequence ...CHIPID 8390, CHIPVER 82, Flash size 256 kB
Done.
CHIPID 8390, CHIPVER 82, Flash size 256 kB
Erasing chip...
/100%
Writing 262144 bytes at 0x00000000
Done.
Verify 262144 bytes at 0x00000000
-100%
Verify Done.
/* ==SNAPSHOT END== */
Change-Id: Iac08e2eeb934c3a4a721e17a85de628ea4d9d065
Signed-off-by: Donald Huang <donald.huang@ite.com.tw>
Reviewed-on: https://chromium-review.googlesource.com/322524
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | util/iteflash.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/util/iteflash.c b/util/iteflash.c index 472f58f515..b74f1d3ca6 100644 --- a/util/iteflash.c +++ b/util/iteflash.c @@ -571,6 +571,7 @@ int command_read_pages(struct ftdi_context *ftdi, uint32_t address, page = address / PAGE_SIZE; draw_spinner(remaining, size); + /* Fast Read command */ if (spi_flash_command_short(ftdi, SPI_CMD_FAST_READ, "fast read") < 0) @@ -852,6 +853,52 @@ int write_flash(struct ftdi_context *ftdi, const char *filename, return 0; } +/* Return zero on success, a negative error value on failures. */ +int verify_flash(struct ftdi_context *ftdi, const char *filename, + uint32_t offset) +{ + int res; + int file_size; + FILE *hnd; + uint8_t *buffer = malloc(flash_size); + uint8_t *buffer2 = malloc(flash_size); + + if (!buffer || !buffer2) { + fprintf(stderr, "Cannot allocate %d bytes\n", flash_size); + return -ENOMEM; + } + + hnd = fopen(filename, "r"); + if (!hnd) { + fprintf(stderr, "Cannot open file %s for reading\n", filename); + res = -EIO; + goto exit; + } + + file_size = fread(buffer, 1, flash_size, hnd); + if (file_size <= 0) { + fprintf(stderr, "Cannot read %s\n", filename); + goto exit; + } + fclose(hnd); + + printf("Verify %d bytes at 0x%08x\n", file_size, offset); + 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"); +exit: + + free(buffer); + free(buffer2); + return res; +} + static struct ftdi_context *open_ftdi_device(int vid, int pid, int interface, char *serial) { @@ -1000,6 +1047,10 @@ int main(int argc, char **argv) ret = write_flash(hnd, output_filename, 0); if (ret) goto terminate; + + ret = verify_flash(hnd, output_filename, 0); + if (ret) + goto terminate; } /* Normal exit */ |