From bc1690366776fb65d8fa773c2f74c4f71f5059e5 Mon Sep 17 00:00:00 2001 From: Todd Broch Date: Mon, 24 Nov 2014 10:20:41 -0800 Subject: pd: Re-factor common flash vdms. CL to migrate the flashing VDMs from zinger's custom vdm to common/usb_pd_flash.c such that other updateable type-C devices can share. Additionally adds gaskets to call standard runtime flashing facilities for USB-PD devices using it. Signed-off-by: Todd Broch BRANCH=samus BUG=chrome-os-partner:31192,chrome-os-partner:31193 TEST=manual, Try following: 1. From samus_pd console w/ zinger in port 1 pd 1 flash version pd 1 flash reboot pd 1 flash info 2. From samus linux prompt w/ zinger in port 1 ectool --name cros_pd flashpd 1 1 Reading 16384 bytes from /usr/local/zinger_v1.1.2528-d809e42.ec.RW.bin... Erasing expected RW hash Rebooting Erasing RW flash Writing RW flash Rebooting PD into new RW Complete 3. Repeat 1&2 above on hoho & dingdong. Change-Id: I018055fa9de128f937c57debdc21dea026137bcf Reviewed-on: https://chromium-review.googlesource.com/231835 Reviewed-by: Vincent Palatin Reviewed-by: Alec Berg Tested-by: Todd Broch Commit-Queue: Todd Broch --- board/zinger/board.c | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'board/zinger/board.c') diff --git a/board/zinger/board.c b/board/zinger/board.c index 5dcbef04fb..3ea9850015 100644 --- a/board/zinger/board.c +++ b/board/zinger/board.c @@ -9,6 +9,7 @@ #include "registers.h" #include "rsa.h" #include "sha256.h" +#include "system.h" #include "task.h" #include "usb_pd.h" #include "util.h" @@ -23,10 +24,6 @@ static const void *rw_sig = (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF /* Large 768-Byte buffer for RSA computation : could be re-use afterwards... */ static uint32_t rsa_workbuf[3 * RSANUMWORDS]; -static uint8_t *rw_hash; -static uint8_t rw_flash_changed; -static uint32_t info_data[6]; - extern void pd_rx_handler(void); /* RW firmware reset vector */ @@ -60,12 +57,16 @@ int is_ro_mode(void) static int check_rw_valid(void) { int good; + void *rw_hash; /* Check if we have a RW firmware flashed */ if (*rw_rst == 0xffffffff) return 0; - good = rsa_verify(&pkey, (void *)rw_sig, (void *)rw_hash, rsa_workbuf); + /* calculate hash of RW */ + rw_hash = flash_hash_rw(); + + good = rsa_verify(&pkey, (void *)rw_sig, rw_hash, rsa_workbuf); if (!good) { debug_printf("RSA verify FAILED\n"); return 0; @@ -74,30 +75,6 @@ static int check_rw_valid(void) return 1; } -uint32_t *board_get_info(void) -{ - if (rw_flash_changed) { - /* re-calculate RW hash */ - rw_hash = flash_hash_rw(); - rw_flash_changed = 0; - } - - /* copy first 20 bytes of RW hash */ - memcpy(info_data, rw_hash, 5 * sizeof(uint32_t)); - - /* copy other info into data msg */ - info_data[5] = VDO_INFO(CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR, - CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR, - ver_get_numcommits(), !is_ro_mode()); - - return info_data; -} - -void board_rw_contents_change(void) -{ - rw_flash_changed = 1; -} - extern void pd_task(void); int main(void) @@ -106,9 +83,6 @@ int main(void) debug_printf("Power supply started ... %s\n", is_ro_mode() ? "RO" : "RW"); - /* calculate hash of RW */ - rw_hash = flash_hash_rw(); - /* Verify RW firmware and use it if valid */ if (is_ro_mode() && check_rw_valid()) jump_to_rw(); @@ -118,6 +92,6 @@ int main(void) debug_printf("background loop exited !\n"); /* we should never reach that point */ - cpu_reset(); + system_reset(0); return 0; } -- cgit v1.2.1