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>
This commit is contained in:
Vadim Bendebury
2017-06-13 15:47:23 -07:00
committed by chrome-bot
parent 94a9cfc02f
commit dcca1de528
2 changed files with 23 additions and 7 deletions

View File

@@ -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.
*

View File

@@ -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);