diff options
-rw-r--r-- | chip/g/board_id.c | 34 | ||||
-rw-r--r-- | chip/g/board_id.h | 6 |
2 files changed, 28 insertions, 12 deletions
diff --git a/chip/g/board_id.c b/chip/g/board_id.c index 2a412d97e7..15a8f54376 100644 --- a/chip/g/board_id.c +++ b/chip/g/board_id.c @@ -14,6 +14,8 @@ #define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) #define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) +#define BLANK_FIELD 0xffffffff + /** * Return the image header for the current image copy */ @@ -23,9 +25,19 @@ const struct SignedHeader *get_current_image_header(void) get_program_memory_addr(system_get_image_copy()); } +static int board_id_type_is_blank(const struct board_id *id) +{ + return (id->type & id->type_inv) == BLANK_FIELD; +} + +static int board_id_flags_are_blank(const struct board_id *id) +{ + return id->flags == BLANK_FIELD; +} + int board_id_is_blank(const struct board_id *id) { - return ~(id->type & id->type_inv & id->flags) == 0; + return board_id_type_is_blank(id) && board_id_flags_are_blank(id); } uint32_t check_board_id_vs_header(const struct board_id *id, @@ -45,20 +57,20 @@ uint32_t check_board_id_vs_header(const struct board_id *id, header_board_id_flags = SIGNED_HEADER_PADDING ^ h->board_id_flags; /* - * Masked bits in header Board ID type must match type and inverse from - * flash. - */ - mismatch = header_board_id_type ^ id->type; - mismatch |= header_board_id_type ^ ~id->type_inv; - mismatch &= header_board_id_mask; - - /* * All 1-bits in header Board ID flags must be present in flags from * flash */ - mismatch |= + mismatch = ((header_board_id_flags & id->flags) != header_board_id_flags); - + /* + * Masked bits in header Board ID type must match type and inverse from + * flash. + */ + if (!mismatch && !board_id_type_is_blank(id)) { + mismatch = header_board_id_type ^ id->type; + mismatch |= header_board_id_type ^ ~id->type_inv; + mismatch &= header_board_id_mask; + } return mismatch; } diff --git a/chip/g/board_id.h b/chip/g/board_id.h index 2c000000dc..f06f23190b 100644 --- a/chip/g/board_id.h +++ b/chip/g/board_id.h @@ -41,7 +41,11 @@ const struct SignedHeader *get_current_image_header(void); * Check if board ID in the image matches board ID field in the INFO1. * * Pass the pointer to the image header to check. If the pointer is set to - * NULL, check board ID against the currently running image's header. + * NULL, check board ID against the currently running image's header. All 1 + * bits in header Board ID flags must be present in the board id from flash. + * + * If the board id from flash is blank, board_id_type field from the header is + * ignored and only board_if_flags field is verified to match. * * Return true if there is a mismatch (the code should not run). */ |