summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2019-10-30 16:19:57 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-07 22:52:10 +0000
commit69fef6d57b29e74839885b20b1f83f1a925f8104 (patch)
treea13b1796be43225eb774b7eed384dea72f1fbe79
parent68ccda60a1ed696d94586d88d209402e4be39c31 (diff)
downloadchrome-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>
-rw-r--r--chip/g/board_id.c34
-rw-r--r--chip/g/board_id.h6
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).
*/