summaryrefslogtreecommitdiff
path: root/chip/g/system.c
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 /chip/g/system.c
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>
Diffstat (limited to 'chip/g/system.c')
-rw-r--r--chip/g/system.c40
1 files changed, 40 insertions, 0 deletions
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);
+}