summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2014-10-30 18:38:09 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-05 01:09:39 +0000
commit2bc0b68c863693ae9e3e315aa3438829e59077ef (patch)
tree8c730a18b5c2cdfa56daa67c2cf871abe977437a
parent63704fd11b1858d9438f6bfefcc0b304c43644ad (diff)
downloadchrome-ec-2bc0b68c863693ae9e3e315aa3438829e59077ef.tar.gz
pd: move get_info to common file.
get_info command needs to be used by all type-C accessories that would entertain being updated in the field. This CL migrates function to common/usb_pd_protocol.c for other boards to use. Signed-off-by: Todd Broch <tbroch@chromium.org> BRANCH=samus BUG=chrome-os-partner:31192,chrome-os-partner:31193 TEST=manual, Using ectool --name=cros_pd infopddev <0|1> Port:1 Devid 1.1 Hash: 0x00ec9619 0x811f3e68 0x4b90c8e9 0xd5b98fa8 0xfd373777 Port:1 Devid 3.0 Hash: 0x682fd366 0x7213f55e 0xddefb802 0xbedfec42 0x5cdcc226 Port:0 Devid 4.0 Hash: 0x57b1e4e0 0x7204075f 0x65c0fa72 0xdcca15ed 0xf3231237 Change-Id: Iffa8699056351f62cf90fdecbc7ef5cee81e67bb Reviewed-on: https://chromium-review.googlesource.com/226891 Reviewed-by: Alec Berg <alecaberg@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org> Commit-Queue: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org>
-rw-r--r--board/dingdong/board.h3
-rw-r--r--board/dingdong/ec.tasklist2
-rw-r--r--board/dingdong/usb_pd_policy.c5
-rw-r--r--board/hoho/board.h3
-rw-r--r--board/hoho/ec.tasklist2
-rw-r--r--board/hoho/usb_pd_policy.c5
-rw-r--r--board/zinger/hardware.c11
-rw-r--r--board/zinger/runtime.c8
-rw-r--r--common/usb_pd_protocol.c32
-rw-r--r--include/usb_pd.h7
-rw-r--r--test/test_config.h1
11 files changed, 66 insertions, 13 deletions
diff --git a/board/dingdong/board.h b/board/dingdong/board.h
index 32678b2ad4..29eeab1891 100644
--- a/board/dingdong/board.h
+++ b/board/dingdong/board.h
@@ -27,8 +27,11 @@
#define CONFIG_USB_INHIBIT_CONNECT
#define CONFIG_USB_POWER_DELIVERY
#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR USB_PD_HW_DEV_ID_DINGDONG
+#define CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR 0
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_CUSTOM_VDM
+#define CONFIG_USB_PD_FLASH
#define CONFIG_USB_PD_INTERNAL_COMP
#define CONFIG_USB_PD_IDENTITY_HW_VERS 1
#define CONFIG_USB_PD_IDENTITY_SW_VERS 1
diff --git a/board/dingdong/ec.tasklist b/board/dingdong/ec.tasklist
index e9c8c1cc1f..d31352893c 100644
--- a/board/dingdong/ec.tasklist
+++ b/board/dingdong/ec.tasklist
@@ -19,4 +19,4 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(PD, pd_task, NULL, TASK_STACK_SIZE)
+ TASK_ALWAYS(PD, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/dingdong/usb_pd_policy.c b/board/dingdong/usb_pd_policy.c
index b38254a83b..a09a432492 100644
--- a/board/dingdong/usb_pd_policy.c
+++ b/board/dingdong/usb_pd_policy.c
@@ -296,6 +296,11 @@ static int pd_custom_vdm(int port, int cnt, uint32_t *payload,
memcpy(payload + 1, &version_data.version, 24);
rsize = 7;
break;
+ case VDO_CMD_READ_INFO:
+ /* copy info into response */
+ pd_get_info(payload + 1);
+ rsize = 7;
+ break;
default:
rsize = 0;
}
diff --git a/board/hoho/board.h b/board/hoho/board.h
index df9a963318..30aa1d49b8 100644
--- a/board/hoho/board.h
+++ b/board/hoho/board.h
@@ -35,8 +35,11 @@
#define CONFIG_USB_INHIBIT_CONNECT
#define CONFIG_USB_POWER_DELIVERY
#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR USB_PD_HW_DEV_ID_HOHO
+#define CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR 0
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_CUSTOM_VDM
+#define CONFIG_USB_PD_FLASH
#define CONFIG_USB_PD_INTERNAL_COMP
#define CONFIG_USB_PD_IDENTITY_HW_VERS 1
#define CONFIG_USB_PD_IDENTITY_SW_VERS 1
diff --git a/board/hoho/ec.tasklist b/board/hoho/ec.tasklist
index e9c8c1cc1f..d31352893c 100644
--- a/board/hoho/ec.tasklist
+++ b/board/hoho/ec.tasklist
@@ -19,4 +19,4 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(PD, pd_task, NULL, TASK_STACK_SIZE)
+ TASK_ALWAYS(PD, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c
index e15dc3d580..50792a0e68 100644
--- a/board/hoho/usb_pd_policy.c
+++ b/board/hoho/usb_pd_policy.c
@@ -295,6 +295,11 @@ static int pd_custom_vdm(int port, int cnt, uint32_t *payload,
memcpy(payload + 1, &version_data.version, 24);
rsize = 7;
break;
+ case VDO_CMD_READ_INFO:
+ /* copy info into response */
+ pd_get_info(payload + 1);
+ rsize = 7;
+ break;
default:
rsize = 0;
}
diff --git a/board/zinger/hardware.c b/board/zinger/hardware.c
index 59e2f8b24b..1238d31a0d 100644
--- a/board/zinger/hardware.c
+++ b/board/zinger/hardware.c
@@ -9,8 +9,6 @@
#include "common.h"
#include "cpu.h"
#include "registers.h"
-#include "rsa.h"
-#include "sha256.h"
#include "task.h"
#include "timer.h"
#include "util.h"
@@ -409,12 +407,3 @@ exit_er:
return res;
}
-
-static struct sha256_ctx ctx;
-uint8_t *flash_hash_rw(void)
-{
- SHA256_init(&ctx);
- SHA256_update(&ctx, (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF,
- CONFIG_FW_RW_SIZE - RSANUMBYTES);
- return SHA256_final(&ctx);
-}
diff --git a/board/zinger/runtime.c b/board/zinger/runtime.c
index 4dda979d46..0724c68c81 100644
--- a/board/zinger/runtime.c
+++ b/board/zinger/runtime.c
@@ -231,6 +231,14 @@ void panic_reboot(void)
cpu_reset();
}
+enum system_image_copy_t system_get_image_copy(void)
+{
+ if (is_ro_mode())
+ return SYSTEM_IMAGE_RO;
+ else
+ return SYSTEM_IMAGE_RW;
+}
+
/* --- stubs --- */
void __hw_timer_enable_clock(int n, int enable)
{ /* Done in hardware init */ }
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index b8783161db..967f002dcd 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -15,12 +15,15 @@
#include "hooks.h"
#include "host_command.h"
#include "registers.h"
+#include "rsa.h"
+#include "sha256.h"
#include "system.h"
#include "task.h"
#include "timer.h"
#include "util.h"
#include "usb_pd.h"
#include "usb_pd_config.h"
+#include "version.h"
#ifdef CONFIG_COMMON_RUNTIME
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
@@ -1322,6 +1325,35 @@ void pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash)
pd_dev_dump_info(dev_id, (uint8_t *)rw_hash);
}
+uint8_t *flash_hash_rw(void)
+{
+ static struct sha256_ctx ctx;
+ SHA256_init(&ctx);
+ SHA256_update(&ctx, (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF,
+ CONFIG_FW_RW_SIZE - RSANUMBYTES);
+ return SHA256_final(&ctx);
+}
+
+void pd_get_info(uint32_t *info_data)
+{
+ void *hash;
+
+ /* calculate RW hash */
+ hash = flash_hash_rw();
+ /* copy first 20 bytes of RW hash */
+ memcpy(info_data, hash, 5 * sizeof(uint32_t));
+ /* copy other info into data msg */
+#if defined(CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR) && \
+ defined(CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR)
+ info_data[5] = VDO_INFO(CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR,
+ CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR,
+ ver_get_numcommits(),
+ (system_get_image_copy() != SYSTEM_IMAGE_RO));
+#else
+ info_data[5] = 0;
+#endif
+}
+
#ifdef CONFIG_USB_PD_DUAL_ROLE
void pd_set_dual_role(enum pd_dual_role_states state)
{
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 9fbfc19ebf..886ca39b11 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -792,6 +792,13 @@ void pd_new_contract(int port, int pr_role, int dr_role,
void pd_execute_data_swap(int port, int data_role);
/**
+ * Get PD device info used for VDO_CMD_SEND_INFO / VDO_CMD_READ_INFO
+ *
+ * @param info_data pointer to info data array
+ */
+void pd_get_info(uint32_t *info_data);
+
+/**
* Handle Vendor Defined Messages
*
* @param port USB-C port number
diff --git a/test/test_config.h b/test/test_config.h
index 2fd090d5d0..56fdf87772 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -130,6 +130,7 @@ int board_discharge_on_ac(int enabled);
#define CONFIG_USB_POWER_DELIVERY
#define CONFIG_USB_PD_CUSTOM_VDM
#define CONFIG_USB_PD_DUAL_ROLE
+#define CONFIG_SHA256
#define CONFIG_SW_CRC
#endif