diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-06-26 16:02:02 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-01 16:14:16 -0700 |
commit | 177dc398d39c1156182cb8e59a4092bd8a18ad93 (patch) | |
tree | dcaac91130b259baafa19e9fc26d07c815f0c4ce /util/ec_flash.c | |
parent | 2730daa5679bc0d2a048a60055a7dc89d060076e (diff) | |
download | chrome-ec-177dc398d39c1156182cb8e59a4092bd8a18ad93.tar.gz |
Allow bigger flash write commands
Version 1 of EC_CMD_FLASH_WRITE will use as big a write as possible given
the available command parameter space. Falls back to 64 byte writes on old
platforms.
BUG=chrome-os-partner:20571
BRANCH=none
TEST=Copy burn_my_ec onto a link and run it. Write size should be 64 bytes
for the first half of the update (since the old EC doesn't support ver.1
of the write command) and 240 bytes for the second half of the update.
Change-Id: I5900de3a5700d7c82a2e0c3cf9921b7ced1c0343
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60511
Diffstat (limited to 'util/ec_flash.c')
-rw-r--r-- | util/ec_flash.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/util/ec_flash.c b/util/ec_flash.c index 0c9c698600..93705694e3 100644 --- a/util/ec_flash.c +++ b/util/ec_flash.c @@ -67,16 +67,46 @@ int ec_flash_verify(const uint8_t *buf, int offset, int size) int ec_flash_write(const uint8_t *buf, int offset, int size) { - struct ec_params_flash_write p; + struct ec_params_flash_write *p = + (struct ec_params_flash_write *)ec_outbuf; + struct ec_response_flash_info info; + int pdata_max_size = (int)(ec_max_outsize - sizeof(*p)); + int step; int rv; int i; + /* + * Determine whether we can use version 1 of the command with more + * data, or only version 0. + */ + if (!ec_cmd_version_supported(EC_CMD_FLASH_WRITE, EC_VER_FLASH_WRITE)) + pdata_max_size = EC_FLASH_WRITE_VER0_SIZE; + + /* + * Determine step size. This must be a multiple of the write block + * size, and must also fit into the host parameter buffer. + */ + rv = ec_command(EC_CMD_FLASH_INFO, 0, NULL, 0, &info, sizeof(info)); + if (rv < 0) + return rv; + + step = (pdata_max_size / info.write_block_size) * info.write_block_size; + + if (!step) { + fprintf(stderr, "Write block size %d > max param size %d\n", + info.write_block_size, pdata_max_size); + return -1; + } + /* Write data in chunks */ - for (i = 0; i < size; i += sizeof(p.data)) { - p.offset = offset + i; - p.size = MIN(size - i, sizeof(p.data)); - memcpy(p.data, buf + i, p.size); - rv = ec_command(EC_CMD_FLASH_WRITE, 0, &p, sizeof(p), NULL, 0); + printf("Write size %d...\n", step); + + for (i = 0; i < size; i += step) { + p->offset = offset + i; + p->size = MIN(size - i, step); + memcpy(p + 1, buf + i, p->size); + rv = ec_command(EC_CMD_FLASH_WRITE, 0, p, sizeof(*p) + p->size, + NULL, 0); if (rv < 0) { fprintf(stderr, "Write error at offset %d\n", i); return rv; |