/* Copyright 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "anx74xx.h" #include "battery.h" #include "comm-host.h" #include "chipset.h" #include "compile_time_macros.h" #include "cros_ec_dev.h" #include "ec_panicinfo.h" #include "ec_flash.h" #include "ec_version.h" #include "ectool.h" #include "i2c.h" #include "lightbar.h" #include "lock/gec_lock.h" #include "misc_util.h" #include "panic.h" #include "ps8xxx.h" #include "usb_pd.h" /* Maximum flash size (16 MB, conservative) */ #define MAX_FLASH_SIZE 0x1000000 /* * Calculate the expected response for a hello ec command. */ #define HELLO_RESP(in_data) ((in_data) + 0x01020304) /* Command line options */ enum { OPT_DEV = 1000, OPT_INTERFACE, OPT_NAME, OPT_ASCII, }; static struct option long_opts[] = { {"dev", 1, 0, OPT_DEV}, {"interface", 1, 0, OPT_INTERFACE}, {"name", 1, 0, OPT_NAME}, {"ascii", 0, 0, OPT_ASCII}, {NULL, 0, 0, 0} }; #define GEC_LOCK_TIMEOUT_SECS 30 /* 30 secs */ const char help_str[] = "Commands:\n" " adcread \n" " Read an ADC channel.\n" " addentropy [reset]\n" " Add entropy to device secret\n" " apreset\n" " Issue AP reset\n" " autofanctrl \n" " Turn on automatic fan speed control.\n" " backlight \n" " Enable/disable LCD backlight\n" " battery\n" " Prints battery info\n" " batterycutoff [at-shutdown]\n" " Cut off battery output power\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" " Prints chip info\n" " cmdversions \n" " 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 \n" " Clears EC host events flags where mask has bits set\n" " eventclearb \n" " Clears EC host events flags copy B where mask has bits set\n" " eventget\n" " 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 \n" " Sets the SCI mask for EC host events\n" " eventsetsmimask \n" " Sets the SMI mask for EC host events\n" " eventsetwakemask \n" " Sets the wake mask for EC host events\n" " extpwrlimit\n" " Set the maximum external power limit\n" " fanduty \n" " Forces the fan PWM to a constant duty cycle\n" " flasherase \n" " Erases EC flash\n" " flasheraseasync \n" " Erases EC flash asynchronously\n" " flashinfo\n" " Prints information on the EC flash\n" " flashspiinfo\n" " Prints information on EC SPI flash, if present\n" " flashpd \n" " Flash commands over PD\n" " flashprotect [now] [enable | disable]\n" " Prints or sets EC flash protection state\n" " flashread \n" " Reads from EC flash to a file\n" " flashwrite \n" " Writes to EC flash from a file\n" " forcelidopen \n" " Forces the lid switch to open position\n" " fpcontext\n" " Sets the fingerprint sensor context\n" " fpencstatus\n" " Prints status of Fingerprint sensor encryption engine\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" " fpseed\n" " Sets the value of the TPM seed.\n" " fpstats\n" " Prints timing statisitcs relating to capture and matching\n" " fptemplate [|]\n" " Add a template if is provided, else dump it\n" " gpioget \n" " Get the value of GPIO signal\n" " gpioset \n" " Set the value of GPIO signal\n" " hangdetect | stop | start\n" " Configure or start/stop the hang detect timer\n" " hello\n" " Checks for basic communication with EC\n" " hibdelay [sec]\n" " Set the delay before going into hibernation\n" " hostsleepstate\n" " Report host sleep state to the EC\n" " i2cprotect [status]\n" " Protect EC's I2C bus\n" " i2cread\n" " Read I2C bus\n" " i2cwrite\n" " Write I2C bus\n" " i2cxfer [write bytes...]\n" " Perform I2C transfer on EC's I2C bus\n" " infopddev \n" " Get info about USB type-C accessory attached to port\n" " inventory\n" " Return the list of supported features\n" " kbfactorytest\n" " Scan out keyboard if any pins are shorted\n" " kbid\n" " Get keyboard ID of supported keyboards\n" " kbinfo\n" " Dump keyboard matrix dimensions\n" " kbpress\n" " Simulate key press\n" " keyscan \n" " Test low-level key scanning\n" " led | =...>\n" " Set the color of an LED or query brightness range\n" " lightbar [CMDS]\n" " Various lightbar control commands\n" " mkbpwakemask [mask]\n" " Get or Set the MKBP event wake mask, or host event wake mask\n" " motionsense [CMDS]\n" " Various motion sense control commands\n" " panicinfo\n" " Prints saved panic info\n" " pause_in_s5 [on|off]\n" " 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 \n" " Get PD chip information\n" " pdlog\n" " Prints the PD event log entries\n" " pdwritelog \n" " Writes a PD event log of the given \n" " pdgetmode \n" " Get All USB-PD alternate SVIDs and modes on \n" " pdsetmode \n" " Set USB-PD alternate SVID and mode on \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 \n" " Reads from EC host persistent storage to a file\n" " pstorewrite \n" " Writes to EC host persistent storage from a file\n" " pwmgetfanrpm [ | 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 \n" " Set target fan RPM\n" " pwmsetkblight \n" " Set keyboard backlight in percent\n" " pwmsetduty\n" " Set 16 bit duty cycle of given PWM\n" " rand \n" " generate of random numbers\n" " readtest \n" " Reads a pattern from the EC via LPC\n" " reboot_ec " " [at-shutdown|switch-slot]\n" " Reboot EC to RO or RW\n" " rollbackinfo\n" " Print rollback block information\n" " rtcget\n" " Print real-time clock\n" " rtcgetalarm\n" " Print # of seconds before real-time clock alarm goes off.\n" " rtcset