summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2022-03-01 18:09:51 +0800
committerCommit Bot <commit-bot@chromium.org>2022-03-11 07:59:15 +0000
commit660c41fbf07015af212aadba8395439f137789e8 (patch)
tree7daae2c4da7164d4176d0169ebfce47a9b044630
parent1662f3f83a494a64c7e7d85428a00d4e942d6b8c (diff)
downloadvboot-660c41fbf07015af212aadba8395439f137789e8.tar.gz
futility: updater: revise building RW-recovery sections
When checking the sections to update in the RW-recovery flow, we should always check the availability before adding them to the list for updating. BUG=None TEST=build and run test BRANCH=None Signed-off-by: Hung-Te Lin <hungte@chromium.org> Change-Id: Id714b1db736cbf4eef879566431e5a496f319cd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3494671 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--futility/updater.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 6e91d6f8..e6834a97 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -1144,14 +1144,17 @@ static enum updater_error_codes update_rw_firmware(
struct firmware_image *image_from,
struct firmware_image *image_to)
{
- int sections_start = 0;
- static const char * const sections[] = {
- FMAP_RW_LEGACY,
+ int i, num = 0;
+ static const char * const required_sections[] = {
FMAP_RW_SECTION_A,
FMAP_RW_SECTION_B,
+ };
+ static const char * const optional_sections[] = {
+ FMAP_RW_LEGACY,
FMAP_RW_SHARED,
- NULL,
};
+ const char *sections[ARRAY_SIZE(required_sections) +
+ ARRAY_SIZE(optional_sections) + 1];
STATUS("RW UPDATE: Updating RW sections (%s, %s, %s, and %s).\n",
FMAP_RW_SECTION_A, FMAP_RW_SECTION_B, FMAP_RW_SHARED,
@@ -1163,17 +1166,29 @@ static enum updater_error_codes update_rw_firmware(
if (check_compatible_tpm_keys(cfg, image_to))
return UPDATE_ERR_TPM_ROLLBACK;
+ for (i = 0; i < ARRAY_SIZE(required_sections); i++)
+ sections[num++] = required_sections[i];
+
/*
+ * The FMAP_RW_LEGACY is a special optional section.
* We may also consider only updating legacy if legacy_needs_update()
* returns true. However, given this is for 'recovery', it is probably
* better to restore everything to the default states. We may revisit
* this if a new scenario is found.
*/
- if (!firmware_section_exists(image_from, sections[sections_start]) ||
- !firmware_section_exists(image_to, sections[sections_start]))
- sections_start++;
+ for (i = 0; i < ARRAY_SIZE(optional_sections); i++) {
+ const char *name = optional_sections[i];
+ if (!firmware_section_exists(image_from, name) ||
+ !firmware_section_exists(image_to, name)) {
+ VB2_DEBUG("Skipped optional section: %s\n", name);
+ continue;
+ }
+ sections[num++] = name;
+ }
+ assert(num < ARRAY_SIZE(sections));
+ sections[num] = NULL;
- if (write_firmware_sections(cfg, image_to, &sections[sections_start]))
+ if (write_firmware_sections(cfg, image_to, sections))
return UPDATE_ERR_WRITE_FIRMWARE;
return UPDATE_ERR_DONE;