From 028505284c631073ba3e4dd12c9291febbb90871 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Fri, 5 Oct 2018 18:15:15 -0700 Subject: iteflash: make use of 256 byte pages when programming over CCD It turns out the write command used by iteflash requires exactly one flash page to be written at a time. Recent usb_i2c protocol enhancement allow to pass up to 4K bytes in one transaction. This patch makes sure that when using CCD exactly one page at a time is programmed. Also, there is no point in trying to sync up more than 10 times. BRANCH=none BUG=b:75976718 TEST=verified that both servo controlled write, running $ make BOARD=dragonegg -j $ ./util/flash_ec --board=dragonegg and direct write over Cr50, running $ make BOARD=dragonegg -j $ cd ./build/dragonegg $ util/iteflash -c -e -w ec.bin succeed. Change-Id: I39c10389dfcccbb32252d8c42fc54bef96330d3a Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/1266677 Reviewed-by: Jett Rink --- util/iteflash.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/util/iteflash.c b/util/iteflash.c index 08db0a0a04..aeb868ec95 100644 --- a/util/iteflash.c +++ b/util/iteflash.c @@ -53,7 +53,6 @@ /* Embedded flash block write size for different programming modes. */ #define FTDI_BLOCK_WRITE_SIZE 65536 -#define CCD_BLOCK_WRITE_SIZE 56 /* Embedded flash number of pages in a sector erase */ #define SECTOR_ERASE_PAGES 4 @@ -262,11 +261,24 @@ static int ccd_i2c_byte_transfer(struct usb_endpoint *uep, uint8_t addr, if (exit_requested) return -1; - /* Build a message following format described in ./include/usb_i2c.h. */ - usb_buffer[0] = 0; /* Hardcode port 0, may need to change this. */ + /* + * Build a message following format described in ./include/usb_i2c.h. + * + * Hardcode port, the lowest 4 bits of the first byte, to 0; may need + * to make this a command line option. + */ + usb_buffer[0] = 0; + usb_buffer[1] = addr; if (write) { - usb_buffer[2] = numbytes; + /* + * Write count might spill over into the top 4 bits of the + * first byte. We trust the caller not to pass numbytes + * exceeding (2^12 - 1). + */ + if (numbytes > 255) + usb_buffer[0] |= (numbytes >> 4) & 0xf0; + usb_buffer[2] = numbytes & 0xff; usb_buffer[3] = 0; memcpy(usb_buffer + USB_I2C_HEADER_SIZE, data, numbytes); } else { @@ -804,7 +816,7 @@ static int send_special_waveform(struct common_hnd *chnd) " is not starting!\n"); } - } while (ret && (iterations++ < 50)); + } while (ret && (iterations++ < 10)); if (ret) printf(" Failed!\n"); @@ -1477,7 +1489,7 @@ int parse_parameters(int argc, char **argv) flags |= FLAG_CCD_MODE; usb_vid = CR50_USB_VID; usb_pid = CR50_USB_PID; - block_write_size_ = CCD_BLOCK_WRITE_SIZE; + block_write_size_ = PAGE_SIZE; break; case 'd': debug = 1; -- cgit v1.2.1