diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-04-16 16:44:54 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-04-17 22:50:20 -0700 |
commit | 5a5c38c2e9d62e6c0f45c2fb7f9df8b995379c46 (patch) | |
tree | 81f24b39ef50701c6d8889ed9c39bbb7c87eff4e | |
parent | e3b520b27a57198bf12670311b7b9bc39af3ad76 (diff) | |
download | chrome-ec-5a5c38c2e9d62e6c0f45c2fb7f9df8b995379c46.tar.gz |
common/usb_update: Statically allocate update buffer
This makes error handling simpler, and also guarantees at compile
time that EC will be able to allocate that much memory.
BRANCH=none
BUG=b:35587171
TEST=Update hammer using usb_updater2
Change-Id: Ifd4c5da80e98ee93b558679ab1cac8d5d89512e3
Reviewed-on: https://chromium-review.googlesource.com/479175
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | common/usb_update.c | 28 | ||||
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/update_fw.h | 8 |
3 files changed, 6 insertions, 33 deletions
diff --git a/common/usb_update.c b/common/usb_update.c index 6a85f19424..cf1f205763 100644 --- a/common/usb_update.c +++ b/common/usb_update.c @@ -9,7 +9,6 @@ #include "consumer.h" #include "extension.h" #include "queue_policies.h" -#include "shared_mem.h" #include "system.h" #include "update_fw.h" #include "usb-stream.h" @@ -70,7 +69,8 @@ enum rx_state { }; enum rx_state rx_state_ = rx_idle; -static uint8_t *block_buffer; +static uint8_t block_buffer[sizeof(struct update_command) + + CONFIG_UPDATE_PDU_SIZE]; static uint32_t block_size; static uint32_t block_index; @@ -131,10 +131,6 @@ static void send_error_reset(uint8_t resp_value) QUEUE_ADD_UNITS(&update_to_usb, &resp_value, 1); rx_state_ = rx_idle; data_was_transferred = 0; - if (block_buffer) { - shared_mem_release(block_buffer); - block_buffer = NULL; - } } /* Called to deal with data from the host */ @@ -151,14 +147,6 @@ static void update_out_handler(struct consumer const *consumer, size_t count) /* If timeout exceeds 5 seconds - let's start over. */ if ((delta_time > 5000000) && (rx_state_ != rx_idle)) { - if (block_buffer) { - /* - * Previous transfer could have been aborted mid - * block. - */ - shared_mem_release(block_buffer); - block_buffer = NULL; - } rx_state_ = rx_idle; CPRINTS("FW update: recovering after timeout"); } @@ -263,20 +251,12 @@ static void update_out_handler(struct consumer const *consumer, size_t count) * Only update start PDU is allowed to have a size 0 payload. */ if (block_size <= sizeof(struct update_command) || - block_size > (UPDATE_PDU_SIZE + - sizeof(struct update_command))) { + block_size > sizeof(block_buffer)) { CPRINTS("Invalid block size (%d).", block_size); send_error_reset(UPDATE_GEN_ERROR); return; } - if (shared_mem_acquire(block_size, (char **)&block_buffer) - != EC_SUCCESS) { - CPRINTS("Alloc error (%d).", block_size); - send_error_reset(UPDATE_MALLOC_ERROR); - return; - } - /* * Copy the rest of the message into the block buffer to pass * to the updater. @@ -321,8 +301,6 @@ static void update_out_handler(struct consumer const *consumer, size_t count) resp_value = block_buffer[0]; QUEUE_ADD_UNITS(&update_to_usb, &resp_value, sizeof(resp_value)); rx_state_ = rx_outside_block; - shared_mem_release(block_buffer); - block_buffer = NULL; } static void update_flush(struct consumer const *consumer) diff --git a/include/config.h b/include/config.h index b65b24f21b..a0877d2097 100644 --- a/include/config.h +++ b/include/config.h @@ -2620,6 +2620,9 @@ /* A different config for the same update. TODO(vbendeb): dedup these */ #undef CONFIG_USB_UPDATE +/* PDU size for fw update over USB (or TPM). */ +#define CONFIG_UPDATE_PDU_SIZE 1024 + /* * If defined, charge_get_state returns a special status if battery is * discharging and battery is nearly full. diff --git a/include/update_fw.h b/include/update_fw.h index 09d72e19d1..dd8b7c1a04 100644 --- a/include/update_fw.h +++ b/include/update_fw.h @@ -141,12 +141,4 @@ enum { UPDATE_RATE_LIMIT_ERROR = 9, }; -/* - * This is the size of the update frame payload, unless this is the last chunk - * of the image. - * - * TODO(b/36375666): Some boards may not be able to allocate that much memory. - */ -#define UPDATE_PDU_SIZE 1024 - #endif /* ! __CROS_EC_UPDATE_FW_H */ |