summaryrefslogtreecommitdiff
path: root/common/fpsensor
diff options
context:
space:
mode:
authorJosie Nordrum <josienordrum@google.com>2023-01-26 15:39:21 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-27 23:51:29 +0000
commit7118dc91b19011daed14b1a77e5276a57fc855fe (patch)
tree1d082f54ddba5867086c9deafcf907a9f4c6e08b /common/fpsensor
parent8a4e2e2c3e1255eda5c239859f2348d93873dd34 (diff)
downloadchrome-ec-7118dc91b19011daed14b1a77e5276a57fc855fe.tar.gz
fpmcu: Add commands to transfer image from/to FPMCU
Add host commands to transfer the image from host to FPMCU (fpupload) and vice-versa (fpdownload). These commands operate directly on the image buffer. BUG=b:267312024 TEST=test with python script BRANCH=None Signed-off-by: Josie Nordrum <josienordrum@google.com> Change-Id: Iab1cae55c3779b71da7fd2a92ec4ea56d17ec203 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4198450 Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'common/fpsensor')
-rw-r--r--common/fpsensor/fpsensor.cc59
1 files changed, 58 insertions, 1 deletions
diff --git a/common/fpsensor/fpsensor.cc b/common/fpsensor/fpsensor.cc
index fa20f42e1f..4b67fb5260 100644
--- a/common/fpsensor/fpsensor.cc
+++ b/common/fpsensor/fpsensor.cc
@@ -2,7 +2,6 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
#include "compile_time_macros.h"
extern "C" {
@@ -810,6 +809,64 @@ DECLARE_CONSOLE_COMMAND_FLAGS(fpcapture, command_fpcapture, NULL,
"Capture fingerprint in PGM format",
CMD_FLAG_RESTRICTED);
+/* Transfer a chunk of the image from the host to the FPMCU
+ *
+ * Command format:
+ * fpupload <offset> <hex encoded pixel string>
+ *
+ * To limit the size of the commands, only a chunk of the image is sent for
+ * each command invocation.
+ */
+static int command_fpupload(int argc, const char **argv)
+{
+ const char *pixels_str;
+ uint8_t *dest;
+ int offset;
+
+ if (argc != 3)
+ return EC_ERROR_PARAM1;
+ if (system_is_locked())
+ return EC_ERROR_ACCESS_DENIED;
+ offset = atoi(argv[1]);
+ if (offset < 0)
+ return EC_ERROR_PARAM1;
+ dest = fp_buffer + FP_SENSOR_IMAGE_OFFSET + offset;
+
+ pixels_str = argv[2];
+ while (*pixels_str) {
+ if (dest >= fp_buffer + FP_SENSOR_IMAGE_SIZE)
+ return EC_ERROR_PARAM1;
+ char hex_str[] = { pixels_str[0], pixels_str[1], '\0' };
+ *dest = static_cast<uint8_t>(strtol(hex_str, NULL, 16));
+ pixels_str += 2;
+ ++dest;
+ }
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fpupload, command_fpupload, NULL,
+ "Copy fp image onto fpmcu fpsensor buffer");
+
+/* Transfer an image from the FPMCU to the host
+ *
+ * Command format:
+ * fpdownload
+ *
+ * This is useful to verify the data was transferred correctly. Note that it
+ * requires the terminal to be configured as explained in the comment above
+ * upload_pgm_image().
+ */
+static int command_fpdownload(int argc, const char **argv)
+{
+ if (system_is_locked())
+ return EC_ERROR_ACCESS_DENIED;
+
+ upload_pgm_image(fp_buffer + FP_SENSOR_IMAGE_OFFSET);
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fpdownload, command_fpdownload, NULL,
+ "Copy fp image from fpmcu fpsensor buffer");
+
static int command_fpenroll(int argc, const char **argv)
{
enum ec_error_list rc;