summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2022-01-14 17:08:44 +1100
committerCommit Bot <commit-bot@chromium.org>2022-01-18 22:50:46 +0000
commit944d47a2a6fba266489a6d48cac5e51022dcefcc (patch)
tree352ee09a7eb04434f5a5633d94b7c10eed43d2ba
parenteba5595b348e4ff252cf2a64ea0105ee8014d2ed (diff)
downloadvboot-944d47a2a6fba266489a6d48cac5e51022dcefcc.tar.gz
Revert "vboot_reference/futility: Inline get_host_wp()"
This reverts commit 5d40740b711a34a006355b877b3ba7303dbf743d. Changing the write path in futility to use libflashrom had the side effect of skipping the code in cli_classic that created a powerd lock file. This could result in powerd suspending during a firmware update, corrupting the RW firmware. Revert back to subprocessing flashrom for M98. BUG=b:214485250 BRANCH=release-R98-14388.B TEST=emerge-grunt vboot_reference TEST=flashed grunt DUT with R98-14388.30.0 test image, deployed \ vboot_reference with reverts TEST=ran `futility --force -i image.bin`, monitored processes \ with `ps -ef | grep flashrom` verified that flashrom ran as \ a separate process for read/wp-status/write ops TEST=verified /run/lock/power_override/flashrom.lock was created \ during update TEST=ran `futility --force -i image.bin --wp=0`, verified only RW \ sections A/B were written TEST=ran `futility --force -i image.bin`, waited for write to start, \ sent restart msg with: `dbus-send --type=method_call --system \ --dest=org.chromium.PowerManager /org/chromium/PowerManager \ org.chromium.PowerManager.RequestRestart`, verified restart was \ deferred until firmware write finished Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Change-Id: Iffead23334e94d9b957e5179e5a66e0d9d5d0fb5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3388970 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/updater_utils.c115
1 files changed, 89 insertions, 26 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index 503747ac..a20a026b 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -26,6 +26,10 @@
#define COMMAND_BUFFER_SIZE 256
#define FLASHROM_OUTPUT_WP_PATTERN "write protect is "
+enum flashrom_ops {
+ FLASHROM_WP_STATUS,
+};
+
/* System environment values. */
static const char * const STR_REV = "rev",
* const FLASHROM_OUTPUT_WP_ENABLED =
@@ -522,6 +526,89 @@ char *host_detect_servo(int *need_prepare_ptr)
return ret;
}
+/*
+ * A helper function to invoke flashrom(8) command.
+ * Returns 0 if success, non-zero if error.
+ */
+static int host_flashrom(enum flashrom_ops op, const char *image_path,
+ const char *programmer, int verbose,
+ const char *section_name, const char *extra)
+{
+ char *command, *result;
+ const char *op_cmd, *dash_i = "-i", *postfix = "";
+ int r;
+
+ switch (verbose) {
+ case 0:
+ postfix = " >/dev/null 2>&1";
+ break;
+ case 1:
+ break;
+ case 2:
+ postfix = "-V";
+ break;
+ case 3:
+ postfix = "-V -V";
+ break;
+ default:
+ postfix = "-V -V -V";
+ break;
+ }
+
+ if (!section_name || !*section_name) {
+ dash_i = "";
+ section_name = "";
+ }
+
+ switch (op) {
+ case FLASHROM_WP_STATUS:
+ op_cmd = "--wp-status";
+ assert(image_path == NULL);
+ image_path = "";
+ /* grep is needed because host_shell only returns 1 line. */
+ postfix = " 2>/dev/null | grep \"" \
+ FLASHROM_OUTPUT_WP_PATTERN "\"";
+ break;
+
+ default:
+ assert(0);
+ return -1;
+ }
+
+ if (!extra)
+ extra = "";
+
+ /* TODO(b/203715651): link with flashrom directly. */
+ ASPRINTF(&command, "flashrom %s %s -p %s %s %s %s %s", op_cmd,
+ image_path, programmer, dash_i, section_name, extra,
+ postfix);
+
+ if (verbose)
+ INFO("Executing: %s\n", command);
+
+ if (op != FLASHROM_WP_STATUS) {
+ r = system(command);
+ free(command);
+ if (r)
+ ERROR("Error code: %d\n", r);
+ return r;
+ }
+
+ result = host_shell(command);
+ strip_string(result, NULL);
+ free(command);
+ VB2_DEBUG("wp-status: %s\n", result);
+
+ if (strstr(result, FLASHROM_OUTPUT_WP_ENABLED))
+ r = WP_ENABLED;
+ else if (strstr(result, FLASHROM_OUTPUT_WP_DISABLED))
+ r = WP_DISABLED;
+ else
+ r = WP_ERROR;
+ free(result);
+ return r;
+}
+
// global to allow verbosity level to be injected into callback.
static enum flashrom_log_level g_verbose_screen = FLASHROM_MSG_INFO;
@@ -664,32 +751,8 @@ err_cleanup:
/* Helper function to return write protection status via given programmer. */
enum wp_state host_get_wp(const char *programmer)
{
- char *command, *result;
- const char *postfix;
- int r;
-
- /* grep is needed because host_shell only returns 1 line. */
- postfix = " 2>/dev/null | grep \"" FLASHROM_OUTPUT_WP_PATTERN "\"";
-
-
- /* TODO(b/203715651): link with flashrom directly. */
- ASPRINTF(&command, "flashrom --wp-status -p %s %s", programmer, postfix);
-
- /* invokes flashrom(8) with non-zero result if error. */
- result = host_shell(command);
- strip_string(result, NULL);
- free(command);
- VB2_DEBUG("wp-status: %s\n", result);
-
- if (strstr(result, FLASHROM_OUTPUT_WP_ENABLED))
- r = WP_ENABLED;
- else if (strstr(result, FLASHROM_OUTPUT_WP_DISABLED))
- r = WP_DISABLED;
- else
- r = WP_ERROR;
- free(result);
-
- return r;
+ return host_flashrom(FLASHROM_WP_STATUS, NULL, programmer, 0, NULL,
+ NULL);
}
/* Helper function to return host software write protection status. */