diff --git a/chip/g/board_id.c b/chip/g/board_id.c index fb3fb8755e..85b84c63ed 100644 --- a/chip/g/board_id.c +++ b/chip/g/board_id.c @@ -39,12 +39,6 @@ uint32_t check_board_id_vs_header(const struct board_id *id, header_board_id_mask = SIGNED_HEADER_PADDING ^ h->board_id_type_mask; header_board_id_flags = SIGNED_HEADER_PADDING ^ h->board_id_flags; - /* Blank header means this is a common image, can run on any device. */ - if ((header_board_id_type | - header_board_id_mask | - header_board_id_flags) == 0) - return 0; - /* * Masked bits in header Board ID type must match type and inverse from * flash. @@ -92,7 +86,7 @@ int read_board_id(struct board_id *id) id_p); if (rv != EC_SUCCESS) { CPRINTF("%s: failed to read word %d, error %d\n", - i, rv); + __func__, i, rv); return rv; } id_p++; @@ -100,6 +94,21 @@ int read_board_id(struct board_id *id) return EC_SUCCESS; } +uint32_t board_id_mismatch(void) +{ + struct board_id id; + const struct SignedHeader *sh; + + /* Get header of the currently running image. */ + sh = get_current_image_header(); + + /* Get Board ID from INFO1. */ + if (read_board_id(&id) != EC_SUCCESS) + return 1; + + return check_board_id_vs_header(&id, sh); +} + /** * Write board ID into the flash INFO1 space. * diff --git a/chip/g/board_id.h b/chip/g/board_id.h index 2599060d79..90633fa309 100644 --- a/chip/g/board_id.h +++ b/chip/g/board_id.h @@ -46,6 +46,13 @@ uint32_t check_board_id_vs_header(const struct board_id *id, */ int read_board_id(struct board_id *id); +/** + * Check if board ID in the current image matches board ID field in the INFO1. + * + * Return true if there is a mismatch (the code should not run). + */ +uint32_t board_id_mismatch(void); + BUILD_ASSERT((offsetof(struct info1_board_space, bid) & 3) == 0); BUILD_ASSERT((INFO_BOARD_ID_SIZE & 3) == 0); BUILD_ASSERT(sizeof(struct info1_board_space) <= INFO_BOARD_SPACE_PROTECT_SIZE);