From aed008f87c3c880edecf7608ab24eaa4bee1bc46 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Wed, 2 Jan 2019 15:27:19 -0800 Subject: ectool: Don't acquire lock when dev interface is used The /dev/cros_ec interface has a built-in mutex, thus we do not need to use /run/lock to arbitrate access since we can assume other tools (mosys, flashrom) also use the dev interface. $ generate_logs ... feedback/cbi_info ... $ cat feedback/cbi_info [0] As integer: 1 (0x1) As binary: 01 02 [1] As integer: 3 (0x3) As binary: 03 [2] As integer: 103 (0x67) As binary: 67 3a Signed-off-by: Daisuke Nojiri BUG=chromium:849399 BRANCH=none TEST=Verify 'ectool version' runs on Nami. Verify lock is acquired when '--interface=lpc' is specified. Verify debugd can run cbi_info. Change-Id: Id94317472917a974218bb137bda11fe5618a4b88 Reviewed-on: https://chromium-review.googlesource.com/1393729 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Daisuke Nojiri Reviewed-by: Aseda Aboagye --- util/comm-host.c | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'util/comm-host.c') diff --git a/util/comm-host.c b/util/comm-host.c index e459bdfaa8..e9e7fb1f5f 100644 --- a/util/comm-host.c +++ b/util/comm-host.c @@ -82,10 +82,33 @@ int ec_command(int command, int version, indata, insize); } -int comm_init(int interfaces, const char *device_name) +int comm_init_alt(int interfaces, const char *device_name) +{ + if ((interfaces & COMM_SERVO) && comm_init_servo_spi && + !comm_init_servo_spi(device_name)) + return 0; + + /* Do not fallback to other communication methods if target is not a + * cros_ec device */ + if (!strcmp(CROS_EC_DEV_NAME, device_name)) { + /* Fallback to direct LPC on x86 */ + if ((interfaces & COMM_LPC) && !comm_init_lpc()) + return 0; + + /* Fallback to direct i2c on ARM */ + if ((interfaces & COMM_I2C) && !comm_init_i2c()) + return 0; + } + + /* Give up */ + fprintf(stderr, "Unable to establish host communication\n"); + return 1; +} + +int comm_init_buffer(void) { - struct ec_response_get_protocol_info info; int allow_large_buffer; + struct ec_response_get_protocol_info info; /* Default memmap access */ ec_readmem = fake_readmem; @@ -96,34 +119,6 @@ int comm_init(int interfaces, const char *device_name) return 1; } - /* Prefer new /dev method */ - if ((interfaces & COMM_DEV) && comm_init_dev && - !comm_init_dev(device_name)) - goto init_ok; - - if ((interfaces & COMM_SERVO) && comm_init_servo_spi && - !comm_init_servo_spi(device_name)) - goto init_ok; - - /* Do not fallback to other communication methods if target is not a - * cros_ec device */ - if (strcmp(CROS_EC_DEV_NAME, device_name)) - goto init_failed; - - /* Fallback to direct LPC on x86 */ - if ((interfaces & COMM_LPC) && comm_init_lpc && !comm_init_lpc()) - goto init_ok; - - /* Fallback to direct i2c on ARM */ - if ((interfaces & COMM_I2C) && comm_init_i2c && !comm_init_i2c()) - goto init_ok; - - init_failed: - /* Give up */ - fprintf(stderr, "Unable to establish host communication\n"); - return 1; - - init_ok: /* Allocate shared I/O buffers */ ec_outbuf = malloc(ec_max_outsize); ec_inbuf = malloc(ec_max_insize); @@ -154,5 +149,4 @@ int comm_init(int interfaces, const char *device_name) } return 0; - } -- cgit v1.2.1