diff options
author | Bill Richardson <wfrichar@chromium.org> | 2016-07-24 23:58:05 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-26 12:27:33 -0700 |
commit | 20a6d75aee99c50a1646b73e11e7bb84276439c6 (patch) | |
tree | 9588552acafe7f29da2f3c3622c0207337d42659 /chip | |
parent | 0564276033dd2615b95fa3f85152b9cc56c166d3 (diff) | |
download | chrome-ec-20a6d75aee99c50a1646b73e11e7bb84276439c6.tar.gz |
g: Improve version info for dual RO & RW images
The SoC looks for two RO images at reset, and is typically
configured for two RW images as well. This CL reports version
strings for all those images, as well as identifying the active
RO and RW copies.
Since the RO image doesn't contain a version string, we create
one using the epoch_, major_, minor_, and img_chk_ members of its
signed header.
BUG=chrome-os-partner:55558
BRANCH=none
TEST=make buildall; run on Cr50 hardware
The "version" command now includes information like this:
RO_A: * 0.0.2/a3c3d5ea
RO_B: 0.0.2/8895c9eb
RW_A: cr50_v1.1.4965-a6c1c73-dirty
RW_B: * cr50_v1.1.4959-2f49d5c
The '*' indicates the active image.
The test/tpm_test/tpmtest.py program has been updated to request
the version information at startup, and it also now reports
similar information, just all on one line:
RO_A:* 0.0.2/a3c3d5ea RO_B: 0.0.2/8895c9eb RW_A: cr50_v1.1 ...
The active images are marked with a '*' following the ':', so
that the same regexp can match either format:
($ro, $rw) = m/RO_[AB]:\s*\*\s+(\S+).*RW_[AB]:\s*\*\s+(\S+)/s;
Change-Id: Ic27e295d9122045b2ec5a638933924b65ecc8e43
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/362861
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r-- | chip/g/config_chip.h | 9 | ||||
-rw-r--r-- | chip/g/system.c | 90 |
2 files changed, 98 insertions, 1 deletions
diff --git a/chip/g/config_chip.h b/chip/g/config_chip.h index 99b9195b8b..97cc56ba94 100644 --- a/chip/g/config_chip.h +++ b/chip/g/config_chip.h @@ -81,6 +81,9 @@ * The following macros try to make this all work. */ +/* This isn't optional, since the bootrom will always look for both */ +#define CHIP_HAS_RO_B + /* It's easier for us to consider each half as having its own RO and RW */ #define CFG_FLASH_HALF (CONFIG_FLASH_SIZE >> 1) @@ -96,11 +99,15 @@ /* The RO images start at the very beginning of each flash half */ #define CONFIG_RO_MEM_OFF 0 +#define CHIP_RO_B_MEM_OFF CFG_FLASH_HALF /* Size reserved for each RO image */ #define CONFIG_RO_SIZE 0x4000 -/* RW images start right after the reserved-for-RO areas in each half */ +/* + * RW images start right after the reserved-for-RO areas in each half, but only + * because that's where the RO images look for them. It's not a HW constraint. + */ #define CONFIG_RW_MEM_OFF CONFIG_RO_SIZE #define CONFIG_RW_B_MEM_OFF (CFG_FLASH_HALF + CONFIG_RW_MEM_OFF) diff --git a/chip/g/system.c b/chip/g/system.c index bf1c39e805..2bbd5d0301 100644 --- a/chip/g/system.c +++ b/chip/g/system.c @@ -3,10 +3,14 @@ * found in the LICENSE file. */ +#include "config.h" #include "cpu.h" +#include "printf.h" #include "registers.h" +#include "signed_header.h" #include "system.h" #include "task.h" +#include "version.h" static void check_reset_cause(void) { @@ -145,3 +149,89 @@ int system_set_vbnvcontext(const uint8_t *block) { return 0; } + +enum system_image_copy_t system_get_ro_image_copy(void) +{ + /* + * The bootrom protects the selected bootloader with REGION0, + * so we should be able to identify the active RO by seeing which one + * is protected. + */ + switch (GREG32(GLOBALSEC, FLASH_REGION0_BASE_ADDR)) { + case CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RO_MEM_OFF: + return SYSTEM_IMAGE_RO; + case CONFIG_PROGRAM_MEMORY_BASE + CHIP_RO_B_MEM_OFF: + return SYSTEM_IMAGE_RO_B; + } + + return SYSTEM_IMAGE_UNKNOWN; +} + +/* + * The RW images contain version strings. The RO images don't, so we'll make + * some here. + */ +#define MAX_RO_VER_LEN 48 +static char ro_str[2][MAX_RO_VER_LEN]; + +const char *system_get_version(enum system_image_copy_t copy) +{ + const struct version_struct *v; + const struct SignedHeader *h; + enum system_image_copy_t this_copy; + uintptr_t vaddr, delta; + int i; + + switch (copy) { + case SYSTEM_IMAGE_RO: + case SYSTEM_IMAGE_RO_B: + /* The RO header is the first thing in each flash half */ + vaddr = get_program_memory_addr(copy); + if (vaddr == INVALID_ADDR) + break; + h = (const struct SignedHeader *)vaddr; + i = (copy == SYSTEM_IMAGE_RO) ? 0 : 1; + /* Use some fields from the header for the version string */ + snprintf(ro_str[i], MAX_RO_VER_LEN, "%d.%d.%d/%08x", + h->epoch_, h->major_, h->minor_, h->img_chk_); + return ro_str[i]; + + case SYSTEM_IMAGE_RW: + case SYSTEM_IMAGE_RW_B: + /* + * This function isn't part of any RO image, so we must be in a + * RW image. If the current image is the one we're asked for, + * we can just return our version string. + */ + this_copy = system_get_image_copy(); + if (copy == this_copy) + return version_data.version; + + /* + * We want the version of the other RW image. The linker script + * puts the version string right after the reset vectors, so + * it's at the same relative offset. Measure that offset here. + */ + vaddr = get_program_memory_addr(this_copy); + delta = (uintptr_t)&version_data - vaddr; + + /* Now look at that offset in the requested image */ + vaddr = get_program_memory_addr(copy); + if (vaddr == INVALID_ADDR) + break; + vaddr += delta; + v = (const struct version_struct *)vaddr; + + /* + * Make sure the version struct cookies match before returning + * the version string. + */ + if (v->cookie1 == version_data.cookie1 && + v->cookie2 == version_data.cookie2) + return v->version; + default: + break; + } + + return "Error"; +} |