diff options
author | Rob Barnes <robbarnes@google.com> | 2021-05-11 09:44:27 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-13 04:15:49 +0000 |
commit | 479c52fe81e43ff26b381a1d216e86c3483ba2c4 (patch) | |
tree | 871cbd7c0d4afd5bdf29834e326ca65e4691fbe8 | |
parent | d702d009c9d388ea5cfdcf61bc24a12248abac7f (diff) | |
download | chrome-ec-479c52fe81e43ff26b381a1d216e86c3483ba2c4.tar.gz |
ectool: Make i2cread/write address print consistent
ectool i2cread and i2cwrite expect an 8-bit address as input. However
the output prints a 7-bit address. This is confusing for ectool users.
This CL changes the output to be the 8-bit address. i2cxfer expects a
7-bit address and is unaffected by this CL.
BUG=b:187811828
TEST=ectool i2cread 8 1 0x52 0
Read from I2C port 1 at 0x52 offset 0x0 = 0x10
BRANCH=None
Signed-off-by: Rob Barnes <robbarnes@google.com>
Change-Id: I71596080200d9ee08b23536d233cf34d958bf9b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2887555
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r-- | util/ectool.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/util/ectool.c b/util/ectool.c index fad8e27a7c..f4722c06df 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -7146,7 +7146,7 @@ static void cmd_i2c_help(void) int cmd_i2c_read(int argc, char *argv[]) { - unsigned int port, addr; + unsigned int port, addr8, addr7; int read_len, write_len; uint8_t write_buf[1]; uint8_t *read_buf = NULL; @@ -7171,13 +7171,12 @@ int cmd_i2c_read(int argc, char *argv[]) return -1; } - addr = strtol(argv[3], &e, 0); + addr8 = strtol(argv[3], &e, 0); if (e && *e) { fprintf(stderr, "Bad address.\n"); return -1; } - /* Convert from 8-bit to 7-bit address */ - addr = addr >> 1; + addr7 = addr8 >> 1; write_buf[0] = strtol(argv[4], &e, 0); if (e && *e) { @@ -7186,20 +7185,21 @@ int cmd_i2c_read(int argc, char *argv[]) } write_len = 1; - rv = do_i2c_xfer(port, addr, write_buf, write_len, &read_buf, read_len); + rv = do_i2c_xfer(port, addr7, write_buf, write_len, &read_buf, + read_len); if (rv < 0) return rv; printf("Read from I2C port %d at 0x%x offset 0x%x = 0x%x\n", - port, addr, write_buf[0], *(uint16_t *)read_buf); + port, addr8, write_buf[0], *(uint16_t *)read_buf); return 0; } int cmd_i2c_write(int argc, char *argv[]) { - unsigned int port, addr; + unsigned int port, addr8, addr7; int write_len; uint8_t write_buf[3]; char *e; @@ -7224,13 +7224,12 @@ int cmd_i2c_write(int argc, char *argv[]) return -1; } - addr = strtol(argv[3], &e, 0); + addr8 = strtol(argv[3], &e, 0); if (e && *e) { fprintf(stderr, "Bad address.\n"); return -1; } - /* Convert from 8-bit to 7-bit address */ - addr = addr >> 1; + addr7 = addr8 >> 1; write_buf[0] = strtol(argv[4], &e, 0); if (e && *e) { @@ -7244,13 +7243,13 @@ int cmd_i2c_write(int argc, char *argv[]) return -1; } - rv = do_i2c_xfer(port, addr, write_buf, write_len, NULL, 0); + rv = do_i2c_xfer(port, addr7, write_buf, write_len, NULL, 0); if (rv < 0) return rv; printf("Wrote 0x%x to I2C port %d at 0x%x offset 0x%x.\n", - *((uint16_t *)&write_buf[1]), port, addr, write_buf[0]); + *((uint16_t *)&write_buf[1]), port, addr8, write_buf[0]); return 0; } |