summaryrefslogtreecommitdiff
path: root/common/system.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-08-15 16:34:52 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-09-12 01:11:59 -0700
commit4dcee1c545c31d288b23221d8e07bc452214ce7b (patch)
tree1ddab11d51dcd5c0571f6f777b655ba333cd84e6 /common/system.c
parenta52cfbc80c060d9883aee9de4e764e0b250d184a (diff)
downloadchrome-ec-4dcee1c545c31d288b23221d8e07bc452214ce7b.tar.gz
EFS: Add support for early firmware selection
Chromebox ECs performs EFS: verifying firmware before the AP boots. This patch updates host commands which are required for the EFS. The change includes: * Update EC_CMD_FLASH_REGION_INFO to accept EC_FLASH_REGION_UPDATE * Update EC_CMD_VBOOT_HASH to accept EC_VBOOT_HASH_OFFSET_UPDATE When EC_FLASHS_REGION_UPDATE is specified, EC_CMD_FLASH_REGION_INFO returns the slot which currently is not hosting a running RW copy. When EC_VBOOT_HASH_OFFSET_UPDATE is specified, EC_CMD_VBOOT_HASH computs the hash of the update slot. This hash covers the entire region, including the signature at the end. This patch undefines CONFIG_CMD_USBMUX and CONFIG_CMD_TYPEC for gru to create space. BUG=b:65028930 BRANCH=none CQ-DEPEND=CL:648071 TEST=On Fizz, verify: 1. RW_B is old and updated by soft sync. RW_B is activated and executed after reboot. System continues to boot to OS. 2. RW_A is old and updated by soft sync. RW_A is activated and executed after reboot. System continues to boot to OS. Change-Id: I9ece907b764d07ce94054ba27996e048c665a80a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/648448
Diffstat (limited to 'common/system.c')
-rw-r--r--common/system.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/common/system.c b/common/system.c
index 07d43da38b..62c036baf9 100644
--- a/common/system.c
+++ b/common/system.c
@@ -420,14 +420,19 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size)
r_size = CONFIG_RO_SIZE;
break;
case SYSTEM_IMAGE_RW:
- r_offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_STORAGE_OFF;
+ r_offset = flash_get_rw_offset(FLASH_RW_SLOT_A);
r_size = CONFIG_RW_SIZE;
#ifdef CONFIG_RWSIG
/* Allow RW sig to be overwritten */
r_size -= CONFIG_RW_SIG_SIZE;
#endif
break;
+#ifdef CONFIG_VBOOT_EFS
+ case SYSTEM_IMAGE_RW_B:
+ r_offset = flash_get_rw_offset(FLASH_RW_SLOT_B);
+ r_size = CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE;
+ break;
+#endif
default:
return 0;
}
@@ -614,6 +619,19 @@ int system_run_image_copy(enum system_image_copy_t copy)
return EC_ERROR_UNKNOWN;
}
+/*
+ * This is defined in system.c instead of flash.c because it's called even
+ * on the boards which don't include flash.o. (e.g. hadoken, stm32l476g-eval)
+ */
+uint32_t flash_get_rw_offset(enum flash_rw_slot slot)
+{
+#ifdef CONFIG_VBOOT_EFS
+ if (slot == FLASH_RW_SLOT_B)
+ return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_B_STORAGE_OFF;
+#endif
+ return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
+}
+
static const struct image_data *system_get_image_data(
enum system_image_copy_t copy)
{
@@ -639,9 +657,17 @@ static const struct image_data *system_get_image_data(
* Read the version information from the proper location
* on storage.
*/
- addr += (is_rw_image(copy)) ?
- CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF :
- CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
+ switch (copy) {
+ case SYSTEM_IMAGE_RW:
+ addr += flash_get_rw_offset(FLASH_RW_SLOT_A);
+ break;
+ case SYSTEM_IMAGE_RW_B:
+ addr += flash_get_rw_offset(FLASH_RW_SLOT_B);
+ break;
+ default:
+ addr += CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
+ break;
+ }
#ifdef CONFIG_MAPPED_STORAGE
addr += CONFIG_MAPPED_STORAGE_BASE;
@@ -1198,10 +1224,12 @@ DECLARE_CONSOLE_COMMAND(sysrq, command_sysrq,
static int host_command_get_version(struct host_cmd_handler_args *args)
{
struct ec_response_get_version *r = args->response;
+ enum flash_rw_slot active_slot = flash_get_active_slot();
strzcpy(r->version_string_ro, system_get_version(SYSTEM_IMAGE_RO),
sizeof(r->version_string_ro));
- strzcpy(r->version_string_rw, system_get_version(SYSTEM_IMAGE_RW),
+ strzcpy(r->version_string_rw,
+ system_get_version(flash_slot_to_image(active_slot)),
sizeof(r->version_string_rw));
switch (system_get_image_copy()) {
@@ -1209,6 +1237,7 @@ static int host_command_get_version(struct host_cmd_handler_args *args)
r->current_image = EC_IMAGE_RO;
break;
case SYSTEM_IMAGE_RW:
+ case SYSTEM_IMAGE_RW_B:
r->current_image = EC_IMAGE_RW;
break;
default: