src/util/ectool/: init
parent
c40ed36e6b
commit
30ac75903b
@ -0,0 +1,58 @@
|
|||||||
|
{ lib
|
||||||
|
, stdenv
|
||||||
|
, pkg-config
|
||||||
|
, fetchFromGitHub
|
||||||
|
, boardName ? "kevin"
|
||||||
|
}:
|
||||||
|
|
||||||
|
let makeTarget = "build/${boardName}/util/ectool";
|
||||||
|
|
||||||
|
in stdenv.mkDerivation {
|
||||||
|
pname = "ectool";
|
||||||
|
version = "1d2c13";
|
||||||
|
|
||||||
|
src = fetchFromGitHub {
|
||||||
|
owner = "coreboot";
|
||||||
|
repo = "chrome-ec";
|
||||||
|
rev = "1d2c13a1630a1a6222411e1c03186cb9b1f576e0";
|
||||||
|
hash = "sha256-xcZQeCEp0q3Wf5XYCY5EtnoIRziu7IA5AYv0ZyXShGk=";
|
||||||
|
};
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
patchShebangs .
|
||||||
|
'';
|
||||||
|
|
||||||
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
|
makeFlags = [
|
||||||
|
"BOARD=${boardName}"
|
||||||
|
|
||||||
|
# ectool's Makefile gets confused when nixpkgs sets $out
|
||||||
|
"out=build/${boardName}"
|
||||||
|
|
||||||
|
# ectool's terminology is crazy; they call the buildPlatform
|
||||||
|
# HOST and they call the hostPlatform BOARD:
|
||||||
|
"HOSTCC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
|
||||||
|
"HOSTCPP=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"
|
||||||
|
|
||||||
|
# they also use CROSS_COMPILE for the targetPrefix of the
|
||||||
|
# platform on which `ectool` runs:
|
||||||
|
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
|
||||||
|
|
||||||
|
# crusty old codebase, new compiler
|
||||||
|
"EXTRA_CFLAGS=-w -Wno-error -Wno-address-of-packed-member"
|
||||||
|
|
||||||
|
#"V=1"
|
||||||
|
|
||||||
|
makeTarget
|
||||||
|
];
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
mv ${makeTarget} $out/bin/
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Communicate with Chromebooks' Embedded Controller (EC)";
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,291 @@
|
|||||||
|
diff --git a/util/comm-dev.c b/util/comm-dev.c
|
||||||
|
index 33a69f9d6..92b76de45 100644
|
||||||
|
--- a/util/comm-dev.c
|
||||||
|
+++ b/util/comm-dev.c
|
||||||
|
@@ -65,10 +65,9 @@ static int ec_command_dev(int command, int version,
|
||||||
|
s_cmd.command = command;
|
||||||
|
s_cmd.version = version;
|
||||||
|
s_cmd.result = 0xff;
|
||||||
|
+ memcpy(s_cmd.outdata, outdata, outsize);
|
||||||
|
s_cmd.outsize = outsize;
|
||||||
|
- s_cmd.outdata = (uint8_t *)outdata;
|
||||||
|
s_cmd.insize = insize;
|
||||||
|
- s_cmd.indata = indata;
|
||||||
|
|
||||||
|
r = ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd);
|
||||||
|
if (r < 0) {
|
||||||
|
@@ -89,6 +88,7 @@ static int ec_command_dev(int command, int version,
|
||||||
|
return -EECRESULT - s_cmd.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ memcpy(indata, s_cmd.indata, insize);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -102,8 +102,8 @@ static int ec_readmem_dev(int offset, int bytes, void *dest)
|
||||||
|
if (!fake_it) {
|
||||||
|
s_mem.offset = offset;
|
||||||
|
s_mem.bytes = bytes;
|
||||||
|
- s_mem.buffer = dest;
|
||||||
|
r = ioctl(fd, CROS_EC_DEV_IOCRDMEM, &s_mem);
|
||||||
|
+ memcpy(dest, s_mem.buffer, bytes);
|
||||||
|
if (r < 0 && errno == ENOTTY)
|
||||||
|
fake_it = 1;
|
||||||
|
else
|
||||||
|
@@ -199,25 +199,28 @@ static int ec_readmem_dev_v2(int offset, int bytes, void *dest)
|
||||||
|
*/
|
||||||
|
static int ec_dev_is_v2(void)
|
||||||
|
{
|
||||||
|
+ /*
|
||||||
|
struct ec_params_hello h_req = {
|
||||||
|
.in_data = 0xa0b0c0d0
|
||||||
|
};
|
||||||
|
struct ec_response_hello h_resp;
|
||||||
|
- struct cros_ec_command s_cmd = { };
|
||||||
|
+ struct cros_ec_command s_cmd = {
|
||||||
|
+ //.indata = 0xa0b0c0d0
|
||||||
|
+ };
|
||||||
|
int r;
|
||||||
|
|
||||||
|
s_cmd.command = EC_CMD_HELLO;
|
||||||
|
s_cmd.result = 0xff;
|
||||||
|
s_cmd.outsize = sizeof(h_req);
|
||||||
|
- s_cmd.outdata = (uint8_t *)&h_req;
|
||||||
|
s_cmd.insize = sizeof(h_resp);
|
||||||
|
- s_cmd.indata = (uint8_t *)&h_resp;
|
||||||
|
|
||||||
|
r = ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd);
|
||||||
|
if (r < 0 && errno == ENOTTY)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
+ */
|
||||||
|
+ return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ec_pollevent_dev(unsigned long mask, void *buffer, size_t buf_size,
|
||||||
|
diff --git a/util/cros_ec_dev.h b/util/cros_ec_dev.h
|
||||||
|
index 7ff87aed9..c5dce4159 100644
|
||||||
|
--- a/util/cros_ec_dev.h
|
||||||
|
+++ b/util/cros_ec_dev.h
|
||||||
|
@@ -13,24 +13,26 @@
|
||||||
|
#define CROS_EC_DEV_NAME "cros_ec"
|
||||||
|
#define CROS_EC_DEV_VERSION "1.0.0"
|
||||||
|
|
||||||
|
+#define CROS_EC_PROTO2_MAX_PARAM_SIZE 252
|
||||||
|
+#define CROS_EC_MEMMAP_SIZE 255
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* @version: Command version number (often 0)
|
||||||
|
* @command: Command to send (EC_CMD_...)
|
||||||
|
- * @outdata: Outgoing data to EC
|
||||||
|
* @outsize: Outgoing length in bytes
|
||||||
|
- * @indata: Where to put the incoming data from EC
|
||||||
|
- * @insize: On call, how much we can accept. On return, how much we got.
|
||||||
|
+ * @insize: Max number of bytes to accept from EC
|
||||||
|
* @result: EC's response to the command (separate from communication failure)
|
||||||
|
- * ioctl returns zero on success, negative on error
|
||||||
|
+ * @outdata: Outgoing data to EC
|
||||||
|
+ * @indata: Where to put the incoming data from EC
|
||||||
|
*/
|
||||||
|
struct cros_ec_command {
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t command;
|
||||||
|
- uint8_t *outdata;
|
||||||
|
uint32_t outsize;
|
||||||
|
- uint8_t *indata;
|
||||||
|
uint32_t insize;
|
||||||
|
uint32_t result;
|
||||||
|
+ uint8_t outdata[CROS_EC_PROTO2_MAX_PARAM_SIZE];
|
||||||
|
+ uint8_t indata[CROS_EC_PROTO2_MAX_PARAM_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@@ -43,12 +45,12 @@ struct cros_ec_command {
|
||||||
|
struct cros_ec_readmem {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t bytes;
|
||||||
|
- char *buffer;
|
||||||
|
+ uint8_t buffer[CROS_EC_MEMMAP_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
-#define CROS_EC_DEV_IOC ':'
|
||||||
|
-#define CROS_EC_DEV_IOCXCMD _IOWR(':', 0, struct cros_ec_command)
|
||||||
|
-#define CROS_EC_DEV_IOCRDMEM _IOWR(':', 1, struct cros_ec_readmem)
|
||||||
|
+#define CROS_EC_DEV_IOC 0xEC
|
||||||
|
+#define CROS_EC_DEV_IOCXCMD _IOWR(CROS_EC_DEV_IOC, 0, struct cros_ec_command)
|
||||||
|
+#define CROS_EC_DEV_IOCRDMEM _IOWR(CROS_EC_DEV_IOC, 1, struct cros_ec_readmem)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @version: Command version number (often 0)
|
||||||
|
diff --git a/util/ecst.c b/util/ecst.c
|
||||||
|
old mode 100755
|
||||||
|
new mode 100644
|
||||||
|
diff --git a/util/ecst.h b/util/ecst.h
|
||||||
|
old mode 100755
|
||||||
|
new mode 100644
|
||||||
|
diff --git a/util/ectool.c b/util/ectool.c
|
||||||
|
index 4285e7ce6..4ac9b8c1c 100644
|
||||||
|
--- a/util/ectool.c
|
||||||
|
+++ b/util/ectool.c
|
||||||
|
@@ -48,26 +48,18 @@ static struct option long_opts[] = {
|
||||||
|
|
||||||
|
const char help_str[] =
|
||||||
|
"Commands:\n"
|
||||||
|
- " autofanctrl <on>\n"
|
||||||
|
- " Turn on automatic fan speed control.\n"
|
||||||
|
- " backlight <enabled>\n"
|
||||||
|
- " Enable/disable LCD backlight\n"
|
||||||
|
" battery\n"
|
||||||
|
" Prints battery info\n"
|
||||||
|
- " batterycutoff [at-shutdown]\n"
|
||||||
|
+ " WARNING! batterycutoff [at-shutdown]\n"
|
||||||
|
" Cut off battery output power\n"
|
||||||
|
- " batteryparam\n"
|
||||||
|
+ " ? batteryparam\n"
|
||||||
|
" Read or write board-specific battery parameter\n"
|
||||||
|
" boardversion\n"
|
||||||
|
" Prints the board version\n"
|
||||||
|
- " cbi\n"
|
||||||
|
- " Get/Set Cros Board Info\n"
|
||||||
|
" chargecurrentlimit\n"
|
||||||
|
" Set the maximum battery charging current\n"
|
||||||
|
" chargecontrol\n"
|
||||||
|
" Force the battery to stop charging or discharge\n"
|
||||||
|
- " chargeoverride\n"
|
||||||
|
- " Overrides charge port selection logic\n"
|
||||||
|
" chargestate\n"
|
||||||
|
" Handle commands related to charge state v2 (and later)\n"
|
||||||
|
" chipinfo\n"
|
||||||
|
@@ -76,8 +68,6 @@ const char help_str[] =
|
||||||
|
" Prints supported version mask for a command number\n"
|
||||||
|
" console\n"
|
||||||
|
" Prints the last output to the EC debug console\n"
|
||||||
|
- " cec\n"
|
||||||
|
- " Read or write CEC messages and settings\n"
|
||||||
|
" echash [CMDS]\n"
|
||||||
|
" Various EC hash commands\n"
|
||||||
|
" eventclear <mask>\n"
|
||||||
|
@@ -88,10 +78,6 @@ const char help_str[] =
|
||||||
|
" Prints raw EC host event flags\n"
|
||||||
|
" eventgetb\n"
|
||||||
|
" Prints raw EC host event flags copy B\n"
|
||||||
|
- " eventgetscimask\n"
|
||||||
|
- " Prints SCI mask for EC host events\n"
|
||||||
|
- " eventgetsmimask\n"
|
||||||
|
- " Prints SMI mask for EC host events\n"
|
||||||
|
" eventgetwakemask\n"
|
||||||
|
" Prints wake mask for EC host events\n"
|
||||||
|
" eventsetscimask <mask>\n"
|
||||||
|
@@ -102,14 +88,10 @@ const char help_str[] =
|
||||||
|
" Sets the wake mask for EC host events\n"
|
||||||
|
" extpwrlimit\n"
|
||||||
|
" Set the maximum external power limit\n"
|
||||||
|
- " fanduty <percent>\n"
|
||||||
|
- " Forces the fan PWM to a constant duty cycle\n"
|
||||||
|
" flasherase <offset> <size>\n"
|
||||||
|
" Erases EC flash\n"
|
||||||
|
" flashinfo\n"
|
||||||
|
" Prints information on the EC flash\n"
|
||||||
|
- " flashspiinfo\n"
|
||||||
|
- " Prints information on EC SPI flash, if present\n"
|
||||||
|
" flashpd <dev_id> <port> <filename>\n"
|
||||||
|
" Flash commands over PD\n"
|
||||||
|
" flashprotect [now] [enable | disable]\n"
|
||||||
|
@@ -118,16 +100,6 @@ const char help_str[] =
|
||||||
|
" Reads from EC flash to a file\n"
|
||||||
|
" flashwrite <offset> <infile>\n"
|
||||||
|
" Writes to EC flash from a file\n"
|
||||||
|
- " fpcheckpixels\n"
|
||||||
|
- " Count the number of dead pixels on the sensor\n"
|
||||||
|
- " fpframe\n"
|
||||||
|
- " Retrieve the finger image as a PGM image\n"
|
||||||
|
- " fpinfo\n"
|
||||||
|
- " Prints information about the Fingerprint sensor\n"
|
||||||
|
- " fpmode [capture|deepsleep|fingerdown|fingerup]\n"
|
||||||
|
- " Configure/Read the fingerprint sensor current mode\n"
|
||||||
|
- " fptemplate [<infile>|<index 0..2>]\n"
|
||||||
|
- " Add a template if <infile> is provided, else dump it\n"
|
||||||
|
" forcelidopen <enable>\n"
|
||||||
|
" Forces the lid switch to open position\n"
|
||||||
|
" gpioget <GPIO name>\n"
|
||||||
|
@@ -164,8 +136,6 @@ const char help_str[] =
|
||||||
|
" Test low-level key scanning\n"
|
||||||
|
" led <name> <query | auto | off | <color> | <color>=<value>...>\n"
|
||||||
|
" Set the color of an LED or query brightness range\n"
|
||||||
|
- " lightbar [CMDS]\n"
|
||||||
|
- " Various lightbar control commands\n"
|
||||||
|
" motionsense [CMDS]\n"
|
||||||
|
" Various motion sense control commands\n"
|
||||||
|
" panicinfo\n"
|
||||||
|
@@ -174,8 +144,6 @@ const char help_str[] =
|
||||||
|
" Whether or not the AP should pause in S5 on shutdown\n"
|
||||||
|
" pdcontrol [suspend|resume|reset|disable|on]\n"
|
||||||
|
" Controls the PD chip\n"
|
||||||
|
- " pdchipinfo <port>\n"
|
||||||
|
- " Get PD chip information\n"
|
||||||
|
" pdlog\n"
|
||||||
|
" Prints the PD event log entries\n"
|
||||||
|
" pdwritelog <type> <port>\n"
|
||||||
|
@@ -184,34 +152,10 @@ const char help_str[] =
|
||||||
|
" Get All USB-PD alternate SVIDs and modes on <port>\n"
|
||||||
|
" pdsetmode <port> <svid> <opos>\n"
|
||||||
|
" Set USB-PD alternate SVID and mode on <port>\n"
|
||||||
|
- " port80flood\n"
|
||||||
|
- " Rapidly write bytes to port 80\n"
|
||||||
|
- " port80read\n"
|
||||||
|
- " Print history of port 80 write\n"
|
||||||
|
" powerinfo\n"
|
||||||
|
" Prints power-related information\n"
|
||||||
|
" protoinfo\n"
|
||||||
|
" Prints EC host protocol information\n"
|
||||||
|
- " pstoreinfo\n"
|
||||||
|
- " Prints information on the EC host persistent storage\n"
|
||||||
|
- " pstoreread <offset> <size> <outfile>\n"
|
||||||
|
- " Reads from EC host persistent storage to a file\n"
|
||||||
|
- " pstorewrite <offset> <infile>\n"
|
||||||
|
- " Writes to EC host persistent storage from a file\n"
|
||||||
|
- " pwmgetfanrpm [<index> | all]\n"
|
||||||
|
- " Prints current fan RPM\n"
|
||||||
|
- " pwmgetkblight\n"
|
||||||
|
- " Prints current keyboard backlight percent\n"
|
||||||
|
- " pwmgetnumfans\n"
|
||||||
|
- " Prints the number of fans present\n"
|
||||||
|
- " pwmgetduty\n"
|
||||||
|
- " Prints the current 16 bit duty cycle for given PWM\n"
|
||||||
|
- " pwmsetfanrpm <targetrpm>\n"
|
||||||
|
- " Set target fan RPM\n"
|
||||||
|
- " pwmsetkblight <percent>\n"
|
||||||
|
- " Set keyboard backlight in percent\n"
|
||||||
|
- " pwmsetduty\n"
|
||||||
|
- " Set 16 bit duty cycle of given PWM\n"
|
||||||
|
" readtest <patternoffset> <size>\n"
|
||||||
|
" Reads a pattern from the EC via LPC\n"
|
||||||
|
" reboot_ec <RO|RW|cold|hibernate|hibernate-clear-ap-off|disable-jump>"
|
||||||
|
@@ -231,26 +175,12 @@ const char help_str[] =
|
||||||
|
" Control the behavior of RWSIG task.\n"
|
||||||
|
" rwsigstatus\n"
|
||||||
|
" Run RW signature verification and get status.\n"
|
||||||
|
- " sertest\n"
|
||||||
|
- " Serial output test for COM2\n"
|
||||||
|
" switches\n"
|
||||||
|
" Prints current EC switch positions\n"
|
||||||
|
- " temps <sensorid>\n"
|
||||||
|
- " Print temperature.\n"
|
||||||
|
- " tempsinfo <sensorid>\n"
|
||||||
|
- " Print temperature sensor info.\n"
|
||||||
|
" thermalget <platform-specific args>\n"
|
||||||
|
" Get the threshold temperature values from the thermal engine.\n"
|
||||||
|
" thermalset <platform-specific args>\n"
|
||||||
|
" Set the threshold temperature values for the thermal engine.\n"
|
||||||
|
- " tpselftest\n"
|
||||||
|
- " Run touchpad self test.\n"
|
||||||
|
- " tpframeget\n"
|
||||||
|
- " Get touchpad frame data.\n"
|
||||||
|
- " tmp006cal <tmp006_index> [params...]\n"
|
||||||
|
- " Get/set TMP006 calibration\n"
|
||||||
|
- " tmp006raw <tmp006_index>\n"
|
||||||
|
- " Get raw TMP006 data\n"
|
||||||
|
" usbchargemode <port> <mode>\n"
|
||||||
|
" Set USB charging mode\n"
|
||||||
|
" usbmux <mux>\n"
|
Loading…
Reference in New Issue