summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-09-06 15:58:44 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-02 11:32:35 +0000
commit4f71afc84acc79f137ee086220743c3c42096f90 (patch)
tree36932a50fe1a7be15383804c4f82ff091b46b57b /util
parent63f8741f4605b163c06a3629da890c12051c3d7f (diff)
downloadchrome-ec-4f71afc84acc79f137ee086220743c3c42096f90.tar.gz
fpsensor: Add async FP_CMD_CONTEXT
Setting the context now triggers a reset of the sensor library (see I3e25bdf7eaaf99f3801547e11a6c524f924f4726), which in turn will end up calling fp_sensor_open to re-initialize the sensor. Since some calibration is performed in that command, it takes ~173 ms, which is close enough to the EC command timeout (200 ms) that it often fails. This change makes the command "asynchronous" so that userspace can poll for the result and avoid the command timeout. BRANCH=nocturne BUG=b:137288498 TEST=make buildall -j TEST=ectool --name=cros_fp fpcontext 01234567890123456789012345678901 Change-Id: I997bf9c5b9e90eceb5375dccffcb535529a86e47 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819115 Reviewed-by: Yicheng Li <yichengli@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/ectool.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 6ca7cfcf8f..d73dd770ee 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -142,6 +142,8 @@ const char help_str[] =
" Writes to EC flash from a file\n"
" forcelidopen <enable>\n"
" Forces the lid switch to open position\n"
+ " fpcontext\n"
+ " Sets the fingerprint sensor context\n"
" fpencstatus\n"
" Prints status of Fingerprint sensor encryption engine\n"
" fpframe\n"
@@ -1726,6 +1728,58 @@ static void print_fp_enc_flags(const char *desc, uint32_t flags)
printf("\n");
}
+static int cmd_fp_context(int argc, char *argv[])
+{
+ struct ec_params_fp_context_v1 p;
+ int rv;
+ int tries = 20; /* Wait at most two seconds */
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <context>\n", argv[0]);
+ return -1;
+ }
+
+ /*
+ * Note that we treat the resulting "userid" as raw byte array, so we
+ * don't want to copy the NUL from the end of the string.
+ */
+ if (strlen(argv[1]) != sizeof(p.userid)) {
+ fprintf(stderr, "Context must be exactly %zu bytes\n",
+ sizeof(p.userid));
+ return -1;
+ }
+
+ p.action = FP_CONTEXT_ASYNC;
+ memcpy(p.userid, argv[1], sizeof(p.userid));
+
+ rv = ec_command(EC_CMD_FP_CONTEXT, 1, &p, sizeof(p), NULL, 0);
+
+ if (rv != EC_RES_SUCCESS)
+ goto out;
+
+ while (tries--) {
+ usleep(100000);
+
+ p.action = FP_CONTEXT_GET_RESULT;
+ rv = ec_command(EC_CMD_FP_CONTEXT, 1, &p, sizeof(p), NULL, 0);
+
+ if (rv == EC_RES_SUCCESS) {
+ printf("Set context successfully\n");
+ return EC_RES_SUCCESS;
+ }
+
+ /* Abort if EC returns an error other than EC_RES_BUSY. */
+ if (rv <= -EECRESULT && rv != -EECRESULT - EC_RES_BUSY)
+ goto out;
+ }
+
+ rv = -EECRESULT - EC_RES_TIMEOUT;
+
+out:
+ fprintf(stderr, "Failed to reset context: %d\n", rv);
+ return rv;
+}
+
int cmd_fp_enc_status(int argc, char *argv[])
{
int rv;
@@ -9008,6 +9062,7 @@ const struct command commands[] = {
{"flashspiinfo", cmd_flash_spi_info},
{"flashpd", cmd_flash_pd},
{"forcelidopen", cmd_force_lid_open},
+ {"fpcontext", cmd_fp_context},
{"fpencstatus", cmd_fp_enc_status},
{"fpframe", cmd_fp_frame},
{"fpinfo", cmd_fp_info},