summaryrefslogtreecommitdiff
path: root/futility
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2022-03-22 18:45:14 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-18 03:31:17 +0000
commit2b2b0c44ec2258609acf5ff6a06027fd890d8b1e (patch)
tree0ab7b8ec3ba4b748369c49e88d7e81f495b6e466 /futility
parent9b08a3c4806153256e13a0d8e9019d6a387becd5 (diff)
downloadvboot-2b2b0c44ec2258609acf5ff6a06027fd890d8b1e.tar.gz
vboot_reference: make flashrom_get_wp() use libflashrom
This makes flashrom_get_wp() use the new libflashrom WP interface that was recently added to flashrom and moves it to host/lib/flashrom_drv.c with the other libflashrom wrapper functions. BUG=b:223291615 BRANCH=none TEST=flashrom --wp-disable; futility update -i image.bin \ futility prints: `Write protection: 0 (disabled; HW=0, SW=0).` TEST=flashrom --wp-enable; futility update -i image.bin \ futility prints: `Write protection: 0 (disabled; HW=0, SW=1).` Change-Id: Ib13eeb2f1f718443271b074969ff69e66149f401 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3540785 Commit-Queue: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Diffstat (limited to 'futility')
-rw-r--r--futility/flashrom_wp_drv.c50
-rw-r--r--futility/updater.c2
-rw-r--r--futility/updater_utils.c2
-rw-r--r--futility/updater_utils.h9
4 files changed, 2 insertions, 61 deletions
diff --git a/futility/flashrom_wp_drv.c b/futility/flashrom_wp_drv.c
deleted file mode 100644
index ff7a8214..00000000
--- a/futility/flashrom_wp_drv.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * The utility functions for firmware updater.
- */
-
-#include <libflashrom.h>
-
-#include "updater.h"
-
-#define FLASHROM_OUTPUT_WP_PATTERN "write protect is "
-
-/* System environment values. */
-static const char * const FLASHROM_OUTPUT_WP_ENABLED =
- FLASHROM_OUTPUT_WP_PATTERN "enabled",
- * const FLASHROM_OUTPUT_WP_DISABLED =
- FLASHROM_OUTPUT_WP_PATTERN "disabled";
-
-
-/* Helper function to return write protection status via given programmer. */
-enum wp_state flashrom_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;
-}
diff --git a/futility/updater.c b/futility/updater.c
index 1a5e99d1..6be7238c 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -393,7 +393,7 @@ static int write_optional_firmware(struct updater_config *cfg,
*/
if (check_programmer_wp &&
get_system_property(SYS_PROP_WP_HW, cfg) == WP_ENABLED &&
- flashrom_get_wp(image->programmer) == WP_ENABLED) {
+ flashrom_get_wp(image->programmer, -1) == WP_ENABLED) {
ERROR("Target %s is write protected, skip updating.\n",
image->programmer);
return 0;
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index d879f783..8a7b6f7b 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -821,7 +821,7 @@ int write_system_firmware(struct updater_config *cfg,
/* Helper function to return host software write protection status. */
static int host_get_wp_sw(void)
{
- return flashrom_get_wp(PROG_HOST);
+ return flashrom_get_wp(PROG_HOST, -1);
}
/* Helper function to configure all properties. */
diff --git a/futility/updater_utils.h b/futility/updater_utils.h
index a99c38c4..49b0adf5 100644
--- a/futility/updater_utils.h
+++ b/futility/updater_utils.h
@@ -181,15 +181,6 @@ int save_file_from_stdin(const char *output);
*/
char *host_shell(const char *command);
-enum wp_state {
- WP_ERROR = -1,
- WP_DISABLED = 0,
- WP_ENABLED,
-};
-
-/* Helper function to return write protection status via given programmer. */
-enum wp_state flashrom_get_wp(const char *programmer);
-
/* The environment variable name for setting servod port. */
#define ENV_SERVOD_PORT "SERVOD_PORT"