diff options
author | Mary Ruthven <mruthven@chromium.org> | 2019-10-30 16:19:57 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-07 22:52:10 +0000 |
commit | 69fef6d57b29e74839885b20b1f83f1a925f8104 (patch) | |
tree | a13b1796be43225eb774b7eed384dea72f1fbe79 /chip/g/board_id.c | |
parent | 68ccda60a1ed696d94586d88d209402e4be39c31 (diff) | |
download | chrome-ec-69fef6d57b29e74839885b20b1f83f1a925f8104.tar.gz |
board_id: ignore erased bid type when checking headers
We will be able to set the board id flags without setting the type. If
only flags are set, then check the flags. If the type is set, also check
the type.
BUG=b:143649068
BRANCH=cr50
TEST=set flags to 0x3f80. Try to update to a ZZAF:0:0:0 image. Make
sure it isn't rejected with board id type mismatch. Try to update to a
prepvt image. Make sure it's rejected.
Change-Id: Ie0efdd7b1b6d76f385688f75c0765c08cab3755c
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1892117
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'chip/g/board_id.c')
-rw-r--r-- | chip/g/board_id.c | 34 |
1 files changed, 23 insertions, 11 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; } |