summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2021-10-21 11:32:10 +1100
committerCommit Bot <commit-bot@chromium.org>2021-11-26 01:08:18 +0000
commit5d40740b711a34a006355b877b3ba7303dbf743d (patch)
treeda65768f531cef533e8bd99008c823fa84910b35
parent2821ee7afac6b1a5d7998246f3a8026e914ef2e7 (diff)
downloadvboot-5d40740b711a34a006355b877b3ba7303dbf743d.tar.gz
vboot_reference/futility: Inline get_host_wp()
writeprotect still requires sub-processing flashrom as libflashrom currently lacks a API to perform this task. Therefore simplify the remaining sub-process logic for just this purpose. BUG=b:203715651 BRANCH=none TEST=cros deploy to nocturne and ran: `/usr/sbin/chromeos-firmwareupdate --mode=recovery --wp=1`. && `$ cros_run_unit_tests --board nocturne --packages vboot_reference`. Signed-off-by: Edward O'Callaghan <quasisec@google.com> Change-Id: I11c0f89997e3f47e97444cc8186823fa536b8d5d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3233704 Tested-by: Edward O'Callaghan <quasisec@chromium.org> Commit-Queue: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Sam McNally <sammc@chromium.org>
-rw-r--r--futility/updater_utils.c115
1 files changed, 26 insertions, 89 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index a20a026b..503747ac 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -26,10 +26,6 @@
#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 =
@@ -526,89 +522,6 @@ 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;
@@ -751,8 +664,32 @@ err_cleanup:
/* Helper function to return write protection status via given programmer. */
enum wp_state host_get_wp(const char *programmer)
{
- return host_flashrom(FLASHROM_WP_STATUS, NULL, programmer, 0, NULL,
- NULL);
+ 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;
}
/* Helper function to return host software write protection status. */