summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2023-04-11 16:32:04 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-20 12:18:02 +0000
commit0b0a37ea56a90c0ff396f476adf3fd814af789cc (patch)
tree15edc1d9747b1cf4f561a8fe7a06b78eabe45d4d
parenta6e3fdfd2424c1f99b4ed3786895c2255a5be023 (diff)
downloadvboot-stabilize-15432.B.tar.gz
futility: make flash --wp-status subcmd check HW statusstabilize-15432.B
Check HW WP status as well as SW WP status by default. A new `--ignore-hw` flag makes it possible to only check SW WP. BUG=b:268574030 BRANCH=none TEST=todo Change-Id: I4a45499ceda52a1e00e7e33742b0bb48d235550b Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4413354 Commit-Queue: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/cmd_flash_util.c32
-rwxr-xr-xtests/futility/test_flash_util.sh2
2 files changed, 25 insertions, 9 deletions
diff --git a/futility/cmd_flash_util.c b/futility/cmd_flash_util.c
index 41554597..858e260f 100644
--- a/futility/cmd_flash_util.c
+++ b/futility/cmd_flash_util.c
@@ -86,7 +86,7 @@ err:
return ret;
}
-static int print_wp_status(struct updater_config *cfg)
+static int print_wp_status(struct updater_config *cfg, bool ignore_hw)
{
/* Get WP_RO region start and length from image */
uint32_t ro_start, ro_len;
@@ -102,7 +102,10 @@ static int print_wp_status(struct updater_config *cfg)
return -1;
}
- if (!wp_mode && wp_start == 0 && wp_len == 0) {
+ /* A 1 implies HWWP is enabled. */
+ int hwwp = ignore_hw ? 1 : dut_get_property(DUT_PROP_WP_HW, cfg);
+
+ if (!hwwp || (!wp_mode && wp_start == 0 && wp_len == 0)) {
printf("WP status: disabled\n");
} else if (wp_mode && wp_start == ro_start && wp_len == ro_len) {
printf("WP status: enabled\n");
@@ -143,6 +146,7 @@ static struct option const long_opts[] = {
/* name has_arg *flag val */
{"help", 0, NULL, 'h'},
{"wp-status", 0, NULL, 's'},
+ {"ignore-hw", 0, NULL, 'o'},
{"wp-enable", 0, NULL, 'e'},
{"wp-disable", 0, NULL, 'd'},
{"flash-info", 0, NULL, 'i'},
@@ -159,11 +163,13 @@ static void print_help(int argc, char *argv[])
"\n"
"Usage: " MYNAME " %s [OPTIONS] \n"
"\n"
- " --wp-status \tGet the current flash WP state.\n"
- " --wp-enable \tEnable protection for the RO image section.\n"
- " --wp-disable \tDisable all write protection.\n"
- " --flash-size \tGet flash size.\n"
- " --flash-info \tGet flash info.\n"
+ " --wp-status \tGet the current flash WP state.\n"
+ " --wp-status \tGet the current HW and SW WP state.\n"
+ " [--ignore-hw] \tGet SW WP state only.\n"
+ " --wp-enable \tEnable protection for the RO image section.\n"
+ " --wp-disable \tDisable all write protection.\n"
+ " --flash-size \tGet flash size.\n"
+ " --flash-info \tGet flash info.\n"
"\n"
SHARED_FLASH_ARGS_HELP,
argv[0]);
@@ -178,6 +184,7 @@ static int do_flash(int argc, char *argv[])
bool enable_wp = false;
bool disable_wp = false;
bool get_wp_status = false;
+ bool ignore_hw_wp = false;
bool get_size = false;
bool get_info = false;
@@ -196,6 +203,9 @@ static int do_flash(int argc, char *argv[])
case 's':
get_wp_status = true;
break;
+ case 'o':
+ ignore_hw_wp = true;
+ break;
case 'e':
enable_wp = true;
break;
@@ -236,6 +246,12 @@ static int do_flash(int argc, char *argv[])
goto out_free;
}
+ if (!get_wp_status && ignore_hw_wp) {
+ ret = -1;
+ ERROR("--ignore-hw must be used with --wp-status.\n");
+ goto out_free;
+ }
+
if (enable_wp && disable_wp) {
ret = -1;
ERROR("--wp-enable and --wp-disable cannot be used together.\n");
@@ -271,7 +287,7 @@ static int do_flash(int argc, char *argv[])
ret = set_flash_wp(cfg, false);
if (!ret && get_wp_status)
- ret = print_wp_status(cfg);
+ ret = print_wp_status(cfg, ignore_hw_wp);
out_free:
prepare_servo_control(prepare_ctrl_name, 0);
diff --git a/tests/futility/test_flash_util.sh b/tests/futility/test_flash_util.sh
index e18a35cb..6af3e499 100755
--- a/tests/futility/test_flash_util.sh
+++ b/tests/futility/test_flash_util.sh
@@ -18,7 +18,7 @@ flash_size=$("${FUTILITY}" flash --flash-size -p "${TEST_PROG}")
[ "${flash_size}" = "Flash size: 0x00800000" ]
# Test WP status (VARIABLE_SIZE always has WP disabled)
-wp_status=$("${FUTILITY}" flash --wp-status -p "${TEST_PROG}")
+wp_status=$("${FUTILITY}" flash --wp-status --ignore-hw -p "${TEST_PROG}")
[ "${wp_status}" = "WP status: disabled" ]
# Cleanup