From ea1f2d28c3618556cb6d18032eafd15f2d215a6f Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Fri, 17 May 2019 10:54:50 -0700 Subject: gsctool: add ability to get/set flash log timestamp base The recently introduced vendor command is used to get or set flash log timestamp. BRANCH=none BUG=b:132287488 TEST=on the device ran various incarnations of the command (> prompt on the Cr50 console, # is the DUT bash): > flo 10 10 > flo 1:00 13:0a 0a 0b 0c 0d 0e 0f 10 11 12 13 ==== afger a few seconds ===== # /var/tmp/gsctool -a -T Current H1 time is 68 ==== afger some more time ===== > flo 5 5 > flo 1:00 13:0a 0a 0b 0c 0d 0e 0f 10 11 12 13 398:05 05 06 07 08 09 # /var/tmp/gsctool -a -T 300 error: return value 1 # /var/tmp/gsctool -a -T 1000000 > flo 6 6 > flo 1:00 13:0a 0a 0b 0c 0d 0e 0f 10 11 12 13 398:05 05 06 07 08 09 1000022:06 06 07 08 09 0a 0b # /var/tmp/gsctool -a -T Current H1 time is 1000052 Change-Id: I16ceb97a32b4d452705f9df3826151f3e4e45832 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/1610721 Legacy-Commit-Queue: Commit Bot Reviewed-by: Andrey Pronin --- extra/usb_updater/gsctool.c | 59 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'extra') diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index 929a0524ac..ffa9a8d32b 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -2282,7 +2282,7 @@ static int process_get_flog(struct transfer_descriptor *td, uint32_t prev_stamp) size_t i; memcpy(&prev_stamp, &entry.r.timestamp, sizeof(prev_stamp)); - printf("%08x:%02x", prev_stamp, entry.r.type); + printf("%10u:%02x", prev_stamp, entry.r.type); for (i = 0; i < FLASH_LOG_PAYLOAD_SIZE(entry.r.size); i++) printf(" %02x", entry.r.payload[i]); printf("\n"); @@ -2293,6 +2293,53 @@ static int process_get_flog(struct transfer_descriptor *td, uint32_t prev_stamp) return 0; } +static int process_tstamp(struct transfer_descriptor *td, + const char *tstamp_ascii) +{ + char *e; + size_t expected_response_size; + size_t message_size; + size_t response_size; + uint32_t rv; + uint32_t tstamp = 0; + uint8_t max_response[sizeof(uint32_t)]; + + if (tstamp_ascii) { + tstamp = strtoul(tstamp_ascii, &e, 10); + if (*e) { + fprintf(stderr, "invalid base timestamp value \"%s\"\n", + tstamp_ascii); + return -1; + } + tstamp = htobe32(tstamp); + expected_response_size = 0; + message_size = sizeof(tstamp); + } else { + expected_response_size = 4; + message_size = 0; + } + + response_size = sizeof(max_response); + rv = send_vendor_command(td, VENDOR_CC_FLOG_TIMESTAMP, &tstamp, + message_size, max_response, &response_size); + + if (rv) { + fprintf(stderr, "error: return value %d\n", rv); + return rv; + } + if (response_size != expected_response_size) { + fprintf(stderr, "error: got %zd bytes, expected %zd\n", + response_size, expected_response_size); + return -1; /* Should never happen. */ + } + + if (response_size) { + memcpy(&tstamp, max_response, sizeof(tstamp)); + printf("Current H1 time is %d\n", be32toh(tstamp)); + } + return 0; +} + /* * Search the passed in zero terminated array of options_map structures for * option 'option'. @@ -2444,6 +2491,8 @@ int main(int argc, char *argv[]) int try_all_transfer = 0; int tpm_mode = 0; bool show_machine_output = false; + int tstamp = 0; + const char *tstamp_arg = NULL; const char *exclusive_opt_error = "Options -a, -s and -t are mutually exclusive\n"; @@ -2595,6 +2644,10 @@ int main(int argc, char *argv[]) } td.ep_type = ts_xfer; break; + case 'T': + tstamp = 1; + tstamp_arg = optarg; + break; case 'v': report_version(); /* This will call exit(). */ break; @@ -2647,6 +2700,7 @@ int main(int argc, char *argv[]) !sn_bits && !sn_inc_rma && !openbox_desc_file && + !tstamp && !tpm_mode && !wp) { if (optind >= argc) { @@ -2729,6 +2783,9 @@ int main(int argc, char *argv[]) exit(rv); } + if (tstamp) + return process_tstamp(&td, tstamp_arg); + if (sn_bits) process_sn_bits(&td, sn_bits_arg); -- cgit v1.2.1