From dbc3f1dad52ead720c270b25dbb4547ca3ee3f46 Mon Sep 17 00:00:00 2001 From: Donald Huang Date: Fri, 6 Nov 2015 16:34:31 +0800 Subject: it8380dev: util: fix iteflash Add support for flash the ite ec from usb gpio port Signed-off-by: Donald Huang BRANCH=none BUG=none TEST=Test OK on ITE8390CX from both GPIO PORT (C1,C2) (H5,H6) 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) (br-iteflash) 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. /* ==SNAPSHOT END== */ Change-Id: I422db6f7007622f8be624a534a482e24d53a061a Reviewed-on: https://chromium-review.googlesource.com/311205 Commit-Ready: Donald Huang Tested-by: Donald Huang Reviewed-by: Randall Spangler Reviewed-by: Donald Huang --- util/iteflash.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/util/iteflash.c b/util/iteflash.c index b13c61d6bc..472f58f515 100644 --- a/util/iteflash.c +++ b/util/iteflash.c @@ -447,10 +447,16 @@ static int config_i2c(struct ftdi_context *ftdi) } /* Special waveform definition */ -#define SPECIAL_LEN_USEC 50000ULL /* us */ -#define SPECIAL_FREQ 400000ULL +#define SPECIAL_LEN_USEC 50000ULL /* us */ +#define SPECIAL_FREQ 400000ULL + #define SPECIAL_PATTERN 0x0000020301010302ULL +#define SPECIAL_PATTERN_SDA_L_SCL_L 0x0000000000000000ULL +#define SPECIAL_PATTERN_SDA_H_SCL_L 0x0202020202020202ULL +#define SPECIAL_PATTERN_SDA_L_SCL_H 0x0101010101010101ULL +#define SPECIAL_PATTERN_SDA_H_SCL_H 0x0303030303030303ULL +#define TICK_COUNT 24 #define MSEC 1000 #define USEC 1000000 @@ -495,8 +501,23 @@ retry: goto special_failed; } + /* do usb special waveform */ + + wave[0] = 0x0; + ftdi_write_data(ftdi, (uint8_t *)wave, 1); + usleep(5000); + + /* program each special tick */ + for (i = 0; i < TICK_COUNT; ) { + wave[i++] = SPECIAL_PATTERN_SDA_L_SCL_L; + wave[i++] = SPECIAL_PATTERN_SDA_H_SCL_L; + wave[i++] = SPECIAL_PATTERN_SDA_L_SCL_L; + } + wave[19] = SPECIAL_PATTERN_SDA_H_SCL_H; + + /* fill the buffer with the waveform pattern */ - for (i = 0; i < SPECIAL_BUFFER_SIZE / sizeof(uint64_t); i++) + for (i = TICK_COUNT; i < SPECIAL_BUFFER_SIZE / sizeof(uint64_t); i++) wave[i] = SPECIAL_PATTERN; ret = ftdi_write_data(ftdi, (uint8_t *)wave, SPECIAL_BUFFER_SIZE); @@ -513,9 +534,10 @@ retry: usleep(10 * MSEC); /* if we cannot communicate, retry the sequence */ - if (check_chipid(ftdi) < 0) + if (check_chipid(ftdi) < 0) { + sleep(1); goto retry; - + } special_failed: printf("Done.\n"); free(wave); -- cgit v1.2.1