summaryrefslogtreecommitdiff
path: root/host
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 /host
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 'host')
-rw-r--r--host/lib/flashrom_drv.c51
-rw-r--r--host/lib/include/flashrom.h16
2 files changed, 67 insertions, 0 deletions
diff --git a/host/lib/flashrom_drv.c b/host/lib/flashrom_drv.c
index 19d6384e..2bc0a7be 100644
--- a/host/lib/flashrom_drv.c
+++ b/host/lib/flashrom_drv.c
@@ -212,3 +212,54 @@ err_init:
free(tmp);
return r;
}
+
+enum wp_state flashrom_get_wp(const char *programmer, int verbosity)
+{
+ enum wp_state r = WP_ERROR;
+
+ g_verbose_screen = (verbosity == -1) ? FLASHROM_MSG_INFO : verbosity;
+
+ struct flashrom_programmer *prog = NULL;
+ struct flashrom_flashctx *flashctx = NULL;
+
+ struct flashrom_wp_cfg *cfg = NULL;
+
+ char *tmp_programmer, *params;
+ char *tmp = flashrom_extract_params(programmer, &tmp_programmer,
+ &params);
+
+ flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb);
+
+ if (flashrom_init(1)
+ || flashrom_programmer_init(&prog, programmer, params))
+ goto err_init;
+
+ if (flashrom_flash_probe(&flashctx, prog, NULL))
+ goto err_probe;
+
+ if (flashrom_wp_cfg_new(&cfg) != FLASHROM_WP_OK)
+ goto err_cleanup;
+
+ if (flashrom_wp_read_cfg(cfg, flashctx) != FLASHROM_WP_OK)
+ goto err_read_cfg;
+
+ if (flashrom_wp_get_mode(cfg) == FLASHROM_WP_MODE_DISABLED)
+ r = WP_DISABLED;
+ else
+ r = WP_ENABLED;
+
+err_read_cfg:
+ flashrom_wp_cfg_release(cfg);
+
+err_cleanup:
+ flashrom_flash_release(flashctx);
+
+err_probe:
+ if (flashrom_programmer_shutdown(prog))
+ r = WP_ERROR;
+
+err_init:
+ free(tmp);
+
+ return r;
+}
diff --git a/host/lib/include/flashrom.h b/host/lib/include/flashrom.h
index 6058d644..9fae8046 100644
--- a/host/lib/include/flashrom.h
+++ b/host/lib/include/flashrom.h
@@ -59,3 +59,19 @@ int flashrom_write_image(const struct firmware_image *image,
const char * const regions[],
const struct firmware_image *diff_image,
int do_verify, int verbosity);
+
+enum wp_state {
+ WP_ERROR = -1,
+ WP_DISABLED = 0,
+ WP_ENABLED,
+};
+
+/**
+ * Get wp state using flashrom.
+ *
+ * @param programmer The name of the programmer to use for reading the
+ * writeprotect state.
+ *
+ * @return WP_DISABLED, WP_ENABLED, ot a relevant error.
+ */
+enum wp_state flashrom_get_wp(const char *programmer, int verbosity);