diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2017-06-13 15:47:23 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-06-15 20:13:51 -0700 |
commit | dcca1de5288660409a78e5682dc2d445450fe1a5 (patch) | |
tree | 8688bccc2f5af293f0977c83607aeb0d418ad296 | |
parent | 94a9cfc02fa2aae6bfde6afc3454bf9089019bdf (diff) | |
download | chrome-ec-dcca1de5288660409a78e5682dc2d445450fe1a5.tar.gz |
g: add a function to report current board ID mismatch status
Until the Board ID check is moved to RO, it is possible to start an RW
with a mismatching Board ID.
Let's add a function to check for mismatch and report the status.
Also eliminating the unnecessary check for empty header Board ID field
- it is going to match any board ID anyways and fixing a CPRINTF
statement in read_board_id().
BRANCH=cr50
BUG=b:35586335
TEST=verified that empty board ID header does not trigger a mismatch
on a board with a non-empty INFO1. With the rest of the patches
applied verified that board ID mismatch is reported properly.
Change-Id: Ie03f8137e494117b7a238e3af72527e0a46369e1
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/535975
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | chip/g/board_id.c | 23 | ||||
-rw-r--r-- | chip/g/board_id.h | 7 |
2 files changed, 23 insertions, 7 deletions
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); |