diff options
author | Namyoon Woo <namyoon@chromium.org> | 2019-02-04 20:17:11 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-07 03:02:21 -0800 |
commit | af216d834e1ec665129d68d8df9256f659371ee8 (patch) | |
tree | b684ad13d2c3427bd98277c62d324d6ff2a7dc7c | |
parent | 9976bf4c2782ce79909723ed67415a8540a04c39 (diff) | |
download | chrome-ec-af216d834e1ec665129d68d8df9256f659371ee8.tar.gz |
cr50/ec: add a console command to display event logs.
'dlog' console command is introduced, which displays event logs on
console. To activate this command, CONFIG_CMD_DLOG should be defined
in board.h.
'dlog clear' clears all event logs.
BUG=b:63760920
BRANCH=cr50
TEST=manually
> help dlog
Usage: dlog [clear]
Display/clear TPM event logs
> tpm_log 1 0xABCD
> tpm_log 2 0x1234
> dlog
TIMESTAMP | TYPE | DATA | SIZE | PAYLOAD
749 1 0xABCD 0
8325 2 0x1234 0
> dlog clear
> dlog
TIMESTAMP | TYPE | DATA | SIZE | PAYLOAD
>
Change-Id: I313beeb2e5ec04c108296cd4c017d938aab24b0d
Signed-off-by: Namyoon Woo <namyoon@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1454136
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r-- | common/event_log.c | 77 | ||||
-rw-r--r-- | common/tpm_registers.c | 2 | ||||
-rw-r--r-- | include/config.h | 1 |
3 files changed, 70 insertions, 10 deletions
diff --git a/common/event_log.c b/common/event_log.c index 8da9c31ceb..994967664c 100644 --- a/common/event_log.c +++ b/common/event_log.c @@ -4,6 +4,7 @@ */ #include "common.h" +#include "console.h" #include "event_log.h" #include "hooks.h" #include "task.h" @@ -12,9 +13,10 @@ /* Event log FIFO */ #define UNIT_SIZE sizeof(struct event_log_entry) -#define LOG_SIZE (CONFIG_EVENT_LOG_SIZE/UNIT_SIZE) -static struct event_log_entry __bss_slow log_events[LOG_SIZE]; -BUILD_ASSERT(POWER_OF_TWO(LOG_SIZE)); +#define UNIT_COUNT (CONFIG_EVENT_LOG_SIZE/UNIT_SIZE) +#define UNIT_COUNT_MASK (UNIT_COUNT - 1) +static struct event_log_entry __bss_slow log_events[UNIT_COUNT]; +BUILD_ASSERT(POWER_OF_TWO(UNIT_COUNT)); /* * The FIFO pointers are defined as following : @@ -58,25 +60,25 @@ void log_add_event(uint8_t type, uint8_t size, uint16_t data, /* --- end of critical section --- */ /* Out of space : discard the oldest entry */ - while ((LOG_SIZE - (current_tail - log_head)) < total_size) { + while ((UNIT_COUNT - (current_tail - log_head)) < total_size) { struct event_log_entry *oldest; /* --- critical section : atomically free-up space --- */ interrupt_disable(); - oldest = log_events + (log_head & (LOG_SIZE - 1)); + oldest = log_events + (log_head & UNIT_COUNT_MASK); log_head += ENTRY_SIZE(EVENT_LOG_SIZE(oldest->size)); interrupt_enable(); /* --- end of critical section --- */ } - r = log_events + (current_tail & (LOG_SIZE - 1)); + r = log_events + (current_tail & UNIT_COUNT_MASK); r->timestamp = timestamp; r->type = type; r->size = size; r->data = data; /* copy the payload into the FIFO */ - first = MIN(total_size - 1, (LOG_SIZE - - (current_tail & (LOG_SIZE - 1))) - 1); + first = MIN(total_size - 1, (UNIT_COUNT - + (current_tail & UNIT_COUNT_MASK)) - 1); if (first) memcpy(r->payload, payload, first * UNIT_SIZE); if (first < total_size - 1) @@ -103,9 +105,9 @@ retry: return UNIT_SIZE; } - entry = log_events + (current_head & (LOG_SIZE - 1)); + entry = log_events + (current_head & UNIT_COUNT_MASK); total_size = ENTRY_SIZE(EVENT_LOG_SIZE(entry->size)); - first = MIN(total_size, LOG_SIZE - (current_head & (LOG_SIZE - 1))); + first = MIN(total_size, UNIT_COUNT - (current_head & UNIT_COUNT_MASK)); memcpy(r, entry, first * UNIT_SIZE); if (first < total_size) memcpy(r + first, log_events, (total_size-first) * UNIT_SIZE); @@ -125,3 +127,58 @@ retry: return total_size * UNIT_SIZE; } + +#ifdef CONFIG_CMD_DLOG +/* + * Display TPM event logs. + */ +static int command_dlog(int argc, char **argv) +{ + size_t log_cur; + const uint8_t * const log_events_end = + (uint8_t *)&log_events[UNIT_COUNT]; + + if (argc > 1) { + if (!strcasecmp(argv[1], "clear")) { + interrupt_disable(); + log_head = log_tail = log_tail_next = 0; + interrupt_enable(); + + return EC_SUCCESS; + } + /* Too many parameters */ + return EC_ERROR_PARAM1; + } + + ccprintf(" TIMESTAMP | TYPE | DATA | SIZE | PAYLOAD\n"); + log_cur = log_head; + while (log_cur != log_tail) { + struct event_log_entry *r; + uint8_t *payload; + uint32_t payload_bytes; + + r = &log_events[log_cur & UNIT_COUNT_MASK]; + payload_bytes = EVENT_LOG_SIZE(r->size); + log_cur += ENTRY_SIZE(payload_bytes); + + ccprintf("%10d %4d 0x%04X %4d ", r->timestamp, r->type, + r->data, payload_bytes); + + /* display payload if exists */ + payload = r->payload; + while (payload_bytes--) { + if (payload >= log_events_end) + payload = (uint8_t *)&log_events[0]; + + ccprintf("%02X", *payload); + payload++; + } + ccprintf("\n"); + } + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(dlog, + command_dlog, + "[clear]", + "Display/clear TPM event logs"); +#endif diff --git a/common/tpm_registers.c b/common/tpm_registers.c index 74fff76082..397d067742 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -764,9 +764,11 @@ int tpm_reset_request(int wait_until_done, int wipe_nvmem_first) return EC_ERROR_BUSY; } +#ifdef CONFIG_TPM_LOGGING /* Record input parameters as two bits in the data field. */ tpm_log_event(TPM_EVENT_INIT, (!!wait_until_done << 1) | !!wipe_nvmem_first); +#endif reset_in_progress = 1; wipe_result = EC_SUCCESS; diff --git a/include/config.h b/include/config.h index 8e54df3253..f2cb596069 100644 --- a/include/config.h +++ b/include/config.h @@ -989,6 +989,7 @@ #undef CONFIG_CMD_COMXTEST #define CONFIG_CMD_CRASH #define CONFIG_CMD_DEVICE_EVENT +#undef CONFIG_CMD_DLOG #undef CONFIG_CMD_ECTEMP #define CONFIG_CMD_FASTCHARGE #undef CONFIG_CMD_FLASH |