ectool: add new parameter to identify proper EC.

Add parameter name to identify which EC to talk to.
Superseed --dev parameter, removed soon.

--name cros_ec (the default): send commands to /dev/cros_ec.
--name cros_pd: send commands to /dev/cros_pd.
...

BUG=chrome-os-partner:31513
TEST=Tested on samus:
check ectool --name cros_pd version returns proper data:
ectool --name=cros_pd version
RO version:    samus_pd_v1.1.2079-8e4f9fc-dirt
....

CQ-DEPEND=CL:217297
BRANCH=ToT

Change-Id: Ie8b5c6c184d73a89b4445e88d6f104169176b9f3
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217311
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Gwendal Grignou
2014-09-09 12:00:49 -07:00
committed by chrome-internal-fetch
parent 9452186389
commit fab7ac3b9a
6 changed files with 21 additions and 12 deletions

View File

@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
{
extern uint8_t data[] asm("_payload_start");
if (comm_init(COMM_ALL) < 0)
if (comm_init(COMM_ALL, NULL) < 0)
return -3;
flash_partition(EC_IMAGE_RW, data + CONFIG_FW_RW_OFF,

View File

@@ -78,13 +78,15 @@ static int ec_readmem_dev(int offset, int bytes, void *dest)
dest, bytes);
}
int comm_init_dev(void)
int comm_init_dev(const char *device_name)
{
char version[80];
char device[80] = "/dev/";
int r;
char *s;
fd = open("/dev/" CROS_EC_DEV_NAME, O_RDWR);
strncat(device, (device_name ? device_name : CROS_EC_DEV_NAME), 40);
fd = open(device, O_RDWR);
if (fd < 0)
return 1;

View File

@@ -23,7 +23,7 @@ void *ec_outbuf;
void *ec_inbuf;
static int command_offset;
int comm_init_dev(void) __attribute__((weak));
int comm_init_dev(const char *device_name) __attribute__((weak));
int comm_init_lpc(void) __attribute__((weak));
int comm_init_i2c(void) __attribute__((weak));
@@ -75,7 +75,7 @@ int ec_command(int command, int version,
indata, insize);
}
int comm_init(int interfaces)
int comm_init(int interfaces, const char *device_name)
{
struct ec_response_get_protocol_info info;
@@ -83,7 +83,8 @@ int comm_init(int interfaces)
ec_readmem = fake_readmem;
/* Prefer new /dev method */
if ((interfaces & COMM_DEV) && comm_init_dev && !comm_init_dev())
if ((interfaces & COMM_DEV) && comm_init_dev &&
!comm_init_dev(device_name))
goto init_ok;
/* Fallback to direct LPC on x86 */

View File

@@ -37,9 +37,10 @@ enum comm_interface {
* Perform initializations needed for subsequent requests
*
* @param interfaces Interfaces to try; use COMM_ALL to try all of them.
* @param device_name For DEV option, the device file to use.
* @return 0 in case of success, or error code.
*/
int comm_init(int interfaces);
int comm_init(int interfaces, const char *device_name);
/**
* Send a command to the EC. Returns the length of output data returned (0 if

View File

@@ -635,7 +635,7 @@ int main(int argc, char *argv[])
exit(1);
}
if (comm_init(interfaces)) {
if (comm_init(interfaces, NULL)) {
fprintf(stderr, "Couldn't find EC\n");
goto out;
}

View File

@@ -29,11 +29,13 @@
enum {
OPT_DEV = 1000,
OPT_INTERFACE,
OPT_NAME,
};
static struct option long_opts[] = {
{"dev", 1, 0, OPT_DEV},
{"interface", 1, 0, OPT_INTERFACE},
{"name", 1, 0, OPT_NAME},
{NULL, 0, 0, 0}
};
@@ -228,9 +230,8 @@ int parse_bool(const char *s, int *dest)
void print_help(const char *prog, int print_cmds)
{
printf("Usage: %s [--dev=n] [--interface=dev|lpc|i2c] <command> "
"[params]\n\n",
prog);
printf("Usage: %s [--dev=n] [--interface=dev|lpc|i2c] ", prog);
printf("[--name=cros_ec|cros_sh|cros_pd] <command> [params]\n\n");
if (print_cmds)
puts(help_str);
else
@@ -4839,6 +4840,7 @@ int main(int argc, char *argv[])
const struct command *cmd;
int dev = 0;
int interfaces = COMM_ALL;
char device_name[40] = "cros_ec";
int rv = 1;
int parse_error = 0;
char *e;
@@ -4873,6 +4875,9 @@ int main(int argc, char *argv[])
parse_error = 1;
}
break;
case OPT_NAME:
strncpy(device_name, optarg, 40);
break;
}
}
@@ -4904,7 +4909,7 @@ int main(int argc, char *argv[])
exit(1);
}
if (comm_init(interfaces)) {
if (comm_init(interfaces, device_name)) {
fprintf(stderr, "Couldn't find EC\n");
goto out;
}