From eda40d1b9352692ac270652b79f2f18e31c5420e Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Mon, 15 May 2023 14:32:18 +1000 Subject: futility/updater.c: Dedup update_legacy_firmware() logic BUG=b:282585789 BRANCH=none TEST=`cros_run_unit_tests --host --packages vboot_reference`. Change-Id: I8fdc14236a478cc1ad0f39e091b19223cb3d9470 Signed-off-by: Edward O'Callaghan Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4532321 Reviewed-by: Nikolai Artemiev Commit-Queue: Edward O'Callaghan Tested-by: Edward O'Callaghan --- futility/updater.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/futility/updater.c b/futility/updater.c index 1a823924..57b18ce1 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -871,6 +871,24 @@ const char * const updater_error_messages[] = { [UPDATE_ERR_UNKNOWN] = "Unknown error.", }; +/* + * The main updater for "Legacy update". + * This is equivalent to --mode=legacy. + * Returns UPDATE_ERR_DONE if success, otherwise error. + */ +static enum updater_error_codes update_legacy_firmware( + struct updater_config *cfg, + struct firmware_image *image_to) +{ + STATUS("LEGACY UPDATE: Updating firmware %s.\n", FMAP_RW_LEGACY); + + const char *sections[2] = { FMAP_RW_LEGACY, NULL }; + if (write_system_firmware(cfg, image_to, sections)) + return UPDATE_ERR_WRITE_FIRMWARE; + + return UPDATE_ERR_DONE; +} + /* * The main updater for "Try-RW update", to update only one RW section * and try if it can boot properly on reboot. @@ -947,9 +965,7 @@ static enum updater_error_codes update_try_rw_firmware( /* Do not fail on updating legacy. */ if (legacy_needs_update(cfg)) { has_update = 1; - STATUS("LEGACY UPDATE: Updating %s.\n", FMAP_RW_LEGACY); - const char *sections[2] = { FMAP_RW_LEGACY, NULL }; - write_system_firmware(cfg, image_to, sections); + update_legacy_firmware(cfg, image_to); } return UPDATE_ERR_DONE; @@ -1015,24 +1031,6 @@ static enum updater_error_codes update_rw_firmware( return UPDATE_ERR_DONE; } -/* - * The main updater for "Legacy update". - * This is equivalent to --mode=legacy. - * Returns UPDATE_ERR_DONE if success, otherwise error. - */ -static enum updater_error_codes update_legacy_firmware( - struct updater_config *cfg, - struct firmware_image *image_to) -{ - STATUS("LEGACY UPDATE: Updating firmware %s.\n", FMAP_RW_LEGACY); - - const char *sections[2] = { FMAP_RW_LEGACY, NULL }; - if (write_system_firmware(cfg, image_to, sections)) - return UPDATE_ERR_WRITE_FIRMWARE; - - return UPDATE_ERR_DONE; -} - /* * The main updater for "Full update". * This was also known as "--mode=factory" or "--mode=recovery, --wp=0" in -- cgit v1.2.1