summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-07-03 14:45:59 -0700
committerGerrit <chrome-bot@google.com>2012-07-07 17:14:18 -0700
commit7f5f7be3e5df92ec2e9447b3d5d0b8ddeb96c9a0 (patch)
treef58e23fa5d053e31163faf8279882f0d9891c1fe /util
parent0e42faf85b3a4adbc83cb087e0bdab7641df9f1b (diff)
downloadchrome-ec-7f5f7be3e5df92ec2e9447b3d5d0b8ddeb96c9a0.tar.gz
Add memory-mapped data support for I2C and SPI protocols
And fix returning memory-mapped string length on LPC as well. BUG=chrome-os-partner:11090 TEST=manual from EC, 'hostevent set 0x40000' from host, 'ectool eventget' --> should print 0x40000 Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I9edbd0a1468b5d4160ce67c471332226e51fa868 Reviewed-on: https://gerrit.chromium.org/gerrit/26719 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/comm-host.h5
-rw-r--r--util/comm-i2c.c64
-rw-r--r--util/comm-lpc.c4
-rw-r--r--util/ectool.c30
4 files changed, 69 insertions, 34 deletions
diff --git a/util/comm-host.h b/util/comm-host.h
index b3790b4717..7a3f856bf9 100644
--- a/util/comm-host.h
+++ b/util/comm-host.h
@@ -29,6 +29,11 @@ int ec_command(int command, const void *indata, int insize,
uint8_t read_mapped_mem8(uint8_t offset);
uint16_t read_mapped_mem16(uint8_t offset);
uint32_t read_mapped_mem32(uint8_t offset);
+/*
+ * Read a memory-mapped string at the specified offset and store into buf,
+ * which must be at least size EC_MEMMAP_TEXT_MAX. Returns the length of
+ * the copied string, not counting the terminating '\0', or <0 if error.
+ */
int read_mapped_string(uint8_t offset, char *buf);
#endif /* COMM_HOST_H */
diff --git a/util/comm-i2c.c b/util/comm-i2c.c
index 47241d392e..5020db3ecf 100644
--- a/util/comm-i2c.c
+++ b/util/comm-i2c.c
@@ -186,30 +186,70 @@ done:
return ret;
}
-
uint8_t read_mapped_mem8(uint8_t offset)
{
- /* Not implemented */
- return 0xff;
-}
+ struct ec_params_read_memmap p;
+ uint8_t val;
+
+ p.offset = offset;
+ p.size = sizeof(val);
+ if (ec_command(EC_CMD_READ_MEMMAP, &p, sizeof(p),
+ &val, sizeof(val)) < 0)
+ return 0xff;
+
+ return val;
+}
uint16_t read_mapped_mem16(uint8_t offset)
{
- /* Not implemented */
- return 0xffff;
-}
+ struct ec_params_read_memmap p;
+ uint16_t val;
+
+ p.offset = offset;
+ p.size = sizeof(val);
+ if (ec_command(EC_CMD_READ_MEMMAP, &p, sizeof(p),
+ &val, sizeof(val)) < 0)
+ return 0xffff;
+
+ return val;
+}
uint32_t read_mapped_mem32(uint8_t offset)
{
- /* Not implemented */
- return 0xffffffff;
-}
+ struct ec_params_read_memmap p;
+ uint32_t val;
+ p.offset = offset;
+ p.size = sizeof(val);
+
+ if (ec_command(EC_CMD_READ_MEMMAP, &p, sizeof(p),
+ &val, sizeof(val)) < 0)
+ return 0xffffffff;
+
+ return val;
+}
int read_mapped_string(uint8_t offset, char *buf)
{
- strncpy(buf, "NOT IMPLEMENTED", EC_MEMMAP_TEXT_MAX);
- return sizeof("NOT IMPLEMENTED");
+ struct ec_params_read_memmap p;
+ int c;
+
+ p.offset = offset;
+ p.size = EC_MEMMAP_TEXT_MAX;
+
+ if (ec_command(EC_CMD_READ_MEMMAP, &p, sizeof(p),
+ buf, EC_MEMMAP_TEXT_MAX) < 0) {
+ *buf = 0;
+ return -1;
+ }
+
+ for (c = 0; c < EC_MEMMAP_TEXT_MAX; c++) {
+ if (buf[c] == 0)
+ return c;
+ }
+
+ buf[EC_MEMMAP_TEXT_MAX - 1] = 0;
+ return EC_MEMMAP_TEXT_MAX - 1;
}
diff --git a/util/comm-lpc.c b/util/comm-lpc.c
index 31e2cdb3a2..d91a8a2cc6 100644
--- a/util/comm-lpc.c
+++ b/util/comm-lpc.c
@@ -157,6 +157,6 @@ int read_mapped_string(uint8_t offset, char *buf)
return c;
}
- buf[EC_MEMMAP_TEXT_MAX-1] = 0;
- return EC_MEMMAP_TEXT_MAX;
+ buf[EC_MEMMAP_TEXT_MAX - 1] = 0;
+ return EC_MEMMAP_TEXT_MAX - 1;
}
diff --git a/util/ectool.c b/util/ectool.c
index 2cb80bedf1..2b1078323b 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1487,32 +1487,22 @@ int cmd_battery(int argc, char *argv[])
printf("Battery info:\n");
rv = read_mapped_string(EC_MEMMAP_BATT_MFGR, batt_text);
- if (rv) {
- if (!is_string_printable(batt_text))
- goto cmd_error;
- printf(" OEM name: %s\n", batt_text);
- }
+ if (rv < 0 || !is_string_printable(batt_text))
+ goto cmd_error;
+ printf(" OEM name: %s\n", batt_text);
rv = read_mapped_string(EC_MEMMAP_BATT_MODEL, batt_text);
- if (rv) {
- if (!is_string_printable(batt_text))
- goto cmd_error;
- printf(" Model number: %s\n", batt_text);
- }
+ if (rv < 0 || !is_string_printable(batt_text))
+ goto cmd_error;
+ printf(" Model number: %s\n", batt_text);
rv = read_mapped_string(EC_MEMMAP_BATT_TYPE, batt_text);
- if (rv) {
- if (!is_string_printable(batt_text))
- goto cmd_error;
- printf(" Chemistry : %s\n", batt_text);
- }
+ if (rv < 0 || !is_string_printable(batt_text))
+ goto cmd_error;
+ printf(" Chemistry : %s\n", batt_text);
rv = read_mapped_string(EC_MEMMAP_BATT_SERIAL, batt_text);
- if (rv) {
- if (!is_string_printable(batt_text))
- goto cmd_error;
- printf(" Serial number: %s\n", batt_text);
- }
+ printf(" Serial number: %s\n", batt_text);
val = read_mapped_mem32(EC_MEMMAP_BATT_DCAP);
if (!is_battery_range(val))