summaryrefslogtreecommitdiff
path: root/common/host_command.c
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-21 14:08:36 -0700
committerTom Hughes <tomhughes@chromium.org>2022-09-22 12:59:38 -0700
commitc453fd704268ef72de871b0c5ac7a989de662334 (patch)
treefcf6ce5810f9ff9e3c8cce434812dd75492269ed /common/host_command.c
parent6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff)
parent28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff)
downloadchrome-ec-firmware-fpmcu-dartmonkey-release.tar.gz
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release Relevant changes: git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint util/getversion.sh ded9307b79 util/getversion.sh: Fix version when not in a git repo 956055e692 board: change Google USB vendor info 71b2ef709d Update license boilerplate text in source code files 33e11afda0 Revert "fpsensor: Build fpsensor source file with C++" c8d0360723 fpsensor: Build fpsensor source file with C++ bc113abd53 fpsensor: Fix g++ compiler error 150a58a0dc fpsensor: Fix fp_set_sensor_mode return type b33b5ce85b fpsensor: Remove nested designators for C++ compatibility 2e864b2539 tree-wide: const-ify argv for console commands 56d8b360f9 test: Add test for get ikm failure when seed not set 3a3d6c3690 test: Add test for fpsensor trivial key failure 233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256 0a041b285b docs/fingerprint: Typo correction c03fab67e2 docs/fingerprint: Fix the path of fputils.py 0b5d4baf5a util/getversion.sh: Fix empty file list handling 6e128fe760 FPMCU dev board environment with Satlab 3eb29b6aa5 builtin: Move ssize_t to sys/types.h 345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release c25ffdb316 common: Conditionally support printf %l and %i modifiers 9a3c514b45 test: Add a test to check if the debugger is connected 54e603413f Move standard library tests to their own file 43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release 25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format 4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format 738de2b575 trng: Rename rand to trng_rand 14b8270edd docs/fingerprint: Update dragonclaw power numbers 0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format 5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format 6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format 58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format 7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format 21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format 98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format 84e53a65da board/nocturne_fp/board.h: Format with clang-format 73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format 0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format 1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format dca9d74321 Revert "trng: Rename rand to trng_rand" a6b0b3554f trng: Rename rand to trng_rand 28d0b75b70 third_party/boringssl: Remove unused header BRANCH=None BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294 BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908 BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010 BUG=b:246424843 b:234181908 b:131913998 TEST=`make -j buildall` TEST=./util/run_device_tests.py --board dartmonkey Test "aes": PASSED Test "cec": PASSED Test "cortexm_fpu": PASSED Test "crc": PASSED Test "flash_physical": PASSED Test "flash_write_protect": PASSED Test "fpsensor_hw": PASSED Test "fpsensor_spi_ro": PASSED Test "fpsensor_spi_rw": PASSED Test "fpsensor_uart_ro": PASSED Test "fpsensor_uart_rw": PASSED Test "mpu_ro": PASSED Test "mpu_rw": PASSED Test "mutex": PASSED Test "pingpong": PASSED Test "printf": PASSED Test "queue": PASSED Test "rollback_region0": PASSED Test "rollback_region1": PASSED Test "rollback_entropy": PASSED Test "rtc": PASSED Test "sha256": PASSED Test "sha256_unrolled": PASSED Test "static_if": PASSED Test "stdlib": PASSED Test "system_is_locked_wp_on": PASSED Test "system_is_locked_wp_off": PASSED Test "timer_dos": PASSED Test "utils": PASSED Test "utils_str": PASSED Test "panic_data_dartmonkey_v2.0.2887": PASSED Test "panic_data_nocturne_fp_v2.2.64": PASSED Test "panic_data_nami_fp_v2.2.144": PASSED Force-Relevant-Builds: all Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'common/host_command.c')
-rw-r--r--common/host_command.c128
1 files changed, 66 insertions, 62 deletions
diff --git a/common/host_command.c b/common/host_command.c
index e05475ce48..89a835a1aa 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,12 +6,14 @@
/* Host command module for Chrome EC */
#include "ap_hang_detect.h"
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "ec_commands.h"
#include "host_command.h"
#include "link_defs.h"
#include "lpc.h"
+#include "printf.h"
#include "shared_mem.h"
#include "system.h"
#include "task.h"
@@ -20,8 +22,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_HOSTCMD, outstr)
-#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ##args)
#define TASK_EVENT_CMD_PENDING TASK_EVENT_CUSTOM_BIT(0)
@@ -42,18 +44,19 @@ static uint8_t host_memmap[EC_MEMMAP_SIZE] __aligned(4);
#endif
static enum {
- HCDEBUG_OFF, /* No host command debug output */
- HCDEBUG_NORMAL, /* Normal output mode; skips repeated commands */
- HCDEBUG_EVERY, /* Print every command */
- HCDEBUG_PARAMS, /* ... and print params for request/response */
+ HCDEBUG_OFF, /* No host command debug output */
+ HCDEBUG_NORMAL, /* Normal output mode; skips repeated commands */
+ HCDEBUG_EVERY, /* Print every command */
+ HCDEBUG_PARAMS, /* ... and print params for request/response */
/* Number of host command debug modes */
HCDEBUG_MODES
} hcdebug = CONFIG_HOSTCMD_DEBUG_MODE;
#ifdef CONFIG_CMD_HCDEBUG
-static const char * const hcdebug_mode_names[HCDEBUG_MODES] = {
- "off", "normal", "every", "params"};
+static const char *const hcdebug_mode_names[HCDEBUG_MODES] = { "off", "normal",
+ "every",
+ "params" };
#endif
#ifdef CONFIG_HOST_COMMAND_STATUS
@@ -343,8 +346,8 @@ void host_packet_receive(struct host_packet *pkt)
args0.version = r->command_version;
args0.params_size = r->data_len;
args0.response = (struct ec_host_response *)(pkt->response) + 1;
- args0.response_max = pkt->response_max -
- sizeof(struct ec_host_response);
+ args0.response_max =
+ pkt->response_max - sizeof(struct ec_host_response);
args0.response_size = 0;
args0.result = EC_RES_SUCCESS;
@@ -440,7 +443,7 @@ void host_command_task(void *u)
/* Process it */
if ((evt & TASK_EVENT_CMD_PENDING) && pending_args) {
pending_args->result =
- host_command_process(pending_args);
+ host_command_process(pending_args);
host_send_response(pending_args);
}
@@ -473,8 +476,7 @@ host_command_proto_version(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION,
- host_command_proto_version,
+DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION, host_command_proto_version,
EC_VER_MASK(0));
static enum ec_status host_command_hello(struct host_cmd_handler_args *args)
@@ -488,9 +490,7 @@ static enum ec_status host_command_hello(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HELLO,
- host_command_hello,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_HELLO, host_command_hello, EC_VER_MASK(0));
static enum ec_status host_command_read_test(struct host_cmd_handler_args *args)
{
@@ -511,9 +511,7 @@ static enum ec_status host_command_read_test(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_READ_TEST,
- host_command_read_test,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_READ_TEST, host_command_read_test, EC_VER_MASK(0));
#ifndef CONFIG_HOSTCMD_X86
/*
@@ -543,8 +541,7 @@ host_command_read_memmap(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP,
- host_command_read_memmap,
+DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP, host_command_read_memmap,
EC_VER_MASK(0));
#endif
@@ -555,9 +552,9 @@ host_command_get_cmd_versions(struct host_cmd_handler_args *args)
const struct ec_params_get_cmd_versions_v1 *p_v1 = args->params;
struct ec_response_get_cmd_versions *r = args->response;
- const struct host_command *cmd =
- (args->version == 1) ? find_host_command(p_v1->cmd) :
- find_host_command(p->cmd);
+ const struct host_command *cmd = (args->version == 1) ?
+ find_host_command(p_v1->cmd) :
+ find_host_command(p->cmd);
if (!cmd)
return EC_RES_INVALID_PARAM;
@@ -568,8 +565,7 @@ host_command_get_cmd_versions(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS,
- host_command_get_cmd_versions,
+DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS, host_command_get_cmd_versions,
EC_VER_MASK(0) | EC_VER_MASK(1));
static int host_command_is_suppressed(uint16_t cmd)
@@ -594,11 +590,13 @@ static void dump_host_command_suppressed(int force)
{
#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
int i;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
return;
- CPRINTF("[%pT HC Suppressed:", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s HC Suppressed:", ts_str);
for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
CPRINTF(" 0x%x=%d", hc_suppressed_cmd[i], hc_suppressed_cnt[i]);
hc_suppressed_cnt[i] = 0;
@@ -614,10 +612,9 @@ static void dump_host_command_suppressed_(void)
{
dump_host_command_suppressed(1);
}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
- dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_SYSJUMP,
- dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, dump_host_command_suppressed_,
+ HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_SYSJUMP, dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
#else
}
#endif /* CONFIG_SUPPRESSED_HOST_COMMANDS */
@@ -659,11 +656,14 @@ static void host_command_debug_request(struct host_cmd_handler_args *args)
hc_prev_cmd = args->command;
}
- if (hcdebug >= HCDEBUG_PARAMS && args->params_size)
- CPRINTS("HC 0x%04x.%d:%ph", args->command,
- args->version,
- HEX_BUF(args->params, args->params_size));
- else
+ if (hcdebug >= HCDEBUG_PARAMS && args->params_size) {
+ char str_buf[hex_str_buf_size(args->params_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(args->params, args->params_size));
+ CPRINTS("HC 0x%04x.%d:%s", args->command, args->version,
+ str_buf);
+ } else
CPRINTS("HC 0x%04x", args->command);
}
@@ -693,9 +693,9 @@ uint16_t host_command_process(struct host_cmd_handler_args *args)
if (args->command >= EC_CMD_PASSTHRU_OFFSET(1) &&
args->command <= EC_CMD_PASSTHRU_MAX(1)) {
rv = pd_host_command(args->command - EC_CMD_PASSTHRU_OFFSET(1),
- args->version,
- args->params, args->params_size,
- args->response, args->response_max);
+ args->version, args->params,
+ args->params_size, args->response,
+ args->response_max);
if (rv >= 0) {
/* Success; store actual response size */
args->response_size = rv;
@@ -719,9 +719,14 @@ uint16_t host_command_process(struct host_cmd_handler_args *args)
if (rv != EC_RES_SUCCESS)
CPRINTS("HC 0x%04x err %d", args->command, rv);
- if (hcdebug >= HCDEBUG_PARAMS && args->response_size)
- CPRINTS("HC resp:%ph",
- HEX_BUF(args->response, args->response_size));
+ if (hcdebug >= HCDEBUG_PARAMS && args->response_size) {
+ char str_buf[hex_str_buf_size(args->response_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(args->response,
+ args->response_size));
+ CPRINTS("HC resp:%s", str_buf);
+ }
return rv;
}
@@ -739,8 +744,7 @@ host_command_get_comms_status(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_COMMS_STATUS,
- host_command_get_comms_status,
+DECLARE_HOST_COMMAND(EC_CMD_GET_COMMS_STATUS, host_command_get_comms_status,
EC_VER_MASK(0));
/* Resend the last saved response */
@@ -756,8 +760,7 @@ host_command_resend_response(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE,
- host_command_resend_response,
+DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE, host_command_resend_response,
EC_VER_MASK(0));
#endif /* CONFIG_HOST_COMMAND_STATUS */
@@ -775,8 +778,7 @@ host_command_test_protocol(struct host_cmd_handler_args *args)
return p->ec_result;
}
-DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL,
- host_command_test_protocol,
+DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, host_command_test_protocol,
EC_VER_MASK(0));
/* Returns supported features. */
@@ -791,16 +793,14 @@ host_command_get_features(struct host_cmd_handler_args *args)
r->flags[1] = get_feature_flags1();
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_FEATURES,
- host_command_get_features,
+DECLARE_HOST_COMMAND(EC_CMD_GET_FEATURES, host_command_get_features,
EC_VER_MASK(0));
-
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_HOSTCMD
-static int parse_byte(char *b, uint8_t *out)
+static int parse_byte(const char *b, uint8_t *out)
{
int i;
*out = 0;
@@ -819,7 +819,7 @@ static int parse_byte(char *b, uint8_t *out)
return EC_SUCCESS;
}
-static int parse_params(char *s, uint8_t *params)
+static int parse_params(const char *s, uint8_t *params)
{
int len = 0;
@@ -833,7 +833,7 @@ static int parse_params(char *s, uint8_t *params)
return len;
}
-static int command_host_command(int argc, char **argv)
+static int command_host_command(int argc, const char **argv)
{
struct host_cmd_handler_args args;
char *cmd_params;
@@ -888,23 +888,27 @@ static int command_host_command(int argc, char **argv)
if (res != EC_RES_SUCCESS)
ccprintf("Command returned %d\n", res);
- else if (args.response_size)
- ccprintf("Response: %ph\n",
- HEX_BUF(cmd_params, args.response_size));
- else
+ else if (args.response_size) {
+ char str_buf[hex_str_buf_size(args.response_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(cmd_params, args.response_size));
+ ccprintf("Response: %s\n", str_buf);
+ } else
ccprintf("Command succeeded; no response.\n");
shared_mem_release(cmd_params);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hostcmd, command_host_command,
- "cmd ver param",
+DECLARE_CONSOLE_COMMAND(hostcmd, command_host_command, "cmd ver param",
"Fake host command");
#endif /* CONFIG_CMD_HOSTCMD */
#ifdef CONFIG_CMD_HCDEBUG
-static int command_hcdebug(int argc, char **argv)
+static int command_hcdebug(int argc, const char **argv)
{
+ if (argc >= 3)
+ return EC_ERROR_PARAM_COUNT;
if (argc > 1) {
int i;