diff options
-rw-r--r-- | board/cr50/factory_mode.c | 3 | ||||
-rw-r--r-- | chip/g/board_id.c | 11 | ||||
-rw-r--r-- | chip/g/board_id.h | 8 |
3 files changed, 17 insertions, 5 deletions
diff --git a/board/cr50/factory_mode.c b/board/cr50/factory_mode.c index 6e07fe00f5..a645fd5aed 100644 --- a/board/cr50/factory_mode.c +++ b/board/cr50/factory_mode.c @@ -25,8 +25,7 @@ static int board_id_is_erased(void) return 0; } - /* If all of the fields are all 0xffffffff, the board id is not set */ - if (~(id.type & id.type_inv & id.flags) == 0) { + if (board_id_is_blank(&id)) { CPRINTS("BID erased"); return 1; } 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 */ |