summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2019-03-14 11:25:09 -0700
committerVadim Bendebury <vbendeb@chromium.org>2019-09-21 19:11:19 -0700
commit707875dd8ff424ffbc09266bff5484ed75047ad6 (patch)
tree37e7bf43a71cc15cbc47e08fd726864bb5052e4a
parent586e5e86f3aedfa506c00ad4200a40115074385e (diff)
downloadchrome-ec-707875dd8ff424ffbc09266bff5484ed75047ad6.tar.gz
cr50: add vendor command for retrieving flash elog (take two)
We want to be able to retrieve flash log contents using the vendor command channel. The input parameter of the command is the timestamp of the last retrieved log event, or zero of the AP wants to start over. The response is the next entry after the one requested by the AP, or an empty message if there are no newer log messages. BRANCH=cr50, cr50-mp BUG=b:63760920 TEST=with the upcoming gsctools changes observed the ability to retrieve flash log messages. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1525146 Reviewed-by: Namyoon Woo <namyoon@chromium.org> (cherry picked from commit 705595bb681f362a5e34fb377d21fa8bfa605f9d) Change-Id: I18bd6ec60930c0b05b71322352b0fd343d0bcdc7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1644045 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit bf5efbd2b40e9eb27aaf8a1e1524afeca0ee75b8) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1705366 (cherry picked from commit e48557edd01266038422748190ba59551c18b012)
-rw-r--r--common/build.mk3
-rw-r--r--common/flash_log_vc.c40
-rw-r--r--common/tpm_log.c79
-rw-r--r--include/config.h3
-rw-r--r--include/tpm_log.h19
-rw-r--r--include/tpm_vendor_cmds.h41
6 files changed, 65 insertions, 120 deletions
diff --git a/common/build.mk b/common/build.mk
index 8a81f8cf52..958099dd3b 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -56,7 +56,7 @@ common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o
common-$(CONFIG_FANS)+=fan.o pwm.o
common-$(CONFIG_FACTORY_MODE)+=factory_mode.o
common-$(CONFIG_FLASH)+=flash.o
-common-$(CONFIG_FLASH_LOG)+=flash_log.o
+common-$(CONFIG_FLASH_LOG)+=flash_log.o flash_log_vc.o
common-$(CONFIG_FLASH_NVCOUNTER)+=nvcounter.o
common-$(CONFIG_FLASH_NVMEM)+=nvmem.o
common-$(CONFIG_FLASH_NVMEM_VARS)+=nvmem_vars.o
@@ -106,7 +106,6 @@ common-$(CONFIG_TABLET_MODE)+=tablet_mode.o
common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
common-$(CONFIG_THROTTLE_AP)+=thermal.o throttle_ap.o
common-$(CONFIG_TPM_I2CS)+=i2cs_tpm.o
-common-$(CONFIG_TPM_LOGGING)+=event_log.o tpm_log.o
common-$(CONFIG_U2F)+=u2f.o
common-$(CONFIG_USB_I2C)+=usb_i2c.o
common-$(CONFIG_USB_CHARGER)+=usb_charger.o
diff --git a/common/flash_log_vc.c b/common/flash_log_vc.c
new file mode 100644
index 0000000000..6f2ec6dd67
--- /dev/null
+++ b/common/flash_log_vc.c
@@ -0,0 +1,40 @@
+/* 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 "console.h"
+#include "extension.h"
+#include "flash_log.h"
+#include "util.h"
+
+static enum vendor_cmd_rc vc_pop_log_entry(enum vendor_cmd_cc code, void *buf,
+ size_t input_size,
+ size_t *response_size)
+{
+ uint32_t prev_timestamp;
+ int byte_size;
+
+ *response_size = 0; /* In case there is an error. */
+
+ if (input_size != sizeof(uint32_t))
+ return VENDOR_RC_BOGUS_ARGS;
+
+ memcpy(&prev_timestamp, buf, sizeof(prev_timestamp));
+
+ byte_size = flash_log_dequeue_event(
+ prev_timestamp, buf,
+ FLASH_LOG_ENTRY_SIZE(MAX_FLASH_LOG_PAYLOAD_SIZE));
+
+ if (byte_size >= 0) {
+ *response_size = byte_size;
+ return VENDOR_RC_SUCCESS;
+ }
+
+ /* Negative value should fit into a byte. */
+ *response_size = 1;
+ ((uint8_t *)buf)[0] = -byte_size;
+
+ return VENDOR_RC_ERR;
+}
+DECLARE_VENDOR_COMMAND(VENDOR_CC_POP_LOG_ENTRY, vc_pop_log_entry);
diff --git a/common/tpm_log.c b/common/tpm_log.c
deleted file mode 100644
index 0dd98740eb..0000000000
--- a/common/tpm_log.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Copyright 2017 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 "console.h"
-#include "endian.h"
-#include "extension.h"
-#include "host_command.h"
-#include "timer.h"
-#include "tpm_log.h"
-#include "tpm_vendor_cmds.h"
-#include "usb_pd.h"
-#include "util.h"
-
-/*
- * TPM event logging uses the standard 'event_log_entry' as its storage,
- * with no additional payload bytes.
- */
-#define TPM_EVENT_LOG_SIZE sizeof(struct event_log_entry)
-
-void tpm_log_event(enum tpm_event type, uint16_t data)
-{
- uint32_t timestamp = get_time().val >> EVENT_LOG_TIMESTAMP_SHIFT;
-
- log_add_event(type, 0, data, NULL, timestamp);
-}
-
-static enum vendor_cmd_rc vc_pop_log_entry(enum vendor_cmd_cc code,
- void *buf,
- size_t input_size,
- size_t *response_size)
-{
- struct event_log_entry *entry = buf;
- int byte_size = log_dequeue_event(entry);
-
- if (entry->type == EVENT_LOG_NO_ENTRY) {
- *response_size = 0;
- return VENDOR_RC_SUCCESS;
- }
- if (byte_size != TPM_EVENT_LOG_SIZE)
- return VENDOR_RC_INTERNAL_ERROR;
-
- entry->timestamp = htobe32(entry->timestamp);
- entry->data = htobe16(entry->data);
- *response_size = byte_size;
-
- return VENDOR_RC_SUCCESS;
-}
-DECLARE_VENDOR_COMMAND(VENDOR_CC_POP_LOG_ENTRY, vc_pop_log_entry);
-
-#ifdef CONFIG_CMD_TPM_LOG
-/* Store an entry in the TPM event log, for testing. */
-int command_tpm_log(int argc, char **argv)
-{
- enum tpm_event type = 0;
- uint16_t data = 0;
- char *e;
-
- if (argc >= 2) {
- type = strtoi(argv[1], &e, 10);
- if (*e)
- return EC_ERROR_PARAM1;
- }
-
- if (argc >= 3) {
- data = strtoi(argv[2], &e, 10);
- if (*e)
- return EC_ERROR_PARAM2;
- }
-
- tpm_log_event(type, data);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(tpm_log,
- command_tpm_log,
- "<type> <data>",
- "Write an entry to TPM log");
-#endif /* CONFIG_CMD_TPM_LOG */
diff --git a/include/config.h b/include/config.h
index 5c104287d7..b0d4e1ba47 100644
--- a/include/config.h
+++ b/include/config.h
@@ -760,7 +760,6 @@
#undef CONFIG_CMD_TASKREADY
#define CONFIG_CMD_TEMP_SENSOR
#define CONFIG_CMD_TIMERINFO
-#undef CONFIG_CMD_TPM_LOG
#define CONFIG_CMD_TYPEC
#undef CONFIG_CMD_USART_INFO
#define CONFIG_CMD_USBMUX
@@ -2352,8 +2351,6 @@
#undef CONFIG_TPM_SPS
/* Speak to the TPM 2.0 hardware protocol on the I2C slave interface */
#undef CONFIG_TPM_I2CS
-/* Record TPM events in circular buffer */
-#undef CONFIG_TPM_LOGGING
/*****************************************************************************/
/* USART stream config */
diff --git a/include/tpm_log.h b/include/tpm_log.h
deleted file mode 100644
index cb1b6e099a..0000000000
--- a/include/tpm_log.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright 2017 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.
- */
-
-#ifndef __CROS_EC_TPM_LOG_H
-#define __CROS_EC_TPM_LOG_H
-
-#include "event_log.h"
-
-enum tpm_event {
- TPM_EVENT_INIT,
- TPM_I2C_RESET,
-};
-
-/* Log TPM event of given type with data payload. */
-void tpm_log_event(enum tpm_event type, uint16_t data);
-
-#endif /* __CROS_EC_TPM_LOG_H */
diff --git a/include/tpm_vendor_cmds.h b/include/tpm_vendor_cmds.h
index 9c344d6f55..62db64e82a 100644
--- a/include/tpm_vendor_cmds.h
+++ b/include/tpm_vendor_cmds.h
@@ -134,7 +134,22 @@ enum vendor_cmd_cc {
LAST_VENDOR_COMMAND = 65535,
};
-/* Error codes reported by extension and vendor commands. */
+/*
+ * Error codes reported by extension and vendor commands.
+ *
+ * As defined by the TPM2 spec, the TPM response code is all zero for success,
+ * and errors are a little complicated:
+ *
+ * Bits 31:12 must be zero.
+ *
+ * Bit 11 S=0 Error
+ * Bit 10 T=1 Vendor defined response code
+ * Bit 9 r=0 reserved
+ * Bit 8 V=1 Conforms to TPMv2 spec
+ * Bit 7 F=0 Confirms to Table 14, Format-Zero Response Codes
+ * Bits 6:0 num 128 possible failure reasons
+ */
+
enum vendor_cmd_rc {
/* EXTENSION_HASH error codes */
/* Attempt to start a session on an active handle. */
@@ -156,8 +171,15 @@ enum vendor_cmd_rc {
VENDOR_RC_IN_PROGRESS = 9,
VENDOR_RC_PASSWORD_REQUIRED = 10,
- /* Only 7 bits available; max is 127 */
+ /* Maximum possible failure reason. */
VENDOR_RC_NO_SUCH_COMMAND = 127,
+
+ /*
+ * Bits 10 and 8 set, this is to be ORed with the rest of the error
+ * values to make the combined value compliant with the spec
+ * requirements.
+ */
+ VENDOR_RC_ERR = 0x500,
};
/*
@@ -172,21 +194,6 @@ enum vendor_cmd_rc {
/* Our vendor-specific command codes go here */
#define TPM_CC_VENDOR_CR50 0x0000
-/*
- * The TPM response code is all zero for success.
- * Errors are a little complicated:
- *
- * Bits 31:12 must be zero.
- *
- * Bit 11 S=0 Error
- * Bit 10 T=1 Vendor defined response code
- * Bit 9 r=0 reserved
- * Bit 8 V=1 Conforms to TPMv2 spec
- * Bit 7 F=0 Confirms to Table 14, Format-Zero Response Codes
- * Bits 6:0 num 128 possible failure reasons
- */
-#define VENDOR_RC_ERR 0x00000500
-
/*** Structures and constants for VENDOR_CC_SPI_HASH ***/
enum vendor_cc_spi_hash_request_subcmd {