summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2020-04-14 11:51:07 -0700
committerCommit Bot <commit-bot@chromium.org>2020-04-14 23:32:08 +0000
commit1a4b4c25245222e546c43f1411bf60e102397a69 (patch)
treee5117437aa06ba4253c7f04b8dda0a53e51b8160
parent5b5a4485101120cfac3739caa7da4ba8fae884cc (diff)
downloadchrome-ec-1a4b4c25245222e546c43f1411bf60e102397a69.tar.gz
gsctool: supprot enabling write protection (WP)
This patch makes use of the modification of the vendor command VENDOR_CC_WP, which allows to enable WP. BUG=b:153881773 TEST=verified that attempts to enable WP when running the unmodified Cr50 image fail with error message "Early Cr50 versions do not support setting WP", and that the updated Cr50 image allows to enable WP using 'gsctool -a -w enable' Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: Ie28c1c9b171dd6ea2e3edc0ae624f953cb4fa4fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2149526 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--extra/usb_updater/gsctool.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c
index a65bd909eb..74c4a1b5fc 100644
--- a/extra/usb_updater/gsctool.c
+++ b/extra/usb_updater/gsctool.c
@@ -321,8 +321,8 @@ static const struct option_container cmd_line_options[] = {
"Enable debug messages"},
{{"version", no_argument, NULL, 'v'},
"Report this utility version"},
- {{"wp", no_argument, NULL, 'w'},
- "Get the current wp setting"}
+ {{"wp", optional_argument, NULL, 'w'},
+ "[enable] Get the current WP setting or enable WP"}
};
/* Helper to print debug messages when verbose flag is specified. */
@@ -1972,7 +1972,7 @@ static void process_ccd_state(struct transfer_descriptor *td, int ccd_unlock,
poll_for_pp(td, VENDOR_CC_CCD, CCDV_PP_POLL_OPEN);
}
-static void process_wp(struct transfer_descriptor *td)
+static void process_wp(struct transfer_descriptor *td, enum wp_options wp)
{
size_t response_size;
uint8_t response;
@@ -1982,10 +1982,25 @@ static void process_wp(struct transfer_descriptor *td)
printf("Getting WP\n");
- rv = send_vendor_command(td, VENDOR_CC_WP, NULL, 0,
- &response, &response_size);
+ if (wp == WP_ENABLE) {
+ uint8_t command = WP_ENABLE;
+
+ rv = send_vendor_command(td, VENDOR_CC_WP, &command,
+ sizeof(command),
+ &response, &response_size);
+ } else {
+ rv = send_vendor_command(td, VENDOR_CC_WP, NULL, 0,
+ &response, &response_size);
+ }
+
if (rv != VENDOR_RC_SUCCESS) {
- fprintf(stderr, "Error %d getting write protect\n", rv);
+ fprintf(stderr, "Error %d %sting write protect\n",
+ rv, (wp == WP_ENABLE) ? "set" : "get");
+ if (wp == WP_ENABLE) {
+ fprintf(stderr,
+ "Early Cr50 versions do not support setting WP"
+ "\n");
+ }
exit(update_error);
}
if (response_size != sizeof(response)) {
@@ -2682,7 +2697,7 @@ int main(int argc, char *argv[])
int ccd_info = 0;
int get_flog = 0;
uint32_t prev_log_entry = 0;
- int wp = 0;
+ enum wp_options wp = WP_NONE;
int get_boot_mode = 0;
int try_all_transfer = 0;
int tpm_mode = 0;
@@ -2720,7 +2735,6 @@ int main(int argc, char *argv[])
{ 'U', &ccd_unlock },
{ 'u', &td.upstart_mode },
{ 'V', &verbose_mode },
- { 'w', &wp },
{},
};
@@ -2855,6 +2869,18 @@ int main(int argc, char *argv[])
case 'v':
report_version(); /* This will call exit(). */
break;
+ case 'w':
+ if (!optarg) {
+ wp = WP_CHECK;
+ break;
+ }
+ if (!strcasecmp(optarg, "enable")) {
+ wp = WP_ENABLE;
+ break;
+ }
+ fprintf(stderr, "Illegal wp option \"%s\"\n", optarg);
+ errorcnt++;
+ break;
case 0: /* auto-handled option */
break;
case '?':
@@ -2908,7 +2934,7 @@ int main(int argc, char *argv[])
!openbox_desc_file &&
!tstamp &&
!tpm_mode &&
- !wp) {
+ (wp == WP_NONE)) {
if (optind >= argc) {
fprintf(stderr,
"\nERROR: Missing required <binary image>\n\n");
@@ -2936,8 +2962,8 @@ int main(int argc, char *argv[])
if (((bid_action != bid_none) + !!rma + !!password + !!ccd_open +
!!ccd_unlock + !!ccd_lock + !!ccd_info + !!get_flog +
- !!get_boot_mode + !!openbox_desc_file + !!factory_mode + !!wp +
- !!get_endorsement_seed) > 1) {
+ !!get_boot_mode + !!openbox_desc_file + !!factory_mode +
+ (wp != WP_NONE) + !!get_endorsement_seed) > 1) {
fprintf(stderr,
"ERROR: options"
"-e, -F, -g, -I, -i, -k, -L, -O, -o, -P, -r, -U and -w "
@@ -2982,8 +3008,8 @@ int main(int argc, char *argv[])
if (factory_mode)
process_factory_mode(&td, factory_mode_arg);
- if (wp)
- process_wp(&td);
+ if (wp != WP_NONE)
+ process_wp(&td, wp);
if (corrupt_inactive_rw)
invalidate_inactive_rw(&td);