summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2022-04-27 17:43:25 +0200
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-04 16:45:20 +0000
commitf2270c5d2fbdf310e3202184237f5baae890e33d (patch)
treeac47af03987b38a7a15476182b0ed1b2522e0741
parent8a50ae7b4008c6e78fedc238999609092036aa2f (diff)
downloadchrome-ec-f2270c5d2fbdf310e3202184237f5baae890e33d.tar.gz
zephyr: Fix duplicated output in EC_CMD_CONSOLE_READ
Zephyr and CrEC implementation of EC_CMD_CONSOLE_READ is different. CrEC allows to read the UART buffer upto character written before EC_CMD_CONSOLE_SNAPSHOT host command. Also an index for CONSOLE_READ_NEXT and CONSOLE_READ_RECENT subcommands is separated. This CL changes Zephyr implementation to match CrEC. BUG=b:229935172 TEST=zmake testall TEST=check if /var/log/cros_ec.log has correct content and messages are not duplicated BRANCH=none Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: I5256b45d04ff8d3994bcbaf2722bacc1f37d73b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3613912 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com> Tested-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Tomasz Michalec <tmichalec@google.com>
-rw-r--r--zephyr/shim/src/console_buffer.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/zephyr/shim/src/console_buffer.c b/zephyr/shim/src/console_buffer.c
index b768bb279f..739d1e2251 100644
--- a/zephyr/shim/src/console_buffer.c
+++ b/zephyr/shim/src/console_buffer.c
@@ -13,6 +13,7 @@
static char console_buf[CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE_BUF_SIZE];
static uint32_t previous_snapshot_idx;
static uint32_t current_snapshot_idx;
+static uint32_t read_next_idx;
static uint32_t head_idx;
static uint32_t tail_idx;
@@ -51,6 +52,8 @@ void console_buf_notify_chars(const char *s, size_t len)
if (new_tail == current_snapshot_idx)
current_snapshot_idx =
next_idx(current_snapshot_idx);
+ if (new_tail == read_next_idx)
+ read_next_idx = next_idx(read_next_idx);
console_buf[tail_idx] = *s++;
tail_idx = new_tail;
@@ -64,8 +67,18 @@ enum ec_status uart_console_read_buffer_init(void)
/* Failed to acquire console buffer mutex */
return EC_RES_TIMEOUT;
+ /* For read next, start reading at the beginning of the buffer */
+ read_next_idx = head_idx;
+ /*
+ * For read recent, start reading at the beginning of the previous
+ * snapshot
+ */
previous_snapshot_idx = current_snapshot_idx;
- current_snapshot_idx = head_idx;
+ /*
+ * Limit read command to characters available at the moment of creating
+ * snapshot
+ */
+ current_snapshot_idx = tail_idx;
k_mutex_unlock(&console_write_lock);
@@ -80,8 +93,11 @@ int uart_console_read_buffer(uint8_t type, char *dest, uint16_t dest_size,
switch (type) {
case CONSOLE_READ_NEXT:
- /* Start from beginning of latest snapshot */
- head = &current_snapshot_idx;
+ /*
+ * Start where we left or from the beginning of the buffer after
+ * snapshot
+ */
+ head = &read_next_idx;
break;
case CONSOLE_READ_RECENT:
/* Start from end of previous snapshot */
@@ -99,7 +115,7 @@ int uart_console_read_buffer(uint8_t type, char *dest, uint16_t dest_size,
/* Failed to acquire console buffer mutex */
return EC_RES_TIMEOUT;
- if (*head == tail_idx) {
+ if (*head == current_snapshot_idx) {
/* No new data, return empty response */
k_mutex_unlock(&console_write_lock);
return EC_RES_SUCCESS;
@@ -113,7 +129,7 @@ int uart_console_read_buffer(uint8_t type, char *dest, uint16_t dest_size,
dest[write_count] = console_buf[*head];
write_count++;
*head = next_idx(*head);
- } while (*head != tail_idx);
+ } while (*head != current_snapshot_idx);
dest[write_count] = '\0';
write_count++;