diff options
author | Brian Granaghan <granaghan@google.com> | 2023-04-05 20:20:43 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-05 11:59:07 +0000 |
commit | 0985905e094b822d6ac8e8ddc621007fed9a41db (patch) | |
tree | ee0b3ab0c5eb2a05caee25eb503cb35a79ccc6f8 | |
parent | ab6783815867275152e9fef03f3567426aabdf7d (diff) | |
download | chrome-ec-0985905e094b822d6ac8e8ddc621007fed9a41db.tar.gz |
gsctool: Add command to get or set factory config.
Add '--factory_config' command to get the factory config if optarg is not
provided and set it if one is provided.
BUG=b:275356839
TEST=localhost ~ # gsctool -a --factory_config
EEDDCCBBAA998877
Failed because already set:
localhost ~ # gsctool -a --factory_config 001122334455667788
Factory config failed. (7)
Successful set:
localhost ~ # gsctool -a --factory_config
0
localhost ~ # gsctool -a --factory_config 001122334455667788
localhost ~ # gsctool -a --factory_config
1122334455667788
Change-Id: I128e9871eb2aece3a9173c5a6e31c2ce5a4d3cd0
Signed-off-by: Brian Granaghan <granaghan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4404231
Commit-Queue: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
(cherry picked from commit 20ee1fabc83507d6fb5786441b22b8c4a0bfdfb9)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4507008
Reviewed-by: Cheng Yueh <cyueh@chromium.org>
Auto-Submit: Wei-Shuo Su <stevesu@google.com>
Tested-by: Wei-Shuo Su <stevesu@google.com>
Commit-Queue: Wei-Shuo Su <stevesu@google.com>
-rw-r--r-- | extra/usb_updater/gsctool.c | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index a000182e19..1ba96bb294 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -451,7 +451,10 @@ static const struct option_container cmd_line_options[] = { {{"version", no_argument, NULL, 'v'}, "Report this utility version"}, {{"wp", optional_argument, NULL, 'w'}, - "[enable] Get the current WP setting or enable WP"} + "[enable] Get the current WP setting or enable WP"}, + {{"factory_config", optional_argument, NULL, 'y'}, + "[value]%Sets the factory config bits in INFO. value should be 64 " + "bit hex."}, }; /* Helper to print debug messages when verbose flag is specified. */ @@ -3367,6 +3370,47 @@ static int getopt_all(int argc, char *argv[]) return i; } +static int process_get_factory_config(struct transfer_descriptor *td) +{ + uint32_t rv; + uint64_t response = 0; + size_t response_size = sizeof(response); + + rv = send_vendor_command(td, VENDOR_CC_GET_FACTORY_CONFIG, NULL, + 0, (uint8_t *) &response, &response_size); + if (rv != VENDOR_RC_SUCCESS) { + printf("Set factory config failed. (%X)\n", rv); + return 1; + } + + if (response_size < sizeof(uint64_t)) { + printf("Unexpected response size. (%zu)", response_size); + return 2; + } + + uint64_t out = be64toh(response); + + printf("%"PRIX64"\n", out); + return 0; +} + +static int process_set_factory_config(struct transfer_descriptor *td, + uint64_t val) +{ + uint64_t val_be = htobe64(val); + uint32_t rv; + + rv = send_vendor_command(td, VENDOR_CC_SET_FACTORY_CONFIG, &val_be, + sizeof(val_be), NULL, NULL); + if (rv != VENDOR_RC_SUCCESS) { + printf("Factory config failed. (%X)\n", rv); + return 1; + } + + return 0; +} + + int main(int argc, char *argv[]) { struct transfer_descriptor td; @@ -3418,6 +3462,9 @@ int main(int argc, char *argv[]) uint8_t sn_inc_rma_arg = 0; int erase_ap_ro_hash = 0; int is_dauntless = 0; + int factory_config = 0; + int set_factory_config = 0; + uint64_t factory_config_arg = 0; /* * All options which result in setting a Boolean flag to True, along @@ -3593,6 +3640,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "Illegal wp option \"%s\"\n", optarg); errorcnt++; break; + case 'y': + factory_config = 1; + if (optarg) { + set_factory_config = 1; + factory_config_arg = strtoull(optarg, NULL, 16); + } + break; case 0: /* auto-handled option */ break; case '?': @@ -3637,6 +3691,7 @@ int main(int argc, char *argv[]) !get_boot_mode && !get_flog && !get_endorsement_seed && + !factory_config && !factory_mode && !erase_ap_ro_hash && !password && @@ -3771,6 +3826,14 @@ int main(int argc, char *argv[]) if (erase_ap_ro_hash) process_erase_ap_ro_hash(&td); + if (factory_config) { + if (set_factory_config) + exit(process_set_factory_config(&td, + factory_config_arg)); + else + exit(process_get_factory_config(&td)); + } + if (data || show_fw_ver) { setup_connection(&td); |