summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@google.com>2019-03-19 13:20:05 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-20 19:51:16 -0700
commitca3f517b0b27e2be1e3d21cecd9958e2e5263512 (patch)
tree8c738a0792936fec4318bf49b0a7e89eb0fec239
parent1d95cefbce43059d2ff74f8ad3ad01ff7c06b50f (diff)
downloadchrome-ec-ca3f517b0b27e2be1e3d21cecd9958e2e5263512.tar.gz
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 <mruthven@google.com> Reviewed-on: https://chromium-review.googlesource.com/1531321 Commit-Ready: Mary Ruthven <mruthven@chromium.org> Tested-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--board/cr50/factory_mode.c3
-rw-r--r--chip/g/board_id.c11
-rw-r--r--chip/g/board_id.h8
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 */