summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-03-06 18:23:17 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-03-09 03:24:01 -0800
commit855ac132242cab78197463bdd7d11fa57c108d9a (patch)
treed2730f62f2ea9b7886fe2cab8f5f39ffdea991c5
parent3c16e87eb4703d3eb029526965bb59d3ada9794d (diff)
downloadchrome-ec-855ac132242cab78197463bdd7d11fa57c108d9a.tar.gz
cr50: add rollback information to the sysinfo command output
With enabling INFO1 map based rollback protection it is important to be able to tell the state of the flash map and the currently installed images' infomap header field. The new function counts number of zero words in the info map and zero bits in both RW headers, and returns them in a string printed out by the sysinfo command. BRANCH=cr50 BUG=b:35774863 TEST=built images with different manifest info field contents and verified that the string printed by the sysinfo command makes sense. Change-Id: If633a6c678dc34197b2dad116b6180b2d549e089 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/450905 Reviewed-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--board/cr50/board.c4
-rw-r--r--chip/g/system.c40
-rw-r--r--chip/g/system_chip.h11
3 files changed, 55 insertions, 0 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c
index 8faf81bb55..ade07be2a5 100644
--- a/board/cr50/board.c
+++ b/board/cr50/board.c
@@ -1293,6 +1293,7 @@ static int command_sysinfo(int argc, char **argv)
uintptr_t vaddr;
const struct SignedHeader *h;
int reset_count = GREG32(PMU, LONG_LIFE_SCRATCH0);
+ char rollback_str[15];
ccprintf("Reset flags: 0x%08x (", system_get_reset_flags());
system_print_reset_flags();
@@ -1317,6 +1318,9 @@ static int command_sysinfo(int argc, char **argv)
ccprintf("DEV_ID: 0x%08x 0x%08x\n",
GREG32(FUSE, DEV_ID0), GREG32(FUSE, DEV_ID1));
+ system_get_rollback_bits(rollback_str, sizeof(rollback_str));
+ ccprintf("Rollback: %s\n", rollback_str);
+
return EC_SUCCESS;
}
DECLARE_SAFE_CONSOLE_COMMAND(sysinfo, command_sysinfo,
diff --git a/chip/g/system.c b/chip/g/system.c
index c9dc325688..e92899a58c 100644
--- a/chip/g/system.c
+++ b/chip/g/system.c
@@ -621,3 +621,43 @@ void system_update_rollback_mask(void)
ccprintf("updated %d info map words\n", updated_words_count);
#endif /* CR50_DEV ^^^^^^^^ NOT defined. */
}
+
+void system_get_rollback_bits(char *value, size_t value_size)
+{
+ int info_count;
+ int i;
+ struct {
+ int count;
+ const struct SignedHeader *h;
+ } headers[] = {
+ {.h = (const struct SignedHeader *)
+ get_program_memory_addr(SYSTEM_IMAGE_RW)},
+
+ {.h = (const struct SignedHeader *)
+ get_program_memory_addr(SYSTEM_IMAGE_RW_B)},
+ };
+
+ flash_info_read_enable(INFO_RW_MAP_OFFSET, INFO_RW_MAP_SIZE);
+ for (i = 0; i < INFO_MAX; i++) {
+ uint32_t w;
+
+ flash_physical_info_read_word(INFO_RW_MAP_OFFSET +
+ i * sizeof(uint32_t),
+ &w);
+ if (w)
+ break;
+ }
+ info_count = i;
+
+ for (i = 0; i < ARRAY_SIZE(headers); i++) {
+ int j;
+
+ for (j = 0; j < INFO_MAX; j++)
+ if (headers[i].h->infomap[j/32] & (1 << (j%32)))
+ break;
+ headers[i].count = j;
+ }
+
+ snprintf(value, value_size, "%d/%d/%d", info_count,
+ headers[0].count, headers[1].count);
+}
diff --git a/chip/g/system_chip.h b/chip/g/system_chip.h
index 4d6b3ec7c9..251c2d3007 100644
--- a/chip/g/system_chip.h
+++ b/chip/g/system_chip.h
@@ -57,4 +57,15 @@ int system_battery_cutoff_support_required(void);
*/
void system_update_rollback_mask(void);
+/*
+ **
+ * Scan INFO1 rollback map and infomap fields of both RW and RW_B image
+ * headers, and return a string showing how many zeros are there at the base
+ * of in each of these objects.
+ *
+ * The passed in parameters are the memory area to put the string in and the
+ * size of this memory area.
+ */
+void system_get_rollback_bits(char *value, size_t value_size);
+
#endif /* __CROS_EC_SYSTEM_CHIP_H */