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 @@ -791,6 +791,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 * 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