From f14134e064903fa3b86c58972e38d505da08c333 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Wed, 22 Apr 2020 18:35:44 -0700 Subject: usb_spi: refactor to allow use in different contexts The code which allows to read a section of AP or EC flash and calculate the section's SHA256 sum does not allow calculating the sum over multiple non-adjacent flash areas. This patch changes the implementation to allow calculations over more than one region. Initialization, calculation and reporting of the result become three separate API entries. The loop counting the number of the read flash chunks, is being simplified, a watchdog kick added to the brief loop interruptions, as it turns out that sleeping alone is not enough to prevent watchdog expiration when calculating hash over large SPI flash ranges. Also simplified prototypes for usb_spi_board_enable() and usb_spi_board_disable(). BUG=b:153764696 TEST=created an RO descriptor for the Atlas DUT and verified that 'gsctool -O' succeeds. Cq-Depend: chrome-internal:2939596 Signed-off-by: Vadim Bendebury Change-Id: Iec7b8634c7c80ebc7600c5b708879eb322bc7fec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2163569 Reviewed-by: Andrey Pronin (cherry picked from commit ca83aee50469799a9b70b03ef6bd3fc1e86d6c38) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242404 Tested-by: Mary Ruthven Reviewed-by: Mary Ruthven Commit-Queue: Mary Ruthven (cherry picked from commit 4858bc55562822a58064029f2c1b78c31355b596) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2261300 --- chip/g/usb_spi.c | 5 +++-- chip/g/usb_spi.h | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'chip/g') diff --git a/chip/g/usb_spi.c b/chip/g/usb_spi.c index d7f7ff031f..e41d9eab67 100644 --- a/chip/g/usb_spi.c +++ b/chip/g/usb_spi.c @@ -74,9 +74,10 @@ void usb_spi_deferred(struct usb_spi_config const *config) if (enabled ^ config->state->enabled) { if (enabled) - rv = usb_spi_board_enable(config); + rv = usb_spi_board_enable(config->state->enabled_host); + else - usb_spi_board_disable(config); + usb_spi_board_disable(); /* Only update our state if we were successful. */ if (rv == EC_SUCCESS) diff --git a/chip/g/usb_spi.h b/chip/g/usb_spi.h index cedfe78485..0c2707df4f 100644 --- a/chip/g/usb_spi.h +++ b/chip/g/usb_spi.h @@ -8,6 +8,7 @@ /* USB SPI driver for Chrome EC */ #include "compile_time_macros.h" +#include "cryptoc/sha256.h" #include "hooks.h" #include "queue.h" #include "queue_policies.h" @@ -239,7 +240,11 @@ int usb_spi_interface(struct usb_spi_config const *config, * usb_spi_board_enable should return EC_SUCCESS on success or an error * otherwise. */ -int usb_spi_board_enable(struct usb_spi_config const *config); -void usb_spi_board_disable(struct usb_spi_config const *config); +int usb_spi_board_enable(int host); +void usb_spi_board_disable(void); + +int usb_spi_sha256_start(HASH_CTX *ctx); +int usb_spi_sha256_update(HASH_CTX *ctx, uint32_t offset, uint32_t size); +void usb_spi_sha256_final(HASH_CTX *ctx, void *digest, size_t digest_size); #endif /* __CROS_EC_USB_SPI_H */ -- cgit v1.2.1