summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-10-16 15:05:25 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-17 13:02:50 -0700
commit9f68af75f6a99134cd03067379d0c1f6a571fe4f (patch)
tree90c8afe50736e4681975946137a3106df75923bd /extra
parente63e0515e46b8799b33a8a034dafef26e3246cc9 (diff)
downloadchrome-ec-9f68af75f6a99134cd03067379d0c1f6a571fe4f.tar.gz
gsctool: allow to pass optional value for --rma
It would be much easier to use the --rma command line option if it allowed to pass the authentication code in a separate invocation. This patch changes the behavior of the --rma command line option and improves the help message to match actual features of gsctool. When passed without an extra parameter it requests the Cr50 to generate the RMA authentication challenge, prints the challenge on the console as before, and then exits instead of waiting for the user to enter the authentication code. When the extra parameter is given, it is considered the authentication code received from the server, the code is passed to the Cr50 and the response is reported to the user. BRANCH=none BUG=b:37952913 TEST=verified the expected behavior: localhost tmp # ./gsctool -r -t Challenge: CCYAQ 5ZUDP 9Q8NY S7TQR 7PVUR ETX7P T5YQK NGV9S 7TY8Z QY7H5 5DEH3 5EEWY UBJPA WN7YX SE35G TPS76 localhost tmp # ./gsctool -t -r EYE3E Processing response... rma unlock failed, code 1 localhost tmp # echo $? 3 localhost tmp # ./gsctool -t -r EYE3EWQG Processing response...RMA unlock succeeded. localhost tmp # echo $? 0 localhost tmp # Change-Id: I2c61ff3a3ef1718eb4f192321bebd8caba388aeb Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/722115
Diffstat (limited to 'extra')
-rw-r--r--extra/usb_updater/gsctool.c104
1 files changed, 59 insertions, 45 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c
index 4a271c23cb..f3ade1c4d7 100644
--- a/extra/usb_updater/gsctool.c
+++ b/extra/usb_updater/gsctool.c
@@ -247,7 +247,7 @@ static const struct option long_opts[] = {
{"fwver", 0, NULL, 'f'},
{"help", 0, NULL, 'h'},
{"post_reset", 0, NULL, 'p'},
- {"rma_auth", 0, NULL, 'r'},
+ {"rma_auth", 2, NULL, 'r'},
{"systemdev", 0, NULL, 's'},
{"trunks_send", 0, NULL, 't'},
{"upstart", 0, NULL, 'u'},
@@ -521,25 +521,32 @@ static void shut_down(struct usb_endpoint *uep)
static void usage(int errs)
{
- printf("\nUsage: %s [options] <binary image>\n"
+ printf("\nUsage: %s [options] [<binary image>]\n"
"\n"
- "This updates the Cr50 RW firmware over USB.\n"
- "The required argument is the full RO+RW image.\n"
+ "This utility allows to update Cr50 RW firmware, configure\n"
+ "various aspects of Cr50 operation, analyze Cr50 binary\n"
+ "images, etc.\n"
+ "The required argument is the file name of a full RO+RW\n"
+ "binary image.\n"
+ "A typical Chromebook use would exepect -s -t options\n"
+ "included in the command line.\n"
"\n"
"Options:\n"
"\n"
" -b,--binvers Report versions of image's "
"RW and RO headers, do not update\n"
- " -c,--corrupt Corrupt the inactive rw.\n"
+ " -c,--corrupt Corrupt the inactive rw\n"
" -d,--device VID:PID USB device (default %04x:%04x)\n"
- " -f,--fwver Report running firmware versions.\n"
+ " -f,--fwver Report running firmware versions\n"
" -h,--help Show this message\n"
" -i,--board_id [ID[:FLAGS]]\n"
- " Get or set Info1 board ID fields.\n"
+ " Get or set Info1 board ID fields\n"
" ID could be 32 bit hex or 4 "
"character string.\n"
" -p,--post_reset Request post reset after transfer\n"
- " -r,--rma_auth Process RMA challenge-response\n"
+ " -r,--rma_auth [auth_code]\n"
+ " Request RMA challenge or process "
+ "RMA authentication code\n"
" -s,--systemdev Use /dev/tpm0 (-d is ignored)\n"
" -t,--trunks_send Use `trunks_send --raw' "
"(-d is ignored)\n"
@@ -1591,52 +1598,53 @@ static void process_bid(struct transfer_descriptor *td,
* and send the code back to Cr50. The Cr50 would report if the code matched
* its expectations or not.
*/
-static void process_rma(struct transfer_descriptor *td)
+static void process_rma(struct transfer_descriptor *td, const char *authcode)
{
char rma_response[81];
size_t response_size = sizeof(rma_response);
size_t i;
- char *authcode = NULL;
size_t auth_size = 0;
- send_vendor_command(td, VENDOR_CC_RMA_CHALLENGE_RESPONSE,
- NULL, 0, rma_response, &response_size);
-
- if (response_size == 1) {
- printf("error %d\n", rma_response[0]);
- if (td->ep_type == usb_xfer)
- shut_down(&td->uep);
- exit(update_error);
- }
-
- printf("Challenge:");
- for (i = 0; i < response_size; i++) {
- if (!(i % 5)) {
- if (!(i % 40))
- printf("\n");
- printf(" ");
- }
- printf("%c", rma_response[i]);
- }
- printf("\nNow enter response: ");
- auth_size = getline(&authcode, &auth_size, stdin);
- if (auth_size > 0) {
-
- response_size = sizeof(rma_response);
-
+ if (!authcode) {
send_vendor_command(td, VENDOR_CC_RMA_CHALLENGE_RESPONSE,
- authcode, auth_size - 1, /* drop the '\n' */
- rma_response, &response_size);
+ NULL, 0, rma_response, &response_size);
if (response_size == 1) {
- printf("\nrma unlock failed, code %d\n",
- *rma_response);
+ printf("error %d\n", rma_response[0]);
if (td->ep_type == usb_xfer)
shut_down(&td->uep);
exit(update_error);
}
- printf("RMA unlock succeeded.\n");
+
+ printf("Challenge:");
+ for (i = 0; i < response_size; i++) {
+ if (!(i % 5)) {
+ if (!(i % 40))
+ printf("\n");
+ printf(" ");
+ }
+ printf("%c", rma_response[i]);
+ }
+ printf("\n");
+ return;
}
+
+ printf("Processing response...");
+ auth_size = strlen(authcode);
+ response_size = sizeof(rma_response);
+
+ send_vendor_command(td, VENDOR_CC_RMA_CHALLENGE_RESPONSE,
+ authcode, auth_size,
+ rma_response, &response_size);
+
+ if (response_size == 1) {
+ printf("\nrma unlock failed, code %d\n",
+ *rma_response);
+ if (td->ep_type == usb_xfer)
+ shut_down(&td->uep);
+ exit(update_error);
+ }
+ printf("RMA unlock succeeded.\n");
}
int main(int argc, char *argv[])
@@ -1652,6 +1660,7 @@ int main(int argc, char *argv[])
int binary_vers = 0;
int show_fw_ver = 0;
int rma = 0;
+ const char *rma_auth_code;
int corrupt_inactive_rw = 0;
struct board_id bid;
enum board_id_action bid_action;
@@ -1691,11 +1700,10 @@ int main(int argc, char *argv[])
usage(errorcnt);
break;
case 'i':
- if (!optarg && argv[optind] && argv[optind][0] != '-') {
+ if (!optarg && argv[optind] && argv[optind][0] != '-')
/* optional argument present. */
- optarg = argv[optind];
- optind++;
- }
+ optarg = argv[optind++];
+
if (!parse_bid(optarg, &bid, &bid_action)) {
printf("Invalid board id argument: \"%s\"\n",
optarg);
@@ -1704,6 +1712,12 @@ int main(int argc, char *argv[])
break;
case 'r':
rma = 1;
+
+ if (!optarg && argv[optind] && argv[optind][0] != '-')
+ /* optional argument present. */
+ optarg = argv[optind++];
+
+ rma_auth_code = optarg;
break;
case 's':
td.ep_type = dev_xfer;
@@ -1782,7 +1796,7 @@ int main(int argc, char *argv[])
process_bid(&td, bid_action, &bid);
if (rma)
- process_rma(&td);
+ process_rma(&td, rma_auth_code);
if (corrupt_inactive_rw)
invalidate_inactive_rw(&td);