From b4ab5c7e02e39a69bf10f40318198b5d5462bd4a Mon Sep 17 00:00:00 2001 From: Mary Ruthven Date: Fri, 14 Jan 2022 09:30:20 -0600 Subject: brdprop: log invalid and ambiguous events Log brdprop errors in flog, so the team can track brdprop errors from the AP without grepping through cr50 logs. BUG=b:214550629 TEST=flash on red board. Verify invalid strap events are logged. enable closed-loop-reset on the red board. Verify "ambiguous" strap logs are ignored. Change-Id: Ibea73fb19119fa81ed3652c5d68e430cdbae9fa5 Signed-off-by: Mary Ruthven Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3386405 Reviewed-by: Vadim Bendebury Commit-Queue: Vadim Bendebury --- board/cr50/board.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ common/flash_log.c | 2 +- include/flash_log.h | 22 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/board/cr50/board.c b/board/cr50/board.c index 3cf0156c26..cfe2d9a4d7 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -828,6 +828,46 @@ static void maybe_trigger_ite_sync(void) generate_ite_sync(); } +/* + * Save the logged events, the system reset flags, and the config for the + * event in flog. + */ +static struct brdprop_payload bp_flog; + +/* Each event can be logged once per boot. */ +static void flog_brdprop_event(enum brdprop_ev event, uint8_t config) +{ + if (event >= BRDPROP_COUNT) { + CPRINTS("%s: invalid event %d", __func__, event); + return; + } + bp_flog.events |= (1 << event); + bp_flog.configs[event] = config; +} + +/* + * The flog isn't initialized when board properties are calculated. Save the + * information in flog once it's ready. + */ +static void process_brdprop_flog(void) +{ + if (!bp_flog.events) + return; + /* + * Boards with closed loop reset are going to have ambiguous straps + * after reboot. Don't log those errors. Only log invalid strap errors + * on those boards. + * Filter these here, because cr50 doesn't know the board properties + * when it's initially logging the errors. + */ + if (board_uses_closed_loop_reset() && + bp_flog.events == (1 << BRDPROP_AMBIGUOUS)) + return; + + bp_flog.reset_flags = system_get_reset_flags(); + flash_log_add_event(FE_LOG_BRDPROP, sizeof(bp_flog), &bp_flog); +} + static void process_board_cfg(void) { uint32_t tpm_board_cfg = board_cfg_reg_read(); @@ -874,6 +914,9 @@ static void board_init(void) */ if (system_get_reset_flags() & EC_RESET_FLAG_HIBERNATE) system_decrement_retry_counter(); + + process_brdprop_flog(); + configure_board_specific_gpios(); init_pmu(); reset_wake_logic(); @@ -1519,6 +1562,7 @@ static int get_strap_config(uint8_t *config) * unused config pins the AP is interfering with. */ if (use_i2c && use_spi) { + flog_brdprop_event(BRDPROP_AMBIGUOUS, *config); spi_prop = (GREG32(PMU, LONG_LIFE_SCRATCH1) & BOARD_PERIPH_CONFIG_SPI); i2c_prop = (GREG32(PMU, LONG_LIFE_SCRATCH1) & @@ -1544,6 +1588,7 @@ static uint32_t get_properties(void) uint32_t properties; if (get_strap_config(&config) != EC_SUCCESS) { + flog_brdprop_event(BRDPROP_INVALID, config); #ifdef H1_RED_BOARD CPRINTS("Unconditionally enabling SPI and platform reset"); return (BOARD_PERIPH_CONFIG_SPI | BOARD_USE_PLT_RESET); @@ -1586,6 +1631,7 @@ static uint32_t get_properties(void) /* All I2C boards use same default properties. */ properties = BOARD_PROPERTIES_DEFAULT; } + flog_brdprop_event(BRDPROP_NO_ENTRY, config); CPRINTS("strap_cfg 0x%x has no table entry, prop = 0x%x", config, properties); return properties; diff --git a/common/flash_log.c b/common/flash_log.c index 798f48a2a6..927c7ac3f7 100644 --- a/common/flash_log.c +++ b/common/flash_log.c @@ -486,7 +486,7 @@ test_export_static void flash_log_init(void) } flash_log_write_disable(); } -DECLARE_HOOK(HOOK_INIT, flash_log_init, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_INIT, flash_log_init, HOOK_PRIO_INIT_CR50_BOARD - 1); uint32_t flash_log_get_tstamp(void) { diff --git a/include/flash_log.h b/include/flash_log.h index cc6c292d49..30bd326712 100644 --- a/include/flash_log.h +++ b/include/flash_log.h @@ -25,6 +25,7 @@ enum flash_event_type { FE_LOG_FIPS_FAILURE = 10, /* Error during continuous and/or known-answer * tests for FIPS 140-2/3 */ + FE_LOG_BRDPROP = 11, /* Detected invalid board properties */ /* * Fixed padding value makes it easier to parse log space * snapshots. @@ -106,6 +107,27 @@ struct ap_ro_entry_payload { enum ap_ro_verification_ev event : 8; } __packed; +/*****************************************************************************/ +/* Brdprop Events */ +/* Each event can only be logged once per boot. */ +enum brdprop_ev { + BRDPROP_INVALID = 0, + BRDPROP_AMBIGUOUS = 1, + BRDPROP_NO_ENTRY = 2, + + /* + * If BRDPROP_COUNT goes above 8, increase the size of events in + * brdprop_payload. + */ + BRDPROP_COUNT = 3, +}; + +struct brdprop_payload { + uint8_t events; + uint32_t reset_flags; + uint8_t configs[BRDPROP_COUNT]; +} __packed; + /* Returned in the "type" field, when there is no entry available */ #define FLASH_LOG_NO_ENTRY 0xff #define MAX_FLASH_LOG_PAYLOAD_SIZE ((1 << 6) - 1) -- cgit v1.2.1