diff options
author | Puthikorn Voravootivat <puthik@chromium.org> | 2014-08-28 14:03:11 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-08-29 21:55:34 +0000 |
commit | 61f2327f072b4600b1b5880da8a858ce528d59d0 (patch) | |
tree | d04befd0327bf8f30c3547a2c354c9c7bb677a5f | |
parent | dcb9bb6026bc9b600b968307bb228f8766e9591d (diff) | |
download | chrome-ec-61f2327f072b4600b1b5880da8a858ce528d59d0.tar.gz |
ectool: read max outsize/insize from ec during comm_init
Current ectool uses max outsize / insize from protocol v2
even if we have a v3 protocol ec. This makes some command
not working when actual size supported by ec is less than
max size from protocol v2.
This CL uses protoinfo command to read max size from ec
during the initialization process to correctly set max size
for ec with protocol v3+. For ec with protocol v2, protoinfo
command won't exist, hence ectool won't modify the max size
and used the size that we set when init the protocol.
BRANCH=none
BUG=chrome-os-partner:31660
TEST=Run 'ectool flashread 0 0x1000 /tmp/fr' in ryu
Change-Id: I226b6c2fb2f7e9be73032f2c5146d2710939b293
Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214838
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | util/comm-host.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/util/comm-host.c b/util/comm-host.c index 3f8c70a4e7..a79a34a385 100644 --- a/util/comm-host.c +++ b/util/comm-host.c @@ -6,6 +6,7 @@ #include <errno.h> #include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "comm-host.h" @@ -76,6 +77,8 @@ int ec_command(int command, int version, int comm_init(int interfaces) { + struct ec_response_get_protocol_info info; + /* Default memmap access */ ec_readmem = fake_readmem; @@ -104,6 +107,23 @@ int comm_init(int interfaces) return 1; } + /* read max request / response size from ec for protocol v3+ */ + if (ec_command(EC_CMD_GET_PROTOCOL_INFO, 0, NULL, 0, &info, + sizeof(info)) == sizeof(info)) { + ec_max_outsize = info.max_request_packet_size - + sizeof(struct ec_host_request); + ec_max_insize = info.max_response_packet_size - + sizeof(struct ec_host_response); + + ec_outbuf = realloc(ec_outbuf, ec_max_outsize); + ec_inbuf = realloc(ec_inbuf, ec_max_insize); + + if (!ec_outbuf || !ec_inbuf) { + fprintf(stderr, "Unable to reallocate buffers\n"); + return 1; + } + } + return 0; } |