summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2021-11-09 19:43:20 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-18 04:52:47 +0000
commitaf71b33619fdd9ec4f787c829b8fdde326ab1920 (patch)
tree53a0a6dab96d142d6707fdbbab73160e6f81ccac /common
parent7bba0b1edb635806250fe617043f93d2f8b0541c (diff)
downloadchrome-ec-af71b33619fdd9ec4f787c829b8fdde326ab1920.tar.gz
Revert "EFS: Switch active slot when current slot is invalid"
This reverts commit 729a4ba2bdc20675e24ed9e7d0a98d19934d72f8. BUG=b:200823466 TEST=make buildall -j Change-Id: I850e674c9bc347520effd97611878ea3e3153a56 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3273448 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/flash.c27
-rw-r--r--common/system.c64
-rw-r--r--common/vboot_hash.c6
3 files changed, 54 insertions, 43 deletions
diff --git a/common/flash.c b/common/flash.c
index 517ad654d2..d28f91fe0e 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -1316,6 +1316,29 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
+enum flash_rw_slot flash_get_active_slot(void)
+{
+ uint8_t slot;
+
+ if (system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, &slot))
+ slot = FLASH_RW_SLOT_A;
+ return slot;
+}
+
+enum flash_rw_slot flash_get_update_slot(void)
+{
+#ifdef CONFIG_VBOOT_EFS
+ return 1 - flash_get_active_slot();
+#else
+ return FLASH_RW_SLOT_A;
+#endif
+}
+
+enum system_image_copy_t flash_slot_to_image(enum flash_rw_slot slot)
+{
+ return slot == FLASH_RW_SLOT_A ? SYSTEM_IMAGE_RW_A : SYSTEM_IMAGE_RW_B;
+}
+
/*
* TODO(crbug.com/239197) : Adding both versions to the version mask is a
* temporary workaround for a problem in the cros_ec driver. Drop
@@ -1339,7 +1362,7 @@ flash_command_region_info(struct host_cmd_handler_args *args)
r->size = CONFIG_RO_SIZE;
break;
case EC_FLASH_REGION_ACTIVE:
- r->offset = flash_get_rw_offset(system_get_active_copy()) -
+ r->offset = flash_get_rw_offset(flash_get_active_slot()) -
EC_FLASH_REGION_START;
r->size = CONFIG_RW_SIZE;
break;
@@ -1349,7 +1372,7 @@ flash_command_region_info(struct host_cmd_handler_args *args)
r->size = CONFIG_WP_STORAGE_SIZE;
break;
case EC_FLASH_REGION_UPDATE:
- r->offset = flash_get_rw_offset(system_get_update_copy()) -
+ r->offset = flash_get_rw_offset(flash_get_update_slot()) -
EC_FLASH_REGION_START;
r->size = CONFIG_RW_SIZE;
break;
diff --git a/common/system.c b/common/system.c
index 392ffbc6de..fb2c388476 100644
--- a/common/system.c
+++ b/common/system.c
@@ -412,24 +412,30 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size)
{
uint32_t r_offset;
uint32_t r_size;
- enum system_image_copy_t copy = system_get_image_copy();
- switch (copy) {
+ switch (system_get_image_copy()) {
case SYSTEM_IMAGE_RO:
+ r_offset = CONFIG_EC_PROTECTED_STORAGE_OFF +
+ CONFIG_RO_STORAGE_OFF;
r_size = CONFIG_RO_SIZE;
break;
case SYSTEM_IMAGE_RW:
- case SYSTEM_IMAGE_RW_B:
+ 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;
}
- r_offset = flash_get_rw_offset(copy);
if ((offset >= r_offset && offset < (r_offset + r_size)) ||
(r_offset >= offset && r_offset < (offset + size)))
@@ -583,45 +589,17 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy)
return EC_ERROR_UNKNOWN;
}
-enum system_image_copy_t system_get_active_copy(void)
-{
- uint8_t slot;
- if (system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, &slot))
- slot = SYSTEM_IMAGE_RW_A;
- /* This makes it return RW_A by default. For example, this happens when
- * BBRAM isn't initialized. */
- return slot == SYSTEM_IMAGE_RW_B ? slot : SYSTEM_IMAGE_RW_A;
-}
-
-enum system_image_copy_t system_get_update_copy(void)
-{
-#ifdef CONFIG_VBOOT_EFS
- return system_get_active_copy() == SYSTEM_IMAGE_RW_A ?
- SYSTEM_IMAGE_RW_B : SYSTEM_IMAGE_RW_A;
-#else
- return SYSTEM_IMAGE_RW_A;
-#endif
-}
-
-int system_set_active_copy(enum system_image_copy_t copy)
-{
- return system_set_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, copy);
-}
-
/*
* 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 system_image_copy_t copy)
+uint32_t flash_get_rw_offset(enum flash_rw_slot slot)
{
#ifdef CONFIG_VBOOT_EFS
- if (copy == SYSTEM_IMAGE_RW_B)
+ if (slot == FLASH_RW_SLOT_B)
return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_B_STORAGE_OFF;
#endif
- if (is_rw_image(copy))
- return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
-
- return CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
+ return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
}
static const struct image_data *system_get_image_data(
@@ -649,7 +627,17 @@ static const struct image_data *system_get_image_data(
* Read the version information from the proper location
* on storage.
*/
- addr += flash_get_rw_offset(copy);
+ 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;
@@ -1224,12 +1212,12 @@ static enum ec_status
host_command_get_version(struct host_cmd_handler_args *args)
{
struct ec_response_get_version *r = args->response;
- enum system_image_copy_t active_slot = system_get_active_copy();
+ 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(active_slot),
+ system_get_version(flash_slot_to_image(active_slot)),
sizeof(r->version_string_rw));
switch (system_get_image_copy()) {
diff --git a/common/vboot_hash.c b/common/vboot_hash.c
index 0642e09e3c..890deef3b8 100644
--- a/common/vboot_hash.c
+++ b/common/vboot_hash.c
@@ -269,7 +269,7 @@ static void vboot_hash_init(void)
#endif
{
/* Start computing the hash of RW firmware */
- vboot_hash_start(flash_get_rw_offset(system_get_active_copy()),
+ vboot_hash_start(flash_get_rw_offset(flash_get_active_slot()),
get_rw_size(), NULL, 0);
}
}
@@ -306,9 +306,9 @@ static int get_offset(int offset)
if (offset == EC_VBOOT_HASH_OFFSET_RO)
return CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
if (offset == EC_VBOOT_HASH_OFFSET_ACTIVE)
- return flash_get_rw_offset(system_get_active_copy());
+ return flash_get_rw_offset(flash_get_active_slot());
if (offset == EC_VBOOT_HASH_OFFSET_UPDATE)
- return flash_get_rw_offset(system_get_update_copy());
+ return flash_get_rw_offset(flash_get_update_slot());
return offset;
}