diff options
-rw-r--r-- | board/cr50/board.c | 4 | ||||
-rw-r--r-- | chip/g/system.c | 40 | ||||
-rw-r--r-- | chip/g/system_chip.h | 11 |
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 5790436b2d..185f88ba99 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 */ |