summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2014-10-31 13:13:51 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-17 22:12:48 +0000
commite96afe490f238f02e6598fe48f66cae895a1732f (patch)
tree59a31311ac931c629c3afa050caa213ee058b661
parent8862b6aaf1c5dc2f2642c634384e15fd4db048b1 (diff)
downloadchrome-ec-e96afe490f238f02e6598fe48f66cae895a1732f.tar.gz
pd: fix alignment issue for print rwhashtable.
struct ec_params_usb_pd_rw_hash_entry is packed so addressing rw_hash array caused alignment faults. CL removes union in favor of just shipping bytes across the host command. BRANCH=samus BUG=none TEST=manual from DUT ectool --name cros_pd infopddev 0 Port:0 Device:1025 Hash: 0xa90a5d48 0xcc2af4ea 0xc7796d08 0x4a8f9e8e 0x0ba7578b ectool --name cros_pd rwhashpd 1025 0xa90a5d48 0xcc2af4ea 0xc7796d08 0x4a8f9e8e 0x0ba7578b from PD MCU console, pd rwhashtable # no exception due to memory read alignment and ... Device:0x0401 Hash: 0xa90a5d48 0xcc2af4ea 0xc7796d08 0x4a8f9e8e 0x0ba7578b Device:0x0000 Hash: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 Device:0x0000 Hash: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 Device:0x0000 Hash: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 Change-Id: I134a5402eac3e5159441ce6c483633ca0d575a03 Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226890 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--common/usb_pd_protocol.c14
-rw-r--r--include/ec_commands.h5
-rw-r--r--util/ectool.c18
3 files changed, 24 insertions, 13 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 5382bc24be..9f7b76670b 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1296,12 +1296,14 @@ static void pd_vdm_send_state_machine(int port)
}
}
-static inline void pd_dev_dump_info(uint16_t dev_id, uint32_t *hash)
+static inline void pd_dev_dump_info(uint16_t dev_id, uint8_t *hash)
{
int j;
ccprintf("Device:0x%04x Hash:", dev_id);
- for (j = 0; j < PD_RW_HASH_SIZE/4; j++)
- ccprintf(" 0x%08x", hash[j]);
+ for (j = 0; j < PD_RW_HASH_SIZE; j += 4) {
+ ccprintf(" 0x%02x%02x%02x%02x", hash[j + 3], hash[j + 2],
+ hash[j + 1], hash[j]);
+ }
ccprintf("\n");
}
@@ -1310,7 +1312,7 @@ void pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash)
pd[port].dev_id = dev_id;
memcpy(pd[port].dev_rw_hash, rw_hash, PD_RW_HASH_SIZE);
if (debug_level >= 1)
- pd_dev_dump_info(dev_id, rw_hash);
+ pd_dev_dump_info(dev_id, (uint8_t *)rw_hash);
}
#ifdef CONFIG_USB_PD_DUAL_ROLE
@@ -2344,7 +2346,7 @@ static int command_pd(int argc, char **argv)
struct ec_params_usb_pd_rw_hash_entry *p;
for (i = 0; i < RW_HASH_ENTRIES; i++) {
p = &rw_hash_table[i];
- pd_dev_dump_info(p->dev_id, p->dev_rw_hash.w);
+ pd_dev_dump_info(p->dev_id, p->dev_rw_hash);
}
return EC_SUCCESS;
}
@@ -2694,7 +2696,7 @@ static int hc_remote_pd_dev_info(struct host_cmd_handler_args *args)
r->dev_id = pd[*port].dev_id;
if (r->dev_id) {
- memcpy(r->dev_rw_hash.b, pd[*port].dev_rw_hash,
+ memcpy(r->dev_rw_hash, pd[*port].dev_rw_hash,
PD_RW_HASH_SIZE);
}
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 574475ea09..31eed3661d 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -2811,10 +2811,7 @@ struct ec_params_usb_pd_fw_update {
#define PD_RW_HASH_SIZE 20
struct ec_params_usb_pd_rw_hash_entry {
uint16_t dev_id;
- union {
- uint8_t b[PD_RW_HASH_SIZE];
- uint32_t w[PD_RW_HASH_SIZE/4];
- } dev_rw_hash;
+ uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
} __packed;
/* Read USB-PD Accessory info */
diff --git a/util/ectool.c b/util/ectool.c
index f8043cefb0..7201c0b2d4 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -793,6 +793,8 @@ int cmd_rw_hash_pd(int argc, char *argv[])
(struct ec_params_usb_pd_rw_hash_entry *)ec_outbuf;
int i, rv;
char *e;
+ uint32_t val;
+ uint8_t *rwp;
if (argc < 7) {
fprintf(stderr, "Usage: %s <dev_id> <HASH[0]> ... <HASH[4]>\n",
@@ -806,12 +808,18 @@ int cmd_rw_hash_pd(int argc, char *argv[])
return -1;
}
+ rwp = p->dev_rw_hash;
for (i = 2; i < 7; i++) {
- p->dev_rw_hash.w[i - 2] = strtol(argv[i], &e, 0);
+ val = strtol(argv[i], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad RW hash\n");
return -1;
}
+ rwp[0] = (uint8_t) (val >> 0) & 0xff;
+ rwp[1] = (uint8_t) (val >> 8) & 0xff;
+ rwp[2] = (uint8_t) (val >> 16) & 0xff;
+ rwp[3] = (uint8_t) (val >> 24) & 0xff;
+ rwp += 4;
}
rv = ec_command(EC_CMD_USB_PD_RW_HASH_ENTRY, 0, p, sizeof(*p), NULL, 0);
@@ -848,9 +856,13 @@ int cmd_pd_device_info(int argc, char *argv[])
if (!r0->dev_id)
printf("Port:%d has no valid device\n", p->port);
else {
+ uint8_t *rwp = r0->dev_rw_hash;
printf("Port:%d Device:%d Hash: ", p->port, r0->dev_id);
- for (i = 0; i < 5; i++)
- printf(" 0x%08x", r0->dev_rw_hash.w[i]);
+ for (i = 0; i < 5; i++) {
+ printf(" 0x%02x%02x%02x%02x ", rwp[3], rwp[2], rwp[1],
+ rwp[0]);
+ rwp += 4;
+ }
printf("\n");
}