From 730c7c469fc06264a67280a62185bfc9f06d88a6 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Mon, 11 Jul 2016 11:52:44 -0700 Subject: [PATCH] cr50: report rw version properly The code reporting the RW version is in fact using a fixed location in flash memory. This is fine for a single RW image (i.e. the vast majority of the EC boards), but is wrong for CR50 which can run one of two RW images. The fix is to account for this by providing the currently running image type to the function retrieving the image version. Note that RW and RW_B versions end up at different offsets into the image, it is impossible to retrieve the version of the not currently running RW by just changing the offset into the flash memory. BRANCH=none BUG=chrome-os-partner:55145 TEST=as follows: - build, update and start a cr50 - check the vers. command output, observe that it is running from RW and reports the correct RW version string: > vers Chip: g cr50 B1 0_0 Board: 0 RO: RW: cr50_v1.1.4856-df14f6a Build: cr50_v1.1.4856-df14f6a 2016-07-11 11:52:44 vbendeb@eskimo.mtv.corp.google.com > - build the image again, update and restart the cr50 - check the vers. command output, observe that it is running from RW_B and reports the correct RW version string: > vers Chip: g cr50 B1 0_0 Board: 0 RO: RW_B: cr50_v1.1.4856-df14f6a Build: cr50_v1.1.4856-df14f6a 2016-07-11 11:52:44 vbendeb@eskimo.mtv.corp.google.com > - erase the RW space base flasherase 0x4000 0x20000 - run the vers command again. It was failing before this fix, now it still shows the proper RW_B version. Change-Id: Iab8bc0e61b50dd65a9e18a0369b18bdd9cc05421 Reviewed-on: https://chromium-review.googlesource.com/359580 Commit-Ready: Vadim Bendebury Tested-by: Vadim Bendebury Reviewed-by: Vadim Bendebury --- common/system.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/common/system.c b/common/system.c index ec7b16c91e..5600a9f70f 100644 --- a/common/system.c +++ b/common/system.c @@ -894,7 +894,38 @@ static int command_version(int argc, char **argv) system_get_chip_name(), system_get_chip_revision()); ccprintf("Board: %d\n", system_get_board_version()); ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); +#ifdef CONFIG_RW_B + + /* + * Code reporting the RW version fails to properly retrieve the + * version of the non actively running RW image. The code always uses a + * fixed offset into the flash memory, which is correct for RW, but + * incorrect for RW_B. + * + * The RW and RW_B versions end up at different offsets into their + * respective image halves, so it is impossible to find the RW_B + * versoin offset by just adding another offset the the RW version + * offset. + * + * To address this issue, when running an RW image, report the version + * of the running part of the image explicitly. + */ + + { + enum system_image_copy_t active_copy = system_get_image_copy(); + + if (active_copy == SYSTEM_IMAGE_RO) { + ccprintf("RW: %s\n", + system_get_version(SYSTEM_IMAGE_RW)); + } else { + ccprintf("RW%s %s\n", + active_copy == SYSTEM_IMAGE_RW ? ": " : "_B:", + system_get_version(active_copy)); + } + } +#else ccprintf("RW: %s\n", system_get_version(SYSTEM_IMAGE_RW)); +#endif ccprintf("Build: %s\n", system_get_build_info()); return EC_SUCCESS; }