From 57aa1891be676b51fb43045a664f476d676948f1 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Mon, 13 May 2019 11:22:44 -0700 Subject: flash_log: add vendor command, timestamp base accessor The new vendor command allows to get and increase the flash log timestamp base. BRANCH=cr50, cr50-mp BUG=b:132287488 TEST=verified in the next patch in the series. Change-Id: Idc76012b7e7894b95cd70eeffeb50562a91b9656 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/1610720 Legacy-Commit-Queue: Commit Bot Reviewed-by: Andrey Pronin Reviewed-by: Namyoon Woo --- common/flash_log_vc.c | 36 +++++++++++++++++++++++++++++++++++- include/tpm_vendor_cmds.h | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/common/flash_log_vc.c b/common/flash_log_vc.c index 6f2ec6dd67..8ed85a57d4 100644 --- a/common/flash_log_vc.c +++ b/common/flash_log_vc.c @@ -5,6 +5,7 @@ #include "console.h" #include "extension.h" +#include "endian.h" #include "flash_log.h" #include "util.h" @@ -17,7 +18,7 @@ static enum vendor_cmd_rc vc_pop_log_entry(enum vendor_cmd_cc code, void *buf, *response_size = 0; /* In case there is an error. */ - if (input_size != sizeof(uint32_t)) + if (input_size != sizeof(prev_timestamp)) return VENDOR_RC_BOGUS_ARGS; memcpy(&prev_timestamp, buf, sizeof(prev_timestamp)); @@ -38,3 +39,36 @@ static enum vendor_cmd_rc vc_pop_log_entry(enum vendor_cmd_cc code, void *buf, return VENDOR_RC_ERR; } DECLARE_VENDOR_COMMAND(VENDOR_CC_POP_LOG_ENTRY, vc_pop_log_entry); + +static enum vendor_cmd_rc vc_flog_tstamp(enum vendor_cmd_cc code, void *buf, + size_t input_size, + size_t *response_size) +{ + uint32_t tstamp; + enum ec_error_list rv; + + if (!input_size) { + /* This is a request to report current flash log time. */ + tstamp = htobe32(flash_log_get_tstamp()); + memcpy(buf, &tstamp, sizeof(tstamp)); + *response_size = sizeof(tstamp); + return VENDOR_RC_SUCCESS; + } + + if (input_size != sizeof(tstamp)) + return VENDOR_RC_BOGUS_ARGS; + + memcpy(&tstamp, buf, sizeof(tstamp)); + tstamp = be32toh(tstamp); + rv = flash_log_set_tstamp(tstamp); + + if (rv == EC_SUCCESS) { + *response_size = 0; + return VENDOR_RC_SUCCESS; + } + + *response_size = 1; + *((uint8_t *)buf) = (uint8_t)rv; + return VENDOR_RC_BOGUS_ARGS; +} +DECLARE_VENDOR_COMMAND(VENDOR_CC_FLOG_TIMESTAMP, vc_flog_tstamp); diff --git a/include/tpm_vendor_cmds.h b/include/tpm_vendor_cmds.h index 62db64e82a..0e17d9d53b 100644 --- a/include/tpm_vendor_cmds.h +++ b/include/tpm_vendor_cmds.h @@ -131,6 +131,8 @@ enum vendor_cmd_cc { VENDOR_CC_U2F_SIGN = 45, VENDOR_CC_U2F_ATTEST = 46, + VENDOR_CC_FLOG_TIMESTAMP = 47, + LAST_VENDOR_COMMAND = 65535, }; -- cgit v1.2.1