From ca3f517b0b27e2be1e3d21cecd9958e2e5263512 Mon Sep 17 00:00:00 2001 From: Mary Ruthven Date: Tue, 19 Mar 2019 13:20:05 -0700 Subject: g: add board_id_is_blank Add board_id_is_blank for checking that all fields of a board id are 0xffffffff. BUG=none BRANCH=cr50 TEST=none Change-Id: I591a3529a7f5a2aa4fcd4a7e0ec43356d0e97237 Signed-off-by: Mary Ruthven Reviewed-on: https://chromium-review.googlesource.com/1531321 Commit-Ready: Mary Ruthven Tested-by: Mary Ruthven Reviewed-by: Mary Ruthven --- chip/g/board_id.c | 11 ++++++++--- chip/g/board_id.h | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'chip/g') diff --git a/chip/g/board_id.c b/chip/g/board_id.c index 1c74184103..18b7be1ffb 100644 --- a/chip/g/board_id.c +++ b/chip/g/board_id.c @@ -23,6 +23,11 @@ const struct SignedHeader *get_current_image_header(void) get_program_memory_addr(system_get_image_copy()); } +int board_id_is_blank(const struct board_id *id) +{ + return ~(id->type & id->type_inv & id->flags) == 0; +} + uint32_t check_board_id_vs_header(const struct board_id *id, const struct SignedHeader *h) { @@ -32,7 +37,7 @@ uint32_t check_board_id_vs_header(const struct board_id *id, uint32_t header_board_id_flags; /* Blank Board ID matches all headers */ - if (~(id->type & id->type_inv & id->flags) == 0) + if (board_id_is_blank(id)) return 0; header_board_id_type = SIGNED_HEADER_PADDING ^ h->board_id_type; @@ -146,7 +151,7 @@ static int write_board_id(const struct board_id *id) return rv; } - if (~(id_test.type & id_test.type_inv & id_test.flags) != 0) { + if (!board_id_is_blank(&id_test)) { CPRINTS("%s: Board ID already programmed", __func__); return EC_ERROR_ACCESS_DENIED; } @@ -216,7 +221,7 @@ static int command_board_id(int argc, char **argv) } ccprintf("Board ID: %08x, flags %08x\n", id.type, id.flags); - if ((~id.type | ~id.type_inv | ~id.flags) == 0) + if (board_id_is_blank(&id)) return rv; /* The space is not initialized. */ if (id.type != ~id.type_inv) diff --git a/chip/g/board_id.h b/chip/g/board_id.h index 5fc8af46ba..2c000000dc 100644 --- a/chip/g/board_id.h +++ b/chip/g/board_id.h @@ -47,4 +47,12 @@ const struct SignedHeader *get_current_image_header(void); */ uint32_t board_id_mismatch(const struct SignedHeader *h); +/** + * Check if every field of the board id is 0xffffffff + * + * @param id Pointer to a Board ID structure + * + * @return True if the board id is all 0xffffffff. + */ +int board_id_is_blank(const struct board_id *id); #endif /* ! __EC_CHIP_G_BOARD_ID_H */ -- cgit v1.2.1