summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2023-03-02 11:45:29 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-09 06:08:41 +0000
commit2bf1f59707de0ec20e4613ae36882e347b46b061 (patch)
treee23e637d8d27c5c4ddf589df5067b250dfa7a770
parentd0c79c0a28fc6ea315269e183f8cd65c389a2369 (diff)
downloadvboot-2bf1f59707de0ec20e4613ae36882e347b46b061.tar.gz
vboot_reference: Change flashrom_get_wp signature
Expose more information about WP state from the flashrom_drv WP status function. The more detailed WP information is required to properly validate the system WP configuration. BUG=b:268574030 TEST=futility update Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Change-Id: If79b7d8cc68a0583cbf1f7049ac7a2dec088fdd0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4301750 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/cmd_gbb_utility.c2
-rw-r--r--futility/updater.c4
-rw-r--r--futility/updater_dut.c10
-rw-r--r--futility/updater_utils.c13
-rw-r--r--host/lib/flashrom_drv.c25
-rw-r--r--host/lib/include/flashrom.h18
6 files changed, 40 insertions, 32 deletions
diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c
index db0c04a1..79c14130 100644
--- a/futility/cmd_gbb_utility.c
+++ b/futility/cmd_gbb_utility.c
@@ -440,7 +440,7 @@ static int write_to_flash(struct updater_config *cfg, uint8_t *outbuf,
off_t filesize)
{
#ifdef USE_FLASHROM
- if (is_write_protection_enabled(cfg) == WP_ENABLED) {
+ if (is_write_protection_enabled(cfg)) {
ERROR("You must disable write protection before setting flags.\n");
return -1;
}
diff --git a/futility/updater.c b/futility/updater.c
index 362d5dfc..7f1e215f 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -348,9 +348,7 @@ static int write_optional_firmware(struct updater_config *cfg,
* EC & PD may have different WP settings and we want to write
* only if it is OK.
*/
- if (check_programmer_wp &&
- dut_get_property(DUT_PROP_WP_HW, cfg) == WP_ENABLED &&
- flashrom_get_wp(image->programmer, -1) == WP_ENABLED) {
+ if (check_programmer_wp && is_write_protection_enabled(cfg)) {
ERROR("Target %s is write protected, skip updating.\n",
image->programmer);
return 0;
diff --git a/futility/updater_dut.c b/futility/updater_dut.c
index 6cb03727..634fd447 100644
--- a/futility/updater_dut.c
+++ b/futility/updater_dut.c
@@ -107,7 +107,7 @@ static int dut_get_tpm_fwver(struct updater_config *cfg)
static int dut_get_wp_hw(struct updater_config *cfg)
{
/* wpsw refers to write protection 'switch', not 'software'. */
- return dut_get_property_int("wpsw_cur", cfg) ? WP_ENABLED : WP_DISABLED;
+ return dut_get_property_int("wpsw_cur", cfg);
}
static int dut_get_platform_version(struct updater_config *cfg)
@@ -125,7 +125,13 @@ static int dut_get_platform_version(struct updater_config *cfg)
static int dut_get_wp_sw(struct updater_config *cfg)
{
assert(cfg->image.programmer);
- return flashrom_get_wp(cfg->image.programmer, -1);
+ bool mode;
+
+ if (flashrom_get_wp(cfg->image.programmer, &mode, NULL, NULL, -1)) {
+ /* Read WP status error */
+ return -1;
+ }
+ return mode;
}
/* Helper functions to use or configure the DUT properties. */
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index b04e56ca..03b0378d 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -362,16 +362,9 @@ const struct vb2_gbb_header *find_gbb(const struct firmware_image *image)
*/
int is_write_protection_enabled(struct updater_config *cfg)
{
- /* Default to enabled. */
- int wp = dut_get_property(DUT_PROP_WP_HW, cfg);
- if (wp == WP_DISABLED)
- return wp;
- /* For error or enabled, check WP SW. */
- wp = dut_get_property(DUT_PROP_WP_SW, cfg);
- /* Consider all errors as enabled. */
- if (wp != WP_DISABLED)
- return WP_ENABLED;
- return wp;
+ /* Assume HW/SW WP are enabled if -1 error code is returned */
+ return dut_get_property(DUT_PROP_WP_HW, cfg) &&
+ dut_get_property(DUT_PROP_WP_SW, cfg);
}
/*
diff --git a/host/lib/flashrom_drv.c b/host/lib/flashrom_drv.c
index ff31e149..09e7f468 100644
--- a/host/lib/flashrom_drv.c
+++ b/host/lib/flashrom_drv.c
@@ -252,9 +252,10 @@ err_init:
return r;
}
-enum wp_state flashrom_get_wp(const char *prog_with_params, int verbosity)
+int flashrom_get_wp(const char *prog_with_params, bool *wp_mode,
+ uint32_t *wp_start, uint32_t *wp_len, int verbosity)
{
- enum wp_state r = WP_ERROR;
+ int ret = -1;
g_verbose_screen = (verbosity == -1) ? FLASHROM_MSG_INFO : verbosity;
@@ -282,10 +283,18 @@ enum wp_state flashrom_get_wp(const char *prog_with_params, int verbosity)
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;
+ /* size_t tmp variables for libflashrom compatibility */
+ size_t tmp_wp_start, tmp_wp_len;
+ flashrom_wp_get_range(&tmp_wp_start, &tmp_wp_len, cfg);
+
+ if (wp_start != NULL)
+ *wp_start = tmp_wp_start;
+ if (wp_start != NULL)
+ *wp_len = tmp_wp_len;
+ if (wp_mode != NULL)
+ *wp_mode = flashrom_wp_get_mode(cfg) != FLASHROM_WP_MODE_DISABLED;
+
+ ret = 0;
err_read_cfg:
flashrom_wp_cfg_release(cfg);
@@ -295,10 +304,10 @@ err_cleanup:
err_probe:
if (flashrom_programmer_shutdown(prog))
- r = WP_ERROR;
+ ret = -1;
err_init:
free(tmp);
- return r;
+ return ret;
}
diff --git a/host/lib/include/flashrom.h b/host/lib/include/flashrom.h
index 0c1b3716..5fb7a03c 100644
--- a/host/lib/include/flashrom.h
+++ b/host/lib/include/flashrom.h
@@ -71,18 +71,20 @@ int flashrom_write_image(const struct firmware_image *image,
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.
+ * @param wp_mode Pointer to a bool to store the WP mode. Will be set to
+ * false if WP is disabled, true if WP is enabled.
+ * NULL can be passed if not needed.
+ * @param wp_start Pointer to a uint32_t to store the WP start addr.
+ * NULL can be passed if not needed.
+ * @param wp_len Pointer to a uint32_t to store the WP region length.
+ * NULL can be passed if not needed.
*
- * @return WP_DISABLED, WP_ENABLED, ot a relevant error.
+ * @return 0 on success, or a relevant error.
*/
-enum wp_state flashrom_get_wp(const char *programmer, int verbosity);
+int flashrom_get_wp(const char *programmer, bool *wp_mode,
+ uint32_t *wp_start, uint32_t *wp_len, int verbosity);