summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-08-23 15:06:57 -0700
committerCommit Bot <commit-bot@chromium.org>2019-09-03 20:48:41 +0000
commitaf51b9ea19c0ba4c6d57cdc4c5f3380647be3034 (patch)
tree92e5b04103e0342380c510bd632cbc7db43579a5
parentdfbc632cd5b5a856086249253a98bc83d8942a29 (diff)
downloadchrome-ec-af51b9ea19c0ba4c6d57cdc4c5f3380647be3034.tar.gz
common: Add uptime host command
This moves the EC_CMD_GET_UPTIME_INFO command from behind the CONFIG_CMD_AP_RESET_LOG config in chipset.c into the generic common/uptime.c file, so that all boards in the codebase can use it. If CONFIG_CMD_AP_RESET_LOG is enabled, the "AP reset stats" will be filled. Otherwise, ap_reset_stats is a no-op and recent_ap_reset is filled with zero. BRANCH=none BUG=chromium:997314 TEST=cat /sys/kernel/debug/cros_fp/uptime Change-Id: I3b6f91b2dd22d3d55b707309ec1fdfd26d42fd70 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1769393 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
-rw-r--r--board/jerry/board.h3
-rw-r--r--common/build.mk1
-rw-r--r--common/chipset.c38
-rw-r--r--common/uptime.c41
-rw-r--r--include/chipset.h21
-rw-r--r--include/common.h2
-rw-r--r--include/config.h3
-rw-r--r--test/build.mk2
-rw-r--r--test/uptime.c73
-rw-r--r--test/uptime.tasklist10
10 files changed, 167 insertions, 27 deletions
diff --git a/board/jerry/board.h b/board/jerry/board.h
index 9b696cfd8f..a7d05165ff 100644
--- a/board/jerry/board.h
+++ b/board/jerry/board.h
@@ -55,6 +55,9 @@
#undef CONFIG_WATCHDOG_HELP
#undef CONFIG_CMD_KEYBOARD
+/* Not enough RO flash space */
+#undef CONFIG_HOSTCMD_GET_UPTIME_INFO
+
#define CONFIG_HIBERNATE_WAKEUP_PINS (STM32_PWR_CSR_EWUP1 | STM32_PWR_CSR_EWUP6)
#ifndef __ASSEMBLER__
diff --git a/common/build.mk b/common/build.mk
index a5af9a3a5e..0ed708347c 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -77,6 +77,7 @@ common-$(CONFIG_FLASH_NVMEM_VARS)+=nvmem_vars.o
common-$(CONFIG_FMAP)+=fmap.o
common-$(CONFIG_GESTURE_SW_DETECTION)+=gesture.o
common-$(CONFIG_HOSTCMD_EVENTS)+=host_event_commands.o
+common-$(CONFIG_HOSTCMD_GET_UPTIME_INFO)+=uptime.o
common-$(CONFIG_HOSTCMD_PD)+=host_command_master.o
common-$(CONFIG_HOSTCMD_RTC)+=rtc.o
common-$(CONFIG_I2C_DEBUG)+=i2c_trace.o
diff --git a/common/chipset.c b/common/chipset.c
index 9c11abe9c0..232c9fcb42 100644
--- a/common/chipset.c
+++ b/common/chipset.c
@@ -101,45 +101,29 @@ void report_ap_reset(enum chipset_shutdown_reason reason)
reset_log_checksum = calc_reset_log_checksum();
}
-static int host_command_get_uptime_info(struct host_cmd_handler_args *args)
+test_mockable enum ec_error_list
+get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
+ size_t num_reset_log_entries, uint32_t *resets_since_ec_boot)
{
- /*
- * In the current implementation, not all terms are preserved across a
- * sysjump. Future implementations may preserve additional information.
- *
- * time_since_ec_boot_ms: preserved, but wraps at ~50 days
- * ec_reset_flags: preserved, with 'sysjump' added
- * ap_resets_since_ec_boot: Not preserved
- * recent_ap_reset[*]: Not preserved
- */
- struct ec_response_uptime_info *r = args->response;
- timestamp_t now = get_time();
- uint32_t now_ms = (uint32_t)(now.val / MSEC);
- size_t log_address = 0;
- size_t i = 0;
-
- r->time_since_ec_boot_ms = now_ms;
- r->ec_reset_flags = system_get_reset_flags();
+ size_t log_address;
+ size_t i;
- memset(r->recent_ap_reset, 0, sizeof(r->recent_ap_reset));
+ if (reset_log_entries == NULL || resets_since_ec_boot == NULL)
+ return EC_ERROR_INVAL;
mutex_lock(&reset_log_mutex);
- r->ap_resets_since_ec_boot = ap_resets_since_ec_boot;
+ *resets_since_ec_boot = ap_resets_since_ec_boot;
for (i = 0;
- i != ARRAY_SIZE(reset_logs) && i != ARRAY_SIZE(r->recent_ap_reset);
+ i != ARRAY_SIZE(reset_logs) && i != num_reset_log_entries;
++i) {
log_address = (next_reset_log + i) &
(ARRAY_SIZE(reset_logs) - 1);
- r->recent_ap_reset[i] = reset_logs[log_address];
+ reset_log_entries[i] = reset_logs[log_address];
}
mutex_unlock(&reset_log_mutex);
- args->response_size = sizeof(*r);
- return EC_RES_SUCCESS;
+ return EC_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_UPTIME_INFO,
- host_command_get_uptime_info,
- EC_VER_MASK(0));
#endif /* !CONFIG_AP_RESET_LOG */
diff --git a/common/uptime.c b/common/uptime.c
new file mode 100644
index 0000000000..2e50ab0fdd
--- /dev/null
+++ b/common/uptime.c
@@ -0,0 +1,41 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <stddef.h>
+
+#include "chipset.h"
+#include "system.h"
+#include "host_command.h"
+#include "util.h"
+
+static int host_command_get_uptime_info(struct host_cmd_handler_args *args)
+{
+ /*
+ * In the current implementation, not all terms are preserved across a
+ * sysjump. Future implementations may preserve additional information.
+ *
+ * time_since_ec_boot_ms: preserved, but wraps at ~50 days
+ * ec_reset_flags: preserved, with 'sysjump' added
+ * ap_resets_since_ec_boot: Not preserved
+ * recent_ap_reset[*]: Not preserved
+ */
+ struct ec_response_uptime_info *r = args->response;
+ timestamp_t now = get_time();
+ uint32_t now_ms = (uint32_t)(now.val / MSEC);
+ enum ec_error_list rc;
+
+ r->time_since_ec_boot_ms = now_ms;
+ r->ec_reset_flags = system_get_reset_flags();
+
+ memset(r->recent_ap_reset, 0, sizeof(r->recent_ap_reset));
+ rc = get_ap_reset_stats(r->recent_ap_reset,
+ ARRAY_SIZE(r->recent_ap_reset),
+ &r->ap_resets_since_ec_boot);
+
+ args->response_size = sizeof(*r);
+ return rc == EC_SUCCESS ? EC_RES_SUCCESS : EC_RES_ERROR;
+}
+DECLARE_HOST_COMMAND(EC_CMD_GET_UPTIME_INFO,
+ host_command_get_uptime_info,
+ EC_VER_MASK(0));
diff --git a/include/chipset.h b/include/chipset.h
index 9b30b7f454..7b684598cb 100644
--- a/include/chipset.h
+++ b/include/chipset.h
@@ -15,7 +15,9 @@
#include "common.h"
#include "compile_time_macros.h"
+#include "ec_commands.h"
#include "gpio.h"
+#include "stddef.h"
/*
* Chipset state mask
@@ -256,10 +258,29 @@ __override_proto enum critical_shutdown board_system_is_idle(
*/
void report_ap_reset(enum chipset_shutdown_reason reason);
+/**
+ * Get statistics about AP resets.
+ *
+ * @param reset_log_entries Pointer to array of log entries.
+ * @param num_reset_log_entries Number of items in reset_log_entries.
+ * @param resets_since_ec_boot Number of AP resets since EC boot.
+ */
+test_mockable enum ec_error_list
+get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
+ size_t num_reset_log_entries,
+ uint32_t *resets_since_ec_boot);
+
#else
static inline void report_ap_reset(enum chipset_shutdown_reason reason) { }
+test_mockable_static_inline enum ec_error_list
+get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
+ size_t num_reset_log_entries, uint32_t *resets_since_ec_boot)
+{
+ return EC_SUCCESS;
+}
+
#endif /* !CONFIG_CMD_AP_RESET_LOG */
#endif /* __CROS_EC_CHIPSET_H */
diff --git a/include/common.h b/include/common.h
index fab97f17b4..37d6db9fb8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -225,10 +225,12 @@ enum ec_error_list {
#ifdef TEST_BUILD
#define test_mockable __attribute__((weak))
#define test_mockable_static __attribute__((weak))
+#define test_mockable_static_inline __attribute__((weak))
#define test_export_static
#else
#define test_mockable
#define test_mockable_static static
+#define test_mockable_static_inline static inline
#define test_export_static static
#endif
diff --git a/include/config.h b/include/config.h
index ff91073ea5..d3547dde72 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2127,6 +2127,9 @@
#define CONFIG_HOSTCMD_LOCATE_CHIP
#endif
+/* Command to get the EC uptime (and optionally AP reset stats) */
+#define CONFIG_HOSTCMD_GET_UPTIME_INFO
+
/* List of host commands whose debug output will be suppressed */
#undef CONFIG_SUPPRESSED_HOST_COMMANDS
diff --git a/test/build.mk b/test/build.mk
index 5868513962..ea0fef7fc1 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -66,6 +66,7 @@ test-list-host += static_if_error
test-list-host += system
test-list-host += thermal
test-list-host += timer_dos
+test-list-host += uptime
test-list-host += usb_pd
test-list-host += usb_pd_giveback
test-list-host += usb_pd_rev30
@@ -140,6 +141,7 @@ system-y=system.o
thermal-y=thermal.o
timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o
+uptime-y=uptime.o
usb_pd-y=usb_pd.o
usb_pd_giveback-y=usb_pd.o
usb_pd_rev30-y=usb_pd.o
diff --git a/test/uptime.c b/test/uptime.c
new file mode 100644
index 0000000000..7ff39f98db
--- /dev/null
+++ b/test/uptime.c
@@ -0,0 +1,73 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <stdbool.h>
+
+#include "common.h"
+#include "ec_commands.h"
+#include "host_command.h"
+#include "test_util.h"
+#include "timer.h"
+#include "util.h"
+
+static bool get_ap_reset_stats_should_succeed = true;
+
+/* Mocks */
+
+enum ec_error_list
+get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
+ size_t num_reset_log_entries, uint32_t *resets_since_ec_boot)
+{
+ return get_ap_reset_stats_should_succeed ? EC_SUCCESS : EC_ERROR_INVAL;
+}
+
+timestamp_t get_time(void)
+{
+ timestamp_t fake_time = { .val = 42 * MSEC };
+ return fake_time;
+}
+
+/* Tests */
+
+test_static int test_host_uptime_info_command_success(void)
+{
+ int rv;
+ struct ec_response_uptime_info resp = { 0 };
+
+ get_ap_reset_stats_should_succeed = true;
+
+ rv = test_send_host_command(EC_CMD_GET_UPTIME_INFO, 0, NULL, 0, &resp,
+ sizeof(resp));
+
+ TEST_ASSERT(rv == EC_RES_SUCCESS);
+ TEST_ASSERT(resp.time_since_ec_boot_ms == 42);
+
+ return EC_RES_SUCCESS;
+}
+
+test_static int test_host_uptime_info_command_failure(void)
+{
+ int rv;
+ struct ec_response_uptime_info resp = { 0 };
+
+ get_ap_reset_stats_should_succeed = false;
+
+ rv = test_send_host_command(EC_CMD_GET_UPTIME_INFO, 0, NULL, 0, &resp,
+ sizeof(resp));
+
+ TEST_ASSERT(rv == EC_RES_ERROR);
+
+ return EC_RES_SUCCESS;
+}
+
+void run_test(void)
+{
+ test_reset();
+
+ RUN_TEST(test_host_uptime_info_command_success);
+ RUN_TEST(test_host_uptime_info_command_failure);
+
+ test_print_result();
+}
diff --git a/test/uptime.tasklist b/test/uptime.tasklist
new file mode 100644
index 0000000000..9bf1c80c20
--- /dev/null
+++ b/test/uptime.tasklist
@@ -0,0 +1,10 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST
+